gristlabs_grist-core/app/client/widgets/ReferenceList.ts
Alex Hall 04e5d90f86 (core) Barely working reference lists in frontend
Summary:
This makes it possible to set the type of a column to ReferenceList, but the UI is terrible

ReferenceList.ts is a mishmash of ChoiceList and Reference that sort of works but something about the CSS is clearly broken

ReferenceListEditor is just a text editor, you have to type in a JSON array of row IDs. Ignore the value that's present when you start editing. I can maybe try mashing together ReferenceEditor and ChoiceListEditor but it doesn't seem wise.
I think @georgegevoian should take over here. Reviewing the diff as it is to check for obvious issues is probably good but I don't think it's worth trying to land/merge anything.

Test Plan: none

Reviewers: dsagal

Reviewed By: dsagal

Subscribers: georgegevoian

Differential Revision: https://phab.getgrist.com/D2914
2021-07-23 18:41:44 +02:00

55 lines
2.1 KiB
TypeScript

import {DataRowModel} from 'app/client/models/DataRowModel';
import {testId} from 'app/client/ui2018/cssVars';
import {isList} from 'app/common/gristTypes';
import {dom} from 'grainjs';
import {cssChoiceList, cssToken} from "./ChoiceListCell";
import {Reference} from "./Reference";
import {choiceToken} from "./ChoiceToken";
/**
* ReferenceList - The widget for displaying lists of references to another table's records.
*/
export class ReferenceList extends Reference {
public buildDom(row: DataRowModel) {
return cssChoiceList(
dom.cls('field_clip'),
cssChoiceList.cls('-wrap', this.wrapping),
dom.style('justify-content', use => use(this.alignment) === 'right' ? 'flex-end' : use(this.alignment)),
dom.domComputed((use) => {
if (use(row._isAddRow) || this.isDisposed() || use(this.field.displayColModel).isDisposed()) {
// Work around JS errors during certain changes (noticed when visibleCol field gets removed
// for a column using per-field settings).
return null;
}
const value = row.cells[use(use(this.field.displayColModel).colId)];
if (!value) {
return null;
}
const content = use(value);
// if (isVersions(content)) { // TODO
// // We can arrive here if the reference value is unchanged (viewed as a foreign key)
// // but the content of its displayCol has changed. Postponing doing anything about
// // this until we have three-way information for computed columns. For now,
// // just showing one version of the cell. TODO: elaborate.
// return use(this._formatValue)(content[1].local || content[1].parent);
// }
const items = isList(content) ? content.slice(1) : [content];
return items.map(use(this._formatValue));
}, (input) => {
if (!input) {
return null;
}
return input.map(token =>
choiceToken(
String(token),
{}, // default colors
dom.cls(cssToken.className),
testId('ref-list-cell-token')
),
);
}),
);
}
}