Skip to content

Commit

Permalink
Move type to type/ui
Browse files Browse the repository at this point in the history
  • Loading branch information
adrinr committed Dec 20, 2024
1 parent fc76f57 commit 546f193
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 29 deletions.
40 changes: 11 additions & 29 deletions packages/frontend-core/src/components/grid/stores/columns.ts
Original file line number Diff line number Diff line change
@@ -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<Column[]>
columns: Writable<UIColumn[]>
}

interface DerivedColumnStore {
tableColumns: Readable<Column[]>
displayColumn: Readable<Column | undefined>
columnLookupMap: Readable<Record<string, Column>>
visibleColumns: Readable<Column[]>
scrollableColumns: Readable<Column[]>
tableColumns: Readable<UIColumn[]>
displayColumn: Readable<UIColumn | undefined>
columnLookupMap: Readable<Record<string, UIColumn>>
visibleColumns: Readable<UIColumn[]>
scrollableColumns: Readable<UIColumn[]>
hasNonAutoColumn: Readable<boolean>
}

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<Column[]>([])
const columns = writable<UIColumn[]>([])

// Enrich columns with metadata about their display position
const enrichedColumns = derived(columns, $columns => {
Expand Down Expand Up @@ -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<string, Column> = {}
let map: Record<string, UIColumn> = {}
$columns.forEach(column => {
map[column.name] = column
})
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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,
Expand Down
19 changes: 19 additions & 0 deletions packages/types/src/ui/stores/grid/columns.ts
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions packages/types/src/ui/stores/grid/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./columns"
1 change: 1 addition & 0 deletions packages/types/src/ui/stores/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./integration"
export * from "./grid"

0 comments on commit 546f193

Please sign in to comment.