Bug fixes and deprecated DynamicFilter
This commit is contained in:
parent
d6ac1be628
commit
6ff192f58c
|
@ -7,6 +7,8 @@
|
||||||
export let type = "number"
|
export let type = "number"
|
||||||
|
|
||||||
$: style = width ? `width:${width}px;` : ""
|
$: style = width ? `width:${width}px;` : ""
|
||||||
|
|
||||||
|
const selectAll = event => event.target.select()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<input
|
<input
|
||||||
|
@ -16,7 +18,7 @@
|
||||||
{value}
|
{value}
|
||||||
{min}
|
{min}
|
||||||
{max}
|
{max}
|
||||||
onclick="this.select()"
|
on:click={selectAll}
|
||||||
on:change
|
on:change
|
||||||
on:input
|
on:input
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -34,7 +34,12 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
const onChangeFrom = (utc: string) => {
|
const onChangeFrom = (utc: string) => {
|
||||||
fromDate = utc ? dayjs(utc).startOf("day") : null
|
// Preserve the time if its editable
|
||||||
|
const fromDate = utc
|
||||||
|
? enableTime
|
||||||
|
? dayjs(utc)
|
||||||
|
: dayjs(utc).startOf("day")
|
||||||
|
: null
|
||||||
if (fromDate && (!toDate || fromDate.isAfter(toDate))) {
|
if (fromDate && (!toDate || fromDate.isAfter(toDate))) {
|
||||||
toDate = !enableTime ? fromDate.endOf("day") : fromDate
|
toDate = !enableTime ? fromDate.endOf("day") : fromDate
|
||||||
} else if (!fromDate) {
|
} else if (!fromDate) {
|
||||||
|
@ -44,9 +49,13 @@
|
||||||
dispatch("change", [fromDate, toDate])
|
dispatch("change", [fromDate, toDate])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pass the raw date not the event
|
|
||||||
const onChangeTo = (utc: string) => {
|
const onChangeTo = (utc: string) => {
|
||||||
toDate = utc ? dayjs(utc).endOf("day") : null
|
// Preserve the time if its editable
|
||||||
|
const toDate = utc
|
||||||
|
? enableTime
|
||||||
|
? dayjs(utc)
|
||||||
|
: dayjs(utc).startOf("day")
|
||||||
|
: null
|
||||||
if (toDate && (!fromDate || toDate.isBefore(fromDate))) {
|
if (toDate && (!fromDate || toDate.isBefore(fromDate))) {
|
||||||
fromDate = !enableTime ? toDate.startOf("day") : toDate
|
fromDate = !enableTime ? toDate.startOf("day") : toDate
|
||||||
} else if (!toDate) {
|
} else if (!toDate) {
|
||||||
|
|
|
@ -85,7 +85,11 @@
|
||||||
schema: TableSchema | undefined,
|
schema: TableSchema | undefined,
|
||||||
tableList: Table[]
|
tableList: Table[]
|
||||||
) => {
|
) => {
|
||||||
return search.getFields(tableList, Object.values(schema || {}), {
|
// Omit calculated fields
|
||||||
|
const filtered = Object.values(schema || {}).filter(
|
||||||
|
field => !("calculationType" in field)
|
||||||
|
)
|
||||||
|
return search.getFields(tableList, filtered, {
|
||||||
allowLinks: true,
|
allowLinks: true,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -5578,6 +5578,7 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"dynamicfilter": {
|
"dynamicfilter": {
|
||||||
|
"deprecated": true,
|
||||||
"name": "Dynamic Filter",
|
"name": "Dynamic Filter",
|
||||||
"icon": "Filter",
|
"icon": "Filter",
|
||||||
"size": {
|
"size": {
|
||||||
|
|
|
@ -21,7 +21,6 @@
|
||||||
import Container from "../container/Container.svelte"
|
import Container from "../container/Container.svelte"
|
||||||
import { getAction } from "@/utils/getAction"
|
import { getAction } from "@/utils/getAction"
|
||||||
import { ActionTypes } from "@/constants"
|
import { ActionTypes } from "@/constants"
|
||||||
import { fetchDatasourceSchema } from "@/utils/schema"
|
|
||||||
import { QueryUtils, fetchData, memo } from "@budibase/frontend-core"
|
import { QueryUtils, fetchData, memo } from "@budibase/frontend-core"
|
||||||
import FilterButton from "./FilterButton.svelte"
|
import FilterButton from "./FilterButton.svelte"
|
||||||
import { onDestroy } from "svelte"
|
import { onDestroy } from "svelte"
|
||||||
|
@ -36,7 +35,8 @@
|
||||||
|
|
||||||
const memoFilters = memo({} as Record<string, SearchFilter>)
|
const memoFilters = memo({} as Record<string, SearchFilter>)
|
||||||
const component = getContext("component")
|
const component = getContext("component")
|
||||||
const { API } = getContext("sdk")
|
const { API, fetchDatasourceSchema, getRelationshipSchemaAdditions } =
|
||||||
|
getContext("sdk")
|
||||||
|
|
||||||
const rowCache = writable({})
|
const rowCache = writable({})
|
||||||
setContext("rows", rowCache)
|
setContext("rows", rowCache)
|
||||||
|
@ -236,17 +236,29 @@
|
||||||
|
|
||||||
async function fetchSchema(datasource: any) {
|
async function fetchSchema(datasource: any) {
|
||||||
if (datasource) {
|
if (datasource) {
|
||||||
const fetchedSchema = await fetchDatasourceSchema(datasource, {
|
const fetchedSchema: TableSchema | null = await fetchDatasourceSchema(
|
||||||
|
datasource,
|
||||||
|
{
|
||||||
enrichRelationships: true,
|
enrichRelationships: true,
|
||||||
formSchema: false,
|
formSchema: false,
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
const filteredSchema = Object.entries(fetchedSchema || {}).filter(
|
const filteredSchemaEntries = Object.entries(fetchedSchema || {}).filter(
|
||||||
([_, field]: [string, FieldSchema]) => {
|
([_, field]: [string, FieldSchema]) => {
|
||||||
return !excludedTypes.includes(field.type)
|
return !excludedTypes.includes(field.type)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
schema = Object.fromEntries(filteredSchema)
|
|
||||||
|
const filteredSchema = Object.fromEntries(filteredSchemaEntries)
|
||||||
|
|
||||||
|
// Necessary to ensure that link fields possess all config required
|
||||||
|
// to render their respective UX
|
||||||
|
const enrichedSchema = await getRelationshipSchemaAdditions(
|
||||||
|
filteredSchema as Record<string, any>
|
||||||
|
)
|
||||||
|
|
||||||
|
schema = { ...filteredSchema, ...enrichedSchema }
|
||||||
} else {
|
} else {
|
||||||
schema = null
|
schema = null
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,10 @@
|
||||||
import { type Writable } from "svelte/store"
|
import { type Writable } from "svelte/store"
|
||||||
import { getContext } from "svelte"
|
import { getContext } from "svelte"
|
||||||
import { isArrayOperator } from "@/utils/filtering"
|
import { isArrayOperator } from "@/utils/filtering"
|
||||||
|
import dayjs from "dayjs"
|
||||||
|
import utc from "dayjs/plugin/utc"
|
||||||
|
|
||||||
|
dayjs.extend(utc)
|
||||||
|
|
||||||
export const show = () => popover?.show()
|
export const show = () => popover?.show()
|
||||||
export const hide = () => popover?.hide()
|
export const hide = () => popover?.hide()
|
||||||
|
@ -268,13 +272,17 @@
|
||||||
value={parseDateRange(editableFilter.value)}
|
value={parseDateRange(editableFilter.value)}
|
||||||
on:change={e => {
|
on:change={e => {
|
||||||
const [from, to] = e.detail
|
const [from, to] = e.detail
|
||||||
const parsedFrom = Helpers.stringifyDate(from, {
|
const parsedFrom = enableTime
|
||||||
|
? from.utc().format()
|
||||||
|
: Helpers.stringifyDate(from, {
|
||||||
enableTime,
|
enableTime,
|
||||||
timeOnly,
|
timeOnly,
|
||||||
ignoreTimezones,
|
ignoreTimezones,
|
||||||
})
|
})
|
||||||
|
|
||||||
const parsedTo = Helpers.stringifyDate(to, {
|
const parsedTo = enableTime
|
||||||
|
? to.utc().format()
|
||||||
|
: Helpers.stringifyDate(to, {
|
||||||
enableTime,
|
enableTime,
|
||||||
timeOnly,
|
timeOnly,
|
||||||
ignoreTimezones,
|
ignoreTimezones,
|
||||||
|
@ -283,7 +291,10 @@
|
||||||
if (!editableFilter) return
|
if (!editableFilter) return
|
||||||
editableFilter = sanitizeOperator({
|
editableFilter = sanitizeOperator({
|
||||||
...editableFilter,
|
...editableFilter,
|
||||||
value: { low: parsedFrom, high: parsedTo },
|
value: {
|
||||||
|
low: parsedFrom,
|
||||||
|
high: parsedTo,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -96,6 +96,7 @@ export interface SDK {
|
||||||
ActionTypes: typeof ActionTypes
|
ActionTypes: typeof ActionTypes
|
||||||
fetchDatasourceSchema: any
|
fetchDatasourceSchema: any
|
||||||
fetchDatasourceDefinition: (datasource: DataFetchDatasource) => Promise<Table>
|
fetchDatasourceDefinition: (datasource: DataFetchDatasource) => Promise<Table>
|
||||||
|
getRelationshipSchemaAdditions: (schema: Record<string, any>) => Promise<any>
|
||||||
enrichButtonActions: any
|
enrichButtonActions: any
|
||||||
generateGoldenSample: any
|
generateGoldenSample: any
|
||||||
createContextStore: any
|
createContextStore: any
|
||||||
|
|
|
@ -29,6 +29,7 @@ import { ActionTypes } from "./constants"
|
||||||
import {
|
import {
|
||||||
fetchDatasourceSchema,
|
fetchDatasourceSchema,
|
||||||
fetchDatasourceDefinition,
|
fetchDatasourceDefinition,
|
||||||
|
getRelationshipSchemaAdditions,
|
||||||
} from "./utils/schema"
|
} from "./utils/schema"
|
||||||
import { getAPIKey } from "./utils/api.js"
|
import { getAPIKey } from "./utils/api.js"
|
||||||
import { enrichButtonActions } from "./utils/buttonActions.js"
|
import { enrichButtonActions } from "./utils/buttonActions.js"
|
||||||
|
@ -71,6 +72,7 @@ export default {
|
||||||
getAction,
|
getAction,
|
||||||
fetchDatasourceSchema,
|
fetchDatasourceSchema,
|
||||||
fetchDatasourceDefinition,
|
fetchDatasourceDefinition,
|
||||||
|
getRelationshipSchemaAdditions,
|
||||||
fetchData,
|
fetchData,
|
||||||
QueryUtils,
|
QueryUtils,
|
||||||
ContextScopes: Constants.ContextScopes,
|
ContextScopes: Constants.ContextScopes,
|
||||||
|
|
|
@ -121,6 +121,7 @@ export const getRelationshipSchemaAdditions = async (
|
||||||
relationshipAdditions[`${fieldKey}.${linkKey}`] = {
|
relationshipAdditions[`${fieldKey}.${linkKey}`] = {
|
||||||
type: linkSchema[linkKey].type,
|
type: linkSchema[linkKey].type,
|
||||||
externalType: linkSchema[linkKey].externalType,
|
externalType: linkSchema[linkKey].externalType,
|
||||||
|
constraints: linkSchema[linkKey].constraints,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,8 +103,6 @@ export const getValidOperatorsForType = (
|
||||||
ops = [Op.Equals, Op.NotEquals, Op.Empty, Op.NotEmpty, Op.In]
|
ops = [Op.Equals, Op.NotEquals, Op.Empty, Op.NotEmpty, Op.In]
|
||||||
} else if (type === FieldType.BB_REFERENCE) {
|
} else if (type === FieldType.BB_REFERENCE) {
|
||||||
ops = [Op.Contains, Op.NotContains, Op.ContainsAny, Op.Empty, Op.NotEmpty]
|
ops = [Op.Contains, Op.NotContains, Op.ContainsAny, Op.Empty, Op.NotEmpty]
|
||||||
} else if (type === FieldType.LINK) {
|
|
||||||
ops = [Op.Equals, Op.NotEquals, Op.Empty, Op.NotEmpty, Op.In]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only allow equal/not equal for _id in SQL tables
|
// Only allow equal/not equal for _id in SQL tables
|
||||||
|
|
Loading…
Reference in New Issue