Skip to content

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

Update SelectEditor to use Listbox component from Ui library

Joshen Lim49ba2b0f6956
diff --git a/studio/components/grid/components/editor/SelectEditor.tsx b/studio/components/grid/components/editor/SelectEditor.tsx
index cdbbd2a547c..fd41a84c46a 100644
--- a/studio/components/grid/components/editor/SelectEditor.tsx
+++ b/studio/components/grid/components/editor/SelectEditor.tsx
@@ -1,6 +1,8 @@
-import * as React from 'react'
+import { Listbox } from '@supabase/ui'
import { EditorProps } from '@supabase/react-data-grid'
+import { useTrackedState } from 'components/grid/store'
+
interface SelectEditorProps<TRow, TSummaryRow = unknown> extends EditorProps<TRow, TSummaryRow> {
options: { label: string; value: string }[]
}
@@ -12,10 +14,12 @@ export function SelectEditor<TRow, TSummaryRow = unknown>({
onClose,
options,
}: SelectEditorProps<TRow, TSummaryRow>) {
+ const state = useTrackedState()
+ const gridColumn = state.gridColumns.find((x) => x.name == column.key)
+
const value = row[column.key as keyof TRow] as unknown as string
- function onChange(event: React.ChangeEvent<HTMLSelectElement>) {
- const value = event.target.value
+ function onChange(value: string) {
if (!value || value == '') {
onRowChange({ ...row, [column.key]: null }, true)
} else {
@@ -28,19 +32,25 @@ export function SelectEditor<TRow, TSummaryRow = unknown>({
}
return (
- <select
- className="sb-grid-select-editor bg-scale-400 text-grid p-0 px-3"
- value={value ?? ''}
+ <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}
- autoFocus
>
- <option value={''}>[null]</option>
+ <Listbox.Option id="NULL" label="NULL" value="">
+ NULL
+ </Listbox.Option>
{options.map(({ label, value }) => (
- <option key={value} value={value}>
+ <Listbox.Option key={value} label={label} value={value}>
{label}
- </option>
+ </Listbox.Option>
))}
- </select>
+ </Listbox>
)
}
diff --git a/studio/components/grid/utils/gridColumns.tsx b/studio/components/grid/utils/gridColumns.tsx
index 049f9066e68..0d815aaab1c 100644
--- a/studio/components/grid/utils/gridColumns.tsx
+++ b/studio/components/grid/utils/gridColumns.tsx
@@ -91,6 +91,8 @@ function getColumnEditor(columnDefinition: SupaColumn, columnType: ColumnType) {
return
}
+ console.log('getColumnEditor', columnType, columnDefinition)
+
switch (columnType) {
case 'boolean': {
return columnDefinition.isNullable ? NullableBooleanEditor : BooleanEditor
@@ -108,7 +110,11 @@ function getColumnEditor(columnDefinition: SupaColumn, columnType: ColumnType) {
const options = columnDefinition.enum!.map((x) => {
return { label: x, value: x }
})
- return (p: any) => <SelectEditor {...p} options={options} />
+ if (columnDefinition.dataType === 'ARRAY') {
+ // MultiSelectEditor
+ } else {
+ return (p: any) => <SelectEditor {...p} options={options} />
+ }
}
case 'array':
case 'json': {
diff --git a/studio/styles/grid.scss b/studio/styles/grid.scss
index 51af1b7e0e9..7da30942b20 100644
--- a/studio/styles/grid.scss
+++ b/studio/styles/grid.scss
@@ -386,7 +386,10 @@
*/
.sb-grid-select-editor {
- @apply h-full w-full;
+ button {
+ @apply border-none rounded-none shadow-none;
+ box-shadow: none !important
+ }
}
/*