Home / Function/ SupabaseGrid() — supabase Function Reference

SupabaseGrid() — supabase Function Reference

Architecture documentation for the SupabaseGrid() function in SupabaseGrid.tsx from the supabase codebase.

Entity Profile

Dependency Diagram

graph TD
  be97f35c_a68f_0a38_2fc8_b1e46b157381["SupabaseGrid()"]
  7775f99d_4807_d4e7_d53b_2326b76302f6["useIsQueueOperationsEnabled()"]
  be97f35c_a68f_0a38_2fc8_b1e46b157381 -->|calls| 7775f99d_4807_d4e7_d53b_2326b76302f6
  c7839dd6_7564_74b6_eab5_3c05bd31b6d2["useIsTableFilterBarEnabled()"]
  be97f35c_a68f_0a38_2fc8_b1e46b157381 -->|calls| c7839dd6_7564_74b6_eab5_3c05bd31b6d2
  a47503db_fa39_e27f_a3b4_341051a9ae62["useTableFilter()"]
  be97f35c_a68f_0a38_2fc8_b1e46b157381 -->|calls| a47503db_fa39_e27f_a3b4_341051a9ae62
  c41253e2_92a8_75b4_b100_945052d97226["useTableSort()"]
  be97f35c_a68f_0a38_2fc8_b1e46b157381 -->|calls| c41253e2_92a8_75b4_b100_945052d97226
  dd8ebed6_bd41_a655_037b_27223ea4d1a6["validateMsSqlSorting()"]
  be97f35c_a68f_0a38_2fc8_b1e46b157381 -->|calls| dd8ebed6_bd41_a655_037b_27223ea4d1a6
  16d57069_e009_dae3_11f3_3e1e07423636["reapplyOptimisticUpdates()"]
  be97f35c_a68f_0a38_2fc8_b1e46b157381 -->|calls| 16d57069_e009_dae3_11f3_3e1e07423636
  style be97f35c_a68f_0a38_2fc8_b1e46b157381 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

apps/studio/components/grid/SupabaseGrid.tsx lines 34–170

export const SupabaseGrid = ({
  customHeader,
  gridProps,
  children,
}: PropsWithChildren<
  Pick<HeaderProps, 'customHeader'> & {
    gridProps?: GridProps
  }
>) => {
  const { id: _id } = useParams()
  const tableId = _id ? Number(_id) : undefined

  const isQueueOperationsEnabled = useIsQueueOperationsEnabled()

  const queryClient = useQueryClient()
  const { data: project } = useSelectedProjectQuery()
  const tableEditorSnap = useTableEditorStateSnapshot()
  const snap = useTableEditorTableStateSnapshot()

  const gridRef = useRef<DataGridHandle>(null)
  const [mounted, setMounted] = useState(false)

  const newFilterBarEnabled = useIsTableFilterBarEnabled()

  const { filters } = useTableFilter()
  const { sorts, onApplySorts } = useTableSort()

  const roleImpersonationState = useRoleImpersonationStateSnapshot()

  const msSqlWarning = isMsSqlForeignTable(snap.originalTable)
    ? validateMsSqlSorting({ filters, sorts, table: snap.originalTable })
    : { warning: null }
  const tableQueriesEnabled = msSqlWarning.warning === null

  const {
    data,
    error,
    isSuccess,
    isError,
    isPending: isLoading,
    isRefetching,
    dataUpdatedAt,
  } = useTableRowsQuery(
    {
      projectRef: project?.ref,
      connectionString: project?.connectionString,
      tableId,
      sorts,
      filters,
      page: snap.page,
      limit: tableEditorSnap.rowsPerPage,
      roleImpersonationState: roleImpersonationState as RoleImpersonationState,
    },
    {
      placeholderData: keepPreviousData,
      enabled: tableQueriesEnabled,
      retry: (_, error: any) => {
        const doesNotExistError = error && error.message?.includes('does not exist')
        if (doesNotExistError) onApplySorts([])
        return false
      },
    }
  )

  useEffect(() => {
    if (!mounted) setMounted(true)
  }, [])

  // Re-apply optimistic updates when table data is loaded/refetched
  // This ensures pending changes remain visible when switching tabs or after data refresh
  // Skip re-applying during save to avoid race condition where refetch completes before queue clears
  const isSaving = tableEditorSnap.operationQueue.status === 'saving'
  useEffect(() => {
    if (
      isSuccess &&
      project?.ref &&
      tableId &&
      isQueueOperationsEnabled &&
      tableEditorSnap.hasPendingOperations &&
      !isSaving
    ) {
      reapplyOptimisticUpdates({
        queryClient,
        projectRef: project.ref,
        tableId,
        operations: tableEditorSnap.operationQueue.operations as readonly QueuedOperation[],
      })
    }
  }, [
    isSuccess,
    dataUpdatedAt,
    project?.ref,
    tableId,
    isQueueOperationsEnabled,
    tableEditorSnap.hasPendingOperations,
    tableEditorSnap.operationQueue.operations,
    queryClient,
    isSaving,
  ])

  const rows = data?.rows ?? EMPTY_ARR

  const HeaderComponent = newFilterBarEnabled ? HeaderNew : Header

  return (
    <DndProvider backend={HTML5Backend} context={window}>
      <div className="sb-grid h-full flex flex-col">
        <HeaderComponent
          customHeader={customHeader}
          isRefetching={isRefetching}
          tableQueriesEnabled={tableQueriesEnabled}
        />

        {msSqlWarning.warning !== null && <msSqlWarning.Component />}

        {children || (
          <>
            <Grid
              ref={gridRef}
              {...gridProps}
              rows={rows}
              error={error}
              isDisabled={!tableQueriesEnabled}
              isLoading={isLoading}
              isSuccess={isSuccess}
              isError={isError}
            />
            <Footer enableForeignRowsQuery={tableQueriesEnabled} />
            <Shortcuts gridRef={gridRef} rows={rows} />
          </>
        )}

        {mounted && createPortal(<RowContextMenu rows={rows} />, document.body)}
      </div>
    </DndProvider>
  )
}

Subdomains

Frequently Asked Questions

What does SupabaseGrid() do?
SupabaseGrid() is a function in the supabase codebase.
What does SupabaseGrid() call?
SupabaseGrid() calls 6 function(s): reapplyOptimisticUpdates, useIsQueueOperationsEnabled, useIsTableFilterBarEnabled, useTableFilter, useTableSort, validateMsSqlSorting.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free