diff --git a/app/client/components/LinkingState.js b/app/client/components/LinkingState.js index 272c53f6..ddce580c 100644 --- a/app/client/components/LinkingState.js +++ b/app/client/components/LinkingState.js @@ -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())) { diff --git a/app/client/ui/selectBy.ts b/app/client/ui/selectBy.ts index 3af1e011..bcbaa082 100644 --- a/app/client/ui/selectBy.ts +++ b/app/client/ui/selectBy.ts @@ -1,6 +1,6 @@ -import { ColumnRec, DocModel, ViewSectionRec } from 'app/client/models/DocModel'; +import { ColumnRec, DocModel, TableRec, ViewSectionRec } from 'app/client/models/DocModel'; import { IPageWidget } from 'app/client/ui/PageWidgetPicker'; -import { removePrefix } from 'app/common/gutil'; +import { getReferencedTableId } from 'app/common/gristTypes'; import { IOptionFull } from 'grainjs'; // some unicode characters @@ -150,7 +150,6 @@ function createNodes(docModel: DocModel, sections: MaybeSection[]) { // Creates an array of LinkNode from a view section record. function fromViewSectionRec(section: ViewSectionRec): LinkNode[] { const table = section.table.peek(); - const columns = table.columns.peek().peek(); const ancestors = new Set(); for (let sec = section; sec.getRowId(); sec = sec.linkSrcSection.peek()) { @@ -170,16 +169,7 @@ function fromViewSectionRec(section: ViewSectionRec): LinkNode[] { section, }; - const nodes: LinkNode[] = [mainNode]; - - // add the column nodes - for (const column of columns) { - const tableId = removePrefix(column.type.peek(), 'Ref:'); - if (tableId) { - nodes.push({...mainNode, tableId, column}); - } - } - return nodes; + return fromColumns(table, mainNode); } // Creates an array of LinkNode from a page widget. @@ -188,7 +178,6 @@ function fromPageWidget(docModel: DocModel, pageWidget: IPageWidget): LinkNode[] if (typeof pageWidget.table !== 'number') { return []; } const table = docModel.tables.getRowModel(pageWidget.table); - const columns = table.columns.peek().peek(); const mainNode: LinkNode = { tableId: table.primaryTableId.peek(), @@ -198,16 +187,18 @@ function fromPageWidget(docModel: DocModel, pageWidget: IPageWidget): LinkNode[] section: docModel.viewSections.getRowModel(pageWidget.section), }; - const nodes: LinkNode[] = [mainNode]; + return fromColumns(table, mainNode); +} - // adds the column nodes +function fromColumns(table: TableRec, mainNode: LinkNode): LinkNode[] { + const nodes = [mainNode]; + const columns = table.columns.peek().peek(); for (const column of columns) { - const tableId = removePrefix(column.type.peek(), 'Ref:'); + const tableId = getReferencedTableId(column.type.peek()); if (tableId) { nodes.push({...mainNode, tableId, column}); } } - return nodes; }