Skip to content

Commit

Permalink
UI: add tables as unique rows (#935)
Browse files Browse the repository at this point in the history
Removes the business of checking if we've expanded a schema and then
inserting rows or not
Simpler: uses lodash functions to attain a unique array of objects while
inserting table rows on schema expand
  • Loading branch information
Amogh-Bharadwaj authored Dec 29, 2023
1 parent 7e30827 commit c67f605
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 25 deletions.
18 changes: 11 additions & 7 deletions ui/app/mirrors/create/cdc/schemabox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,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 @@ -133,14 +130,21 @@ const SchemaBox = ({
setHandlingAll(false);
};

const rowsDoNotHaveSchemaTables = (schema: string) => {
return !rows.some((row) => row.schema === schema);
};

const handleSchemaClick = (schemaName: string) => {
if (!schemaIsExpanded(schemaName)) {
setExpandedSchemas((curr) => [...curr, schemaName]);
if (!schemaLoadedSet.has(schemaName)) {

if (rowsDoNotHaveSchemaTables(schemaName)) {
setTablesLoading(true);
setSchemaLoadedSet((loaded) => new Set(loaded).add(schemaName));
fetchTables(sourcePeer, schemaName, peerType).then((tableRows) => {
setRows((value) => [...value, ...tableRows]);
fetchTables(sourcePeer, schemaName, peerType).then((newRows) => {
setRows((oldRows) => [
...oldRows.filter((oldRow) => oldRow.schema !== schema),
...newRows,
]);
setTablesLoading(false);
});
}
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

0 comments on commit c67f605

Please sign in to comment.