From 546f193af7b61bcd22f7783d5132b78d5f725862 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 20 Dec 2024 15:57:03 +0100 Subject: [PATCH] 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"