(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
This commit is contained in:
Alex Hall
2021-07-23 17:29:35 +02:00
parent 8d68c1c567
commit 04e5d90f86
17 changed files with 228 additions and 41 deletions

View File

@@ -1,5 +1,6 @@
import { CellValue, CellVersions } from 'app/common/DocActions';
import isString = require('lodash/isString');
import {removePrefix} from "./gutil";
// tslint:disable:object-literal-key-quotes
@@ -10,7 +11,8 @@ export type GristType = 'Any' | 'Attachments' | 'Blob' | 'Bool' | 'Choice' | 'Ch
export type GristTypeInfo =
{type: 'DateTime', timezone: string} |
{type: 'Ref', tableId: string} |
{type: Exclude<GristType, 'DateTime'|'Ref'>};
{type: 'RefList', tableId: string} |
{type: Exclude<GristType, 'DateTime'|'Ref'|'RefList'>};
// Letter codes for CellValue types encoded as [code, args...] tuples.
@@ -76,6 +78,7 @@ export function extractInfoFromColType(colType: string): GristTypeInfo {
const colon = colType.indexOf(':');
const [type, arg] = (colon === -1) ? [colType] : [colType.slice(0, colon), colType.slice(colon + 1)];
return (type === 'Ref') ? {type, tableId: String(arg)} :
(type === 'RefList') ? {type, tableId: String(arg)} :
(type === 'DateTime') ? {type, timezone: String(arg)} :
{type} as GristTypeInfo;
}
@@ -321,3 +324,11 @@ export function sequelizeToGristType(sqlType: string): GristType {
throw new Error('Unrecognized datatype: `' + sqlType + '`');
}
}
export function getReferencedTableId(type: string) {
return removePrefix(type, "Ref:") || removePrefix(type, "RefList:");
}
export function isFullReferencingType(type: string) {
return type.startsWith('Ref:') || type.startsWith('RefList:');
}