(core) tolerate table renames when displaying differences

Summary:
This makes data diff rendering robust to changes in the names of tables.
It does not yet show information about those changes, but at least it
won't fail to show table content changes.

Added a missing case to ActionSummary concatenation that came up in
testing.

Test Plan: added test, updated test

Reviewers: dsagal

Reviewed By: dsagal

Differential Revision: https://phab.getgrist.com/D2661
This commit is contained in:
Paul Fitzpatrick
2020-11-12 10:35:15 -05:00
parent 6b582b9ace
commit f1842cd89e
4 changed files with 51 additions and 12 deletions

View File

@@ -233,3 +233,25 @@ export function getAffectedTables(summary: ActionSummary): string[] {
...Object.keys(summary.tableDeltas)
];
}
/**
* Given a tableId from after the specified renames, figure out what the tableId was before
* the renames. Returns null if table didn't exist.
*/
export function getTableIdBefore(renames: LabelDelta[], tableIdAfter: string|null): string|null {
if (tableIdAfter === null) { return tableIdAfter; }
const rename = renames.find(rename => rename[1] === tableIdAfter);
return rename ? rename[0] : tableIdAfter;
}
/**
* Given a tableId from before the specified renames, figure out what the tableId is after
* the renames. Returns null if there is no valid tableId to return.
*/
export function getTableIdAfter(renames: LabelDelta[], tableIdBefore: string|null): string|null {
if (tableIdBefore === null) { return tableIdBefore; }
const rename = renames.find(rename => rename[0] === tableIdBefore);
const tableIdAfter = rename ? rename[1] : tableIdBefore;
if (tableIdAfter?.startsWith('-')) { return null; }
return tableIdAfter;
}