From 90b663912585f11f02a2394c1e4b7f28c1b09cde Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 23 Dec 2024 09:33:55 +0100 Subject: [PATCH 01/27] Extract action interface --- .../grid/stores/datasources/index.ts | 19 +++++++++++++++++++ .../grid/stores/datasources/nonPlus.ts | 11 ++--------- .../grid/stores/datasources/table.ts | 12 ++---------- .../grid/stores/datasources/viewV2.ts | 11 ++--------- 4 files changed, 25 insertions(+), 28 deletions(-) create mode 100644 packages/frontend-core/src/components/grid/stores/datasources/index.ts diff --git a/packages/frontend-core/src/components/grid/stores/datasources/index.ts b/packages/frontend-core/src/components/grid/stores/datasources/index.ts new file mode 100644 index 0000000000..1d1a2103b1 --- /dev/null +++ b/packages/frontend-core/src/components/grid/stores/datasources/index.ts @@ -0,0 +1,19 @@ +import { + Row, + SaveRowRequest, + SaveTableRequest, + UIDatasource, + UpdateViewRequest, +} from "@budibase/types" + +export interface DatasourceActions< + TSaveDefinitionRequest = UpdateViewRequest | SaveTableRequest +> { + saveDefinition: (newDefinition: TSaveDefinitionRequest) => Promise + addRow: (row: SaveRowRequest) => Promise + updateRow: (row: SaveRowRequest) => Promise + deleteRows: (rows: (string | Row)[]) => Promise + getRow: (id: string) => Promise + isDatasourceValid: (datasource: UIDatasource) => boolean + canUseColumn: (name: string) => boolean +} diff --git a/packages/frontend-core/src/components/grid/stores/datasources/nonPlus.ts b/packages/frontend-core/src/components/grid/stores/datasources/nonPlus.ts index dcc4d47076..2ea5a05a0e 100644 --- a/packages/frontend-core/src/components/grid/stores/datasources/nonPlus.ts +++ b/packages/frontend-core/src/components/grid/stores/datasources/nonPlus.ts @@ -1,18 +1,11 @@ import { SortOrder, UIDatasource } from "@budibase/types" import { get } from "svelte/store" import { Store as StoreContext } from ".." +import { DatasourceActions } from "." interface NonPlusActions { nonPlus: { - actions: { - saveDefinition: () => Promise - addRow: () => Promise - updateRow: () => Promise - deleteRows: () => Promise - getRow: () => Promise - isDatasourceValid: (datasource: UIDatasource) => boolean - canUseColumn: (name: string) => boolean - } + actions: DatasourceActions } } diff --git a/packages/frontend-core/src/components/grid/stores/datasources/table.ts b/packages/frontend-core/src/components/grid/stores/datasources/table.ts index e905c89e44..9f1a490306 100644 --- a/packages/frontend-core/src/components/grid/stores/datasources/table.ts +++ b/packages/frontend-core/src/components/grid/stores/datasources/table.ts @@ -1,27 +1,19 @@ import { Row, SaveRowRequest, - SaveRowResponse, SaveTableRequest, SortOrder, UIDatasource, } from "@budibase/types" import { get } from "svelte/store" import { Store as StoreContext } from ".." +import { DatasourceActions } from "." const SuppressErrors = true interface TableActions { table: { - actions: { - saveDefinition: (newDefinition: SaveTableRequest) => Promise - addRow: (row: SaveRowRequest) => Promise - updateRow: (row: SaveRowRequest) => Promise - deleteRows: (rows: (string | Row)[]) => Promise - getRow: (id: string) => Promise - isDatasourceValid: (datasource: UIDatasource) => boolean - canUseColumn: (name: string) => boolean - } + actions: DatasourceActions } } diff --git a/packages/frontend-core/src/components/grid/stores/datasources/viewV2.ts b/packages/frontend-core/src/components/grid/stores/datasources/viewV2.ts index 677a85312f..70a83b4594 100644 --- a/packages/frontend-core/src/components/grid/stores/datasources/viewV2.ts +++ b/packages/frontend-core/src/components/grid/stores/datasources/viewV2.ts @@ -7,20 +7,13 @@ import { UpdateViewRequest, } from "@budibase/types" import { Store as StoreContext } from ".." +import { DatasourceActions } from "." const SuppressErrors = true interface ViewActions { viewV2: { - actions: { - saveDefinition: (newDefinition: UpdateViewRequest) => Promise - addRow: (row: SaveRowRequest) => Promise - updateRow: (row: SaveRowRequest) => Promise - deleteRows: (rows: (string | Row)[]) => Promise - getRow: (id: string) => Promise - isDatasourceValid: (datasource: UIDatasource) => boolean - canUseColumn: (name: string) => boolean - } + actions: DatasourceActions } } From 10979c43f7b15abf36379efc25a9ad4d052d05c8 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 23 Dec 2024 09:40:23 +0100 Subject: [PATCH 02/27] Initial typing --- .../stores/{datasource.js => datasource.ts} | 67 ++++++++++++++----- .../src/components/grid/stores/index.ts | 8 ++- .../types/src/ui/stores/grid/datasource.ts | 7 ++ 3 files changed, 65 insertions(+), 17 deletions(-) rename packages/frontend-core/src/components/grid/stores/{datasource.js => datasource.ts} (80%) diff --git a/packages/frontend-core/src/components/grid/stores/datasource.js b/packages/frontend-core/src/components/grid/stores/datasource.ts similarity index 80% rename from packages/frontend-core/src/components/grid/stores/datasource.js rename to packages/frontend-core/src/components/grid/stores/datasource.ts index 6aa607f7ed..8fda936d04 100644 --- a/packages/frontend-core/src/components/grid/stores/datasource.js +++ b/packages/frontend-core/src/components/grid/stores/datasource.ts @@ -1,10 +1,47 @@ -import { derived, get } from "svelte/store" +import { derived, get, Readable, Writable } from "svelte/store" import { getDatasourceDefinition, getDatasourceSchema } from "../../../fetch" import { enrichSchemaWithRelColumns, memo } from "../../../utils" import { cloneDeep } from "lodash" -import { ViewV2Type } from "@budibase/types" +import { + FieldSchema, + SaveTableRequest, + UIDatasource, + UpdateViewRequest, + ViewV2Type, +} from "@budibase/types" +import { Store as StoreContext } from "." +import { DatasourceActions } from "./datasources" -export const createStores = () => { +interface DatasourceStore { + definition: Writable + schemaMutations: Writable> + subSchemaMutations: Writable> +} + +interface DerivedDatasourceStore { + schema: Readable> + enrichedSchema: Readable> + hasBudibaseIdentifiers: Readable +} + +interface ActionDatasourceStore { + datasource: DatasourceStore["definition"] & { + actions: DatasourceActions & { + refreshDefinition: () => Promise + changePrimaryDisplay: any + addSchemaMutation: any + addSubSchemaMutation: any + saveSchemaMutations: any + resetSchemaMutations: any + } + } +} + +export type Store = DatasourceStore & + DerivedDatasourceStore & + ActionDatasourceStore + +export const createStores = (): DatasourceStore => { const definition = memo(null) const schemaMutations = memo({}) const subSchemaMutations = memo({}) @@ -16,7 +53,7 @@ export const createStores = () => { } } -export const deriveStores = context => { +export const deriveStores = (context: StoreContext): DerivedDatasourceStore => { const { API, definition, @@ -27,7 +64,7 @@ export const deriveStores = context => { } = context const schema = derived(definition, $definition => { - let schema = getDatasourceSchema({ + let schema: Record = getDatasourceSchema({ API, datasource: get(datasource), definition: $definition, @@ -40,7 +77,7 @@ export const deriveStores = context => { // Certain datasources like queries use primitives. Object.keys(schema || {}).forEach(key => { if (typeof schema[key] !== "object") { - schema[key] = { type: schema[key] } + schema[key] = { type: schema[key] } as any // TODO } }) @@ -68,9 +105,8 @@ export const deriveStores = context => { if ($subSchemaMutations[field]) { enrichedSchema[field].columns ??= {} - for (const [fieldName, mutation] of Object.entries( - $subSchemaMutations[field] - )) { + for (const fieldName of Object.keys($subSchemaMutations[field])) { + const mutation = $subSchemaMutations[field][fieldName] enrichedSchema[field].columns[fieldName] = { ...enrichedSchema[field].columns[fieldName], ...mutation, @@ -104,7 +140,7 @@ export const deriveStores = context => { } } -export const createActions = context => { +export const createActions = (context: StoreContext): ActionDatasourceStore => { const { API, datasource, @@ -147,7 +183,9 @@ export const createActions = context => { } // Saves the datasource definition - const saveDefinition = async newDefinition => { + const saveDefinition = async ( + newDefinition: UpdateViewRequest | SaveTableRequest + ) => { // Update local state const originalDefinition = get(definition) definition.set(newDefinition) @@ -155,7 +193,7 @@ export const createActions = context => { // Update server if (get(config).canSaveSchema) { try { - await getAPI()?.actions.saveDefinition(newDefinition) + await getAPI()?.actions.saveDefinition(newDefinition as any) // Broadcast change so external state can be updated, as this change // will not be received by the builder websocket because we caused it @@ -242,9 +280,8 @@ export const createActions = context => { } if ($subSchemaMutations[column]) { newSchema[column].columns ??= {} - for (const [fieldName, mutation] of Object.entries( - $subSchemaMutations[column] - )) { + for (const fieldName of Object.keys($subSchemaMutations[column])) { + const mutation = $subSchemaMutations[column][fieldName] newSchema[column].columns[fieldName] = { ...newSchema[column].columns[fieldName], ...mutation, diff --git a/packages/frontend-core/src/components/grid/stores/index.ts b/packages/frontend-core/src/components/grid/stores/index.ts index 1ef5da03b6..d7d922f793 100644 --- a/packages/frontend-core/src/components/grid/stores/index.ts +++ b/packages/frontend-core/src/components/grid/stores/index.ts @@ -59,7 +59,8 @@ export type Store = BaseStore & Columns.Store & Table.Store & ViewV2.Store & - NonPlus.Store & { + NonPlus.Store & + Datasource.Store & { // TODO while typing the rest of stores datasource: Writable & { actions: any } definition: Writable @@ -75,6 +76,9 @@ export type Store = BaseStore & rows: Writable & { actions: any } subscribe: any config: Writable + dispatch: (event: string, data: any) => any + notifications: Writable + schemaOverrides: Writable } export const attachStores = (context: Store): Store => { @@ -106,5 +110,5 @@ export const attachStores = (context: Store): Store => { } } - return context + return context as Store } diff --git a/packages/types/src/ui/stores/grid/datasource.ts b/packages/types/src/ui/stores/grid/datasource.ts index d7367352d5..b1ed806b35 100644 --- a/packages/types/src/ui/stores/grid/datasource.ts +++ b/packages/types/src/ui/stores/grid/datasource.ts @@ -1,5 +1,12 @@ +import { SortOrder } from "@budibase/types" + export interface UIDatasource { type: string id: string tableId: string + sort?: { + field: string + order?: SortOrder + } + queryUI: any // TODO } From f114f1529bffd42e3b80af1c31d203953b1249e8 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 23 Dec 2024 10:01:33 +0100 Subject: [PATCH 03/27] Intial relatedColumns utils conversion --- packages/frontend-core/src/utils/{index.js => index.ts} | 0 .../src/utils/{relatedColumns.js => relatedColumns.ts} | 6 ++++-- 2 files changed, 4 insertions(+), 2 deletions(-) rename packages/frontend-core/src/utils/{index.js => index.ts} (100%) rename packages/frontend-core/src/utils/{relatedColumns.js => relatedColumns.ts} (94%) diff --git a/packages/frontend-core/src/utils/index.js b/packages/frontend-core/src/utils/index.ts similarity index 100% rename from packages/frontend-core/src/utils/index.js rename to packages/frontend-core/src/utils/index.ts diff --git a/packages/frontend-core/src/utils/relatedColumns.js b/packages/frontend-core/src/utils/relatedColumns.ts similarity index 94% rename from packages/frontend-core/src/utils/relatedColumns.js rename to packages/frontend-core/src/utils/relatedColumns.ts index 6e7968f70c..60be13bec9 100644 --- a/packages/frontend-core/src/utils/relatedColumns.js +++ b/packages/frontend-core/src/utils/relatedColumns.ts @@ -1,4 +1,4 @@ -import { FieldType, RelationshipType } from "@budibase/types" +import { FieldType, RelationshipType, UIFieldSchema } from "@budibase/types" import { Helpers } from "@budibase/bbui" const columnTypeManyTypeOverrides = { @@ -36,7 +36,9 @@ const columnTypeManyParser = { [FieldType.ARRAY]: value => Array.from(new Set(value)), } -export function enrichSchemaWithRelColumns(schema) { +export function enrichSchemaWithRelColumns( + schema: Record +) { if (!schema) { return } From c6d1b2be5b63ba43dcbdd98b08fe770f6e37b5c2 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 23 Dec 2024 10:03:08 +0100 Subject: [PATCH 04/27] Use types --- .../frontend-core/src/components/grid/stores/datasource.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/datasource.ts b/packages/frontend-core/src/components/grid/stores/datasource.ts index 8fda936d04..c97ee305ca 100644 --- a/packages/frontend-core/src/components/grid/stores/datasource.ts +++ b/packages/frontend-core/src/components/grid/stores/datasource.ts @@ -6,6 +6,7 @@ import { FieldSchema, SaveTableRequest, UIDatasource, + UIFieldSchema, UpdateViewRequest, ViewV2Type, } from "@budibase/types" @@ -20,7 +21,7 @@ interface DatasourceStore { interface DerivedDatasourceStore { schema: Readable> - enrichedSchema: Readable> + enrichedSchema: Readable> hasBudibaseIdentifiers: Readable } @@ -95,7 +96,7 @@ export const deriveStores = (context: StoreContext): DerivedDatasourceStore => { const schemaWithRelatedColumns = enrichSchemaWithRelColumns($schema) - const enrichedSchema = {} + const enrichedSchema: Record = {} Object.keys(schemaWithRelatedColumns).forEach(field => { enrichedSchema[field] = { ...schemaWithRelatedColumns[field], From 795da9f9765023964f9a40c0d63e7b14aa1d8b3b Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 23 Dec 2024 10:03:16 +0100 Subject: [PATCH 05/27] Exports --- packages/types/src/ui/stores/grid/index.ts | 1 + packages/types/src/ui/stores/grid/table.ts | 3 +++ 2 files changed, 4 insertions(+) create mode 100644 packages/types/src/ui/stores/grid/table.ts diff --git a/packages/types/src/ui/stores/grid/index.ts b/packages/types/src/ui/stores/grid/index.ts index f6c3472aaa..a4d8770576 100644 --- a/packages/types/src/ui/stores/grid/index.ts +++ b/packages/types/src/ui/stores/grid/index.ts @@ -1,2 +1,3 @@ export * from "./columns" export * from "./datasource" +export * from "./table" diff --git a/packages/types/src/ui/stores/grid/table.ts b/packages/types/src/ui/stores/grid/table.ts new file mode 100644 index 0000000000..09bbb7672d --- /dev/null +++ b/packages/types/src/ui/stores/grid/table.ts @@ -0,0 +1,3 @@ +import { BasicViewFieldMetadata, FieldSchema } from "@budibase/types" + +export type UIFieldSchema = FieldSchema & BasicViewFieldMetadata From 32bba9b1ab36d8e414c0b2af6fefdb5b166fb624 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 23 Dec 2024 19:34:58 +0100 Subject: [PATCH 06/27] More typings --- .../src/components/grid/stores/datasource.ts | 2 +- .../frontend-core/src/utils/relatedColumns.ts | 38 +++++++++++++------ packages/types/src/ui/stores/grid/table.ts | 12 +++++- 3 files changed, 38 insertions(+), 14 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/datasource.ts b/packages/frontend-core/src/components/grid/stores/datasource.ts index c97ee305ca..0bda8b0d64 100644 --- a/packages/frontend-core/src/components/grid/stores/datasource.ts +++ b/packages/frontend-core/src/components/grid/stores/datasource.ts @@ -65,7 +65,7 @@ export const deriveStores = (context: StoreContext): DerivedDatasourceStore => { } = context const schema = derived(definition, $definition => { - let schema: Record = getDatasourceSchema({ + let schema: Record = getDatasourceSchema({ API, datasource: get(datasource), definition: $definition, diff --git a/packages/frontend-core/src/utils/relatedColumns.ts b/packages/frontend-core/src/utils/relatedColumns.ts index 60be13bec9..6d29ef9ce4 100644 --- a/packages/frontend-core/src/utils/relatedColumns.ts +++ b/packages/frontend-core/src/utils/relatedColumns.ts @@ -1,5 +1,11 @@ -import { FieldType, RelationshipType, UIFieldSchema } from "@budibase/types" import { Helpers } from "@budibase/bbui" +import { + FieldType, + isRelationshipField, + RelationshipType, + Row, + UIFieldSchema, +} from "@budibase/types" const columnTypeManyTypeOverrides = { [FieldType.DATETIME]: FieldType.STRING, @@ -8,8 +14,8 @@ const columnTypeManyTypeOverrides = { } const columnTypeManyParser = { - [FieldType.DATETIME]: (value, field) => { - function parseDate(value) { + [FieldType.DATETIME]: (value: any[], field: any) => { + function parseDate(value: any) { const { timeOnly, dateOnly, ignoreTimezones } = field || {} const enableTime = !dateOnly const parsedValue = Helpers.parseDate(value, { @@ -26,14 +32,14 @@ const columnTypeManyParser = { return value.map(v => parseDate(v)) }, - [FieldType.BOOLEAN]: value => value.map(v => !!v), - [FieldType.BB_REFERENCE_SINGLE]: value => [ + [FieldType.BOOLEAN]: (value: any[]) => value.map(v => !!v), + [FieldType.BB_REFERENCE_SINGLE]: (value: any[]) => [ ...new Map(value.map(i => [i._id, i])).values(), ], - [FieldType.BB_REFERENCE]: value => [ + [FieldType.BB_REFERENCE]: (value: any[]) => [ ...new Map(value.map(i => [i._id, i])).values(), ], - [FieldType.ARRAY]: value => Array.from(new Set(value)), + [FieldType.ARRAY]: (value: any[]) => Array.from(new Set(value)), } export function enrichSchemaWithRelColumns( @@ -46,7 +52,11 @@ export function enrichSchemaWithRelColumns( const field = schema[fieldName] result[fieldName] = field - if (field.visible !== false && field.columns) { + if ( + field.visible !== false && + isRelationshipField(field) && + field.columns + ) { const fromSingle = field?.relationshipType === RelationshipType.ONE_TO_MANY @@ -72,8 +82,13 @@ export function enrichSchemaWithRelColumns( return result } -export function getRelatedTableValues(row, field, fromField) { +export function getRelatedTableValues( + row: Row, + field: UIFieldSchema, + fromField: UIFieldSchema +) { const fromSingle = + isRelationshipField(fromField) && fromField?.relationshipType === RelationshipType.ONE_TO_MANY let result = "" @@ -85,7 +100,8 @@ export function getRelatedTableValues(row, field, fromField) { const value = row[field.related.field] ?.flatMap(r => r[field.related.subField]) ?.filter(i => i !== undefined && i !== null) - result = parser(value || [], field) + const parsed = parser(value || [], field) + result = parsed if ( [ FieldType.STRING, @@ -97,7 +113,7 @@ export function getRelatedTableValues(row, field, fromField) { FieldType.BARCODEQR, ].includes(field.type) ) { - result = result?.join(", ") + result = parsed?.join(", ") } } diff --git a/packages/types/src/ui/stores/grid/table.ts b/packages/types/src/ui/stores/grid/table.ts index 09bbb7672d..f1040a1369 100644 --- a/packages/types/src/ui/stores/grid/table.ts +++ b/packages/types/src/ui/stores/grid/table.ts @@ -1,3 +1,11 @@ -import { BasicViewFieldMetadata, FieldSchema } from "@budibase/types" +import { + BasicViewFieldMetadata, + FieldSchema, + RelationSchemaField, +} from "@budibase/types" -export type UIFieldSchema = FieldSchema & BasicViewFieldMetadata +export type UIFieldSchema = FieldSchema & + BasicViewFieldMetadata & { + related?: { field: string; subField: string } + columns?: Record + } From 26d1243e689b5c2a3c194efd83dd33d2af12a9a4 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 23 Dec 2024 19:44:40 +0100 Subject: [PATCH 07/27] More typings --- .../src/components/grid/stores/datasource.ts | 25 ++++++++++++------- .../frontend-core/src/utils/relatedColumns.ts | 9 ++++++- .../types/src/ui/stores/grid/datasource.ts | 5 ++++ 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/datasource.ts b/packages/frontend-core/src/components/grid/stores/datasource.ts index 0bda8b0d64..c969e05694 100644 --- a/packages/frontend-core/src/components/grid/stores/datasource.ts +++ b/packages/frontend-core/src/components/grid/stores/datasource.ts @@ -4,8 +4,11 @@ import { enrichSchemaWithRelColumns, memo } from "../../../utils" import { cloneDeep } from "lodash" import { FieldSchema, + Row, + SaveRowRequest, SaveTableRequest, UIDatasource, + UIFieldMutation, UIFieldSchema, UpdateViewRequest, ViewV2Type, @@ -211,7 +214,7 @@ export const createActions = (context: StoreContext): ActionDatasourceStore => { } // Updates the datasources primary display column - const changePrimaryDisplay = async column => { + const changePrimaryDisplay = async (column: string) => { let newDefinition = cloneDeep(get(definition)) // Update primary display @@ -227,7 +230,7 @@ export const createActions = (context: StoreContext): ActionDatasourceStore => { } // Adds a schema mutation for a single field - const addSchemaMutation = (field, mutation) => { + const addSchemaMutation = (field: string, mutation: UIFieldMutation) => { if (!field || !mutation) { return } @@ -243,7 +246,11 @@ export const createActions = (context: StoreContext): ActionDatasourceStore => { } // Adds a nested schema mutation for a single field - const addSubSchemaMutation = (field, fromField, mutation) => { + const addSubSchemaMutation = ( + field: string, + fromField: string, + mutation: UIFieldMutation + ) => { if (!field || !fromField || !mutation) { return } @@ -305,32 +312,32 @@ export const createActions = (context: StoreContext): ActionDatasourceStore => { } // Adds a row to the datasource - const addRow = async row => { + const addRow = async (row: SaveRowRequest) => { return await getAPI()?.actions.addRow(row) } // Updates an existing row in the datasource - const updateRow = async row => { + const updateRow = async (row: SaveRowRequest) => { return await getAPI()?.actions.updateRow(row) } // Deletes rows from the datasource - const deleteRows = async rows => { + const deleteRows = async (rows: Row[]) => { return await getAPI()?.actions.deleteRows(rows) } // Gets a single row from a datasource - const getRow = async id => { + const getRow = async (id: string) => { return await getAPI()?.actions.getRow(id) } // Checks if a certain datasource config is valid - const isDatasourceValid = datasource => { + const isDatasourceValid = (datasource: UIDatasource) => { return getAPI()?.actions.isDatasourceValid(datasource) } // Checks if this datasource can use a specific column by name - const canUseColumn = name => { + const canUseColumn = (name: string) => { return getAPI()?.actions.canUseColumn(name) } diff --git a/packages/frontend-core/src/utils/relatedColumns.ts b/packages/frontend-core/src/utils/relatedColumns.ts index 6d29ef9ce4..5b63e25625 100644 --- a/packages/frontend-core/src/utils/relatedColumns.ts +++ b/packages/frontend-core/src/utils/relatedColumns.ts @@ -14,7 +14,14 @@ const columnTypeManyTypeOverrides = { } const columnTypeManyParser = { - [FieldType.DATETIME]: (value: any[], field: any) => { + [FieldType.DATETIME]: ( + value: any[], + field: { + timeOnly?: boolean + dateOnly?: boolean + ignoreTimezones?: boolean + } + ) => { function parseDate(value: any) { const { timeOnly, dateOnly, ignoreTimezones } = field || {} const enableTime = !dateOnly diff --git a/packages/types/src/ui/stores/grid/datasource.ts b/packages/types/src/ui/stores/grid/datasource.ts index b1ed806b35..ea6e8d1368 100644 --- a/packages/types/src/ui/stores/grid/datasource.ts +++ b/packages/types/src/ui/stores/grid/datasource.ts @@ -10,3 +10,8 @@ export interface UIDatasource { } queryUI: any // TODO } + +export interface UIFieldMutation { + visible: boolean + readonly?: boolean +} From be1eef29765ba79443283e35b55c3876a4ea14f6 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 24 Dec 2024 00:42:57 +0100 Subject: [PATCH 08/27] More typings --- .../frontend-core/src/utils/relatedColumns.ts | 67 +++++++++---------- packages/types/src/ui/stores/grid/table.ts | 7 +- 2 files changed, 39 insertions(+), 35 deletions(-) diff --git a/packages/frontend-core/src/utils/relatedColumns.ts b/packages/frontend-core/src/utils/relatedColumns.ts index 5b63e25625..37859e7ca1 100644 --- a/packages/frontend-core/src/utils/relatedColumns.ts +++ b/packages/frontend-core/src/utils/relatedColumns.ts @@ -19,17 +19,12 @@ const columnTypeManyParser = { field: { timeOnly?: boolean dateOnly?: boolean - ignoreTimezones?: boolean } ) => { function parseDate(value: any) { - const { timeOnly, dateOnly, ignoreTimezones } = field || {} + const { timeOnly, dateOnly } = field || {} const enableTime = !dateOnly - const parsedValue = Helpers.parseDate(value, { - timeOnly, - enableTime, - ignoreTimezones, - }) + const parsedValue = Helpers.parseDate(value, { enableTime }) const parsed = Helpers.getDateDisplayValue(parsedValue, { enableTime, timeOnly, @@ -51,40 +46,44 @@ const columnTypeManyParser = { export function enrichSchemaWithRelColumns( schema: Record -) { +): Record { if (!schema) { return } - const result = Object.keys(schema).reduce((result, fieldName) => { - const field = schema[fieldName] - result[fieldName] = field + const result = Object.keys(schema).reduce>( + (result, fieldName) => { + const field = schema[fieldName] + result[fieldName] = field - if ( - field.visible !== false && - isRelationshipField(field) && - field.columns - ) { - const fromSingle = - field?.relationshipType === RelationshipType.ONE_TO_MANY + if ( + field.visible !== false && + isRelationshipField(field) && + field.columns + ) { + const fromSingle = + field?.relationshipType === RelationshipType.ONE_TO_MANY - for (const relColumn of Object.keys(field.columns)) { - const relField = field.columns[relColumn] - if (!relField.visible) { - continue - } - const name = `${field.name}.${relColumn}` - result[name] = { - ...relField, - name, - related: { field: fieldName, subField: relColumn }, - cellRenderType: - (!fromSingle && columnTypeManyTypeOverrides[relField.type]) || - relField.type, + for (const relColumn of Object.keys(field.columns)) { + const relField = field.columns[relColumn] + if (!relField.visible) { + continue + } + const name = `${field.name}.${relColumn}` + result[name] = { + ...relField, + type: null, // TODO + name, + related: { field: fieldName, subField: relColumn }, + cellRenderType: + (!fromSingle && columnTypeManyTypeOverrides[relField.type]) || + relField.type, + } } } - } - return result - }, {}) + return result + }, + {} + ) return result } diff --git a/packages/types/src/ui/stores/grid/table.ts b/packages/types/src/ui/stores/grid/table.ts index f1040a1369..d58bc93f8b 100644 --- a/packages/types/src/ui/stores/grid/table.ts +++ b/packages/types/src/ui/stores/grid/table.ts @@ -7,5 +7,10 @@ import { export type UIFieldSchema = FieldSchema & BasicViewFieldMetadata & { related?: { field: string; subField: string } - columns?: Record + columns?: Record + cellRenderType?: string } + +interface UIRelationSchemaField extends RelationSchemaField { + type: string +} From 853ba4e20cfce22576b2d93a2293a3c02a5e1515 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 24 Dec 2024 00:50:20 +0100 Subject: [PATCH 09/27] More and more types --- .../src/components/grid/stores/datasource.ts | 2 +- .../src/components/grid/stores/datasources/index.ts | 10 +++++----- packages/frontend-core/src/utils/relatedColumns.ts | 12 ++++++------ packages/types/src/ui/stores/grid/table.ts | 5 +++-- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/datasource.ts b/packages/frontend-core/src/components/grid/stores/datasource.ts index c969e05694..2d013fd23a 100644 --- a/packages/frontend-core/src/components/grid/stores/datasource.ts +++ b/packages/frontend-core/src/components/grid/stores/datasource.ts @@ -203,7 +203,7 @@ export const createActions = (context: StoreContext): ActionDatasourceStore => { // will not be received by the builder websocket because we caused it // ourselves dispatch("updatedatasource", newDefinition) - } catch (error) { + } catch (error: any) { const msg = error?.message || error || "Unknown error" get(notifications).error(`Error saving schema: ${msg}`) diff --git a/packages/frontend-core/src/components/grid/stores/datasources/index.ts b/packages/frontend-core/src/components/grid/stores/datasources/index.ts index 1d1a2103b1..a1ade22317 100644 --- a/packages/frontend-core/src/components/grid/stores/datasources/index.ts +++ b/packages/frontend-core/src/components/grid/stores/datasources/index.ts @@ -10,10 +10,10 @@ export interface DatasourceActions< TSaveDefinitionRequest = UpdateViewRequest | SaveTableRequest > { saveDefinition: (newDefinition: TSaveDefinitionRequest) => Promise - addRow: (row: SaveRowRequest) => Promise - updateRow: (row: SaveRowRequest) => Promise + addRow: (row: SaveRowRequest) => Promise + updateRow: (row: SaveRowRequest) => Promise deleteRows: (rows: (string | Row)[]) => Promise - getRow: (id: string) => Promise - isDatasourceValid: (datasource: UIDatasource) => boolean - canUseColumn: (name: string) => boolean + getRow: (id: string) => Promise + isDatasourceValid: (datasource: UIDatasource) => boolean | void + canUseColumn: (name: string) => boolean | void } diff --git a/packages/frontend-core/src/utils/relatedColumns.ts b/packages/frontend-core/src/utils/relatedColumns.ts index 37859e7ca1..ed4ccf438d 100644 --- a/packages/frontend-core/src/utils/relatedColumns.ts +++ b/packages/frontend-core/src/utils/relatedColumns.ts @@ -7,7 +7,7 @@ import { UIFieldSchema, } from "@budibase/types" -const columnTypeManyTypeOverrides = { +const columnTypeManyTypeOverrides: Partial> = { [FieldType.DATETIME]: FieldType.STRING, [FieldType.BOOLEAN]: FieldType.STRING, [FieldType.SIGNATURE_SINGLE]: FieldType.ATTACHMENTS, @@ -46,7 +46,7 @@ const columnTypeManyParser = { export function enrichSchemaWithRelColumns( schema: Record -): Record { +): Record | undefined { if (!schema) { return } @@ -71,7 +71,7 @@ export function enrichSchemaWithRelColumns( const name = `${field.name}.${relColumn}` result[name] = { ...relField, - type: null, // TODO + type: relField.type as any, // TODO name, related: { field: fieldName, subField: relColumn }, cellRenderType: @@ -102,10 +102,10 @@ export function getRelatedTableValues( if (fromSingle) { result = row[field.related.field]?.[0]?.[field.related.subField] } else { - const parser = columnTypeManyParser[field.type] || (value => value) + const parser = columnTypeManyParser[field.type] || ((value: any) => value) const value = row[field.related.field] - ?.flatMap(r => r[field.related.subField]) - ?.filter(i => i !== undefined && i !== null) + ?.flatMap((r: Row) => r[field.related.subField]) + ?.filter((i: any) => i !== undefined && i !== null) const parsed = parser(value || [], field) result = parsed if ( diff --git a/packages/types/src/ui/stores/grid/table.ts b/packages/types/src/ui/stores/grid/table.ts index d58bc93f8b..8975ef4cfc 100644 --- a/packages/types/src/ui/stores/grid/table.ts +++ b/packages/types/src/ui/stores/grid/table.ts @@ -1,16 +1,17 @@ import { BasicViewFieldMetadata, FieldSchema, + FieldType, RelationSchemaField, } from "@budibase/types" export type UIFieldSchema = FieldSchema & BasicViewFieldMetadata & { related?: { field: string; subField: string } - columns?: Record + columns?: Record cellRenderType?: string } interface UIRelationSchemaField extends RelationSchemaField { - type: string + type: FieldType } From e3a811d1a68c1dbe27e56b2be1e1dceef8f8610e Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 24 Dec 2024 01:24:52 +0100 Subject: [PATCH 10/27] 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 } From 577df882ae5fd50dce9de5b6bcba319f5cf6bde6 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 24 Dec 2024 10:07:57 +0100 Subject: [PATCH 11/27] More typings --- .../src/components/grid/stores/datasource.ts | 10 +++++----- .../src/components/grid/stores/datasources/index.ts | 2 +- .../src/components/grid/stores/datasources/nonPlus.ts | 2 +- .../src/components/grid/stores/datasources/table.ts | 2 +- .../src/components/grid/stores/datasources/viewV2.ts | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/datasource.ts b/packages/frontend-core/src/components/grid/stores/datasource.ts index 472f598299..6b4fb8dc52 100644 --- a/packages/frontend-core/src/components/grid/stores/datasource.ts +++ b/packages/frontend-core/src/components/grid/stores/datasource.ts @@ -19,7 +19,7 @@ import { DatasourceActions } from "./datasources" interface DatasourceStore { definition: Writable schemaMutations: Writable> - subSchemaMutations: Writable> + subSchemaMutations: Writable>> } interface DerivedDatasourceStore { @@ -197,7 +197,7 @@ export const createActions = (context: StoreContext): ActionDatasourceStore => { // Update server if (get(config).canSaveSchema) { try { - await getAPI()?.actions.saveDefinition(newDefinition) + await getAPI()?.actions.saveDefinition(newDefinition as never) // Broadcast change so external state can be updated, as this change // will not be received by the builder websocket because we caused it @@ -277,15 +277,15 @@ export const createActions = (context: StoreContext): ActionDatasourceStore => { const $definition = get(definition) const $schemaMutations = get(schemaMutations) const $subSchemaMutations = get(subSchemaMutations) - const $schema = get(schema) - let newSchema = {} + const $schema = get(schema) || {} + let newSchema: Record = {} // Build new updated datasource schema Object.keys($schema).forEach(column => { newSchema[column] = { ...$schema[column], ...$schemaMutations[column], - } + } as UIFieldSchema // TODO if ($subSchemaMutations[column]) { newSchema[column].columns ??= {} for (const fieldName of Object.keys($subSchemaMutations[column])) { diff --git a/packages/frontend-core/src/components/grid/stores/datasources/index.ts b/packages/frontend-core/src/components/grid/stores/datasources/index.ts index a1ade22317..4c3ffc7a74 100644 --- a/packages/frontend-core/src/components/grid/stores/datasources/index.ts +++ b/packages/frontend-core/src/components/grid/stores/datasources/index.ts @@ -12,7 +12,7 @@ export interface DatasourceActions< saveDefinition: (newDefinition: TSaveDefinitionRequest) => Promise addRow: (row: SaveRowRequest) => Promise updateRow: (row: SaveRowRequest) => Promise - deleteRows: (rows: (string | Row)[]) => Promise + deleteRows: (rows: Row[]) => Promise getRow: (id: string) => Promise isDatasourceValid: (datasource: UIDatasource) => boolean | void canUseColumn: (name: string) => boolean | void diff --git a/packages/frontend-core/src/components/grid/stores/datasources/nonPlus.ts b/packages/frontend-core/src/components/grid/stores/datasources/nonPlus.ts index 2ea5a05a0e..65fc6d8696 100644 --- a/packages/frontend-core/src/components/grid/stores/datasources/nonPlus.ts +++ b/packages/frontend-core/src/components/grid/stores/datasources/nonPlus.ts @@ -5,7 +5,7 @@ import { DatasourceActions } from "." interface NonPlusActions { nonPlus: { - actions: DatasourceActions + actions: DatasourceActions } } diff --git a/packages/frontend-core/src/components/grid/stores/datasources/table.ts b/packages/frontend-core/src/components/grid/stores/datasources/table.ts index 9f1a490306..5f3d27159e 100644 --- a/packages/frontend-core/src/components/grid/stores/datasources/table.ts +++ b/packages/frontend-core/src/components/grid/stores/datasources/table.ts @@ -34,7 +34,7 @@ export const createActions = (context: StoreContext): TableActions => { return await API.saveRow(row, SuppressErrors) } - const deleteRows = async (rows: (string | Row)[]) => { + const deleteRows = async (rows: Row[]) => { await API.deleteRows(get(datasource).tableId, rows) } diff --git a/packages/frontend-core/src/components/grid/stores/datasources/viewV2.ts b/packages/frontend-core/src/components/grid/stores/datasources/viewV2.ts index 70a83b4594..edafd94d6f 100644 --- a/packages/frontend-core/src/components/grid/stores/datasources/viewV2.ts +++ b/packages/frontend-core/src/components/grid/stores/datasources/viewV2.ts @@ -39,7 +39,7 @@ export const createActions = (context: StoreContext): ViewActions => { } } - const deleteRows = async (rows: (string | Row)[]) => { + const deleteRows = async (rows: Row[]) => { await API.deleteRows(get(datasource).id, rows) } From 17590cb5e672e62b2aa408cd0a409e72446600a1 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 24 Dec 2024 10:57:07 +0100 Subject: [PATCH 12/27] Type some of the anys --- .../src/components/grid/stores/datasource.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/datasource.ts b/packages/frontend-core/src/components/grid/stores/datasource.ts index 6b4fb8dc52..721b964626 100644 --- a/packages/frontend-core/src/components/grid/stores/datasource.ts +++ b/packages/frontend-core/src/components/grid/stores/datasource.ts @@ -32,11 +32,15 @@ interface ActionDatasourceStore { datasource: DatasourceStore["definition"] & { actions: DatasourceActions & { refreshDefinition: () => Promise - changePrimaryDisplay: any - addSchemaMutation: any - addSubSchemaMutation: any - saveSchemaMutations: any - resetSchemaMutations: any + changePrimaryDisplay: (column: string) => Promise + addSchemaMutation: (field: string, mutation: UIFieldMutation) => void + addSubSchemaMutation: ( + field: string, + fromField: string, + mutation: UIFieldMutation + ) => void + saveSchemaMutations: () => Promise + resetSchemaMutations: () => void } } } From e6cccaee6d708274f05de684457879b01911d4b6 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 24 Dec 2024 11:10:55 +0100 Subject: [PATCH 13/27] Remove some todos --- packages/frontend-core/src/components/grid/stores/datasource.ts | 2 +- packages/types/src/ui/stores/grid/table.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/datasource.ts b/packages/frontend-core/src/components/grid/stores/datasource.ts index 721b964626..17ce098555 100644 --- a/packages/frontend-core/src/components/grid/stores/datasource.ts +++ b/packages/frontend-core/src/components/grid/stores/datasource.ts @@ -85,7 +85,7 @@ export const deriveStores = (context: StoreContext): DerivedDatasourceStore => { // Certain datasources like queries use primitives. Object.keys(schema || {}).forEach(key => { if (typeof schema[key] !== "object") { - schema[key] = { type: schema[key] } as any // TODO + schema[key] = { name: key, type: schema[key] } } }) diff --git a/packages/types/src/ui/stores/grid/table.ts b/packages/types/src/ui/stores/grid/table.ts index 6160a05640..8975ef4cfc 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 } From f1f2b90cfb7ea30e055f7599ffd92ebbff473793 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 24 Dec 2024 11:14:23 +0100 Subject: [PATCH 14/27] Fix some unwanted anys --- .../src/components/grid/stores/datasource.ts | 12 +++++++----- .../src/components/grid/stores/index.ts | 3 --- packages/types/src/ui/stores/grid/datasource.ts | 4 +++- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/datasource.ts b/packages/frontend-core/src/components/grid/stores/datasource.ts index 17ce098555..c1757dd59e 100644 --- a/packages/frontend-core/src/components/grid/stores/datasource.ts +++ b/packages/frontend-core/src/components/grid/stores/datasource.ts @@ -131,7 +131,7 @@ export const deriveStores = (context: StoreContext): DerivedDatasourceStore => { ([$datasource, $definition]) => { let type = $datasource?.type if (type === "provider") { - type = $datasource.value?.datasource?.type + type = ($datasource as any).value?.datasource?.type } // Handle calculation views if (type === "viewV2" && $definition?.type === ViewV2Type.CALCULATION) { @@ -196,7 +196,7 @@ export const createActions = (context: StoreContext): ActionDatasourceStore => { ) => { // Update local state const originalDefinition = get(definition) - definition.set(newDefinition) + definition.set(newDefinition as any) // Update server if (get(config).canSaveSchema) { @@ -229,8 +229,10 @@ export const createActions = (context: StoreContext): ActionDatasourceStore => { newDefinition.schema[column].constraints = {} } newDefinition.schema[column].constraints.presence = { allowEmpty: false } - delete newDefinition.schema[column].default - return await saveDefinition(newDefinition) + if ("default" in newDefinition.schema[column]) { + delete newDefinition.schema[column].default + } + return await saveDefinition(newDefinition as any) } // Adds a schema mutation for a single field @@ -306,7 +308,7 @@ export const createActions = (context: StoreContext): ActionDatasourceStore => { await saveDefinition({ ...$definition, schema: newSchema, - }) + } as any) resetSchemaMutations() } diff --git a/packages/frontend-core/src/components/grid/stores/index.ts b/packages/frontend-core/src/components/grid/stores/index.ts index d7d922f793..f2b6c973b9 100644 --- a/packages/frontend-core/src/components/grid/stores/index.ts +++ b/packages/frontend-core/src/components/grid/stores/index.ts @@ -62,9 +62,6 @@ export type Store = BaseStore & NonPlus.Store & Datasource.Store & { // TODO while typing the rest of stores - datasource: Writable & { actions: any } - definition: Writable - enrichedSchema: any fetch: Writable filter: Writable inlineFilters: Writable diff --git a/packages/types/src/ui/stores/grid/datasource.ts b/packages/types/src/ui/stores/grid/datasource.ts index ea6e8d1368..ec115d28a0 100644 --- a/packages/types/src/ui/stores/grid/datasource.ts +++ b/packages/types/src/ui/stores/grid/datasource.ts @@ -1,14 +1,16 @@ -import { SortOrder } from "@budibase/types" +import { SortOrder, UIFieldSchema } from "@budibase/types" export interface UIDatasource { type: string id: string tableId: string + primaryDisplay?: string sort?: { field: string order?: SortOrder } queryUI: any // TODO + schema: Record } export interface UIFieldMutation { From 812d19b9b03d822de8193deab33fd9584a29668b Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 24 Dec 2024 11:25:05 +0100 Subject: [PATCH 15/27] More types --- packages/types/src/ui/stores/grid/datasource.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/types/src/ui/stores/grid/datasource.ts b/packages/types/src/ui/stores/grid/datasource.ts index ec115d28a0..818b4f00da 100644 --- a/packages/types/src/ui/stores/grid/datasource.ts +++ b/packages/types/src/ui/stores/grid/datasource.ts @@ -1,15 +1,16 @@ -import { SortOrder, UIFieldSchema } from "@budibase/types" +import { SortOrder, UIFieldSchema, UISearchFilter } from "@budibase/types" export interface UIDatasource { type: string + name: string id: string tableId: string primaryDisplay?: string sort?: { field: string - order?: SortOrder + order: SortOrder } - queryUI: any // TODO + queryUI: UISearchFilter schema: Record } From a31829051825ea8b436f5aedeff3a5c8d4ad1971 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 24 Dec 2024 11:52:05 +0100 Subject: [PATCH 16/27] Improve types --- .../components/grid/stores/datasources/index.ts | 16 ++++++++++++++-- .../grid/stores/datasources/nonPlus.ts | 10 +++++----- .../components/grid/stores/datasources/table.ts | 7 ++++--- .../components/grid/stores/datasources/viewV2.ts | 12 ++++++------ packages/types/src/ui/stores/grid/datasource.ts | 16 +++++++++++++++- 5 files changed, 44 insertions(+), 17 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/datasources/index.ts b/packages/frontend-core/src/components/grid/stores/datasources/index.ts index 4c3ffc7a74..8127a9fecf 100644 --- a/packages/frontend-core/src/components/grid/stores/datasources/index.ts +++ b/packages/frontend-core/src/components/grid/stores/datasources/index.ts @@ -3,10 +3,13 @@ import { SaveRowRequest, SaveTableRequest, UIDatasource, + UITable, + UIView, UpdateViewRequest, } from "@budibase/types" -export interface DatasourceActions< +interface DatasourceActions< + TDatasource = UITable | UIView, TSaveDefinitionRequest = UpdateViewRequest | SaveTableRequest > { saveDefinition: (newDefinition: TSaveDefinitionRequest) => Promise @@ -14,6 +17,15 @@ export interface DatasourceActions< updateRow: (row: SaveRowRequest) => Promise deleteRows: (rows: Row[]) => Promise getRow: (id: string) => Promise - isDatasourceValid: (datasource: UIDatasource) => boolean | void + isDatasourceValid: (datasource: TDatasource) => boolean | void canUseColumn: (name: string) => boolean | void } + +export interface DatasourceTableActions + extends DatasourceActions {} + +export interface DatasourceViewActions + extends DatasourceActions {} + +export interface DatasourceNonPlusActions + extends DatasourceActions {} diff --git a/packages/frontend-core/src/components/grid/stores/datasources/nonPlus.ts b/packages/frontend-core/src/components/grid/stores/datasources/nonPlus.ts index 65fc6d8696..46b224730b 100644 --- a/packages/frontend-core/src/components/grid/stores/datasources/nonPlus.ts +++ b/packages/frontend-core/src/components/grid/stores/datasources/nonPlus.ts @@ -1,11 +1,11 @@ -import { SortOrder, UIDatasource } from "@budibase/types" +import { SortOrder, UIDatasource, UITable, UIView } from "@budibase/types" import { get } from "svelte/store" import { Store as StoreContext } from ".." -import { DatasourceActions } from "." +import { DatasourceNonPlusActions } from "." interface NonPlusActions { nonPlus: { - actions: DatasourceActions + actions: DatasourceNonPlusActions } } @@ -34,8 +34,8 @@ export const createActions = (context: StoreContext): NonPlusActions => { // There are many different types and shapes of datasource, so we only // check that we aren't null return ( - !table.actions.isDatasourceValid(datasource) && - !viewV2.actions.isDatasourceValid(datasource) && + !table.actions.isDatasourceValid(datasource as UITable) && + !viewV2.actions.isDatasourceValid(datasource as UIView) && datasource?.type != null ) } diff --git a/packages/frontend-core/src/components/grid/stores/datasources/table.ts b/packages/frontend-core/src/components/grid/stores/datasources/table.ts index 5f3d27159e..5c8b3e1a1a 100644 --- a/packages/frontend-core/src/components/grid/stores/datasources/table.ts +++ b/packages/frontend-core/src/components/grid/stores/datasources/table.ts @@ -4,16 +4,17 @@ import { SaveTableRequest, SortOrder, UIDatasource, + UITable, } from "@budibase/types" import { get } from "svelte/store" import { Store as StoreContext } from ".." -import { DatasourceActions } from "." +import { DatasourceTableActions } from "." const SuppressErrors = true interface TableActions { table: { - actions: DatasourceActions + actions: DatasourceTableActions } } @@ -97,7 +98,7 @@ export const initialise = (context: StoreContext) => { // Clear previous subscriptions unsubscribers?.forEach(unsubscribe => unsubscribe()) unsubscribers = [] - if (!table.actions.isDatasourceValid($datasource)) { + if (!table.actions.isDatasourceValid($datasource as UITable)) { return } diff --git a/packages/frontend-core/src/components/grid/stores/datasources/viewV2.ts b/packages/frontend-core/src/components/grid/stores/datasources/viewV2.ts index edafd94d6f..f70059e016 100644 --- a/packages/frontend-core/src/components/grid/stores/datasources/viewV2.ts +++ b/packages/frontend-core/src/components/grid/stores/datasources/viewV2.ts @@ -3,17 +3,17 @@ import { Row, SaveRowRequest, SortOrder, - UIDatasource, + UIView, UpdateViewRequest, } from "@budibase/types" import { Store as StoreContext } from ".." -import { DatasourceActions } from "." +import { DatasourceViewActions } from "." const SuppressErrors = true interface ViewActions { viewV2: { - actions: DatasourceActions + actions: DatasourceViewActions } } @@ -56,7 +56,7 @@ export const createActions = (context: StoreContext): ViewActions => { return res?.rows?.[0] } - const isDatasourceValid = (datasource: UIDatasource) => { + const isDatasourceValid = (datasource: UIView) => { return ( datasource?.type === "viewV2" && !!datasource?.id && !!datasource?.tableId ) @@ -108,7 +108,7 @@ export const initialise = (context: StoreContext) => { // Clear previous subscriptions unsubscribers?.forEach(unsubscribe => unsubscribe()) unsubscribers = [] - if (!viewV2.actions.isDatasourceValid($datasource)) { + if (!viewV2.actions.isDatasourceValid($datasource as UIView)) { return } @@ -147,7 +147,7 @@ export const initialise = (context: StoreContext) => { unsubscribers.push( sort.subscribe(async $sort => { // Ensure we're updating the correct view - const $view = get(definition) + const $view = get(definition) as UIView if ($view?.id !== $datasource.id) { return } diff --git a/packages/types/src/ui/stores/grid/datasource.ts b/packages/types/src/ui/stores/grid/datasource.ts index 818b4f00da..5d27183806 100644 --- a/packages/types/src/ui/stores/grid/datasource.ts +++ b/packages/types/src/ui/stores/grid/datasource.ts @@ -1,6 +1,8 @@ import { SortOrder, UIFieldSchema, UISearchFilter } from "@budibase/types" -export interface UIDatasource { +export type UIDatasource = UITable | UIView + +export interface UITable { type: string name: string id: string @@ -14,6 +16,18 @@ export interface UIDatasource { schema: Record } +export interface UIView { + type: string + version: 2 + id: string + tableId: string + sort?: { + field: string + order: SortOrder + } + queryUI: UISearchFilter +} + export interface UIFieldMutation { visible: boolean readonly?: boolean From 6c17d3e257995518f6dc5f739075c5d2a736d08d Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 24 Dec 2024 11:56:39 +0100 Subject: [PATCH 17/27] Split types --- .../src/components/grid/stores/datasource.ts | 4 +-- .../grid/stores/datasources/index.ts | 13 ++++++--- .../types/src/ui/stores/grid/datasource.ts | 28 +------------------ packages/types/src/ui/stores/grid/index.ts | 1 + packages/types/src/ui/stores/grid/table.ts | 16 +++++++++++ packages/types/src/ui/stores/grid/view.ts | 16 +++++++++++ 6 files changed, 45 insertions(+), 33 deletions(-) create mode 100644 packages/types/src/ui/stores/grid/view.ts diff --git a/packages/frontend-core/src/components/grid/stores/datasource.ts b/packages/frontend-core/src/components/grid/stores/datasource.ts index c1757dd59e..4c8933611e 100644 --- a/packages/frontend-core/src/components/grid/stores/datasource.ts +++ b/packages/frontend-core/src/components/grid/stores/datasource.ts @@ -30,7 +30,7 @@ interface DerivedDatasourceStore { interface ActionDatasourceStore { datasource: DatasourceStore["definition"] & { - actions: DatasourceActions & { + actions: DatasourceActions & { refreshDefinition: () => Promise changePrimaryDisplay: (column: string) => Promise addSchemaMutation: (field: string, mutation: UIFieldMutation) => void @@ -339,7 +339,7 @@ export const createActions = (context: StoreContext): ActionDatasourceStore => { // Checks if a certain datasource config is valid const isDatasourceValid = (datasource: UIDatasource) => { - return getAPI()?.actions.isDatasourceValid(datasource) + return getAPI()?.actions.isDatasourceValid(datasource as any) } // Checks if this datasource can use a specific column by name diff --git a/packages/frontend-core/src/components/grid/stores/datasources/index.ts b/packages/frontend-core/src/components/grid/stores/datasources/index.ts index 8127a9fecf..4f570bd3eb 100644 --- a/packages/frontend-core/src/components/grid/stores/datasources/index.ts +++ b/packages/frontend-core/src/components/grid/stores/datasources/index.ts @@ -8,7 +8,7 @@ import { UpdateViewRequest, } from "@budibase/types" -interface DatasourceActions< +interface DatasourceBaseActions< TDatasource = UITable | UIView, TSaveDefinitionRequest = UpdateViewRequest | SaveTableRequest > { @@ -22,10 +22,15 @@ interface DatasourceActions< } export interface DatasourceTableActions - extends DatasourceActions {} + extends DatasourceBaseActions {} export interface DatasourceViewActions - extends DatasourceActions {} + extends DatasourceBaseActions {} export interface DatasourceNonPlusActions - extends DatasourceActions {} + extends DatasourceBaseActions {} + +export type DatasourceActions = + | DatasourceTableActions + | DatasourceViewActions + | DatasourceNonPlusActions diff --git a/packages/types/src/ui/stores/grid/datasource.ts b/packages/types/src/ui/stores/grid/datasource.ts index 5d27183806..32ac7d5fe1 100644 --- a/packages/types/src/ui/stores/grid/datasource.ts +++ b/packages/types/src/ui/stores/grid/datasource.ts @@ -1,33 +1,7 @@ -import { SortOrder, UIFieldSchema, UISearchFilter } from "@budibase/types" +import { UITable, UIView } from "@budibase/types" export type UIDatasource = UITable | UIView -export interface UITable { - type: string - name: string - id: string - tableId: string - primaryDisplay?: string - sort?: { - field: string - order: SortOrder - } - queryUI: UISearchFilter - schema: Record -} - -export interface UIView { - type: string - version: 2 - id: string - tableId: string - sort?: { - field: string - order: SortOrder - } - queryUI: UISearchFilter -} - export interface UIFieldMutation { visible: boolean readonly?: boolean diff --git a/packages/types/src/ui/stores/grid/index.ts b/packages/types/src/ui/stores/grid/index.ts index a4d8770576..bcd7e3267d 100644 --- a/packages/types/src/ui/stores/grid/index.ts +++ b/packages/types/src/ui/stores/grid/index.ts @@ -1,3 +1,4 @@ export * from "./columns" export * from "./datasource" export * from "./table" +export * from "./view" diff --git a/packages/types/src/ui/stores/grid/table.ts b/packages/types/src/ui/stores/grid/table.ts index 8975ef4cfc..4c19cbf882 100644 --- a/packages/types/src/ui/stores/grid/table.ts +++ b/packages/types/src/ui/stores/grid/table.ts @@ -3,8 +3,24 @@ import { FieldSchema, FieldType, RelationSchemaField, + SortOrder, + UISearchFilter, } from "@budibase/types" +export interface UITable { + type: string + name: string + id: string + tableId: string + primaryDisplay?: string + sort?: { + field: string + order: SortOrder + } + queryUI: UISearchFilter + schema: Record +} + export type UIFieldSchema = FieldSchema & BasicViewFieldMetadata & { related?: { field: string; subField: string } diff --git a/packages/types/src/ui/stores/grid/view.ts b/packages/types/src/ui/stores/grid/view.ts new file mode 100644 index 0000000000..af214e7d82 --- /dev/null +++ b/packages/types/src/ui/stores/grid/view.ts @@ -0,0 +1,16 @@ +import { SortOrder, UISearchFilter } from "@budibase/types" +import { UIFieldSchema } from "./table" + +export interface UIView { + type: string + version: 2 + id: string + tableId: string + primaryDisplay?: string + schema: Record + sort?: { + field: string + order: SortOrder + } + queryUI: UISearchFilter +} From 5add8336037ac8d33c7b59760c6e8e5f16d61316 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 24 Dec 2024 12:00:56 +0100 Subject: [PATCH 18/27] Remove todo --- .../frontend-core/src/components/grid/stores/datasource.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/datasource.ts b/packages/frontend-core/src/components/grid/stores/datasource.ts index 4c8933611e..6a3bced620 100644 --- a/packages/frontend-core/src/components/grid/stores/datasource.ts +++ b/packages/frontend-core/src/components/grid/stores/datasource.ts @@ -3,7 +3,6 @@ import { getDatasourceDefinition, getDatasourceSchema } from "../../../fetch" import { enrichSchemaWithRelColumns, memo } from "../../../utils" import { cloneDeep } from "lodash" import { - FieldSchema, Row, SaveRowRequest, SaveTableRequest, @@ -23,7 +22,7 @@ interface DatasourceStore { } interface DerivedDatasourceStore { - schema: Readable | null> + schema: Readable | null> enrichedSchema: Readable | null> hasBudibaseIdentifiers: Readable } @@ -291,7 +290,7 @@ export const createActions = (context: StoreContext): ActionDatasourceStore => { newSchema[column] = { ...$schema[column], ...$schemaMutations[column], - } as UIFieldSchema // TODO + } if ($subSchemaMutations[column]) { newSchema[column].columns ??= {} for (const fieldName of Object.keys($subSchemaMutations[column])) { From d117ac8febe1ca1da119fd68bb4cc4264882c8a7 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 24 Dec 2024 12:03:56 +0100 Subject: [PATCH 19/27] Fix types --- packages/frontend-core/src/utils/relatedColumns.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/frontend-core/src/utils/relatedColumns.ts b/packages/frontend-core/src/utils/relatedColumns.ts index 07a9efe5d4..e7bd3662d3 100644 --- a/packages/frontend-core/src/utils/relatedColumns.ts +++ b/packages/frontend-core/src/utils/relatedColumns.ts @@ -90,7 +90,7 @@ export function enrichSchemaWithRelColumns( export function getRelatedTableValues( row: Row, - field: UIFieldSchema, + field: UIFieldSchema & { related: { field: string; subField: string } }, fromField: UIFieldSchema ) { const fromSingle = From 7c05c5473de6242177b9e90237fe3b9f2ed2bc06 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 24 Dec 2024 12:18:49 +0100 Subject: [PATCH 20/27] Fix UIFieldMutation --- packages/types/src/ui/stores/grid/datasource.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/types/src/ui/stores/grid/datasource.ts b/packages/types/src/ui/stores/grid/datasource.ts index 32ac7d5fe1..c8a6a6fc83 100644 --- a/packages/types/src/ui/stores/grid/datasource.ts +++ b/packages/types/src/ui/stores/grid/datasource.ts @@ -3,6 +3,7 @@ import { UITable, UIView } from "@budibase/types" export type UIDatasource = UITable | UIView export interface UIFieldMutation { - visible: boolean + visible?: boolean readonly?: boolean + width?: number } From 78dd802d3abc8d7b65eeb3c8f91eafb93fff3f91 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 24 Dec 2024 12:23:38 +0100 Subject: [PATCH 21/27] Improve some typings --- .../src/components/grid/stores/datasources/index.ts | 4 +--- .../src/components/grid/stores/datasources/viewV2.ts | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/datasources/index.ts b/packages/frontend-core/src/components/grid/stores/datasources/index.ts index 4f570bd3eb..a03d85e74f 100644 --- a/packages/frontend-core/src/components/grid/stores/datasources/index.ts +++ b/packages/frontend-core/src/components/grid/stores/datasources/index.ts @@ -31,6 +31,4 @@ export interface DatasourceNonPlusActions extends DatasourceBaseActions {} export type DatasourceActions = - | DatasourceTableActions - | DatasourceViewActions - | DatasourceNonPlusActions + | DatasourceTableActions & DatasourceViewActions & DatasourceNonPlusActions diff --git a/packages/frontend-core/src/components/grid/stores/datasources/viewV2.ts b/packages/frontend-core/src/components/grid/stores/datasources/viewV2.ts index f70059e016..e83d866455 100644 --- a/packages/frontend-core/src/components/grid/stores/datasources/viewV2.ts +++ b/packages/frontend-core/src/components/grid/stores/datasources/viewV2.ts @@ -168,7 +168,7 @@ export const initialise = (context: StoreContext) => { field: $sort.column, order: $sort.order || SortOrder.ASCENDING, }, - }) + } as never as UpdateViewRequest) } // Also update the fetch to ensure the new sort is respected. @@ -198,7 +198,7 @@ export const initialise = (context: StoreContext) => { await datasource.actions.saveDefinition({ ...$view, queryUI: $filter, - }) + } as never as UpdateViewRequest) // Refresh data since view definition changed await rows.actions.refreshData() From fc51b4e132a8807481c4fcbfbca04f0f646bff05 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 24 Dec 2024 13:01:26 +0100 Subject: [PATCH 22/27] Fix "type" conflicts --- .../src/components/grid/stores/datasource.ts | 9 +++++++-- .../components/grid/stores/datasources/index.ts | 11 ++++------- .../components/grid/stores/datasources/nonPlus.ts | 6 +++--- .../components/grid/stores/datasources/table.ts | 3 +-- .../components/grid/stores/datasources/viewV2.ts | 7 ++++--- packages/types/src/ui/stores/grid/datasource.ts | 4 +++- packages/types/src/ui/stores/grid/table.ts | 1 - packages/types/src/ui/stores/grid/view.ts | 14 ++------------ 8 files changed, 24 insertions(+), 31 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/datasource.ts b/packages/frontend-core/src/components/grid/stores/datasource.ts index 6a3bced620..b60e488db2 100644 --- a/packages/frontend-core/src/components/grid/stores/datasource.ts +++ b/packages/frontend-core/src/components/grid/stores/datasource.ts @@ -133,7 +133,11 @@ export const deriveStores = (context: StoreContext): DerivedDatasourceStore => { type = ($datasource as any).value?.datasource?.type } // Handle calculation views - if (type === "viewV2" && $definition?.type === ViewV2Type.CALCULATION) { + if ( + type === "viewV2" && + "type" in $definition && + $definition?.type === ViewV2Type.CALCULATION + ) { return false } return ["table", "viewV2", "link"].includes(type) @@ -167,6 +171,7 @@ export const createActions = (context: StoreContext): ActionDatasourceStore => { const getAPI = () => { const $datasource = get(datasource) const type = $datasource?.type + console.error({ type }) if (!type) { return null } @@ -338,7 +343,7 @@ export const createActions = (context: StoreContext): ActionDatasourceStore => { // Checks if a certain datasource config is valid const isDatasourceValid = (datasource: UIDatasource) => { - return getAPI()?.actions.isDatasourceValid(datasource as any) + return getAPI()?.actions.isDatasourceValid(datasource) } // Checks if this datasource can use a specific column by name diff --git a/packages/frontend-core/src/components/grid/stores/datasources/index.ts b/packages/frontend-core/src/components/grid/stores/datasources/index.ts index a03d85e74f..c58aef37e9 100644 --- a/packages/frontend-core/src/components/grid/stores/datasources/index.ts +++ b/packages/frontend-core/src/components/grid/stores/datasources/index.ts @@ -3,13 +3,10 @@ import { SaveRowRequest, SaveTableRequest, UIDatasource, - UITable, - UIView, UpdateViewRequest, } from "@budibase/types" interface DatasourceBaseActions< - TDatasource = UITable | UIView, TSaveDefinitionRequest = UpdateViewRequest | SaveTableRequest > { saveDefinition: (newDefinition: TSaveDefinitionRequest) => Promise @@ -17,18 +14,18 @@ interface DatasourceBaseActions< updateRow: (row: SaveRowRequest) => Promise deleteRows: (rows: Row[]) => Promise getRow: (id: string) => Promise - isDatasourceValid: (datasource: TDatasource) => boolean | void + isDatasourceValid: (datasource: UIDatasource) => boolean | void canUseColumn: (name: string) => boolean | void } export interface DatasourceTableActions - extends DatasourceBaseActions {} + extends DatasourceBaseActions {} export interface DatasourceViewActions - extends DatasourceBaseActions {} + extends DatasourceBaseActions {} export interface DatasourceNonPlusActions - extends DatasourceBaseActions {} + extends DatasourceBaseActions {} export type DatasourceActions = | DatasourceTableActions & DatasourceViewActions & DatasourceNonPlusActions diff --git a/packages/frontend-core/src/components/grid/stores/datasources/nonPlus.ts b/packages/frontend-core/src/components/grid/stores/datasources/nonPlus.ts index 46b224730b..17e5e8b8d9 100644 --- a/packages/frontend-core/src/components/grid/stores/datasources/nonPlus.ts +++ b/packages/frontend-core/src/components/grid/stores/datasources/nonPlus.ts @@ -1,4 +1,4 @@ -import { SortOrder, UIDatasource, UITable, UIView } from "@budibase/types" +import { SortOrder, UIDatasource } from "@budibase/types" import { get } from "svelte/store" import { Store as StoreContext } from ".." import { DatasourceNonPlusActions } from "." @@ -34,8 +34,8 @@ export const createActions = (context: StoreContext): NonPlusActions => { // There are many different types and shapes of datasource, so we only // check that we aren't null return ( - !table.actions.isDatasourceValid(datasource as UITable) && - !viewV2.actions.isDatasourceValid(datasource as UIView) && + !table.actions.isDatasourceValid(datasource) && + !viewV2.actions.isDatasourceValid(datasource) && datasource?.type != null ) } diff --git a/packages/frontend-core/src/components/grid/stores/datasources/table.ts b/packages/frontend-core/src/components/grid/stores/datasources/table.ts index 5c8b3e1a1a..894a65ba4c 100644 --- a/packages/frontend-core/src/components/grid/stores/datasources/table.ts +++ b/packages/frontend-core/src/components/grid/stores/datasources/table.ts @@ -4,7 +4,6 @@ import { SaveTableRequest, SortOrder, UIDatasource, - UITable, } from "@budibase/types" import { get } from "svelte/store" import { Store as StoreContext } from ".." @@ -98,7 +97,7 @@ export const initialise = (context: StoreContext) => { // Clear previous subscriptions unsubscribers?.forEach(unsubscribe => unsubscribe()) unsubscribers = [] - if (!table.actions.isDatasourceValid($datasource as UITable)) { + if (!table.actions.isDatasourceValid($datasource)) { return } diff --git a/packages/frontend-core/src/components/grid/stores/datasources/viewV2.ts b/packages/frontend-core/src/components/grid/stores/datasources/viewV2.ts index e83d866455..d9cac5397d 100644 --- a/packages/frontend-core/src/components/grid/stores/datasources/viewV2.ts +++ b/packages/frontend-core/src/components/grid/stores/datasources/viewV2.ts @@ -3,6 +3,7 @@ import { Row, SaveRowRequest, SortOrder, + UIDatasource, UIView, UpdateViewRequest, } from "@budibase/types" @@ -56,7 +57,7 @@ export const createActions = (context: StoreContext): ViewActions => { return res?.rows?.[0] } - const isDatasourceValid = (datasource: UIView) => { + const isDatasourceValid = (datasource: UIDatasource) => { return ( datasource?.type === "viewV2" && !!datasource?.id && !!datasource?.tableId ) @@ -108,7 +109,7 @@ export const initialise = (context: StoreContext) => { // Clear previous subscriptions unsubscribers?.forEach(unsubscribe => unsubscribe()) unsubscribers = [] - if (!viewV2.actions.isDatasourceValid($datasource as UIView)) { + if (!viewV2.actions.isDatasourceValid($datasource)) { return } @@ -168,7 +169,7 @@ export const initialise = (context: StoreContext) => { field: $sort.column, order: $sort.order || SortOrder.ASCENDING, }, - } as never as UpdateViewRequest) + }) } // Also update the fetch to ensure the new sort is respected. diff --git a/packages/types/src/ui/stores/grid/datasource.ts b/packages/types/src/ui/stores/grid/datasource.ts index c8a6a6fc83..1d9b6740a4 100644 --- a/packages/types/src/ui/stores/grid/datasource.ts +++ b/packages/types/src/ui/stores/grid/datasource.ts @@ -1,6 +1,8 @@ import { UITable, UIView } from "@budibase/types" -export type UIDatasource = UITable | UIView +export type UIDatasource = (UITable | UIView) & { + type: string +} export interface UIFieldMutation { visible?: boolean diff --git a/packages/types/src/ui/stores/grid/table.ts b/packages/types/src/ui/stores/grid/table.ts index 4c19cbf882..6fae1e908a 100644 --- a/packages/types/src/ui/stores/grid/table.ts +++ b/packages/types/src/ui/stores/grid/table.ts @@ -8,7 +8,6 @@ import { } from "@budibase/types" export interface UITable { - type: string name: string id: string tableId: string diff --git a/packages/types/src/ui/stores/grid/view.ts b/packages/types/src/ui/stores/grid/view.ts index af214e7d82..f81cc34aaf 100644 --- a/packages/types/src/ui/stores/grid/view.ts +++ b/packages/types/src/ui/stores/grid/view.ts @@ -1,16 +1,6 @@ -import { SortOrder, UISearchFilter } from "@budibase/types" +import { ViewV2 } from "@budibase/types" import { UIFieldSchema } from "./table" -export interface UIView { - type: string - version: 2 - id: string - tableId: string - primaryDisplay?: string +export interface UIView extends ViewV2 { schema: Record - sort?: { - field: string - order: SortOrder - } - queryUI: UISearchFilter } From 69312c31afb7e429dc0afb736c51a570426ef47a Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 24 Dec 2024 13:03:39 +0100 Subject: [PATCH 23/27] Updates --- .../src/components/grid/stores/datasource.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/datasource.ts b/packages/frontend-core/src/components/grid/stores/datasource.ts index b60e488db2..ab083f413d 100644 --- a/packages/frontend-core/src/components/grid/stores/datasource.ts +++ b/packages/frontend-core/src/components/grid/stores/datasource.ts @@ -5,11 +5,9 @@ import { cloneDeep } from "lodash" import { Row, SaveRowRequest, - SaveTableRequest, UIDatasource, UIFieldMutation, UIFieldSchema, - UpdateViewRequest, ViewV2Type, } from "@budibase/types" import { Store as StoreContext } from "." @@ -195,12 +193,10 @@ export const createActions = (context: StoreContext): ActionDatasourceStore => { } // Saves the datasource definition - const saveDefinition = async ( - newDefinition: UpdateViewRequest | SaveTableRequest - ) => { + const saveDefinition = async (newDefinition: UIDatasource) => { // Update local state const originalDefinition = get(definition) - definition.set(newDefinition as any) + definition.set(newDefinition) // Update server if (get(config).canSaveSchema) { From 06feba95ad98d574e3fef76b74fbf5e9e85b4d07 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 24 Dec 2024 13:14:52 +0100 Subject: [PATCH 24/27] Remove console.log --- packages/frontend-core/src/components/grid/stores/datasource.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/frontend-core/src/components/grid/stores/datasource.ts b/packages/frontend-core/src/components/grid/stores/datasource.ts index ab083f413d..62c79e8e78 100644 --- a/packages/frontend-core/src/components/grid/stores/datasource.ts +++ b/packages/frontend-core/src/components/grid/stores/datasource.ts @@ -169,7 +169,6 @@ export const createActions = (context: StoreContext): ActionDatasourceStore => { const getAPI = () => { const $datasource = get(datasource) const type = $datasource?.type - console.error({ type }) if (!type) { return null } From 68eb809d28e58f093f1d20792f2b7d6c569d0a57 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 24 Dec 2024 13:25:34 +0100 Subject: [PATCH 25/27] Fix "type" conflicts --- .../src/components/grid/stores/datasource.ts | 8 ++++++-- packages/types/src/ui/stores/grid/table.ts | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/datasource.ts b/packages/frontend-core/src/components/grid/stores/datasource.ts index 62c79e8e78..ce9f2837bb 100644 --- a/packages/frontend-core/src/components/grid/stores/datasource.ts +++ b/packages/frontend-core/src/components/grid/stores/datasource.ts @@ -5,9 +5,11 @@ import { cloneDeep } from "lodash" import { Row, SaveRowRequest, + SaveTableRequest, UIDatasource, UIFieldMutation, UIFieldSchema, + UpdateViewRequest, ViewV2Type, } from "@budibase/types" import { Store as StoreContext } from "." @@ -192,10 +194,12 @@ export const createActions = (context: StoreContext): ActionDatasourceStore => { } // Saves the datasource definition - const saveDefinition = async (newDefinition: UIDatasource) => { + const saveDefinition = async ( + newDefinition: SaveTableRequest | UpdateViewRequest + ) => { // Update local state const originalDefinition = get(definition) - definition.set(newDefinition) + definition.set(newDefinition as UIDatasource) // Update server if (get(config).canSaveSchema) { diff --git a/packages/types/src/ui/stores/grid/table.ts b/packages/types/src/ui/stores/grid/table.ts index 6fae1e908a..a5a13d5fa2 100644 --- a/packages/types/src/ui/stores/grid/table.ts +++ b/packages/types/src/ui/stores/grid/table.ts @@ -4,12 +4,14 @@ import { FieldType, RelationSchemaField, SortOrder, + Table, UISearchFilter, } from "@budibase/types" -export interface UITable { +export interface UITable extends Omit { name: string id: string + type: string tableId: string primaryDisplay?: string sort?: { From 67f511da7285bde76cf8ecf74e6f48bcdcc7b8c4 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 27 Dec 2024 18:25:29 +0100 Subject: [PATCH 26/27] Fix css warnings --- packages/bbui/src/Form/Core/DatePicker/NumberInput.svelte | 1 + packages/bbui/src/Form/Core/Slider.svelte | 1 + packages/bbui/src/Tabs/Tabs.svelte | 2 -- packages/bbui/src/Tooltip/AbsTooltip.svelte | 1 + packages/frontend-core/src/components/grid/cells/AICell.svelte | 1 + .../src/components/grid/cells/LongFormCell.svelte | 1 + .../frontend-core/src/components/grid/cells/TextCell.svelte | 3 +++ 7 files changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/bbui/src/Form/Core/DatePicker/NumberInput.svelte b/packages/bbui/src/Form/Core/DatePicker/NumberInput.svelte index 6c06ce4e79..84b55c403f 100644 --- a/packages/bbui/src/Form/Core/DatePicker/NumberInput.svelte +++ b/packages/bbui/src/Form/Core/DatePicker/NumberInput.svelte @@ -51,6 +51,7 @@ } input.hide-arrows { -moz-appearance: textfield; + appearance: textfield; } input[type="time"]::-webkit-calendar-picker-indicator { display: none; diff --git a/packages/bbui/src/Form/Core/Slider.svelte b/packages/bbui/src/Form/Core/Slider.svelte index 1a601d0185..0fcadd8bad 100644 --- a/packages/bbui/src/Form/Core/Slider.svelte +++ b/packages/bbui/src/Form/Core/Slider.svelte @@ -39,6 +39,7 @@ padding: 0; margin: 0; -webkit-appearance: none; + appearance: none; background: transparent; } input::-webkit-slider-thumb { diff --git a/packages/bbui/src/Tabs/Tabs.svelte b/packages/bbui/src/Tabs/Tabs.svelte index c94b396398..3955145ad1 100644 --- a/packages/bbui/src/Tabs/Tabs.svelte +++ b/packages/bbui/src/Tabs/Tabs.svelte @@ -124,8 +124,6 @@ .spectrum-Tabs-selectionIndicator.emphasized { background-color: var(--spectrum-global-color-blue-400); } - .spectrum-Tabs--horizontal .spectrum-Tabs-selectionIndicator { - } .noHorizPadding { padding: 0; } diff --git a/packages/bbui/src/Tooltip/AbsTooltip.svelte b/packages/bbui/src/Tooltip/AbsTooltip.svelte index 4d2399aaf8..b85f4e1c03 100644 --- a/packages/bbui/src/Tooltip/AbsTooltip.svelte +++ b/packages/bbui/src/Tooltip/AbsTooltip.svelte @@ -134,6 +134,7 @@ .spectrum-Tooltip-label { display: -webkit-box; -webkit-line-clamp: 3; + line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; font-size: 12px; diff --git a/packages/frontend-core/src/components/grid/cells/AICell.svelte b/packages/frontend-core/src/components/grid/cells/AICell.svelte index 38e81cefd3..b56e67b752 100644 --- a/packages/frontend-core/src/components/grid/cells/AICell.svelte +++ b/packages/frontend-core/src/components/grid/cells/AICell.svelte @@ -73,6 +73,7 @@ .value { display: -webkit-box; -webkit-line-clamp: var(--content-lines); + line-clamp: var(--content-lines); -webkit-box-orient: vertical; overflow: hidden; line-height: 20px; diff --git a/packages/frontend-core/src/components/grid/cells/LongFormCell.svelte b/packages/frontend-core/src/components/grid/cells/LongFormCell.svelte index 7829e5da7d..80da91e091 100644 --- a/packages/frontend-core/src/components/grid/cells/LongFormCell.svelte +++ b/packages/frontend-core/src/components/grid/cells/LongFormCell.svelte @@ -93,6 +93,7 @@ .value { display: -webkit-box; -webkit-line-clamp: var(--content-lines); + line-clamp: var(--content-lines); -webkit-box-orient: vertical; overflow: hidden; line-height: 20px; diff --git a/packages/frontend-core/src/components/grid/cells/TextCell.svelte b/packages/frontend-core/src/components/grid/cells/TextCell.svelte index 9275bca3c6..b9a63eb401 100644 --- a/packages/frontend-core/src/components/grid/cells/TextCell.svelte +++ b/packages/frontend-core/src/components/grid/cells/TextCell.svelte @@ -74,12 +74,14 @@ .value { display: -webkit-box; -webkit-line-clamp: var(--content-lines); + line-clamp: var(--content-lines); -webkit-box-orient: vertical; overflow: hidden; line-height: 20px; } .number .value { -webkit-line-clamp: 1; + line-clamp: 1; } input { flex: 1 1 auto; @@ -110,5 +112,6 @@ } input[type="number"] { -moz-appearance: textfield; + appearance: textfield; } From 6aedc253924ef8e863e3da41ec707bb7574f6c43 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Sun, 29 Dec 2024 12:50:17 +0100 Subject: [PATCH 27/27] Fix wrong "in" of undefined --- .../frontend-core/src/components/grid/stores/datasource.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/datasource.ts b/packages/frontend-core/src/components/grid/stores/datasource.ts index ce9f2837bb..7aee6e8515 100644 --- a/packages/frontend-core/src/components/grid/stores/datasource.ts +++ b/packages/frontend-core/src/components/grid/stores/datasource.ts @@ -133,11 +133,7 @@ export const deriveStores = (context: StoreContext): DerivedDatasourceStore => { type = ($datasource as any).value?.datasource?.type } // Handle calculation views - if ( - type === "viewV2" && - "type" in $definition && - $definition?.type === ViewV2Type.CALCULATION - ) { + if (type === "viewV2" && $definition?.type === ViewV2Type.CALCULATION) { return false } return ["table", "viewV2", "link"].includes(type)