The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
fix: jsonb warning (#46828)
Vaibhav8300e6a14abe
diff --git a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/InputField.tsx b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/InputField.tsxindex 1843f4937df..39467a3ea3c 100644--- a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/InputField.tsx+++ b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/InputField.tsx@@ -173,7 +173,7 @@ export const InputField = ({}if (includes(TEXT_TYPES, field.format)) {- const isTruncated = isValueTruncated(field.value)+ const isTruncated = isValueTruncated(field.value, field.format)/*** Handle `undefined` as the default value of the input field@@ -250,7 +250,7 @@ export const InputField = ({}if (includes(JSON_TYPES, field.format)) {- const isTruncated = isValueTruncated(field.value)+ const isTruncated = isValueTruncated(field.value, field.format)return (<FormItemLayout@@ -373,7 +373,7 @@ export const InputField = ({)}- const isTruncated = isValueTruncated(field.value)+ const isTruncated = isValueTruncated(field.value, field.format)return (<FormItemLayoutdiff --git a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/JsonEditor/index.tsx b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/JsonEditor/index.tsxindex cc906632951..cc52411c09f 100644--- a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/JsonEditor/index.tsx+++ b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/JsonEditor/index.tsx@@ -53,7 +53,10 @@ export const JsonEditor = ({// sometimes the value is a JSON object if it was truncated, then fully loaded from the grid.const value = row?.[column as keyof typeof row] as unknownconst jsonString = typeof value === 'object' ? JSON.stringify(value) : (value as string)- const isTruncated = isValueTruncated(jsonString)+ const columnFormat = selectedTable?.columns?.find(+ (candidate) => candidate.name === column+ )?.format+ const isTruncated = isValueTruncated(jsonString, columnFormat)const { mutate: getCellValue, isPending, isSuccess, reset } = useGetCellValueMutation()diff --git a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/RowEditor.utils.test.ts b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/RowEditor.utils.test.tsindex d6e7bdd4a9a..da3ab85c0c8 100644--- a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/RowEditor.utils.test.ts+++ b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/RowEditor.utils.test.ts@@ -274,12 +274,12 @@ describe('isValueTruncated', () => {// Pattern 4: Multi-dimensional array (lines 211-212)// column[1:50]::type[] - no special marker, just detect by [[ pattern- expect(isValueTruncated('[["item"]]')).toBe(true)- expect(isValueTruncated('[["item1","item2"]]')).toBe(true)+ expect(isValueTruncated('[["item"]]', '_text')).toBe(true)+ expect(isValueTruncated('[["item1","item2"]]', '_text')).toBe(true)})it('should detect multidimensional arrays', () => {- expect(isValueTruncated('[["item1", "item2"]]')).toBe(true)+ expect(isValueTruncated('[["item1", "item2"]]', '_text')).toBe(true)})it('should detect truncated JSON arrays with truncated flag', () => {@@ -303,6 +303,12 @@ describe('isValueTruncated', () => {expect(isValueTruncated({} as any)).toBe(false)})+ it('should not flag small jsonb arrays as truncated', () => {+ expect(+ isValueTruncated('[["infrequently","frequently","constantly"],["90","30","180"]]', 'jsonb')+ ).toBe(false)+ })+it('should test edge cases that could break coordination with table-row-query.ts', () => {// Test values that are just under/at the thresholds to ensure boundaries are correctdiff --git a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/RowEditor.utils.ts b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/RowEditor.utils.tsindex 0d9da5a66ac..1837ede1343 100644--- a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/RowEditor.utils.ts+++ b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/RowEditor.utils.ts@@ -97,7 +97,7 @@ export const validateFields = (fields: RowField[]) => {}}if (field.format.includes('json') && (field.value?.length ?? 0) > 0) {- const isTruncated = isValueTruncated(field.value)+ const isTruncated = isValueTruncated(field.value, field.format)// don't validate if the value is truncatedif (isTruncated) return@@ -244,7 +244,7 @@ export const generateUpdateRowPayload = (originalRow: any, fields: RowField[]) =} else if (type !== undefined && JSON_TYPES.includes(type)) {// don't update if the value is truncated. This is to enable the user to change cell values on rows which have// truncated JSON values. If the user- const isTruncated = isValueTruncated(field?.value)+ const isTruncated = isValueTruncated(field?.value, field?.format)if (!isTruncated) {payload[property] = rowObject[property]}@@ -263,7 +263,9 @@ export const generateUpdateRowPayload = (originalRow: any, fields: RowField[]) =/*** Checks if the value is truncated. The JSON types are usually truncated if they're too big to show in the editor.*/-export const isValueTruncated = (value: string | null | undefined) => {+export const isValueTruncated = (value: string | null | undefined, format?: string | null) => {+ const isArrayColumn = typeof format === 'string' && format.startsWith('_')+return ((typeof value === 'string' && value.endsWith('...') && value.length > MAX_CHARACTERS) ||// if the value is an array which total representation is > MAX_CHARACTERS@@ -275,9 +277,7 @@ export const isValueTruncated = (value: string | null | undefined) => {// If the array have MAX_ARRAY_SIZE elements in it// its a large truncated array(value.match(/","/g) || []).length === MAX_ARRAY_SIZE) ||- // if the string represent a multi-dimentional array we always consider it as possibly truncated- // so user load the whole value before edition- (typeof value === 'string' && value.startsWith('[["')) ||+ (typeof value === 'string' && isArrayColumn && value.startsWith('[["')) ||// [Joshen] For json arrays, refer to getTableRowsSql from table-row-query// for array types, we're adding {"truncated": true} as the last item of the JSON to// maintain the JSON array structure