(core) Filter linking by reference list columns

Summary:
Use 'intersects' query operation when linking against a RefList column, otherwise the rest is the same as linking with a Ref column.

Add RefList columns to Select By options along with Ref columns.

Test Plan: Added new test and fixture similar to SelectBySummary

Reviewers: dsagal

Reviewed By: dsagal

Differential Revision: https://phab.getgrist.com/D2986
This commit is contained in:
Alex Hall
2021-08-20 15:46:59 +02:00
parent 572b59cc0c
commit 54b932300b
2 changed files with 15 additions and 20 deletions

View File

@@ -2,6 +2,7 @@ const _ = require('underscore');
const ko = require('knockout');
const dispose = require('../lib/dispose');
const gutil = require('app/common/gutil');
const {isRefListType} = require("app/common/gristTypes");
/**
* Returns if the first table is a summary of the second. If both are summary tables, returns true
@@ -65,7 +66,10 @@ function LinkingState(gristDoc, srcSection, srcColId, tgtSection, tgtColId, byAl
// A computed that evaluates to a filter function to use, or null if not filtering. If
// filtering, depends on srcSection.activeRowId().
if (tgtColId) {
const tgtCol = tgtSection.table().columns().all().find(c => c.colId() === tgtColId);
const operations = {[tgtColId]: isRefListType(tgtCol.type()) ? 'intersects' : 'in'};
if (byAllShown) {
// (This is legacy code that isn't currently reachable)
// Include all values present in srcSection.
this.filterColValues = this.autoDispose(ko.computed(() => {
const srcValues = new Set();
@@ -88,13 +92,13 @@ function LinkingState(gristDoc, srcSection, srcColId, tgtSection, tgtColId, byAl
this.filterColValues = this.autoDispose(ko.computed(() => {
const srcRowId = srcSection.activeRowId();
srcRowModel.assign(srcRowId);
return {filters: {[tgtColId]: [srcCell()]}};
return {filters: {[tgtColId]: [srcCell()]}, operations};
}));
}
} else {
this.filterColValues = this.autoDispose(ko.computed(() => {
const srcRowId = srcSection.activeRowId();
return {filters: {[tgtColId]: [srcRowId]}};
return {filters: {[tgtColId]: [srcRowId]}, operations};
}));
}
} else if (isSummaryOf(srcSection.table(), tgtSection.table())) {