Move type to type/ui

This commit is contained in:
Adria Navarro 2024-12-20 15:57:03 +01:00
parent fc76f573aa
commit 546f193af7
4 changed files with 32 additions and 29 deletions

View File

@ -1,43 +1,25 @@
import { derived, get, Readable, Writable, writable } from "svelte/store" import { derived, get, Readable, Writable, writable } from "svelte/store"
import { DefaultColumnWidth, GutterWidth } from "../lib/constants" import { DefaultColumnWidth, GutterWidth } from "../lib/constants"
import { CalculationType, FieldSchema, FieldType } from "@budibase/types" import { UIColumn } from "@budibase/types"
import { Store as StoreContext } from "." import { Store as StoreContext } from "."
interface ColumnStore { interface ColumnStore {
columns: Writable<Column[]> columns: Writable<UIColumn[]>
} }
interface DerivedColumnStore { interface DerivedColumnStore {
tableColumns: Readable<Column[]> tableColumns: Readable<UIColumn[]>
displayColumn: Readable<Column | undefined> displayColumn: Readable<UIColumn | undefined>
columnLookupMap: Readable<Record<string, Column>> columnLookupMap: Readable<Record<string, UIColumn>>
visibleColumns: Readable<Column[]> visibleColumns: Readable<UIColumn[]>
scrollableColumns: Readable<Column[]> scrollableColumns: Readable<UIColumn[]>
hasNonAutoColumn: Readable<boolean> hasNonAutoColumn: Readable<boolean>
} }
export type Store = ColumnStore & DerivedColumnStore 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 => { export const createStores = (): ColumnStore => {
const columns = writable<Column[]>([]) const columns = writable<UIColumn[]>([])
// Enrich columns with metadata about their display position // Enrich columns with metadata about their display position
const enrichedColumns = derived(columns, $columns => { const enrichedColumns = derived(columns, $columns => {
@ -70,7 +52,7 @@ export const deriveStores = (context: StoreContext): DerivedColumnStore => {
// Derive a lookup map for all columns by name // Derive a lookup map for all columns by name
const columnLookupMap = derived(columns, $columns => { const columnLookupMap = derived(columns, $columns => {
let map: Record<string, Column> = {} let map: Record<string, UIColumn> = {}
$columns.forEach(column => { $columns.forEach(column => {
map[column.name] = column map[column.name] = column
}) })
@ -136,7 +118,7 @@ export const createActions = (context: StoreContext) => {
} }
// Checks if a column is readonly // Checks if a column is readonly
const isReadonly = (column: Column) => { const isReadonly = (column: UIColumn) => {
if (!column?.schema) { if (!column?.schema) {
return false return false
} }
@ -186,7 +168,7 @@ export const initialise = (context: StoreContext) => {
.map(field => { .map(field => {
const fieldSchema = $enrichedSchema[field] const fieldSchema = $enrichedSchema[field]
const oldColumn = $columns?.find(col => col.name === field) const oldColumn = $columns?.find(col => col.name === field)
const column: Column = { const column: UIColumn = {
type: fieldSchema.type, type: fieldSchema.type,
name: field, name: field,
label: fieldSchema.displayName || field, label: fieldSchema.displayName || field,

View File

@ -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
}

View File

@ -0,0 +1 @@
export * from "./columns"

View File

@ -1 +1,2 @@
export * from "./integration" export * from "./integration"
export * from "./grid"