From 810d2eba02ef03f1839d348385dbc3b3fb2d4681 Mon Sep 17 00:00:00 2001 From: jingsam Date: Tue, 10 Sep 2024 17:52:09 +0800 Subject: [PATCH] feat: add gis features --- .../Database/ProtectedSchemaWarning.tsx | 4 +- .../interfaces/GIS/Features/FeatureList.tsx | 115 ++++++++++++++++ .../interfaces/GIS/Features/FeaturesList.tsx | 124 ++++++++++++++++++ .../interfaces/GIS/Tiles/TileList.tsx | 13 +- .../interfaces/GIS/Tiles/TilesList.tsx | 21 ++- .../studio/components/interfaces/GIS/index.ts | 3 +- .../TableEditorLayout/TableEditorMenu.tsx | 2 +- apps/studio/data/gis/gis-features-query.ts | 43 ++++++ ...gis-tiles-query.tsx => gis-tiles-query.ts} | 0 apps/studio/data/gis/keys.ts | 2 + apps/studio/pages/api/gis/[ref]/features.ts | 33 +++++ .../pages/project/[ref]/gis/features.tsx | 2 + 12 files changed, 346 insertions(+), 16 deletions(-) create mode 100644 apps/studio/components/interfaces/GIS/Features/FeatureList.tsx create mode 100644 apps/studio/components/interfaces/GIS/Features/FeaturesList.tsx create mode 100644 apps/studio/data/gis/gis-features-query.ts rename apps/studio/data/gis/{gis-tiles-query.tsx => gis-tiles-query.ts} (100%) create mode 100644 apps/studio/pages/api/gis/[ref]/features.ts diff --git a/apps/studio/components/interfaces/Database/ProtectedSchemaWarning.tsx b/apps/studio/components/interfaces/Database/ProtectedSchemaWarning.tsx index a8c16d4a416b2..610c3612f2ab7 100644 --- a/apps/studio/components/interfaces/Database/ProtectedSchemaWarning.tsx +++ b/apps/studio/components/interfaces/Database/ProtectedSchemaWarning.tsx @@ -33,7 +33,7 @@ export const ProtectedSchemaModal = ({ >

- 以下模式由系统管理,当前被设置为只读,无法通过表编辑器进行编辑。 + 以下模式由系统管理,当前被设置为只读,无法通过本界面进行编辑。

{EXCLUDED_SCHEMAS.map((schema) => ( @@ -63,7 +63,7 @@ const ProtectedSchemaWarning = ({ schema, entity }: { schema: string; entity: st 当前正在一个受保护的模式下查看{entity}

- 模式 {schema} 是由系统管理的,当前被设置为只读,无法通过表编辑器进行编辑。 + 模式 {schema} 是由系统管理的,当前被设置为只读,无法通过本界面进行编辑。

+ +
+ + + ) + })} + + ) +} + +export default FeatureList diff --git a/apps/studio/components/interfaces/GIS/Features/FeaturesList.tsx b/apps/studio/components/interfaces/GIS/Features/FeaturesList.tsx new file mode 100644 index 0000000000000..cbff20fd02922 --- /dev/null +++ b/apps/studio/components/interfaces/GIS/Features/FeaturesList.tsx @@ -0,0 +1,124 @@ +import { Search } from 'lucide-react' +import { partition } from 'lodash' +import { useRouter } from 'next/router' + +import { useParams } from 'common' +import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext' +import ProductEmptyState from 'components/to-be-cleaned/ProductEmptyState' +import Table from 'components/to-be-cleaned/Table' +import AlertError from 'components/ui/AlertError' +import SchemaSelector from 'components/ui/SchemaSelector' +import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader' +import { useGISFeaturesQuery } from 'data/gis/gis-features-query' +import { useSchemasQuery } from 'data/database/schemas-query' +import { useQuerySchemaState } from 'hooks/misc/useSchemaQueryState' +import { EXCLUDED_SCHEMAS } from 'lib/constants/schemas' +import { Input } from 'ui' +import ProtectedSchemaWarning from 'components/interfaces/Database/ProtectedSchemaWarning' +import FeatureList from './FeatureList' + +const FeaturesList = () => { + const { project } = useProjectContext() + const router = useRouter() + const { search } = useParams() + const { selectedSchema, setSelectedSchema } = useQuerySchemaState() + const filterString = search ?? '' + + const setFilterString = (str: string) => { + const url = new URL(document.URL) + if (str === '') { + url.searchParams.delete('search') + } else { + url.searchParams.set('search', str) + } + router.push(url) + } + + const { data: schemas } = useSchemasQuery({ + projectRef: project?.ref, + connectionString: project?.connectionString, + }) + const [protectedSchemas] = partition(schemas ?? [], (schema) => + EXCLUDED_SCHEMAS.includes(schema?.name ?? '') + ) + const foundSchema = schemas?.find((schema) => schema.name === selectedSchema) + const isLocked = protectedSchemas.some((s) => s.id === foundSchema?.id) + + const { + data: features, + error, + isLoading, + isError, + } = useGISFeaturesQuery({ + projectRef: project?.ref, + }) + + if (isLoading) return + if (isError) return + + return ( + <> + {(features ?? []).length == 0 ? ( +
+ +

+ 要素服务是基于数据库的矢量数据服务,用户可以查询和获取空间要素。 +

+
+
+ ) : ( +
+
+
+ { + const url = new URL(document.URL) + url.searchParams.delete('search') + router.push(url) + setSelectedSchema(schema) + }} + /> + } + value={filterString} + className="w-64" + onChange={(e) => setFilterString(e.target.value)} + /> +
+
+ + {isLocked && } + + + 服务 ID + + 服务描述 + + + + } + body={ + + } + /> + + )} + + ) +} + +export default FeaturesList diff --git a/apps/studio/components/interfaces/GIS/Tiles/TileList.tsx b/apps/studio/components/interfaces/GIS/Tiles/TileList.tsx index 637ae0106ffdb..8f8e0bc6fa23d 100644 --- a/apps/studio/components/interfaces/GIS/Tiles/TileList.tsx +++ b/apps/studio/components/interfaces/GIS/Tiles/TileList.tsx @@ -30,7 +30,7 @@ const TileList = ({ ) const _tiles = sortBy( filteredTiles.filter((x) => x.schema == schema), - (func) => func.name.toLocaleLowerCase() + (tile) => tile.name.toLocaleLowerCase() ) const { data, error } = useProjectApiQuery({ projectRef: selectedProject?.ref }) @@ -51,7 +51,7 @@ const TileList = ({ if (_tiles.length === 0 && filterString.length === 0) { return ( - +

未找到瓦片服务

在模式 "{schema}" 中未找到瓦片服务 @@ -64,7 +64,7 @@ const TileList = ({ if (_tiles.length === 0 && filterString.length > 0) { return ( - +

未找到结果

您搜索的 "{filterString}" 没有返回任何结果 @@ -91,19 +91,16 @@ const TileList = ({

无描述信息

)}
- -

{x.type}

-
diff --git a/apps/studio/components/interfaces/GIS/Tiles/TilesList.tsx b/apps/studio/components/interfaces/GIS/Tiles/TilesList.tsx index 0de914d9d8b5d..9a3c0e240c464 100644 --- a/apps/studio/components/interfaces/GIS/Tiles/TilesList.tsx +++ b/apps/studio/components/interfaces/GIS/Tiles/TilesList.tsx @@ -1,4 +1,5 @@ import { Search } from 'lucide-react' +import { partition } from 'lodash' import { useRouter } from 'next/router' import { useParams } from 'common' @@ -9,8 +10,11 @@ import AlertError from 'components/ui/AlertError' import SchemaSelector from 'components/ui/SchemaSelector' import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader' import { useGISTilesQuery } from 'data/gis/gis-tiles-query' +import { useSchemasQuery } from 'data/database/schemas-query' import { useQuerySchemaState } from 'hooks/misc/useSchemaQueryState' +import { EXCLUDED_SCHEMAS } from 'lib/constants/schemas' import { Input } from 'ui' +import ProtectedSchemaWarning from 'components/interfaces/Database/ProtectedSchemaWarning' import TileList from './TileList' const TilesList = () => { @@ -30,6 +34,16 @@ const TilesList = () => { router.push(url) } + const { data: schemas } = useSchemasQuery({ + projectRef: project?.ref, + connectionString: project?.connectionString, + }) + const [protectedSchemas] = partition(schemas ?? [], (schema) => + EXCLUDED_SCHEMAS.includes(schema?.name ?? '') + ) + const foundSchema = schemas?.find((schema) => schema.name === selectedSchema) + const isLocked = protectedSchemas.some((s) => s.id === foundSchema?.id) + const { data: tiles, error, @@ -81,17 +95,16 @@ const TilesList = () => { + {isLocked && } +
- 服务名称 + 服务 ID 服务描述 - - 数据源类型 - } diff --git a/apps/studio/components/interfaces/GIS/index.ts b/apps/studio/components/interfaces/GIS/index.ts index 92871071cd8d2..7dab982b2db8c 100644 --- a/apps/studio/components/interfaces/GIS/index.ts +++ b/apps/studio/components/interfaces/GIS/index.ts @@ -1 +1,2 @@ -export { default as TilesList } from './Tiles/TilesList' \ No newline at end of file +export { default as TilesList } from './Tiles/TilesList' +export { default as FeaturesList } from './Features/FeaturesList' \ No newline at end of file diff --git a/apps/studio/components/layouts/TableEditorLayout/TableEditorMenu.tsx b/apps/studio/components/layouts/TableEditorLayout/TableEditorMenu.tsx index f90023185471d..18f236678a011 100644 --- a/apps/studio/components/layouts/TableEditorLayout/TableEditorMenu.tsx +++ b/apps/studio/components/layouts/TableEditorLayout/TableEditorMenu.tsx @@ -157,7 +157,7 @@ const TableEditorMenu = () => {

- 此模式是系统模式,在表编辑器中只读 + 此模式是系统模式,在本界面中执行只读操作