The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Midway implementing MultiSelectEditor
Joshen Lim0df9a7a39dd1
diff --git a/studio/components/grid/components/editor/MultiSelectEditor.tsx b/studio/components/grid/components/editor/MultiSelectEditor.tsxnew file mode 100644index 00000000000..c8f316acd30--- /dev/null+++ b/studio/components/grid/components/editor/MultiSelectEditor.tsx@@ -0,0 +1,76 @@+import { Listbox } from '@supabase/ui'+import { EditorProps } from '@supabase/react-data-grid'++import { useTrackedState } from 'components/grid/store'+import MultiSelect from 'components/ui/MultiSelect'++interface MultiSelectEditorProps<TRow, TSummaryRow = unknown>+ extends EditorProps<TRow, TSummaryRow> {+ options?: { label: string; value: string }[]+}++// Mainly for arrays (specifically enums)+// Array elements are not unique, so this supports selecting an option more than once+export function MultiSelectEditor<TRow, TSummaryRow = unknown>({+ row,+ column,+ onRowChange,+ onClose,+}: MultiSelectEditorProps<TRow, TSummaryRow>) {+ const state = useTrackedState()+ const gridColumn = state.gridColumns.find((x) => x.name == column.key)++ // Hardcoded options for now+ const options = [+ { label: 'Apple', value: 'apple' },+ { label: 'Orange', value: 'orange' },+ ]++ const value = row[column.key as keyof TRow] as unknown as string+ console.log('value', value)++ function onChange(value: string) {+ if (!value || value == '') {+ onRowChange({ ...row, [column.key]: null }, true)+ } else {+ onRowChange({ ...row, [column.key]: value }, true)+ }+ }++ function onBlur() {+ onClose(false)+ }++ // return (+ // <MultiSelect+ // options={options}+ // value={selectedRoles}+ // placeholder="Defaults to all roles if none selected"+ // searchPlaceholder="Search for a role"+ // onChange={onUpdateSelectedRoles}+ // />+ // )++ return (+ <Listbox+ autoFocus+ id="select-editor"+ name="select-editor"+ size="small"+ defaultValue={value ?? ''}+ className="sb-grid-select-editor !gap-2"+ style={{ width: `${gridColumn?.width || column.width}px` }}+ onChange={onChange}+ onBlur={onBlur}+ >+ <Listbox.Option id="NULL" label="NULL" value="">+ NULL+ </Listbox.Option>+ {options.map(({ label, value }) => (+ <Listbox.Option key={value} label={label} value={value}>+ {label}+ </Listbox.Option>+ ))}+ </Listbox>+ )+}diff --git a/studio/components/grid/components/editor/index.ts b/studio/components/grid/components/editor/index.tsindex af37e035773..d11ccfedb78 100644--- a/studio/components/grid/components/editor/index.ts+++ b/studio/components/grid/components/editor/index.ts@@ -5,5 +5,6 @@ export * from './JsonEditor'export * from './NullableBooleanEditor'export * from './NumberEditor'export * from './SelectEditor'+export * from './MultiSelectEditor'export * from './TextEditor'export * from './TimeEditor'diff --git a/studio/components/grid/utils/gridColumns.tsx b/studio/components/grid/utils/gridColumns.tsxindex 0d815aaab1c..33ed4bda265 100644--- a/studio/components/grid/utils/gridColumns.tsx+++ b/studio/components/grid/utils/gridColumns.tsx@@ -19,6 +19,7 @@ import {DateTimeEditor,DateTimeWithTimezoneEditor,JsonEditor,+ MultiSelectEditor,NullableBooleanEditor,NumberEditor,SelectEditor,@@ -91,8 +92,6 @@ function getColumnEditor(columnDefinition: SupaColumn, columnType: ColumnType) {return}- console.log('getColumnEditor', columnType, columnDefinition)-switch (columnType) {case 'boolean': {return columnDefinition.isNullable ? NullableBooleanEditor : BooleanEditor@@ -110,13 +109,11 @@ function getColumnEditor(columnDefinition: SupaColumn, columnType: ColumnType) {const options = columnDefinition.enum!.map((x) => {return { label: x, value: x }})- if (columnDefinition.dataType === 'ARRAY') {- // MultiSelectEditor- } else {- return (p: any) => <SelectEditor {...p} options={options} />- }+ return (p: any) => <SelectEditor {...p} options={options} />+ }+ case 'array': {+ return MultiSelectEditor}- case 'array':case 'json': {return JsonEditor}diff --git a/studio/components/ui/MultiSelect/index.tsx b/studio/components/ui/MultiSelect/index.tsxindex a3a85005d46..67c102f1e49 100644--- a/studio/components/ui/MultiSelect/index.tsx+++ b/studio/components/ui/MultiSelect/index.tsx@@ -12,14 +12,15 @@ export interface MultiSelectOption {}interface Props {- options: MultiSelectOption[]value: string[]+ options: MultiSelectOption[]label?: stringplaceholder?: string | ReactNodesearchPlaceholder?: stringdescriptionText?: string | ReactNodeemptyMessage?: string | ReactNodedisabled?: boolean+ allowDuplicateSelection?: booleanonChange?(x: string[]): void}