(core) Fix reporting of errors when saving cells by clicking away, and deduplicate memos.

Test Plan: Enhanced the test case for memos to check these cases too (fails without this fix).

Reviewers: paulfitz

Reviewed By: paulfitz

Differential Revision: https://phab.getgrist.com/D2876
This commit is contained in:
Dmitry S 2021-06-22 18:19:28 -04:00
parent 7a0cd6c2b4
commit 6240fd6982
2 changed files with 11 additions and 3 deletions

View File

@ -443,8 +443,10 @@ function setupReadonlyEditorCleanup(
* - Arrange for UnsavedChange protection against leaving the page with unsaved changes. * - Arrange for UnsavedChange protection against leaving the page with unsaved changes.
*/ */
function setupEditorCleanup( function setupEditorCleanup(
owner: MultiHolder, gristDoc: GristDoc, field: ViewFieldRec, saveEdit: () => Promise<unknown> owner: MultiHolder, gristDoc: GristDoc, field: ViewFieldRec, _saveEdit: () => Promise<unknown>
) { ) {
const saveEdit = () => _saveEdit().catch(reportError);
// Whenever focus returns to the Clipboard component, close the editor by saving the value. // Whenever focus returns to the Clipboard component, close the editor by saving the value.
gristDoc.app.on('clipboard_focus', saveEdit); gristDoc.app.on('clipboard_focus', saveEdit);

View File

@ -25,11 +25,17 @@ export type PermissionSetWithContext = PermissionSetWithContextOf<PermissionSet<
// Accumulator for memos of relevant rules. // Accumulator for memos of relevant rules.
export type MemoSet = PermissionSet<string[]>; export type MemoSet = PermissionSet<string[]>;
// Merge MemoSets straightforwardly, by concatenation. // Merge MemoSets by collecting all memos with de-duplication.
export function mergeMemoSets(psets: MemoSet[]): MemoSet { export function mergeMemoSets(psets: MemoSet[]): MemoSet {
const result: Partial<MemoSet> = {}; const result: Partial<MemoSet> = {};
for (const prop of ALL_PERMISSION_PROPS) { for (const prop of ALL_PERMISSION_PROPS) {
result[prop] = ([] as string[]).concat(...psets.map(p => p[prop])); const merged = new Set<string>();
for (const p of psets) {
for (const memo of p[prop]) {
merged.add(memo);
}
}
result[prop] = [...merged];
} }
return result as MemoSet; return result as MemoSet;
} }