Add back in query extension capability to new data provider
This commit is contained in:
parent
c6792f9903
commit
5c26f07d26
|
@ -3,6 +3,7 @@
|
||||||
import { ProgressCircle, Pagination } from "@budibase/bbui"
|
import { ProgressCircle, Pagination } from "@budibase/bbui"
|
||||||
import Placeholder from "./Placeholder.svelte"
|
import Placeholder from "./Placeholder.svelte"
|
||||||
import { fetchData } from "utils/fetch/fetchData.js"
|
import { fetchData } from "utils/fetch/fetchData.js"
|
||||||
|
import { buildLuceneQuery } from "builder/src/helpers/lucene"
|
||||||
|
|
||||||
export let dataSource
|
export let dataSource
|
||||||
export let filter
|
export let filter
|
||||||
|
@ -14,9 +15,16 @@
|
||||||
const { styleable, Provider, ActionTypes } = getContext("sdk")
|
const { styleable, Provider, ActionTypes } = getContext("sdk")
|
||||||
const component = getContext("component")
|
const component = getContext("component")
|
||||||
|
|
||||||
|
// We need to manage our lucene query manually as we want to allow components
|
||||||
|
// to extend it
|
||||||
|
let queryExtensions = {}
|
||||||
|
$: defaultQuery = buildLuceneQuery(filter)
|
||||||
|
$: query = extendQuery(defaultQuery, queryExtensions)
|
||||||
|
|
||||||
|
// Keep our data fetch instance up to date
|
||||||
$: fetch = createFetch(dataSource)
|
$: fetch = createFetch(dataSource)
|
||||||
$: fetch.update({
|
$: fetch.update({
|
||||||
filter,
|
query,
|
||||||
sortColumn,
|
sortColumn,
|
||||||
sortOrder,
|
sortOrder,
|
||||||
limit,
|
limit,
|
||||||
|
@ -30,14 +38,14 @@
|
||||||
callback: () => fetch.refresh(),
|
callback: () => fetch.refresh(),
|
||||||
metadata: { dataSource },
|
metadata: { dataSource },
|
||||||
},
|
},
|
||||||
// {
|
{
|
||||||
// type: ActionTypes.AddDataProviderQueryExtension,
|
type: ActionTypes.AddDataProviderQueryExtension,
|
||||||
// callback: addQueryExtension,
|
callback: addQueryExtension,
|
||||||
// },
|
},
|
||||||
// {
|
{
|
||||||
// type: ActionTypes.RemoveDataProviderQueryExtension,
|
type: ActionTypes.RemoveDataProviderQueryExtension,
|
||||||
// callback: removeQueryExtension,
|
callback: removeQueryExtension,
|
||||||
// },
|
},
|
||||||
{
|
{
|
||||||
type: ActionTypes.SetDataProviderSorting,
|
type: ActionTypes.SetDataProviderSorting,
|
||||||
callback: ({ column, order }) => {
|
callback: ({ column, order }) => {
|
||||||
|
@ -74,13 +82,43 @@
|
||||||
|
|
||||||
const createFetch = datasource => {
|
const createFetch = datasource => {
|
||||||
return fetchData(datasource, {
|
return fetchData(datasource, {
|
||||||
filter,
|
query,
|
||||||
sortColumn,
|
sortColumn,
|
||||||
sortOrder,
|
sortOrder,
|
||||||
limit,
|
limit,
|
||||||
paginate,
|
paginate,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const addQueryExtension = (key, extension) => {
|
||||||
|
if (!key || !extension) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
queryExtensions = { ...queryExtensions, [key]: extension }
|
||||||
|
}
|
||||||
|
|
||||||
|
const removeQueryExtension = key => {
|
||||||
|
if (!key) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const newQueryExtensions = { ...queryExtensions }
|
||||||
|
delete newQueryExtensions[key]
|
||||||
|
queryExtensions = newQueryExtensions
|
||||||
|
}
|
||||||
|
|
||||||
|
const extendQuery = (defaultQuery, extensions) => {
|
||||||
|
const extensionValues = Object.values(extensions || {})
|
||||||
|
let extendedQuery = { ...defaultQuery }
|
||||||
|
extensionValues.forEach(extension => {
|
||||||
|
Object.entries(extension || {}).forEach(([operator, fields]) => {
|
||||||
|
extendedQuery[operator] = {
|
||||||
|
...extendedQuery[operator],
|
||||||
|
...fields,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
return extendedQuery
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div use:styleable={$component.styles} class="container">
|
<div use:styleable={$component.styles} class="container">
|
||||||
|
|
Loading…
Reference in New Issue