From 06956f84a5699a66eb06d17c40ea4cc69e9fe836 Mon Sep 17 00:00:00 2001 From: Alex Hall Date: Fri, 25 Mar 2022 15:55:09 +0200 Subject: [PATCH] (core) Make Attachments columns get treated like RefLists more Summary: Treat the column type 'Attachments' as equivalent to 'RefList:_grist_Attachments' in a few places, because that's essentially what it is. The main goal was to fix parsing strings representing attachments (reflists). Also removed an unused function. Test Plan: Tested manually that pasting a CSV/JSON string representation of an attachments reflists works now. Reviewers: paulfitz Reviewed By: paulfitz Subscribers: paulfitz Differential Revision: https://phab.getgrist.com/D3338 --- app/common/ValueParser.ts | 1 + app/common/gristTypes.ts | 19 +++++++------------ 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/app/common/ValueParser.ts b/app/common/ValueParser.ts index df9b9535..f0781202 100644 --- a/app/common/ValueParser.ts +++ b/app/common/ValueParser.ts @@ -220,6 +220,7 @@ export const valueParserClasses: { [type: string]: typeof ValueParser } = { ChoiceList: ChoiceListParser, Ref: ReferenceParser, RefList: ReferenceListParser, + Attachments: ReferenceListParser, }; /** diff --git a/app/common/gristTypes.ts b/app/common/gristTypes.ts index 977014e7..79e48646 100644 --- a/app/common/gristTypes.ts +++ b/app/common/gristTypes.ts @@ -56,6 +56,9 @@ export function getDefaultForType(colType: string, options: {sqlFormatted?: bool * object. */ export function extractInfoFromColType(colType: string): GristTypeInfo { + if (colType === "Attachments") { + return {type: "RefList", tableId: "_grist_Attachments"}; + } 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)} : @@ -223,17 +226,6 @@ export function extractTypeFromColType(type: string): string { return (colon === -1 ? type : type.slice(0, colon)); } -/** - * Convert pureType to Grist python type name, e.g. 'Ref' to 'Reference'. - */ -export function getGristType(pureType: string): string { - switch (pureType) { - case 'Ref': return 'Reference'; - case 'RefList': return 'ReferenceList'; - default: return pureType; - } -} - /** * Enum for values of columns' recalcWhen property, corresponding to Python definitions in * schema.py. @@ -331,11 +323,14 @@ export function sequelizeToGristType(sqlType: string): GristType { } export function getReferencedTableId(type: string) { + if (type === "Attachments") { + return "_grist_Attachments"; + } return removePrefix(type, "Ref:") || removePrefix(type, "RefList:"); } export function isRefListType(type: string) { - return type.startsWith('RefList:'); + return type === "Attachments" || type.startsWith('RefList:'); } export function isFullReferencingType(type: string) {