Remove anys and fix types
This commit is contained in:
parent
2d36eab278
commit
6d1f2c9200
|
@ -1,40 +1,35 @@
|
||||||
import { derivedMemo } from "../../../utils"
|
import { derivedMemo } from "../../../utils"
|
||||||
import { derived, Readable } from "svelte/store"
|
import { derived, Readable } from "svelte/store"
|
||||||
import {
|
import { ViewV2Type } from "@budibase/types"
|
||||||
SortOrder,
|
import { BaseStoreProps, Store as StoreContext } from "."
|
||||||
UIDatasource,
|
|
||||||
UISearchFilter,
|
|
||||||
ViewV2Type,
|
|
||||||
} from "@budibase/types"
|
|
||||||
import { Store as StoreContext } from "."
|
|
||||||
|
|
||||||
export interface ConfigStore {
|
interface ConfigStore {
|
||||||
datasource: Readable<UIDatasource>
|
datasource: Readable<BaseStoreProps["datasource"]>
|
||||||
initialSortColumn: Readable<string | null>
|
initialSortColumn: Readable<BaseStoreProps["initialSortColumn"]>
|
||||||
initialSortOrder: Readable<SortOrder | null>
|
initialSortOrder: Readable<BaseStoreProps["initialSortOrder"]>
|
||||||
initialFilter: Readable<UISearchFilter | null>
|
initialFilter: Readable<BaseStoreProps["initialFilter"]>
|
||||||
fixedRowHeight: Readable<number | null>
|
fixedRowHeight: Readable<BaseStoreProps["fixedRowHeight"]>
|
||||||
schemaOverrides: Readable<Record<
|
schemaOverrides: Readable<BaseStoreProps["schemaOverrides"]>
|
||||||
string,
|
notifySuccess: Readable<BaseStoreProps["notifySuccess"]>
|
||||||
{
|
notifyError: Readable<BaseStoreProps["notifyError"]>
|
||||||
displayName?: string
|
canAddRows?: Readable<BaseStoreProps["canAddRows"]>
|
||||||
disabled?: boolean
|
canEditRows?: Readable<BaseStoreProps["canEditRows"]>
|
||||||
}
|
canDeleteRows?: Readable<BaseStoreProps["canDeleteRows"]>
|
||||||
> | null>
|
canEditColumns?: Readable<BaseStoreProps["canEditColumns"]>
|
||||||
notifySuccess: (message: string) => void
|
canExpandRows?: Readable<BaseStoreProps["canExpandRows"]>
|
||||||
notifyError: (message: string) => void
|
canSaveSchema?: Readable<BaseStoreProps["canSaveSchema"]>
|
||||||
}
|
}
|
||||||
|
|
||||||
interface PropsContext {
|
interface ConfigDerivedStore {
|
||||||
props: Readable<ConfigStore>
|
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 { props } = context
|
||||||
const getProp = <T extends keyof ConfigStore>(prop: T) =>
|
const getProp = <T extends keyof BaseStoreProps>(prop: T) =>
|
||||||
derivedMemo(props, ($props: ConfigStore) => $props[prop])
|
derivedMemo(props, $props => $props[prop])
|
||||||
|
|
||||||
// Derive and memoize some props so that we can react to them in isolation
|
// Derive and memoize some props so that we can react to them in isolation
|
||||||
const datasource = getProp("datasource")
|
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
|
const { props, definition, hasNonAutoColumn } = context
|
||||||
|
|
||||||
// Derive features
|
// Derive features
|
||||||
|
|
|
@ -12,9 +12,8 @@ import {
|
||||||
UpdateViewRequest,
|
UpdateViewRequest,
|
||||||
ViewV2Type,
|
ViewV2Type,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import { Store as StoreContext } from "."
|
import { Store as StoreContext, BaseStoreProps } from "."
|
||||||
import { DatasourceActions } from "./datasources"
|
import { DatasourceActions } from "./datasources"
|
||||||
import { ConfigStore } from "./config"
|
|
||||||
|
|
||||||
interface DatasourceStore {
|
interface DatasourceStore {
|
||||||
definition: Writable<UIDatasource | null>
|
definition: Writable<UIDatasource | null>
|
||||||
|
@ -29,7 +28,7 @@ interface DerivedDatasourceStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ActionDatasourceStore {
|
interface ActionDatasourceStore {
|
||||||
datasource: ConfigStore["datasource"] & {
|
datasource: BaseStoreProps["datasource"] & {
|
||||||
actions: DatasourceActions & {
|
actions: DatasourceActions & {
|
||||||
refreshDefinition: () => Promise<void>
|
refreshDefinition: () => Promise<void>
|
||||||
changePrimaryDisplay: (column: string) => Promise<void>
|
changePrimaryDisplay: (column: string) => Promise<void>
|
||||||
|
|
|
@ -24,7 +24,7 @@ import * as ViewV2 from "./datasources/viewV2"
|
||||||
import * as NonPlus from "./datasources/nonPlus"
|
import * as NonPlus from "./datasources/nonPlus"
|
||||||
import * as Cache from "./cache"
|
import * as Cache from "./cache"
|
||||||
import * as Conditions from "./conditions"
|
import * as Conditions from "./conditions"
|
||||||
import { UIDatasource } from "@budibase/types"
|
import { SortOrder, UIDatasource, UISearchFilter } from "@budibase/types"
|
||||||
|
|
||||||
const DependencyOrderedStores = [
|
const DependencyOrderedStores = [
|
||||||
Sort,
|
Sort,
|
||||||
|
@ -52,18 +52,33 @@ const DependencyOrderedStores = [
|
||||||
Cache,
|
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 {
|
export interface BaseStore {
|
||||||
API: APIClient
|
API: APIClient
|
||||||
gridID: string
|
gridID: string
|
||||||
props: Writable<{
|
props: Writable<BaseStoreProps>
|
||||||
datasource: UIDatasource
|
|
||||||
canAddRows: boolean
|
|
||||||
canEditRows: boolean
|
|
||||||
canDeleteRows: boolean
|
|
||||||
canEditColumns: boolean
|
|
||||||
canExpandRows: boolean
|
|
||||||
canSaveSchema: boolean
|
|
||||||
}>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Store = BaseStore &
|
export type Store = BaseStore &
|
||||||
|
@ -82,7 +97,6 @@ export type Store = BaseStore &
|
||||||
// TODO while typing the rest of stores
|
// TODO while typing the rest of stores
|
||||||
sort: Writable<any>
|
sort: Writable<any>
|
||||||
subscribe: any
|
subscribe: any
|
||||||
config: Writable<any>
|
|
||||||
dispatch: (event: string, data: any) => any
|
dispatch: (event: string, data: any) => any
|
||||||
notifications: Writable<any>
|
notifications: Writable<any>
|
||||||
width: Writable<number>
|
width: Writable<number>
|
||||||
|
|
|
@ -6,5 +6,5 @@ declare module "./memo" {
|
||||||
export function derivedMemo<TStore, TResult>(
|
export function derivedMemo<TStore, TResult>(
|
||||||
store: Readable<TStore>,
|
store: Readable<TStore>,
|
||||||
derivation: (store: TStore) => TResult
|
derivation: (store: TStore) => TResult
|
||||||
): TResult
|
): Readable<TResult>
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue