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