From d8a80535cbfaa496ff8ade3d1a31826890a591c6 Mon Sep 17 00:00:00 2001 From: Joshen Lim Date: Tue, 16 Sep 2025 16:34:19 +0800 Subject: [PATCH] Contextual error for foreign tables in table editor --- .../components/grid/components/grid/Grid.tsx | 62 +++++++++++++++---- 1 file changed, 50 insertions(+), 12 deletions(-) diff --git a/apps/studio/components/grid/components/grid/Grid.tsx b/apps/studio/components/grid/components/grid/Grid.tsx index 1818e82ebba..ea4af1fad80 100644 --- a/apps/studio/components/grid/components/grid/Grid.tsx +++ b/apps/studio/components/grid/components/grid/Grid.tsx @@ -5,6 +5,7 @@ import { ref as valtioRef } from 'valtio' import { handleCopyCell } from 'components/grid/SupabaseGrid.utils' import { formatForeignKeys } from 'components/interfaces/TableGridEditor/SidePanelEditor/ForeignKeySelector/ForeignKeySelector.utils' import AlertError from 'components/ui/AlertError' +import { InlineLink } from 'components/ui/InlineLink' import { useForeignKeyConstraintsQuery } from 'data/database/foreign-key-constraints-query' import { ENTITY_TYPE } from 'data/entity-types/entity-type-constants' import { useSendEventMutation } from 'data/telemetry/send-event-mutation' @@ -14,6 +15,7 @@ import { useCsvFileDrop } from 'hooks/ui/useCsvFileDrop' import { useTableEditorStateSnapshot } from 'state/table-editor' import { useTableEditorTableStateSnapshot } from 'state/table-editor-table' import { Button, cn } from 'ui' +import { Admonition } from 'ui-patterns' import { GenericSkeletonLoader } from 'ui-patterns/ShimmeringLoader' import type { Filter, GridProps, SupaRow } from '../../types' import { useOnRowsChange } from './Grid.utils' @@ -58,6 +60,8 @@ export const Grid = memo( const { data: org } = useSelectedOrganizationQuery() const { data: project } = useSelectedProjectQuery() + const isBranch = project?.parent_project_ref !== undefined + console.log({ isBranch }) const onRowsChange = useOnRowsChange(rows) @@ -77,6 +81,9 @@ export const Grid = memo( const isForeignTable = tableEntityType === ENTITY_TYPE.FOREIGN_TABLE const isTableEmpty = (rows ?? []).length === 0 + const isForeignTableMissingVaultKeyError = + isForeignTable && isError && error.message.includes('query vault failed') + const { mutate: sendEvent } = useSendEventMutation() const { isDraggedOver, onDragOver, onFileDrop } = useCsvFileDrop({ @@ -149,20 +156,51 @@ export const Grid = memo( className="absolute top-9 p-2 w-full z-[1] pointer-events-none" > {isLoading && } - {isError && ( - - {filters.length > 0 && ( + {isError ? ( + isForeignTableMissingVaultKeyError ? ( +

- Verify that the filter values are correct, as the error may stem from an - incorrectly applied filter + The key that's used to retrieve data from your foreign table is either + incorrect or missing. Verify the key in your{' '} + + wrapper's settings + {' '} + or in{' '} + + Vault + + .

- )} -
- )} + {isBranch && ( +

+ Note: Vault keys from the main project do not sync to branches. You may add + them manually into{' '} + + Vault + {' '} + if you want to query foreign tables while on a branch. +

+ )} + + ) : ( + + {filters.length > 0 && ( +

+ Verify that the filter values are correct, as the error may stem from an + incorrectly applied filter +

+ )} +
+ ) + ) : null} {isSuccess && ( <> {(filters ?? []).length === 0 ? (