Skip to content

Commit

Permalink
tablepicker: insert as unique rows
Browse files Browse the repository at this point in the history
  • Loading branch information
Amogh-Bharadwaj committed Dec 29, 2023
1 parent d8a0d0f commit e20f898
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 29 deletions.
17 changes: 6 additions & 11 deletions ui/app/mirrors/create/cdc/schemabox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -43,9 +44,6 @@ const SchemaBox = ({
const [columnsLoading, setColumnsLoading] = useState(false);
const [expandedSchemas, setExpandedSchemas] = useState<string[]>([]);
const [tableQuery, setTableQuery] = useState<string>('');
const [schemaLoadedSet, setSchemaLoadedSet] = useState<Set<string>>(
new Set()
);

const [handlingAll, setHandlingAll] = useState(false);

Expand Down Expand Up @@ -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)
Expand Down
38 changes: 20 additions & 18 deletions ui/app/mirrors/create/cdc/tablemapping.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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]);
Expand Down Expand Up @@ -56,23 +62,19 @@ const TableMapping = ({
</div>
</div>
<div style={{ maxHeight: '70vh', overflow: 'scroll' }}>
{allSchemas ? (
allSchemas
?.filter((schema) => {
return schema.toLowerCase().includes(schemaQuery.toLowerCase());
})
.map((schema) => (
<SchemaBox
key={schema}
schema={schema}
sourcePeer={sourcePeerName}
rows={rows}
setRows={setRows}
tableColumns={tableColumns}
setTableColumns={setTableColumns}
peerType={peerType}
/>
))
{searchedSchemas ? (
searchedSchemas.map((schema) => (
<SchemaBox
key={schema}
schema={schema}
sourcePeer={sourcePeerName}
rows={rows}
setRows={setRows}
tableColumns={tableColumns}
setTableColumns={setTableColumns}
peerType={peerType}
/>
))
) : (
<div style={loaderContainer}>
<BarLoader color='#36d7b7' width='40%' />
Expand Down
1 change: 1 addition & 0 deletions ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit e20f898

Please sign in to comment.