From 956e07e877d5618dda176aedbce00c1bfee69ad5 Mon Sep 17 00:00:00 2001 From: Dmitry S Date: Fri, 5 Feb 2021 09:49:23 -0500 Subject: [PATCH] (core) When filter-linking by a reference column, update the filter-linking when the value in that column changes Test Plan: Added a test case for the fix. Reviewers: paulfitz Reviewed By: paulfitz Differential Revision: https://phab.getgrist.com/D2724 --- app/client/components/LinkingState.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/app/client/components/LinkingState.js b/app/client/components/LinkingState.js index f62681a6..76541e76 100644 --- a/app/client/components/LinkingState.js +++ b/app/client/components/LinkingState.js @@ -48,7 +48,8 @@ function isSummaryOf(summary, detail) { function LinkingState(gristDoc, srcSection, srcColId, tgtSection, tgtColId, byAllShown) { this._srcSection = srcSection; - let srcTableData = gristDoc.getTableModel(srcSection.table().tableId()).tableData; + let srcTableModel = gristDoc.getTableModel(srcSection.table().tableId()); + let srcTableData = srcTableModel.tableData; // Function from srcRowId (i.e. srcSection.activeRowId()) to the source value. It is used for // filtering or for cursor positioning, depending on the setting of tgtCol. @@ -78,11 +79,22 @@ function LinkingState(gristDoc, srcSection, srcColId, tgtSection, tgtColId, byAl } return {[tgtColId]: Array.from(srcValues)}; })); + } else if (srcColId) { + let srcRowModel = this.autoDispose(srcTableModel.createFloatingRowModel()); + let srcCell = srcRowModel.cells[srcColId]; + // If no srcCell, linking is broken; do nothing. This shouldn't happen, but may happen + // transiently while the separate linking-related observables get updated. + if (srcCell) { + this.filterColValues = this.autoDispose(ko.computed(() => { + const srcRowId = srcSection.activeRowId(); + srcRowModel.assign(srcRowId); + return {[tgtColId]: [srcCell()]}; + })); + } } else { this.filterColValues = this.autoDispose(ko.computed(() => { const srcRowId = srcSection.activeRowId(); - const srcValue = srcValueFunc(srcRowId); - return {[tgtColId]: [srcValue]}; + return {[tgtColId]: [srcRowId]}; })); } } else if (isSummaryOf(srcSection.table(), tgtSection.table())) {