From e20f898cee8355f474e7235b8c64797bc243ae8c Mon Sep 17 00:00:00 2001 From: Amogh-Bharadwaj Date: Fri, 29 Dec 2023 22:42:04 +0530 Subject: [PATCH] tablepicker: insert as unique rows --- ui/app/mirrors/create/cdc/schemabox.tsx | 17 ++++------ ui/app/mirrors/create/cdc/tablemapping.tsx | 38 ++++++++++++---------- ui/package-lock.json | 1 + ui/package.json | 1 + 4 files changed, 28 insertions(+), 29 deletions(-) diff --git a/ui/app/mirrors/create/cdc/schemabox.tsx b/ui/app/mirrors/create/cdc/schemabox.tsx index d9b15a703c..b725663c30 100644 --- a/ui/app/mirrors/create/cdc/schemabox.tsx +++ b/ui/app/mirrors/create/cdc/schemabox.tsx @@ -7,6 +7,7 @@ import { Label } from '@/lib/Label'; import { RowWithCheckbox } from '@/lib/Layout'; import { SearchField } from '@/lib/SearchField'; import { TextField } from '@/lib/TextField'; +import _ from 'lodash'; import { Dispatch, SetStateAction, @@ -43,9 +44,6 @@ const SchemaBox = ({ const [columnsLoading, setColumnsLoading] = useState(false); const [expandedSchemas, setExpandedSchemas] = useState([]); const [tableQuery, setTableQuery] = useState(''); - const [schemaLoadedSet, setSchemaLoadedSet] = useState>( - new Set() - ); const [handlingAll, setHandlingAll] = useState(false); @@ -136,14 +134,11 @@ const SchemaBox = ({ const handleSchemaClick = (schemaName: string) => { if (!schemaIsExpanded(schemaName)) { setExpandedSchemas((curr) => [...curr, schemaName]); - if (!schemaLoadedSet.has(schemaName)) { - setTablesLoading(true); - setSchemaLoadedSet((loaded) => new Set(loaded).add(schemaName)); - fetchTables(sourcePeer, schemaName, peerType).then((tableRows) => { - setRows((value) => [...value, ...tableRows]); - setTablesLoading(false); - }); - } + setTablesLoading(true); + fetchTables(sourcePeer, schemaName, peerType).then((tableRows) => { + setRows((value) => _.uniqWith([...value, ...tableRows], _.isEqual)); + setTablesLoading(false); + }); } else { setExpandedSchemas((curr) => curr.filter((expandedSchema) => expandedSchema != schemaName) diff --git a/ui/app/mirrors/create/cdc/tablemapping.tsx b/ui/app/mirrors/create/cdc/tablemapping.tsx index 2cccea321f..d231812319 100644 --- a/ui/app/mirrors/create/cdc/tablemapping.tsx +++ b/ui/app/mirrors/create/cdc/tablemapping.tsx @@ -2,7 +2,7 @@ import { DBType } from '@/grpc_generated/peers'; import { Label } from '@/lib/Label'; import { SearchField } from '@/lib/SearchField'; -import { Dispatch, SetStateAction, useEffect, useState } from 'react'; +import { Dispatch, SetStateAction, useEffect, useMemo, useState } from 'react'; import { BarLoader } from 'react-spinners/'; import { TableMapRow } from '../../../dto/MirrorsDTO'; import { fetchSchemas } from '../handlers'; @@ -27,6 +27,12 @@ const TableMapping = ({ const [tableColumns, setTableColumns] = useState< { tableName: string; columns: string[] }[] >([]); + const searchedSchemas = useMemo(() => { + return allSchemas?.filter((schema) => { + return schema.toLowerCase().includes(schemaQuery.toLowerCase()); + }); + }, [allSchemas, schemaQuery]); + useEffect(() => { fetchSchemas(sourcePeerName).then((res) => setAllSchemas(res)); }, [sourcePeerName]); @@ -56,23 +62,19 @@ const TableMapping = ({
- {allSchemas ? ( - allSchemas - ?.filter((schema) => { - return schema.toLowerCase().includes(schemaQuery.toLowerCase()); - }) - .map((schema) => ( - - )) + {searchedSchemas ? ( + searchedSchemas.map((schema) => ( + + )) ) : (
diff --git a/ui/package-lock.json b/ui/package-lock.json index 45aa54a55f..95ec8b2676 100644 --- a/ui/package-lock.json +++ b/ui/package-lock.json @@ -31,6 +31,7 @@ "@types/react-dom": "^18.2.18", "classnames": "^2.3.3", "clsx": "^2.0.0", + "lodash": "^4.17.21", "long": "^5.2.3", "lucide-react": "^0.302.0", "material-symbols": "^0.14.3", diff --git a/ui/package.json b/ui/package.json index 84155f6e23..677d47a061 100644 --- a/ui/package.json +++ b/ui/package.json @@ -37,6 +37,7 @@ "@types/react-dom": "^18.2.18", "classnames": "^2.3.3", "clsx": "^2.0.0", + "lodash": "^4.17.21", "long": "^5.2.3", "lucide-react": "^0.302.0", "material-symbols": "^0.14.3",