Skip to content

Commit

Permalink
Avoid mutating react state, change exclude from string[] to Set<string>
Browse files Browse the repository at this point in the history
Also have /mirrors/errors link to /mirrors/edit
  • Loading branch information
serprex committed Jan 24, 2024
1 parent 23a97b1 commit c98077e
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 25 deletions.
2 changes: 1 addition & 1 deletion ui/app/dto/MirrorsDTO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export type TableMapRow = {
source: string;
destination: string;
partitionKey: string;
exclude: string[];
exclude: Set<string>;
selected: boolean;
canMirror: boolean;
};
Expand Down
19 changes: 11 additions & 8 deletions ui/app/mirrors/create/cdc/columnbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 4 additions & 8 deletions ui/app/mirrors/create/cdc/schemabox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ const SchemaBox = ({
const [expandedSchemas, setExpandedSchemas] = useState<string[]>([]);
const [tableQuery, setTableQuery] = useState<string>('');

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

const searchedTables = useMemo(() => {
const tableQueryLower = tableQuery.toLowerCase();
return rows
Expand Down Expand Up @@ -125,17 +123,16 @@ const SchemaBox = ({
e: React.MouseEvent<HTMLInputElement, MouseEvent>,
schemaName: string
) => {
setHandlingAll(true);
const newRows = [...rows];
for (const row of newRows) {
for (let i=0; i<newRows.length; i++) {
const row = newRows[i];
if (row.schema === schemaName) {
row.selected = e.currentTarget.checked;
newRows[i] = { ...row, selected: e.currentTarget.checked };
if (e.currentTarget.checked) addTableColumns(row.source);
else removeTableColumns(row.source);
}
}
setRows(newRows);
setHandlingAll(false);
};

const rowsDoNotHaveSchemaTables = (schema: string) => {
Expand Down Expand Up @@ -199,8 +196,7 @@ const SchemaBox = ({
</div>
</div>
{/* TABLE BOX */}
{handlingAll && <BarLoader />}
{!handlingAll && schemaIsExpanded(schema) && (
{schemaIsExpanded(schema) && (
<div className='ml-5 mt-3' style={{ width: '90%' }}>
{searchedTables.length ? (
searchedTables.map((row) => {
Expand Down
4 changes: 2 additions & 2 deletions ui/app/mirrors/create/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};
}
})
Expand Down Expand Up @@ -306,7 +306,7 @@ export const fetchTables = async (
source: `${schemaName}.${tableObject.tableName}`,
destination: dstName,
partitionKey: '',
exclude: [],
exclude: new Set(),
selected: false,
canMirror: tableObject.canMirror,
});
Expand Down
4 changes: 2 additions & 2 deletions ui/app/mirrors/create/mirrorcards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const MirrorCards = ({
borderRadius: '1rem',
}}
>
<div>
<label style={{ display: 'block' }}>
<RowWithRadiobutton
label={
<Label>
Expand All @@ -70,7 +70,7 @@ const MirrorCards = ({
<Label>
<div style={{ fontSize: 14 }}>{card.description}</div>
</Label>
</div>
</label>
<Label
as={Link}
target='_blank'
Expand Down
2 changes: 1 addition & 1 deletion ui/app/mirrors/create/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const tableMappingSchema = z
destinationTableIdentifier: z
.string()
.min(1, 'destination table names, if added, must be non-empty'),
exclude: z.array(z.string()).optional(),
exclude: z.set(z.string()).optional(),
partitionKey: z.string().optional(),
})
)
Expand Down
6 changes: 5 additions & 1 deletion ui/app/mirrors/errors/[mirrorName]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ export default function MirrorError() {
<Label variant='body'>
<b>Mirror name</b>:
</Label>
<Label variant='body'>{params.mirrorName}</Label>
<Label variant='body'>
<a href={`/mirrors/edit/${params.mirrorName}`}>
{params.mirrorName}
</a>
</Label>

<div>
<Label as='label' style={{ fontSize: 14, marginTop: '1rem' }}>
Expand Down
3 changes: 1 addition & 2 deletions ui/app/mirrors/status/qrep/[mirrorId]/qrepStatusTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ export default function QRepStatusTable({
);
const [sortDir, setSortDir] = useState<'asc' | 'dsc'>('dsc');
const displayedPartitions = useMemo(() => {
let currentPartitions = [...visiblePartitions];
currentPartitions = currentPartitions.filter(
const currentPartitions = visiblePartitions.filter(
(partition: QRepPartitionStatus) => {
return partition.partitionId
.toLowerCase()
Expand Down

0 comments on commit c98077e

Please sign in to comment.