Skip to content

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

chore: replace tiny popover with supabase/ui popover

Jonathan Summers-Muirc051101add4c
diff --git a/studio/components/grid/components/editor/JsonEditor.tsx b/studio/components/grid/components/editor/JsonEditor.tsx
index 63a2e5e1120..66c3fa1e65d 100644
--- a/studio/components/grid/components/editor/JsonEditor.tsx
+++ b/studio/components/grid/components/editor/JsonEditor.tsx
@@ -1,52 +1,53 @@
-import * as React from 'react';
-import { Popover } from 'react-tiny-popover';
-import { EditorProps } from '@supabase/react-data-grid';
-import { useTrackedState } from '../../store';
-import { BlockKeys, MonacoEditor, NullValue } from '../common';
+import * as React from 'react'
+
+import { EditorProps } from '@supabase/react-data-grid'
+import { useTrackedState } from '../../store'
+import { BlockKeys, MonacoEditor, NullValue } from '../common'
+import { Popover } from '@supabase/ui'
export function JsonEditor<TRow, TSummaryRow = unknown>({
row,
column,
onRowChange,
}: EditorProps<TRow, TSummaryRow>) {
- const state = useTrackedState();
- const [isPopoverOpen, setIsPopoverOpen] = React.useState(true);
- const gridColumn = state.gridColumns.find(x => x.name == column.key);
- const initialValue = row[column.key as keyof TRow] as unknown;
- const jsonString = initialValue ? JSON.stringify(initialValue) : '';
- const prettyJsonValue = prettifyJSON(jsonString);
- const [value, setValue] = React.useState<string | null>(prettyJsonValue);
+ const state = useTrackedState()
+ const [isPopoverOpen, setIsPopoverOpen] = React.useState(true)
+ const gridColumn = state.gridColumns.find((x) => x.name == column.key)
+ const initialValue = row[column.key as keyof TRow] as unknown
+ const jsonString = initialValue ? JSON.stringify(initialValue) : ''
+ const prettyJsonValue = prettifyJSON(jsonString)
+ const [value, setValue] = React.useState<string | null>(prettyJsonValue)
const onEscape = React.useCallback((newValue: string | null) => {
- commitChange(newValue);
- setIsPopoverOpen(false);
- }, []);
+ commitChange(newValue)
+ setIsPopoverOpen(false)
+ }, [])
function onChange(_value: string | undefined) {
- if (!_value || _value == '') setValue(null);
- else setValue(_value);
+ if (!_value || _value == '') setValue(null)
+ else setValue(_value)
}
function commitChange(newValue: string | null) {
if (!newValue) {
- onRowChange({ ...row, [column.key]: null }, true);
+ onRowChange({ ...row, [column.key]: null }, true)
} else if (verifyJSON(newValue)) {
- const jsonValue = JSON.parse(newValue);
- onRowChange({ ...row, [column.key]: jsonValue }, true);
+ const jsonValue = JSON.parse(newValue)
+ onRowChange({ ...row, [column.key]: jsonValue }, true)
} else {
- const { onError } = state;
- if (onError) onError(Error('invalid input'));
+ const { onError } = state
+ if (onError) onError(Error('invalid input'))
}
}
return (
<Popover
- isOpen={isPopoverOpen}
- padding={-35}
- containerClassName=""
- positions={['bottom', 'top', 'left']}
+ open={isPopoverOpen}
+ side="bottom"
align="start"
- content={
+ sideOffset={-35}
+ className="rounded-none"
+ overlay={
<BlockKeys value={value} onEscape={onEscape}>
<MonacoEditor
width={`${gridColumn?.width || column.width}px`}
@@ -59,45 +60,43 @@ export function JsonEditor<TRow, TSummaryRow = unknown>({
>
<div
className={`${
- !!value && jsonString.trim().length == 0
- ? 'sb-grid-fill-container'
- : ''
+ !!value && jsonString.trim().length == 0 ? 'sb-grid-fill-container' : ''
} sb-grid-json-editor__trigger`}
onClick={() => setIsPopoverOpen(!isPopoverOpen)}
>
{value === null || value === '' ? <NullValue /> : jsonString}
</div>
</Popover>
- );
+ )
}
export const prettifyJSON = (value: string) => {
if (value.length > 0) {
try {
- return JSON.stringify(JSON.parse(value), undefined, 2);
+ return JSON.stringify(JSON.parse(value), undefined, 2)
} catch (err) {
// dont need to throw error, just return text value
// Users have to fix format if they want to save
- return value;
+ return value
}
} else {
- return value;
+ return value
}
-};
+}
export const minifyJSON = (value: string) => {
try {
- return JSON.stringify(JSON.parse(value));
+ return JSON.stringify(JSON.parse(value))
} catch (err) {
- throw err;
+ throw err
}
-};
+}
export const verifyJSON = (value: string) => {
try {
- JSON.parse(value);
- return true;
+ JSON.parse(value)
+ return true
} catch (err) {
- return false;
+ return false
}
-};
+}
diff --git a/studio/components/grid/components/editor/TextEditor.tsx b/studio/components/grid/components/editor/TextEditor.tsx
index d9604a25cd2..00dd5cd671c 100644
--- a/studio/components/grid/components/editor/TextEditor.tsx
+++ b/studio/components/grid/components/editor/TextEditor.tsx
@@ -1,38 +1,38 @@
-import * as React from 'react';
-import { Popover } from 'react-tiny-popover';
-import { EditorProps } from '@supabase/react-data-grid';
-import { useTrackedState } from '../../store';
-import { BlockKeys, MonacoEditor, NullValue, EmptyValue } from '../common';
+import * as React from 'react'
+import { EditorProps } from '@supabase/react-data-grid'
+import { useTrackedState } from '../../store'
+import { BlockKeys, MonacoEditor, NullValue, EmptyValue } from '../common'
+import { Popover } from '@supabase/ui'
export function TextEditor<TRow, TSummaryRow = unknown>({
row,
column,
onRowChange,
}: EditorProps<TRow, TSummaryRow>) {
- const state = useTrackedState();
- const [isPopoverOpen, setIsPopoverOpen] = React.useState(true);
- const gridColumn = state.gridColumns.find(x => x.name == column.key);
- const initialValue = (row[column.key as keyof TRow] as unknown) as string;
- const [value, setValue] = React.useState<string | null>(initialValue);
+ const state = useTrackedState()
+ const [isPopoverOpen, setIsPopoverOpen] = React.useState(true)
+ const gridColumn = state.gridColumns.find((x) => x.name == column.key)
+ const initialValue = row[column.key as keyof TRow] as unknown as string
+ const [value, setValue] = React.useState<string | null>(initialValue)
const onEscape = React.useCallback((newValue: string | null) => {
- onRowChange({ ...row, [column.key]: newValue }, true);
- setIsPopoverOpen(false);
- }, []);
+ onRowChange({ ...row, [column.key]: newValue }, true)
+ setIsPopoverOpen(false)
+ }, [])
function onChange(_value: string | undefined) {
- if (!_value) setValue('');
- else setValue(_value);
+ if (!_value) setValue('')
+ else setValue(_value)
}
return (
<Popover
- isOpen={isPopoverOpen}
- padding={-35}
- containerClassName=""
- positions={['bottom', 'top', 'left']}
+ open={isPopoverOpen}
+ side="bottom"
align="start"
- content={
+ sideOffset={-35}
+ className="rounded-none"
+ overlay={
<BlockKeys value={value} onEscape={onEscape}>
<MonacoEditor
width={`${gridColumn?.width || column.width}px`}
@@ -51,5 +51,5 @@ export function TextEditor<TRow, TSummaryRow = unknown>({
{value === null ? <NullValue /> : value === '' ? <EmptyValue /> : value}
</div>
</Popover>
- );
+ )
}