Type DataProvider
This commit is contained in:
parent
85ab9e3ce3
commit
7d284ae50e
|
@ -1,8 +1,18 @@
|
||||||
<script>
|
<script lang="ts">
|
||||||
import { getContext } from "svelte"
|
import { getContext } from "svelte"
|
||||||
import { Pagination, ProgressCircle } from "@budibase/bbui"
|
import { Pagination, ProgressCircle } from "@budibase/bbui"
|
||||||
import { fetchData, QueryUtils } from "@budibase/frontend-core"
|
import {
|
||||||
import { LogicalOperator, EmptyFilterOption } from "@budibase/types"
|
fetchData,
|
||||||
|
QueryUtils,
|
||||||
|
DataFetchOptions,
|
||||||
|
} from "@budibase/frontend-core"
|
||||||
|
import {
|
||||||
|
LogicalOperator,
|
||||||
|
EmptyFilterOption,
|
||||||
|
TableSchema,
|
||||||
|
SortOrder,
|
||||||
|
} from "@budibase/types"
|
||||||
|
import { SDK, Component } from "../../index"
|
||||||
|
|
||||||
export let dataSource
|
export let dataSource
|
||||||
export let filter
|
export let filter
|
||||||
|
@ -12,10 +22,10 @@
|
||||||
export let paginate
|
export let paginate
|
||||||
export let autoRefresh
|
export let autoRefresh
|
||||||
|
|
||||||
const { styleable, Provider, ActionTypes, API } = getContext("sdk")
|
const { styleable, Provider, ActionTypes, API } = getContext<SDK>("sdk")
|
||||||
const component = getContext("component")
|
const component = getContext<Component>("component")
|
||||||
|
|
||||||
let interval
|
let interval: NodeJS.Timeout
|
||||||
let queryExtensions = {}
|
let queryExtensions = {}
|
||||||
|
|
||||||
$: defaultQuery = QueryUtils.buildQuery(filter)
|
$: defaultQuery = QueryUtils.buildQuery(filter)
|
||||||
|
@ -49,8 +59,14 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: ActionTypes.SetDataProviderSorting,
|
type: ActionTypes.SetDataProviderSorting,
|
||||||
callback: ({ column, order }) => {
|
callback: ({
|
||||||
let newOptions = {}
|
column,
|
||||||
|
order,
|
||||||
|
}: {
|
||||||
|
column: string
|
||||||
|
order: SortOrder | undefined
|
||||||
|
}) => {
|
||||||
|
let newOptions: Partial<DataFetchOptions<never>> = {}
|
||||||
if (column) {
|
if (column) {
|
||||||
newOptions.sortColumn = column
|
newOptions.sortColumn = column
|
||||||
}
|
}
|
||||||
|
@ -96,7 +112,7 @@
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const sanitizeSchema = schema => {
|
const sanitizeSchema = (schema: TableSchema | null) => {
|
||||||
if (!schema) {
|
if (!schema) {
|
||||||
return schema
|
return schema
|
||||||
}
|
}
|
||||||
|
@ -109,14 +125,14 @@
|
||||||
return cloned
|
return cloned
|
||||||
}
|
}
|
||||||
|
|
||||||
const addQueryExtension = (key, extension) => {
|
const addQueryExtension = (key: string, extension) => {
|
||||||
if (!key || !extension) {
|
if (!key || !extension) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
queryExtensions = { ...queryExtensions, [key]: extension }
|
queryExtensions = { ...queryExtensions, [key]: extension }
|
||||||
}
|
}
|
||||||
|
|
||||||
const removeQueryExtension = key => {
|
const removeQueryExtension = (key: string) => {
|
||||||
if (!key) {
|
if (!key) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -145,7 +161,7 @@
|
||||||
: null
|
: null
|
||||||
}
|
}
|
||||||
|
|
||||||
const setUpAutoRefresh = autoRefresh => {
|
const setUpAutoRefresh = (autoRefresh: number) => {
|
||||||
clearInterval(interval)
|
clearInterval(interval)
|
||||||
if (autoRefresh) {
|
if (autoRefresh) {
|
||||||
interval = setInterval(fetch.refresh, Math.max(10000, autoRefresh * 1000))
|
interval = setInterval(fetch.refresh, Math.max(10000, autoRefresh * 1000))
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { APIClient } from "@budibase/frontend-core"
|
import { APIClient } from "@budibase/frontend-core"
|
||||||
import type { ActionTypes } from "./constants"
|
import type { ActionTypes } from "./constants"
|
||||||
|
import { Readable } from "svelte/store"
|
||||||
|
|
||||||
export interface SDK {
|
export interface SDK {
|
||||||
API: APIClient
|
API: APIClient
|
||||||
|
@ -7,3 +8,7 @@ export interface SDK {
|
||||||
Provider: unknown
|
Provider: unknown
|
||||||
ActionTypes: typeof ActionTypes
|
ActionTypes: typeof ActionTypes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type Component = Readable<{
|
||||||
|
id: string
|
||||||
|
}>
|
|
@ -435,7 +435,7 @@ export default abstract class BaseDataFetch<
|
||||||
* Resets the data set and updates options
|
* Resets the data set and updates options
|
||||||
* @param newOptions any new options
|
* @param newOptions any new options
|
||||||
*/
|
*/
|
||||||
async update(newOptions: DataFetchOptions<never>) {
|
async update(newOptions: Partial<DataFetchOptions<never>>) {
|
||||||
// Check if any settings have actually changed
|
// Check if any settings have actually changed
|
||||||
let refresh = false
|
let refresh = false
|
||||||
for (const [key, value] of Object.entries(newOptions || {})) {
|
for (const [key, value] of Object.entries(newOptions || {})) {
|
||||||
|
|
Loading…
Reference in New Issue