More types

This commit is contained in:
Adria Navarro 2025-01-14 12:58:53 +01:00
parent 5b4b27dc16
commit 2ad7e73813
2 changed files with 16 additions and 12 deletions

View File

@ -11,6 +11,7 @@
EmptyFilterOption, EmptyFilterOption,
TableSchema, TableSchema,
SortOrder, SortOrder,
SearchFilters,
} from "@budibase/types" } from "@budibase/types"
import { SDK, Component } from "../../index" import { SDK, Component } from "../../index"
@ -26,7 +27,7 @@
const component = getContext<Component>("component") const component = getContext<Component>("component")
let interval: NodeJS.Timeout let interval: NodeJS.Timeout
let queryExtensions = {} let queryExtensions: Record<string, any> = {}
$: defaultQuery = QueryUtils.buildQuery(filter) $: defaultQuery = QueryUtils.buildQuery(filter)
@ -79,6 +80,7 @@
}, },
}, },
] ]
$: dataContext = { $: dataContext = {
rows: $fetch.rows, rows: $fetch.rows,
info: $fetch.info, info: $fetch.info,
@ -91,14 +93,12 @@
id: $component?.id, id: $component?.id,
state: { state: {
query: $fetch.query, query: $fetch.query,
sortColumn: $fetch.sortColumn,
sortOrder: $fetch.sortOrder,
}, },
limit, limit,
primaryDisplay: $fetch.definition?.primaryDisplay, primaryDisplay: ($fetch.definition as any)?.primaryDisplay,
} }
const createFetch = datasource => { const createFetch = (datasource: any) => {
return fetchData({ return fetchData({
API, API,
datasource, datasource,
@ -125,7 +125,7 @@
return cloned return cloned
} }
const addQueryExtension = (key: string, extension) => { const addQueryExtension = (key: string, extension: any) => {
if (!key || !extension) { if (!key || !extension) {
return return
} }
@ -141,11 +141,14 @@
queryExtensions = newQueryExtensions queryExtensions = newQueryExtensions
} }
const extendQuery = (defaultQuery, extensions) => { const extendQuery = (
defaultQuery: SearchFilters,
extensions: Record<string, any>
): SearchFilters => {
if (!Object.keys(extensions).length) { if (!Object.keys(extensions).length) {
return defaultQuery return defaultQuery
} }
const extended = { const extended: SearchFilters = {
[LogicalOperator.AND]: { [LogicalOperator.AND]: {
conditions: [ conditions: [
...(defaultQuery ? [defaultQuery] : []), ...(defaultQuery ? [defaultQuery] : []),
@ -156,9 +159,9 @@
} }
// If there are no conditions applied at all, clear the request. // If there are no conditions applied at all, clear the request.
return extended[LogicalOperator.AND]?.conditions?.length > 0 return (extended[LogicalOperator.AND]?.conditions?.length ?? 0) > 0
? extended ? extended
: null : {}
} }
const setUpAutoRefresh = (autoRefresh: number) => { const setUpAutoRefresh = (autoRefresh: number) => {

View File

@ -4,11 +4,12 @@ import { Readable } from "svelte/store"
export interface SDK { export interface SDK {
API: APIClient API: APIClient
styleable: unknown styleable: any
Provider: unknown Provider: any
ActionTypes: typeof ActionTypes ActionTypes: typeof ActionTypes
} }
export type Component = Readable<{ export type Component = Readable<{
id: string id: string
styles: any
}> }>