Skip to content

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

Improvements to WrapperTableEditor

Joshen Limc455ebad0e3c
diff --git a/studio/components/interfaces/Database/Wrappers/WrapperTableEditor.tsx b/studio/components/interfaces/Database/Wrappers/WrapperTableEditor.tsx
index 0f8a4db53ee..22e86236c77 100644
--- a/studio/components/interfaces/Database/Wrappers/WrapperTableEditor.tsx
+++ b/studio/components/interfaces/Database/Wrappers/WrapperTableEditor.tsx
@@ -1,6 +1,7 @@
import ActionBar from 'components/interfaces/TableGridEditor/SidePanelEditor/ActionBar'
+import MultiSelect from 'components/ui/MultiSelect'
import { useEffect, useState } from 'react'
-import { Accordion, Checkbox, Form, Input, Listbox, SidePanel } from 'ui'
+import { Form, Input, Listbox, SidePanel } from 'ui'
import { Table, TableOption } from './types'
import { makeValidateRequired } from './utils'
@@ -72,8 +73,16 @@ const WrapperTableEditor = ({
{tables.map((table, i) => {
return (
- <Listbox.Option key={String(i)} value={String(i)} label={table.label}>
- <div className="flex items-center gap-2">{table.label}</div>
+ <Listbox.Option
+ className="group"
+ key={String(i)}
+ value={String(i)}
+ label={table.label}
+ >
+ <div className="space-y-1">
+ <p>{table.label}</p>
+ <p className="opacity-50">{table.description}</p>
+ </div>
</Listbox.Option>
)
})}
@@ -122,7 +131,7 @@ const TableForm = ({
const initialValues = initialData ?? {
table_name: '',
- columns: [],
+ columns: table.availableColumns.map((column) => column.name),
...Object.fromEntries(table.options.map((option) => [option.name, option.defaultValue ?? ''])),
}
@@ -140,62 +149,46 @@ const TableForm = ({
onSubmit={onSubmit}
enableReinitialize={true}
>
- {({ errors, touched, values }: any) => (
- <div className="space-y-4">
- <Input
- id="table_name"
- name="table_name"
- label="Table name"
- descriptionText="The name of the local table table you will query after the wrapper is enabled."
- />
-
- {requiredOptions.map((option) => (
- <Option key={option.name} option={option} />
- ))}
-
- <div className="space-y-2">
- <label className="block text-sm break-all text-scale-1100">Columns</label>
-
- <div>
- {table.availableColumns.map((column, k) => (
- <Checkbox
- key={k}
- id={column.name}
- name="columns"
- value={column.name}
- checked={values.columns.includes(column.name)}
- label={`${column.name} (${column.type})`}
- />
- ))}
- </div>
-
- {touched.columns && errors.columns && (
- <p className="text-sm text-red-900 transition-all data-show:mt-2 data-show:animate-slide-down-normal data-hide:animate-slide-up-normal">
- {errors.columns}
- </p>
- )}
+ {({ errors, values, resetForm }: any) => {
+ return (
+ <div className="space-y-4">
+ <Input
+ id="table_name"
+ name="table_name"
+ label="Table name"
+ descriptionText="You can query from this table after the wrapper is enabled."
+ />
+
+ {requiredOptions.map((option) => (
+ <Option key={option.name} option={option} />
+ ))}
+
+ <MultiSelect
+ label="Columns"
+ options={table.availableColumns.map((column) => {
+ return {
+ id: column.name,
+ value: column.name,
+ name: column.name,
+ description: column.type,
+ disabled: false,
+ }
+ })}
+ error={errors.columns}
+ value={values.columns}
+ placeholder="Select at least one column"
+ searchPlaceholder="Search for a column"
+ onChange={(columns) => {
+ resetForm({ values: { ...values, columns } })
+ }}
+ />
+
+ {optionalOptions.map((option) => (
+ <Option key={option.name} option={option} />
+ ))}
</div>
-
- {optionalOptions.length > 0 && (
- <Accordion
- className="text-sm"
- justified={false}
- openBehaviour="multiple"
- type="default"
- chevronAlign="left"
- size="small"
- bordered={false}
- iconPosition="left"
- >
- <Accordion.Item id="1" header="Optional Fields">
- {optionalOptions.map((option) => (
- <Option key={option.name} option={option} />
- ))}
- </Accordion.Item>
- </Accordion>
- )}
- </div>
- )}
+ )
+ }}
</Form>
)
}
diff --git a/studio/components/interfaces/Database/Wrappers/data.ts b/studio/components/interfaces/Database/Wrappers/data.ts
index 05f7a29374f..e5446326ccf 100644
--- a/studio/components/interfaces/Database/Wrappers/data.ts
+++ b/studio/components/interfaces/Database/Wrappers/data.ts
@@ -78,6 +78,7 @@ export const wrappers: Wrapper[] = [
tables: [
{
label: 'Users',
+ description: 'Shows your Firebase users',
availableColumns: [
{
name: 'local_id',
@@ -110,6 +111,7 @@ export const wrappers: Wrapper[] = [
},
{
label: 'Firestore Collection',
+ description: 'Map to a Firestore collection',
availableColumns: [
{
name: 'name',
diff --git a/studio/components/interfaces/Database/Wrappers/utils.ts b/studio/components/interfaces/Database/Wrappers/utils.ts
index 6bf0b68c509..19b48c207f1 100644
--- a/studio/components/interfaces/Database/Wrappers/utils.ts
+++ b/studio/components/interfaces/Database/Wrappers/utils.ts
@@ -10,7 +10,11 @@ export const makeValidateRequired =
([key, value]) =>
requiredOptionsSet.has(key) && (Array.isArray(value) ? value.length < 1 : !value)
)
- .map(([key]) => [key, 'Required'])
+ .map(([key]) => {
+ if (key === 'table_name') return [key, 'Please provide a name for your table']
+ else if (key === 'columns') return [key, 'Please select at least one column']
+ else return [key, 'This field is required']
+ })
)
return errors
diff --git a/studio/components/ui/MultiSelect/index.tsx b/studio/components/ui/MultiSelect/index.tsx
index 18a49705e77..a0b91cf0f99 100644
--- a/studio/components/ui/MultiSelect/index.tsx
+++ b/studio/components/ui/MultiSelect/index.tsx
@@ -8,6 +8,7 @@ export interface MultiSelectOption {
id: string | number
value: string
name: string
+ description?: string
disabled: boolean
}
@@ -166,7 +167,12 @@ export default function MultiSelect({
`${active ? ' dark:bg-green-600 dark:bg-opacity-25' : ''}`,
].join(' ')}
>
- <span>{option.name}</span>
+ <div className="flex items-center space-x-2">
+ <p>{option.name}</p>
+ {option.description !== undefined && (
+ <p className="opacity-50">{option.description}</p>
+ )}
+ </div>
{active && (
<IconCheck
size={16}