From a62a857c01dca23f80ebdf1c8f77e4fde985de99 Mon Sep 17 00:00:00 2001 From: Joshen Lim Date: Thu, 16 Mar 2023 14:50:19 +0800 Subject: [PATCH] Update boolean selector in grid --- .../grid/components/editor/BooleanEditor.tsx | 49 +++++++++++----- .../editor/NullableBooleanEditor.tsx | 58 ------------------- .../grid/components/editor/index.ts | 1 - studio/components/grid/utils/gridColumns.tsx | 3 +- 4 files changed, 36 insertions(+), 75 deletions(-) delete mode 100644 studio/components/grid/components/editor/NullableBooleanEditor.tsx diff --git a/studio/components/grid/components/editor/BooleanEditor.tsx b/studio/components/grid/components/editor/BooleanEditor.tsx index 3396d2a1d55..052ba484a86 100644 --- a/studio/components/grid/components/editor/BooleanEditor.tsx +++ b/studio/components/grid/components/editor/BooleanEditor.tsx @@ -1,25 +1,46 @@ -import * as React from 'react' +import { Select } from 'ui' import { EditorProps } from '@supabase/react-data-grid' -import { Toggle } from 'ui' +import { useTrackedState } from 'components/grid/store' + +interface Props extends EditorProps { + isNullable?: boolean +} export function BooleanEditor({ row, column, + isNullable, onRowChange, onClose, -}: EditorProps) { - const onBlur = () => onClose(true) - const onChange = (value: boolean) => onRowChange({ ...row, [column.key]: value }) +}: Props) { + 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 + + const onBlur = () => onClose(false) + const onChange = (event: any) => { + const value = event.target.value + if (value === 'null') { + onRowChange({ ...row, [column.key]: null }, true) + } else { + onRowChange({ ...row, [column.key]: value === 'true' }, true) + } + } return ( -
- -
+ ) } diff --git a/studio/components/grid/components/editor/NullableBooleanEditor.tsx b/studio/components/grid/components/editor/NullableBooleanEditor.tsx deleted file mode 100644 index 5b8bac0ddef..00000000000 --- a/studio/components/grid/components/editor/NullableBooleanEditor.tsx +++ /dev/null @@ -1,58 +0,0 @@ -import React, { useEffect } from 'react' -import * as Tooltip from '@radix-ui/react-tooltip' -import { EditorProps } from '@supabase/react-data-grid' -import { Toggle, Button, IconX } from 'ui' - -export function NullableBooleanEditor({ - row, - column, - onRowChange, - onClose, -}: EditorProps) { - const value = row[column.key as keyof TRow] as unknown as boolean | null - - useEffect(() => { - // if value is null, set it to false on initial render - if (value === null) { - onRowChange({ ...row, [column.key]: false }) - } - }, []) - - const onBlur = () => onClose(true) - const onClear = () => onRowChange({ ...row, [column.key]: null }, true) - const onChange = (value: boolean) => onRowChange({ ...row, [column.key]: value }) - - return ( -
- - - -
- ) -} diff --git a/studio/components/grid/components/editor/index.ts b/studio/components/grid/components/editor/index.ts index af37e035773..4869badf6da 100644 --- a/studio/components/grid/components/editor/index.ts +++ b/studio/components/grid/components/editor/index.ts @@ -2,7 +2,6 @@ export * from './BooleanEditor' export * from './DateEditor' export * from './DateTimeEditor' export * from './JsonEditor' -export * from './NullableBooleanEditor' export * from './NumberEditor' export * from './SelectEditor' export * from './TextEditor' diff --git a/studio/components/grid/utils/gridColumns.tsx b/studio/components/grid/utils/gridColumns.tsx index c4883af6a69..e85da89d8d7 100644 --- a/studio/components/grid/utils/gridColumns.tsx +++ b/studio/components/grid/utils/gridColumns.tsx @@ -19,7 +19,6 @@ import { DateTimeEditor, DateTimeWithTimezoneEditor, JsonEditor, - NullableBooleanEditor, NumberEditor, SelectEditor, TextEditor, @@ -105,7 +104,7 @@ function getColumnEditor( switch (columnType) { case 'boolean': { - return columnDefinition.isNullable ? NullableBooleanEditor : BooleanEditor + return (p: any) => } case 'date': { return DateEditor