Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI: add tables as unique rows #935

Merged
merged 2 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading