From e3a811d1a68c1dbe27e56b2be1e1dceef8f8610e Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 24 Dec 2024 01:24:52 +0100 Subject: [PATCH] More types --- .../src/components/grid/stores/datasource.ts | 14 +++++++------- packages/frontend-core/src/utils/relatedColumns.ts | 8 +++++--- packages/types/src/ui/stores/grid/table.ts | 2 +- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/datasource.ts b/packages/frontend-core/src/components/grid/stores/datasource.ts index 2d013fd23a..472f598299 100644 --- a/packages/frontend-core/src/components/grid/stores/datasource.ts +++ b/packages/frontend-core/src/components/grid/stores/datasource.ts @@ -18,13 +18,13 @@ import { DatasourceActions } from "./datasources" interface DatasourceStore { definition: Writable - schemaMutations: Writable> - subSchemaMutations: Writable> + schemaMutations: Writable> + subSchemaMutations: Writable> } interface DerivedDatasourceStore { - schema: Readable> - enrichedSchema: Readable> + schema: Readable | null> + enrichedSchema: Readable | null> hasBudibaseIdentifiers: Readable } @@ -100,9 +100,9 @@ export const deriveStores = (context: StoreContext): DerivedDatasourceStore => { const schemaWithRelatedColumns = enrichSchemaWithRelColumns($schema) const enrichedSchema: Record = {} - Object.keys(schemaWithRelatedColumns).forEach(field => { + Object.keys(schemaWithRelatedColumns || {}).forEach(field => { enrichedSchema[field] = { - ...schemaWithRelatedColumns[field], + ...schemaWithRelatedColumns?.[field], ...$schemaOverrides?.[field], ...$schemaMutations[field], } @@ -197,7 +197,7 @@ export const createActions = (context: StoreContext): ActionDatasourceStore => { // Update server if (get(config).canSaveSchema) { try { - await getAPI()?.actions.saveDefinition(newDefinition as any) + await getAPI()?.actions.saveDefinition(newDefinition) // Broadcast change so external state can be updated, as this change // will not be received by the builder websocket because we caused it diff --git a/packages/frontend-core/src/utils/relatedColumns.ts b/packages/frontend-core/src/utils/relatedColumns.ts index ed4ccf438d..07a9efe5d4 100644 --- a/packages/frontend-core/src/utils/relatedColumns.ts +++ b/packages/frontend-core/src/utils/relatedColumns.ts @@ -102,12 +102,14 @@ export function getRelatedTableValues( if (fromSingle) { result = row[field.related.field]?.[0]?.[field.related.subField] } else { - const parser = columnTypeManyParser[field.type] || ((value: any) => value) + const parser = + columnTypeManyParser[field.type as keyof typeof columnTypeManyParser] || + ((value: any) => value) const value = row[field.related.field] ?.flatMap((r: Row) => r[field.related.subField]) ?.filter((i: any) => i !== undefined && i !== null) - const parsed = parser(value || [], field) - result = parsed + const parsed = parser(value || [], field as any) + result = parsed as any if ( [ FieldType.STRING, diff --git a/packages/types/src/ui/stores/grid/table.ts b/packages/types/src/ui/stores/grid/table.ts index 8975ef4cfc..6160a05640 100644 --- a/packages/types/src/ui/stores/grid/table.ts +++ b/packages/types/src/ui/stores/grid/table.ts @@ -7,7 +7,7 @@ import { export type UIFieldSchema = FieldSchema & BasicViewFieldMetadata & { - related?: { field: string; subField: string } + related: { field: string; subField: string } columns?: Record cellRenderType?: string }