From 1c4a1c6b99adcff90b0e8d2421271a2a675f61f4 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 20 Dec 2024 11:50:28 +0100 Subject: [PATCH 01/10] initial ts conversion --- .../grid/stores/{columns.js => columns.ts} | 28 +++++++++++++++---- .../grid/stores/{index.js => index.ts} | 8 ++++++ 2 files changed, 31 insertions(+), 5 deletions(-) rename packages/frontend-core/src/components/grid/stores/{columns.js => columns.ts} (90%) rename packages/frontend-core/src/components/grid/stores/{index.js => index.ts} (92%) diff --git a/packages/frontend-core/src/components/grid/stores/columns.js b/packages/frontend-core/src/components/grid/stores/columns.ts similarity index 90% rename from packages/frontend-core/src/components/grid/stores/columns.js rename to packages/frontend-core/src/components/grid/stores/columns.ts index 5f2800ba7a..44f9039de5 100644 --- a/packages/frontend-core/src/components/grid/stores/columns.js +++ b/packages/frontend-core/src/components/grid/stores/columns.ts @@ -1,7 +1,25 @@ -import { derived, get, writable } from "svelte/store" +import { derived, get, Writable, writable } from "svelte/store" import { DefaultColumnWidth, GutterWidth } from "../lib/constants" +import { FieldSchema } from "@budibase/types" +import { StoreContext } from "." -export const createStores = () => { +export interface Store { + columns: Writable +} + +type Column = FieldSchema & { + related?: { + field: string + subField: string + } + primaryDisplay: boolean + + schema?: { + autocolumn: boolean + } +} + +export const createStores = (): Store => { const columns = writable([]) // Enrich columns with metadata about their display position @@ -30,7 +48,7 @@ export const createStores = () => { } } -export const deriveStores = context => { +export const deriveStores = (context: Store) => { const { columns } = context // Derive a lookup map for all columns by name @@ -78,7 +96,7 @@ export const deriveStores = context => { } } -export const createActions = context => { +export const createActions = (context: StoreContext) => { const { columns, datasource } = context // Updates the width of all columns @@ -125,7 +143,7 @@ export const createActions = context => { } } -export const initialise = context => { +export const initialise = (context: StoreContext) => { const { definition, columns, displayColumn, enrichedSchema } = context // Merge new schema fields with existing schema in order to preserve widths diff --git a/packages/frontend-core/src/components/grid/stores/index.js b/packages/frontend-core/src/components/grid/stores/index.ts similarity index 92% rename from packages/frontend-core/src/components/grid/stores/index.js rename to packages/frontend-core/src/components/grid/stores/index.ts index 6671cc729c..80898713e5 100644 --- a/packages/frontend-core/src/components/grid/stores/index.js +++ b/packages/frontend-core/src/components/grid/stores/index.ts @@ -71,3 +71,11 @@ export const attachStores = context => { return context } + +export interface StoreContext { + columns: Columns.Store["columns"] + datasource: any + definition: any + displayColumn: any + enrichedSchema: any +} From e70dc86202597317fb3ca983c2f83edcbb48a32d Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 20 Dec 2024 11:55:47 +0100 Subject: [PATCH 02/10] Fix tsconfig --- packages/builder/tsconfig.json | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/builder/tsconfig.json b/packages/builder/tsconfig.json index a7a4c3d800..da5dcd67c6 100644 --- a/packages/builder/tsconfig.json +++ b/packages/builder/tsconfig.json @@ -1,6 +1,7 @@ { "extends": "./tsconfig.build.json", "compilerOptions": { + "outDir": "./dist", "baseUrl": ".", "paths": { "assets/*": ["./assets/*"], From 675e1957084b922d7bbfe77e77e5fd75d91643e1 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 20 Dec 2024 11:59:57 +0100 Subject: [PATCH 03/10] Improve typings --- .../src/components/grid/stores/columns.ts | 12 ++++++++---- .../src/components/grid/stores/index.ts | 6 ++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/columns.ts b/packages/frontend-core/src/components/grid/stores/columns.ts index 44f9039de5..881c4dff6f 100644 --- a/packages/frontend-core/src/components/grid/stores/columns.ts +++ b/packages/frontend-core/src/components/grid/stores/columns.ts @@ -1,6 +1,6 @@ import { derived, get, Writable, writable } from "svelte/store" import { DefaultColumnWidth, GutterWidth } from "../lib/constants" -import { FieldSchema } from "@budibase/types" +import { CalculationType, FieldSchema } from "@budibase/types" import { StoreContext } from "." export interface Store { @@ -8,15 +8,18 @@ export interface Store { } type Column = FieldSchema & { + label: string + readonly: boolean + conditions: any related?: { field: string subField: string } - primaryDisplay: boolean - + primaryDisplay?: boolean schema?: { autocolumn: boolean } + calculationType: CalculationType } export const createStores = (): Store => { @@ -169,7 +172,8 @@ export const initialise = (context: StoreContext) => { .map(field => { const fieldSchema = $enrichedSchema[field] const oldColumn = $columns?.find(col => col.name === field) - const column = { + const column: Column = { + type: fieldSchema.type, name: field, label: fieldSchema.displayName || field, schema: fieldSchema, diff --git a/packages/frontend-core/src/components/grid/stores/index.ts b/packages/frontend-core/src/components/grid/stores/index.ts index 80898713e5..fdbd6b4f91 100644 --- a/packages/frontend-core/src/components/grid/stores/index.ts +++ b/packages/frontend-core/src/components/grid/stores/index.ts @@ -1,3 +1,5 @@ +import { Writable } from "svelte/store" + import * as Bounds from "./bounds" import * as Columns from "./columns" import * as Menu from "./menu" @@ -75,7 +77,7 @@ export const attachStores = context => { export interface StoreContext { columns: Columns.Store["columns"] datasource: any - definition: any - displayColumn: any + definition: Writable + displayColumn: Writable enrichedSchema: any } From 624df90edabbaeeb291d0f793afd64ba30271553 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 20 Dec 2024 12:23:50 +0100 Subject: [PATCH 04/10] Type derivedStore --- .../src/components/grid/stores/columns.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/columns.ts b/packages/frontend-core/src/components/grid/stores/columns.ts index 881c4dff6f..7831305e1b 100644 --- a/packages/frontend-core/src/components/grid/stores/columns.ts +++ b/packages/frontend-core/src/components/grid/stores/columns.ts @@ -1,4 +1,4 @@ -import { derived, get, Writable, writable } from "svelte/store" +import { derived, get, Readable, Writable, writable } from "svelte/store" import { DefaultColumnWidth, GutterWidth } from "../lib/constants" import { CalculationType, FieldSchema } from "@budibase/types" import { StoreContext } from "." @@ -7,6 +7,15 @@ export interface Store { columns: Writable } +export interface DerivedStore { + tableColumns: Readable + displayColumn: Readable + columnLookupMap: Readable> + visibleColumns: Readable + scrollableColumns: Readable + hasNonAutoColumn: Readable +} + type Column = FieldSchema & { label: string readonly: boolean @@ -51,7 +60,7 @@ export const createStores = (): Store => { } } -export const deriveStores = (context: Store) => { +export const deriveStores = (context: Store): DerivedStore => { const { columns } = context // Derive a lookup map for all columns by name From 0ed387d9ba4874ed7c9eecc84481d61030b4071f Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 20 Dec 2024 12:35:09 +0100 Subject: [PATCH 05/10] Improve store --- .../src/components/grid/stores/columns.ts | 2 +- .../src/components/grid/stores/index.ts | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/columns.ts b/packages/frontend-core/src/components/grid/stores/columns.ts index 7831305e1b..9a85918d6d 100644 --- a/packages/frontend-core/src/components/grid/stores/columns.ts +++ b/packages/frontend-core/src/components/grid/stores/columns.ts @@ -1,7 +1,7 @@ import { derived, get, Readable, Writable, writable } from "svelte/store" import { DefaultColumnWidth, GutterWidth } from "../lib/constants" import { CalculationType, FieldSchema } from "@budibase/types" -import { StoreContext } from "." +import { Store as StoreContext } from "." export interface Store { columns: Writable diff --git a/packages/frontend-core/src/components/grid/stores/index.ts b/packages/frontend-core/src/components/grid/stores/index.ts index fdbd6b4f91..602dfa969a 100644 --- a/packages/frontend-core/src/components/grid/stores/index.ts +++ b/packages/frontend-core/src/components/grid/stores/index.ts @@ -50,7 +50,16 @@ const DependencyOrderedStores = [ Cache, ] -export const attachStores = context => { +export type Store = Columns.Store & + Columns.DerivedStore & { + // TODO while typing the rest of stores + datasource: any + definition: Writable + displayColumn: Writable + enrichedSchema: any + } + +export const attachStores = (context): Store => { // Atomic store creation for (let store of DependencyOrderedStores) { context = { ...context, ...store.createStores?.(context) } @@ -73,11 +82,3 @@ export const attachStores = context => { return context } - -export interface StoreContext { - columns: Columns.Store["columns"] - datasource: any - definition: Writable - displayColumn: Writable - enrichedSchema: any -} From bec5ad6c95c6c626bae951acc934ff91903e3283 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 20 Dec 2024 12:38:57 +0100 Subject: [PATCH 06/10] More typing --- .../frontend-core/src/components/grid/stores/columns.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/columns.ts b/packages/frontend-core/src/components/grid/stores/columns.ts index 9a85918d6d..a457ca0caf 100644 --- a/packages/frontend-core/src/components/grid/stores/columns.ts +++ b/packages/frontend-core/src/components/grid/stores/columns.ts @@ -1,6 +1,6 @@ import { derived, get, Readable, Writable, writable } from "svelte/store" import { DefaultColumnWidth, GutterWidth } from "../lib/constants" -import { CalculationType, FieldSchema } from "@budibase/types" +import { CalculationType, FieldSchema, FieldType } from "@budibase/types" import { Store as StoreContext } from "." export interface Store { @@ -26,6 +26,9 @@ type Column = FieldSchema & { } primaryDisplay?: boolean schema?: { + disabled: boolean + type: FieldType + readonly: boolean autocolumn: boolean } calculationType: CalculationType @@ -112,7 +115,7 @@ export const createActions = (context: StoreContext) => { const { columns, datasource } = context // Updates the width of all columns - const changeAllColumnWidths = async width => { + const changeAllColumnWidths = async (width: number) => { const $columns = get(columns) $columns.forEach(column => { const { related } = column @@ -131,7 +134,7 @@ export const createActions = (context: StoreContext) => { } // Checks if a column is readonly - const isReadonly = column => { + const isReadonly = (column: Column) => { if (!column?.schema) { return false } From 10615bbce42c18b6560ce76302c84067d5ad89ff Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 20 Dec 2024 12:45:01 +0100 Subject: [PATCH 07/10] Use right type --- packages/frontend-core/src/components/grid/stores/columns.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/frontend-core/src/components/grid/stores/columns.ts b/packages/frontend-core/src/components/grid/stores/columns.ts index a457ca0caf..b5897769cd 100644 --- a/packages/frontend-core/src/components/grid/stores/columns.ts +++ b/packages/frontend-core/src/components/grid/stores/columns.ts @@ -63,7 +63,7 @@ export const createStores = (): Store => { } } -export const deriveStores = (context: Store): DerivedStore => { +export const deriveStores = (context: StoreContext): DerivedStore => { const { columns } = context // Derive a lookup map for all columns by name From acc9da38769abbaf6baa31877a307e628b727887 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 20 Dec 2024 13:36:40 +0100 Subject: [PATCH 08/10] Unify --- .../src/components/grid/stores/columns.ts | 10 ++++++---- .../src/components/grid/stores/index.ts | 15 +++++++-------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/columns.ts b/packages/frontend-core/src/components/grid/stores/columns.ts index b5897769cd..219f604c9b 100644 --- a/packages/frontend-core/src/components/grid/stores/columns.ts +++ b/packages/frontend-core/src/components/grid/stores/columns.ts @@ -3,11 +3,11 @@ import { DefaultColumnWidth, GutterWidth } from "../lib/constants" import { CalculationType, FieldSchema, FieldType } from "@budibase/types" import { Store as StoreContext } from "." -export interface Store { +interface ColumnStore { columns: Writable } -export interface DerivedStore { +interface DerivedColumnStore { tableColumns: Readable displayColumn: Readable columnLookupMap: Readable> @@ -16,6 +16,8 @@ export interface DerivedStore { hasNonAutoColumn: Readable } +export type Store = ColumnStore & DerivedColumnStore + type Column = FieldSchema & { label: string readonly: boolean @@ -34,7 +36,7 @@ type Column = FieldSchema & { calculationType: CalculationType } -export const createStores = (): Store => { +export const createStores = (): ColumnStore => { const columns = writable([]) // Enrich columns with metadata about their display position @@ -63,7 +65,7 @@ export const createStores = (): Store => { } } -export const deriveStores = (context: StoreContext): DerivedStore => { +export const deriveStores = (context: StoreContext): DerivedColumnStore => { const { columns } = context // Derive a lookup map for all columns by name diff --git a/packages/frontend-core/src/components/grid/stores/index.ts b/packages/frontend-core/src/components/grid/stores/index.ts index 602dfa969a..56ad5b9b48 100644 --- a/packages/frontend-core/src/components/grid/stores/index.ts +++ b/packages/frontend-core/src/components/grid/stores/index.ts @@ -50,14 +50,13 @@ const DependencyOrderedStores = [ Cache, ] -export type Store = Columns.Store & - Columns.DerivedStore & { - // TODO while typing the rest of stores - datasource: any - definition: Writable - displayColumn: Writable - enrichedSchema: any - } +export type Store = Columns.Store & { + // TODO while typing the rest of stores + datasource: any + definition: Writable + displayColumn: Writable + enrichedSchema: any +} export const attachStores = (context): Store => { // Atomic store creation From fc76f573aa083a45f2dc912eba6d7350104965e8 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 20 Dec 2024 13:58:56 +0100 Subject: [PATCH 09/10] Fix types --- .../src/components/grid/stores/columns.ts | 12 +++---- .../src/components/grid/stores/index.ts | 34 ++++++++++++------- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/columns.ts b/packages/frontend-core/src/components/grid/stores/columns.ts index 219f604c9b..b04cd31a99 100644 --- a/packages/frontend-core/src/components/grid/stores/columns.ts +++ b/packages/frontend-core/src/components/grid/stores/columns.ts @@ -9,7 +9,7 @@ interface ColumnStore { interface DerivedColumnStore { tableColumns: Readable - displayColumn: Readable + displayColumn: Readable columnLookupMap: Readable> visibleColumns: Readable scrollableColumns: Readable @@ -37,7 +37,7 @@ type Column = FieldSchema & { } export const createStores = (): ColumnStore => { - const columns = writable([]) + const columns = writable([]) // Enrich columns with metadata about their display position const enrichedColumns = derived(columns, $columns => { @@ -51,7 +51,7 @@ export const createStores = (): ColumnStore => { } if (col.visible) { idx++ - offset += col.width + offset += col.width ?? 0 } return enriched }) @@ -70,7 +70,7 @@ export const deriveStores = (context: StoreContext): DerivedColumnStore => { // Derive a lookup map for all columns by name const columnLookupMap = derived(columns, $columns => { - let map = {} + let map: Record = {} $columns.forEach(column => { map[column.name] = column }) @@ -164,7 +164,7 @@ export const initialise = (context: StoreContext) => { const { definition, columns, displayColumn, enrichedSchema } = context // Merge new schema fields with existing schema in order to preserve widths - const processColumns = $enrichedSchema => { + const processColumns = ($enrichedSchema: any) => { if (!$enrichedSchema) { columns.set([]) return @@ -174,7 +174,7 @@ export const initialise = (context: StoreContext) => { const $displayColumn = get(displayColumn) // Find primary display - let primaryDisplay + let primaryDisplay: string const candidatePD = $definition.primaryDisplay || $displayColumn?.name if (candidatePD && $enrichedSchema[candidatePD]) { primaryDisplay = candidatePD diff --git a/packages/frontend-core/src/components/grid/stores/index.ts b/packages/frontend-core/src/components/grid/stores/index.ts index 56ad5b9b48..763a33c398 100644 --- a/packages/frontend-core/src/components/grid/stores/index.ts +++ b/packages/frontend-core/src/components/grid/stores/index.ts @@ -50,33 +50,43 @@ const DependencyOrderedStores = [ Cache, ] -export type Store = Columns.Store & { - // TODO while typing the rest of stores - datasource: any - definition: Writable - displayColumn: Writable - enrichedSchema: any -} +export interface BaseStore {} -export const attachStores = (context): Store => { +export type Store = BaseStore & + Columns.Store & { + // TODO while typing the rest of stores + datasource: any + definition: Writable + enrichedSchema: any + } + +export const attachStores = (context: Store): Store => { // Atomic store creation for (let store of DependencyOrderedStores) { - context = { ...context, ...store.createStores?.(context) } + if ("createStores" in store) { + context = { ...context, ...store.createStores?.(context) } + } } // Derived store creation for (let store of DependencyOrderedStores) { - context = { ...context, ...store.deriveStores?.(context) } + if ("deriveStores" in store) { + context = { ...context, ...store.deriveStores?.(context) } + } } // Action creation for (let store of DependencyOrderedStores) { - context = { ...context, ...store.createActions?.(context) } + if ("createActions" in store) { + context = { ...context, ...store.createActions?.(context) } + } } // Initialise any store logic for (let store of DependencyOrderedStores) { - store.initialise?.(context) + if ("initialise" in store) { + store.initialise?.(context) + } } return context From 546f193af7b61bcd22f7783d5132b78d5f725862 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 20 Dec 2024 15:57:03 +0100 Subject: [PATCH 10/10] Move type to type/ui --- .../src/components/grid/stores/columns.ts | 40 +++++-------------- packages/types/src/ui/stores/grid/columns.ts | 19 +++++++++ packages/types/src/ui/stores/grid/index.ts | 1 + packages/types/src/ui/stores/index.ts | 1 + 4 files changed, 32 insertions(+), 29 deletions(-) create mode 100644 packages/types/src/ui/stores/grid/columns.ts create mode 100644 packages/types/src/ui/stores/grid/index.ts diff --git a/packages/frontend-core/src/components/grid/stores/columns.ts b/packages/frontend-core/src/components/grid/stores/columns.ts index b04cd31a99..b201cc7f7b 100644 --- a/packages/frontend-core/src/components/grid/stores/columns.ts +++ b/packages/frontend-core/src/components/grid/stores/columns.ts @@ -1,43 +1,25 @@ import { derived, get, Readable, Writable, writable } from "svelte/store" import { DefaultColumnWidth, GutterWidth } from "../lib/constants" -import { CalculationType, FieldSchema, FieldType } from "@budibase/types" +import { UIColumn } from "@budibase/types" import { Store as StoreContext } from "." interface ColumnStore { - columns: Writable + columns: Writable } interface DerivedColumnStore { - tableColumns: Readable - displayColumn: Readable - columnLookupMap: Readable> - visibleColumns: Readable - scrollableColumns: Readable + tableColumns: Readable + displayColumn: Readable + columnLookupMap: Readable> + visibleColumns: Readable + scrollableColumns: Readable hasNonAutoColumn: Readable } export type Store = ColumnStore & DerivedColumnStore -type Column = FieldSchema & { - label: string - readonly: boolean - conditions: any - related?: { - field: string - subField: string - } - primaryDisplay?: boolean - schema?: { - disabled: boolean - type: FieldType - readonly: boolean - autocolumn: boolean - } - calculationType: CalculationType -} - export const createStores = (): ColumnStore => { - const columns = writable([]) + const columns = writable([]) // Enrich columns with metadata about their display position const enrichedColumns = derived(columns, $columns => { @@ -70,7 +52,7 @@ export const deriveStores = (context: StoreContext): DerivedColumnStore => { // Derive a lookup map for all columns by name const columnLookupMap = derived(columns, $columns => { - let map: Record = {} + let map: Record = {} $columns.forEach(column => { map[column.name] = column }) @@ -136,7 +118,7 @@ export const createActions = (context: StoreContext) => { } // Checks if a column is readonly - const isReadonly = (column: Column) => { + const isReadonly = (column: UIColumn) => { if (!column?.schema) { return false } @@ -186,7 +168,7 @@ export const initialise = (context: StoreContext) => { .map(field => { const fieldSchema = $enrichedSchema[field] const oldColumn = $columns?.find(col => col.name === field) - const column: Column = { + const column: UIColumn = { type: fieldSchema.type, name: field, label: fieldSchema.displayName || field, diff --git a/packages/types/src/ui/stores/grid/columns.ts b/packages/types/src/ui/stores/grid/columns.ts new file mode 100644 index 0000000000..d12739fffe --- /dev/null +++ b/packages/types/src/ui/stores/grid/columns.ts @@ -0,0 +1,19 @@ +import { CalculationType, FieldSchema, FieldType } from "@budibase/types" + +export type UIColumn = FieldSchema & { + label: string + readonly: boolean + conditions: any + related?: { + field: string + subField: string + } + primaryDisplay?: boolean + schema?: { + disabled: boolean + type: FieldType + readonly: boolean + autocolumn: boolean + } + calculationType: CalculationType +} diff --git a/packages/types/src/ui/stores/grid/index.ts b/packages/types/src/ui/stores/grid/index.ts new file mode 100644 index 0000000000..81f23bae69 --- /dev/null +++ b/packages/types/src/ui/stores/grid/index.ts @@ -0,0 +1 @@ +export * from "./columns" diff --git a/packages/types/src/ui/stores/index.ts b/packages/types/src/ui/stores/index.ts index 658691cc6d..7a6382c6b0 100644 --- a/packages/types/src/ui/stores/index.ts +++ b/packages/types/src/ui/stores/index.ts @@ -1 +1,2 @@ export * from "./integration" +export * from "./grid"