Remove anys and fix types

This commit is contained in:
Adria Navarro 2024-12-30 12:39:52 +01:00
parent 2d36eab278
commit 6d1f2c9200
4 changed files with 52 additions and 44 deletions

View File

@ -1,40 +1,35 @@
import { derivedMemo } from "../../../utils"
import { derived, Readable } from "svelte/store"
import {
SortOrder,
UIDatasource,
UISearchFilter,
ViewV2Type,
} from "@budibase/types"
import { Store as StoreContext } from "."
import { ViewV2Type } from "@budibase/types"
import { BaseStoreProps, Store as StoreContext } from "."
export interface ConfigStore {
datasource: Readable<UIDatasource>
initialSortColumn: Readable<string | null>
initialSortOrder: Readable<SortOrder | null>
initialFilter: Readable<UISearchFilter | null>
fixedRowHeight: Readable<number | null>
schemaOverrides: Readable<Record<
string,
{
displayName?: string
disabled?: boolean
}
> | null>
notifySuccess: (message: string) => void
notifyError: (message: string) => void
interface ConfigStore {
datasource: Readable<BaseStoreProps["datasource"]>
initialSortColumn: Readable<BaseStoreProps["initialSortColumn"]>
initialSortOrder: Readable<BaseStoreProps["initialSortOrder"]>
initialFilter: Readable<BaseStoreProps["initialFilter"]>
fixedRowHeight: Readable<BaseStoreProps["fixedRowHeight"]>
schemaOverrides: Readable<BaseStoreProps["schemaOverrides"]>
notifySuccess: Readable<BaseStoreProps["notifySuccess"]>
notifyError: Readable<BaseStoreProps["notifyError"]>
canAddRows?: Readable<BaseStoreProps["canAddRows"]>
canEditRows?: Readable<BaseStoreProps["canEditRows"]>
canDeleteRows?: Readable<BaseStoreProps["canDeleteRows"]>
canEditColumns?: Readable<BaseStoreProps["canEditColumns"]>
canExpandRows?: Readable<BaseStoreProps["canExpandRows"]>
canSaveSchema?: Readable<BaseStoreProps["canSaveSchema"]>
}
interface PropsContext {
props: Readable<ConfigStore>
interface ConfigDerivedStore {
config: Readable<BaseStoreProps>
}
export type Store = ConfigStore
export type Store = ConfigStore & ConfigDerivedStore
export const createStores = (context: PropsContext): ConfigStore => {
export const createStores = (context: StoreContext): ConfigStore => {
const { props } = context
const getProp = <T extends keyof ConfigStore>(prop: T) =>
derivedMemo(props, ($props: ConfigStore) => $props[prop])
const getProp = <T extends keyof BaseStoreProps>(prop: T) =>
derivedMemo(props, $props => $props[prop])
// Derive and memoize some props so that we can react to them in isolation
const datasource = getProp("datasource")
@ -58,7 +53,7 @@ export const createStores = (context: PropsContext): ConfigStore => {
}
}
export const deriveStores = (context: StoreContext) => {
export const deriveStores = (context: StoreContext): ConfigDerivedStore => {
const { props, definition, hasNonAutoColumn } = context
// Derive features

View File

@ -12,9 +12,8 @@ import {
UpdateViewRequest,
ViewV2Type,
} from "@budibase/types"
import { Store as StoreContext } from "."
import { Store as StoreContext, BaseStoreProps } from "."
import { DatasourceActions } from "./datasources"
import { ConfigStore } from "./config"
interface DatasourceStore {
definition: Writable<UIDatasource | null>
@ -29,7 +28,7 @@ interface DerivedDatasourceStore {
}
interface ActionDatasourceStore {
datasource: ConfigStore["datasource"] & {
datasource: BaseStoreProps["datasource"] & {
actions: DatasourceActions & {
refreshDefinition: () => Promise<void>
changePrimaryDisplay: (column: string) => Promise<void>

View File

@ -24,7 +24,7 @@ import * as ViewV2 from "./datasources/viewV2"
import * as NonPlus from "./datasources/nonPlus"
import * as Cache from "./cache"
import * as Conditions from "./conditions"
import { UIDatasource } from "@budibase/types"
import { SortOrder, UIDatasource, UISearchFilter } from "@budibase/types"
const DependencyOrderedStores = [
Sort,
@ -52,18 +52,33 @@ const DependencyOrderedStores = [
Cache,
]
export interface BaseStoreProps {
datasource: UIDatasource
initialSortColumn: string | null
initialSortOrder: SortOrder | null
initialFilter: UISearchFilter | null
fixedRowHeight: number | null
schemaOverrides: Record<
string,
{
displayName?: string
disabled?: boolean
}
> | null
notifySuccess: (message: string) => void
notifyError: (message: string) => void
canAddRows: boolean
canEditRows: boolean
canDeleteRows: boolean
canEditColumns: boolean
canExpandRows: boolean
canSaveSchema: boolean
}
export interface BaseStore {
API: APIClient
gridID: string
props: Writable<{
datasource: UIDatasource
canAddRows: boolean
canEditRows: boolean
canDeleteRows: boolean
canEditColumns: boolean
canExpandRows: boolean
canSaveSchema: boolean
}>
props: Writable<BaseStoreProps>
}
export type Store = BaseStore &
@ -82,7 +97,6 @@ export type Store = BaseStore &
// TODO while typing the rest of stores
sort: Writable<any>
subscribe: any
config: Writable<any>
dispatch: (event: string, data: any) => any
notifications: Writable<any>
width: Writable<number>

View File

@ -6,5 +6,5 @@ declare module "./memo" {
export function derivedMemo<TStore, TResult>(
store: Readable<TStore>,
derivation: (store: TStore) => TResult
): TResult
): Readable<TResult>
}