From c98077e8a75c5a6c4c8ea0decb74ecc3f015c2d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20Dub=C3=A9?= Date: Thu, 18 Jan 2024 05:30:45 +0000 Subject: [PATCH] Avoid mutating react state, change exclude from string[] to Set Also have /mirrors/errors link to /mirrors/edit --- ui/app/dto/MirrorsDTO.ts | 2 +- ui/app/mirrors/create/cdc/columnbox.tsx | 19 +++++++++++-------- ui/app/mirrors/create/cdc/schemabox.tsx | 12 ++++-------- ui/app/mirrors/create/handlers.ts | 4 ++-- ui/app/mirrors/create/mirrorcards.tsx | 4 ++-- ui/app/mirrors/create/schema.ts | 2 +- ui/app/mirrors/errors/[mirrorName]/page.tsx | 6 +++++- .../qrep/[mirrorId]/qrepStatusTable.tsx | 3 +-- 8 files changed, 27 insertions(+), 25 deletions(-) diff --git a/ui/app/dto/MirrorsDTO.ts b/ui/app/dto/MirrorsDTO.ts index f76904b08d..33234a557d 100644 --- a/ui/app/dto/MirrorsDTO.ts +++ b/ui/app/dto/MirrorsDTO.ts @@ -23,7 +23,7 @@ export type TableMapRow = { source: string; destination: string; partitionKey: string; - exclude: string[]; + exclude: Set; selected: boolean; canMirror: boolean; }; diff --git a/ui/app/mirrors/create/cdc/columnbox.tsx b/ui/app/mirrors/create/cdc/columnbox.tsx index b68560419f..f017edfa8c 100644 --- a/ui/app/mirrors/create/cdc/columnbox.tsx +++ b/ui/app/mirrors/create/cdc/columnbox.tsx @@ -23,18 +23,21 @@ export default function ColumnBox({ include: boolean ) => { const currRows = [...rows]; - const rowOfSource = currRows.find((row) => row.source === source); - if (rowOfSource) { + const rowIndex = currRows.findIndex((row) => row.source === source); + if (rowIndex !== -1) { + const sourceRow = currRows[rowIndex], + newExclude = new Set(sourceRow.exclude); if (include) { - const updatedExclude = rowOfSource.exclude.filter( - (col) => col !== column - ); - rowOfSource.exclude = updatedExclude; + newExclude.delete(column); } else { - rowOfSource.exclude.push(column); + newExclude.add(column); } + currRows[rowIndex] = { + ...sourceRow, + exclude: newExclude, + }; + setRows(currRows); } - setRows(currRows); }; const columnExclusion = new Set(tableRow.exclude); diff --git a/ui/app/mirrors/create/cdc/schemabox.tsx b/ui/app/mirrors/create/cdc/schemabox.tsx index 34c49c0b16..7e09767c4f 100644 --- a/ui/app/mirrors/create/cdc/schemabox.tsx +++ b/ui/app/mirrors/create/cdc/schemabox.tsx @@ -50,8 +50,6 @@ const SchemaBox = ({ const [expandedSchemas, setExpandedSchemas] = useState([]); const [tableQuery, setTableQuery] = useState(''); - const [handlingAll, setHandlingAll] = useState(false); - const searchedTables = useMemo(() => { const tableQueryLower = tableQuery.toLowerCase(); return rows @@ -125,17 +123,16 @@ const SchemaBox = ({ e: React.MouseEvent, schemaName: string ) => { - setHandlingAll(true); const newRows = [...rows]; - for (const row of newRows) { + for (let i=0; i { @@ -199,8 +196,7 @@ const SchemaBox = ({ {/* TABLE BOX */} - {handlingAll && } - {!handlingAll && schemaIsExpanded(schema) && ( + {schemaIsExpanded(schema) && (
{searchedTables.length ? ( searchedTables.map((row) => { diff --git a/ui/app/mirrors/create/handlers.ts b/ui/app/mirrors/create/handlers.ts index 00dab7347b..34d9aa2106 100644 --- a/ui/app/mirrors/create/handlers.ts +++ b/ui/app/mirrors/create/handlers.ts @@ -149,7 +149,7 @@ const reformattedTableMapping = (tableMapping: TableMapRow[]) => { sourceTableIdentifier: row.source, destinationTableIdentifier: row.destination, partitionKey: row.partitionKey, - exclude: row.exclude, + exclude: Array.from(row.exclude), }; } }) @@ -306,7 +306,7 @@ export const fetchTables = async ( source: `${schemaName}.${tableObject.tableName}`, destination: dstName, partitionKey: '', - exclude: [], + exclude: new Set(), selected: false, canMirror: tableObject.canMirror, }); diff --git a/ui/app/mirrors/create/mirrorcards.tsx b/ui/app/mirrors/create/mirrorcards.tsx index 9e781324f1..5816fbaee5 100644 --- a/ui/app/mirrors/create/mirrorcards.tsx +++ b/ui/app/mirrors/create/mirrorcards.tsx @@ -58,7 +58,7 @@ const MirrorCards = ({ borderRadius: '1rem', }} > -
+
+ - +