Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typing grid columns store #15228

Merged
merged 11 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/builder/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "./tsconfig.build.json",
"compilerOptions": {
"outDir": "./dist",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IDE were complaining for this field missing

"baseUrl": ".",
"paths": {
"assets/*": ["./assets/*"],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,40 @@
import { derived, get, writable } from "svelte/store"
import { derived, get, Readable, Writable, writable } from "svelte/store"
import { DefaultColumnWidth, GutterWidth } from "../lib/constants"
import { CalculationType, FieldSchema, FieldType } from "@budibase/types"
import { Store as StoreContext } from "."

export const createStores = () => {
export interface Store {
columns: Writable<Column[]>
}

export interface DerivedStore {
tableColumns: Readable<Column[]>
displayColumn: Readable<Column>
columnLookupMap: Readable<Record<string, Column>>
visibleColumns: Readable<Column[]>
scrollableColumns: Readable<Column[]>
hasNonAutoColumn: Readable<boolean>
}

type Column = FieldSchema & {
label: string
adrinr marked this conversation as resolved.
Show resolved Hide resolved
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 = (): Store => {
const columns = writable([])

// Enrich columns with metadata about their display position
Expand Down Expand Up @@ -30,7 +63,7 @@ export const createStores = () => {
}
}

export const deriveStores = context => {
export const deriveStores = (context: StoreContext): DerivedStore => {
const { columns } = context

// Derive a lookup map for all columns by name
Expand Down Expand Up @@ -78,11 +111,11 @@ export const deriveStores = context => {
}
}

export const createActions = context => {
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
Expand All @@ -101,7 +134,7 @@ export const createActions = context => {
}

// Checks if a column is readonly
const isReadonly = column => {
const isReadonly = (column: Column) => {
if (!column?.schema) {
return false
}
Expand All @@ -125,7 +158,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
Expand All @@ -151,7 +184,8 @@ export const initialise = context => {
.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,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Writable } from "svelte/store"

import * as Bounds from "./bounds"
import * as Columns from "./columns"
import * as Menu from "./menu"
Expand Down Expand Up @@ -48,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<any>
displayColumn: Writable<any>
enrichedSchema: any
}

export const attachStores = (context): Store => {
// Atomic store creation
for (let store of DependencyOrderedStores) {
context = { ...context, ...store.createStores?.(context) }
Expand Down
Loading