From 2796f5ef5ff5eadfcede88176e22b5c528285cb5 Mon Sep 17 00:00:00 2001 From: Alaister Young Date: Tue, 12 Sep 2023 22:43:25 +1200 Subject: [PATCH] address feedback --- .../Publications/PublicationsTables.tsx | 6 ++ .../Database/Schemas/SchemaGraph.tsx | 31 ++++--- .../interfaces/Database/Tables/TableList.tsx | 20 +--- .../DeleteConfirmationDialogs.tsx | 13 ++- .../SidePanelEditor/SidePanelEditor.tsx | 11 ++- .../TableEditorLayout/TableEditorLayout.tsx | 4 +- .../TableEditorLayout/TableEditorMenu.tsx | 4 +- studio/data/tables/tables-query.ts | 3 +- studio/pages/project/[ref]/auth/policies.tsx | 8 +- .../project/[ref]/database/functions.tsx | 10 +- .../pages/project/[ref]/database/schemas.tsx | 91 +++++++++++-------- studio/pages/project/[ref]/editor/[id].tsx | 15 ++- 12 files changed, 127 insertions(+), 89 deletions(-) diff --git a/studio/components/interfaces/Database/Publications/PublicationsTables.tsx b/studio/components/interfaces/Database/Publications/PublicationsTables.tsx index 70e44d7c19e..0e6b650674b 100644 --- a/studio/components/interfaces/Database/Publications/PublicationsTables.tsx +++ b/studio/components/interfaces/Database/Publications/PublicationsTables.tsx @@ -5,6 +5,7 @@ import { useState } from 'react' import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext' import NoSearchResults from 'components/to-be-cleaned/NoSearchResults' import Table from 'components/to-be-cleaned/Table' +import AlertError from 'components/ui/AlertError' import InformationBox from 'components/ui/InformationBox' import Connecting from 'components/ui/Loading/Loading' import { useTablesQuery } from 'data/tables/tables-query' @@ -31,6 +32,8 @@ const PublicationsTables = ({ selectedPublication, onSelectBack }: PublicationsT data: tables, isLoading, isSuccess, + isError, + error, } = useTablesQuery( { projectRef: project?.ref, @@ -110,6 +113,9 @@ const PublicationsTables = ({ selectedPublication, onSelectBack }: PublicationsT )} + + {isError && } + {isSuccess && (tables.length === 0 ? ( diff --git a/studio/components/interfaces/Database/Schemas/SchemaGraph.tsx b/studio/components/interfaces/Database/Schemas/SchemaGraph.tsx index d76abe61581..c2701e5e5b2 100644 --- a/studio/components/interfaces/Database/Schemas/SchemaGraph.tsx +++ b/studio/components/interfaces/Database/Schemas/SchemaGraph.tsx @@ -1,7 +1,8 @@ import dagre from '@dagrejs/dagre' import clsx from 'clsx' -import { observer } from 'mobx-react-lite' import { uniqBy } from 'lodash' +import { Diamond, Fingerprint } from 'lucide-react' +import { observer } from 'mobx-react-lite' import { useEffect, useMemo } from 'react' import ReactFlow, { Background, @@ -17,11 +18,10 @@ import ReactFlow, { import { PostgresTable } from '@supabase/postgres-meta' import { useTheme } from 'common/Providers' -import { useStore } from 'hooks' -import { IconHash, IconKey, IconLoader, IconLock } from 'ui' -import { Diamond, Fingerprint } from 'lucide-react' - +import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext' +import { useTablesQuery } from 'data/tables/tables-query' import 'reactflow/dist/style.css' +import { IconHash, IconKey, IconLoader, IconLock } from 'ui' type TableNodeData = { name: string @@ -347,23 +347,32 @@ const TablesGraph = ({ tables }: { tables: PostgresTable[] }) => { } const SchemaGraph = ({ schema }: { schema: string }) => { - const { meta } = useStore() - const tables = meta.tables.list((table: { schema: string }) => table.schema === schema) + const { project } = useProjectContext() + const { + data: tables, + isLoading, + isError, + error, + } = useTablesQuery({ + projectRef: project?.ref, + connectionString: project?.connectionString, + schema, + }) - if (meta.tables.isLoading) { + if (isLoading) { return (
-

Loading schemas...

+

Loading table...

) } - if (meta.tables.hasError) { + if (isError) { return (

Error connecting to API

-

{`${meta.tables.error?.message ?? 'Unknown error'}`}

+

{`${error?.message ?? 'Unknown error'}`}

) } diff --git a/studio/components/interfaces/Database/Tables/TableList.tsx b/studio/components/interfaces/Database/Tables/TableList.tsx index 624ea54e786..1e190ba7eb8 100644 --- a/studio/components/interfaces/Database/Tables/TableList.tsx +++ b/studio/components/interfaces/Database/Tables/TableList.tsx @@ -25,6 +25,7 @@ import { Input, Listbox, } from 'ui' +import AlertError from 'components/ui/AlertError' interface TableListProps { onAddTable: () => void @@ -58,6 +59,8 @@ const TableList = ({ data: tables, isLoading, isSuccess, + isError, + error, } = useTablesQuery( { projectRef: project?.ref, @@ -180,6 +183,8 @@ const TableList = ({ )} + {isError && } + {isSuccess && (tables.length === 0 ? ( @@ -323,21 +328,6 @@ const TableList = ({ )} - - {/*