Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Remove hardcoded stuff

Joshen Lim465d1c752e0c
diff --git a/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/InputField.tsx b/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/InputField.tsx
index f72b4eec940..ce96a02b2f0 100644
--- a/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/InputField.tsx
+++ b/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/InputField.tsx
@@ -25,44 +25,38 @@ const InputField: FC<Props> = ({
onEditJson = () => {},
onViewForeignKey = () => {},
}) => {
- // Hardcode for now
- if (field.name === 'test') {
- const formattedValue = convertPgArrayToJsArray(field.value)
- const options = [
- { id: uuidv4(), value: 'VALUE_0', name: 'VALUE_0', disabled: false },
- { id: uuidv4(), value: 'VALUE_1', name: 'VALUE_1', disabled: false },
- { id: uuidv4(), value: 'VALUE_2', name: 'VALUE_2', disabled: false },
- ]
- return (
- <div className="grid gap-x-2 md:grid-cols-12 md:gap-x-4">
- <div className="col-span-4">
- <label className="block text-scale-1100 text-sm break-all">{field.name}</label>
- <span className="text-scale-900 text-sm" id="-optional">
- {field.format}
- </span>
- </div>
- <div className="col-span-8">
- <MultiSelect
- allowDuplicateSelection
- options={options}
- value={formattedValue}
- searchPlaceholder="Search for a value"
- placeholder="NULL"
- onChange={(values) => {
- const formattedValues = convertJsArraytoPgArray(values)
- onUpdateField({ [field.name]: formattedValues })
- }}
- />
- </div>
- </div>
- )
- }
-
if (field.enums.length > 0) {
const isArray = field.format[0] === '_'
if (isArray) {
- console.log('Render')
+ const formattedValue = convertPgArrayToJsArray(field.value)
+ const options = field.enums.map((value: string) => {
+ return { id: uuidv4(), value, name: value, disabled: false }
+ })
+ return (
+ <div className="grid gap-x-2 md:grid-cols-12 md:gap-x-4">
+ <div className="col-span-4">
+ <label className="block text-scale-1100 text-sm break-all">{field.name}</label>
+ <span className="text-scale-900 text-sm" id="-optional">
+ {field.format}
+ </span>
+ </div>
+ <div className="col-span-8">
+ <MultiSelect
+ allowDuplicateSelection
+ options={options}
+ value={formattedValue}
+ searchPlaceholder="Search for a value"
+ placeholder="NULL"
+ error={errors[field.name]}
+ onChange={(values) => {
+ const formattedValues = convertJsArraytoPgArray(values)
+ onUpdateField({ [field.name]: formattedValues })
+ }}
+ />
+ </div>
+ </div>
+ )
} else {
return (
<Select
diff --git a/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/RowEditor.utils.ts b/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/RowEditor.utils.ts
index e6863a4269e..cd8cb9f3bce 100644
--- a/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/RowEditor.utils.ts
+++ b/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/RowEditor.utils.ts
@@ -60,18 +60,11 @@ export const generateRowFields = (
export const validateFields = (fields: RowField[]) => {
const errors = {} as any
fields.forEach((field) => {
- if (field.format.startsWith('_') && field.value?.length > 0) {
- try {
- minifyJSON(field.value)
- } catch {
- errors[field.name] = 'Invalid array'
- }
- }
if (field.format.includes('json') && field.value?.length > 0) {
try {
minifyJSON(field.value)
} catch {
- errors[field.name] = 'Invalid JSON'
+ errors[field.name] = 'Value is an invalid JSON'
}
}
if (field.isIdentity || field.defaultValue) return
@@ -270,13 +263,11 @@ export const generateRowObjectFromFields = (
const rowObject = {} as any
fields.forEach((field) => {
const value = (field?.value ?? '').length === 0 ? null : field.value
- if (field.format.includes('json') || (field.format.startsWith('_') && value)) {
+ if (field.format.includes('json')) {
if (typeof field.value === 'object') {
rowObject[field.name] = value
- } else {
- if (isString(value)) {
- rowObject[field.name] = tryParseJson(value)
- }
+ } else if (isString(value)) {
+ rowObject[field.name] = tryParseJson(value)
}
} else if (field.format === 'bool' && value) {
rowObject[field.name] = value === 'true'
diff --git a/studio/components/ui/MultiSelect/index.tsx b/studio/components/ui/MultiSelect/index.tsx
index 871eac8b8c1..5ab7659d276 100644
--- a/studio/components/ui/MultiSelect/index.tsx
+++ b/studio/components/ui/MultiSelect/index.tsx
@@ -15,6 +15,7 @@ interface Props {
value: string[]
options: MultiSelectOption[]
label?: string
+ error?: string
placeholder?: string | ReactNode
searchPlaceholder?: string
descriptionText?: string | ReactNode
@@ -33,6 +34,7 @@ export default function MultiSelect({
options,
value,
label,
+ error,
descriptionText,
placeholder,
searchPlaceholder = 'Search for option',
@@ -116,6 +118,7 @@ export default function MultiSelect({
'form-control form-control--multi-select',
'bg-scaleA-200 border-scale-700 border',
'multi-select relative block w-full w-full space-x-1 overflow-auto rounded',
+ `${error !== undefined ? 'border-red-800 bg-red-100' : ''}`,
].join(' ')}
ref={ref}
>
@@ -254,6 +257,7 @@ export default function MultiSelect({
{descriptionText && (
<span className="form-text text-muted text-sm mt-2">{descriptionText}</span>
)}
+ {error && <span className="text-red-900 text-sm mt-2">{error}</span>}
</div>
)
}
diff --git a/studio/lib/helpers.ts b/studio/lib/helpers.ts
index 1883401f9b8..1a4ad535f67 100644
--- a/studio/lib/helpers.ts
+++ b/studio/lib/helpers.ts
@@ -216,6 +216,8 @@ export const detectBrowser = () => {
}
export const convertPgArrayToJsArray = (value: string): string[] => {
+ if (!value) return []
+
const valueArray = value
.slice(1, value.length - 1)
.split(',')