(core) Polish and enable Reference List widget

Summary:
Adds Reference List as a widget type.

Reference List is similar to Choice List: multiple references can be added
to each cell through a similar editor, and the individual references
will always reflect their current value from the referenced table.

Test Plan: Browser tests.

Reviewers: dsagal

Reviewed By: dsagal

Subscribers: paulfitz, jarek, alexmojaki, dsagal

Differential Revision: https://phab.getgrist.com/D2959
This commit is contained in:
George Gevoian
2021-08-12 11:06:40 -07:00
parent 34e9ad3498
commit 79f6f605f8
16 changed files with 594 additions and 93 deletions

View File

@@ -1,7 +1,7 @@
import { CellValue } from "app/common/DocActions";
import { FilterState, makeFilterState } from "app/common/FilterState";
import { decodeObject } from "app/plugin/objtypes";
import { isList } from "./gristTypes";
import { isList, isRefListType } from "./gristTypes";
export type ColumnFilterFunc = (value: CellValue) => boolean;
@@ -13,7 +13,7 @@ export function makeFilterFunc({ include, values }: FilterState,
// For example, a TypeError in the formula column and the string '["E","TypeError"]' would be seen as the same.
// TODO: This narrow corner case seems acceptable for now, but may be worth revisiting.
return (val: CellValue) => {
if (isList(val) && columnType === 'ChoiceList') {
if (isList(val) && (columnType === 'ChoiceList' || isRefListType(String(columnType)))) {
const list = decodeObject(val) as unknown[];
return list.some(item => values.has(item as any) === include);
}

View File

@@ -329,6 +329,10 @@ export function getReferencedTableId(type: string) {
return removePrefix(type, "Ref:") || removePrefix(type, "RefList:");
}
export function isFullReferencingType(type: string) {
return type.startsWith('Ref:') || type.startsWith('RefList:');
export function isRefListType(type: string) {
return type.startsWith('RefList:');
}
export function isFullReferencingType(type: string) {
return type.startsWith('Ref:') || isRefListType(type);
}