mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(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:
@@ -11,6 +11,7 @@ import * as gristTypes from 'app/common/gristTypes';
|
||||
import {isFullReferencingType} from 'app/common/gristTypes';
|
||||
import * as gutil from 'app/common/gutil';
|
||||
import {TableData} from 'app/common/TableData';
|
||||
import {decodeObject} from 'app/plugin/objtypes';
|
||||
|
||||
export interface ColInfo {
|
||||
type: string;
|
||||
@@ -92,9 +93,11 @@ export async function prepTransformColInfo(docModel: DocModel, origCol: ColumnRe
|
||||
} else {
|
||||
// Set suggested choices. Limit to 100, since too many choices is more likely to cause
|
||||
// trouble than desired behavior. For many choices, recommend using a Ref to helper table.
|
||||
const columnData = tableData.getDistinctValues(origCol.colId(), 100);
|
||||
const colId = isReferenceCol(origCol) ? origDisplayCol.colId() : origCol.colId();
|
||||
const columnData = tableData.getDistinctValues(colId, 100);
|
||||
if (columnData) {
|
||||
columnData.delete("");
|
||||
columnData.delete(null);
|
||||
widgetOptions = {choices: Array.from(columnData, String)};
|
||||
}
|
||||
}
|
||||
@@ -108,8 +111,10 @@ export async function prepTransformColInfo(docModel: DocModel, origCol: ColumnRe
|
||||
// Set suggested choices. This happens before the conversion to ChoiceList, so we do some
|
||||
// light guessing for likely choices to suggest.
|
||||
const choices = new Set<string>();
|
||||
for (let value of tableData.getColValues(origCol.colId()) || []) {
|
||||
value = String(value).trim();
|
||||
const colId = isReferenceCol(origCol) ? origDisplayCol.colId() : origCol.colId();
|
||||
for (let value of tableData.getColValues(colId) || []) {
|
||||
if (value === null) { continue; }
|
||||
value = String(decodeObject(value)).trim();
|
||||
const tags: string[] = (value.startsWith('[') && gutil.safeJsonParse(value, null)) || value.split(",");
|
||||
for (const tag of tags) {
|
||||
choices.add(tag.trim());
|
||||
|
||||
Reference in New Issue
Block a user