Bug fixes and deprecated DynamicFilter

This commit is contained in:
Dean 2025-05-02 09:52:14 +01:00
parent d6ac1be628
commit 6ff192f58c
10 changed files with 67 additions and 26 deletions

View File

@ -7,6 +7,8 @@
export let type = "number"
$: style = width ? `width:${width}px;` : ""
const selectAll = event => event.target.select()
</script>
<input
@ -16,7 +18,7 @@
{value}
{min}
{max}
onclick="this.select()"
on:click={selectAll}
on:change
on:input
/>

View File

@ -34,7 +34,12 @@
}
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))) {
toDate = !enableTime ? fromDate.endOf("day") : fromDate
} else if (!fromDate) {
@ -44,9 +49,13 @@
dispatch("change", [fromDate, toDate])
}
// Pass the raw date not the event
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))) {
fromDate = !enableTime ? toDate.startOf("day") : toDate
} else if (!toDate) {

View File

@ -85,7 +85,11 @@
schema: TableSchema | undefined,
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,
})
}

View File

@ -5578,6 +5578,7 @@
]
},
"dynamicfilter": {
"deprecated": true,
"name": "Dynamic Filter",
"icon": "Filter",
"size": {

View File

@ -21,7 +21,6 @@
import Container from "../container/Container.svelte"
import { getAction } from "@/utils/getAction"
import { ActionTypes } from "@/constants"
import { fetchDatasourceSchema } from "@/utils/schema"
import { QueryUtils, fetchData, memo } from "@budibase/frontend-core"
import FilterButton from "./FilterButton.svelte"
import { onDestroy } from "svelte"
@ -36,7 +35,8 @@
const memoFilters = memo({} as Record<string, SearchFilter>)
const component = getContext("component")
const { API } = getContext("sdk")
const { API, fetchDatasourceSchema, getRelationshipSchemaAdditions } =
getContext("sdk")
const rowCache = writable({})
setContext("rows", rowCache)
@ -236,17 +236,29 @@
async function fetchSchema(datasource: any) {
if (datasource) {
const fetchedSchema = await fetchDatasourceSchema(datasource, {
enrichRelationships: true,
formSchema: false,
})
const fetchedSchema: TableSchema | null = await fetchDatasourceSchema(
datasource,
{
enrichRelationships: true,
formSchema: false,
}
)
const filteredSchema = Object.entries(fetchedSchema || {}).filter(
const filteredSchemaEntries = Object.entries(fetchedSchema || {}).filter(
([_, field]: [string, FieldSchema]) => {
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 {
schema = null
}

View File

@ -30,6 +30,10 @@
import { type Writable } from "svelte/store"
import { getContext } from "svelte"
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 hide = () => popover?.hide()
@ -268,22 +272,29 @@
value={parseDateRange(editableFilter.value)}
on:change={e => {
const [from, to] = e.detail
const parsedFrom = Helpers.stringifyDate(from, {
enableTime,
timeOnly,
ignoreTimezones,
})
const parsedFrom = enableTime
? from.utc().format()
: Helpers.stringifyDate(from, {
enableTime,
timeOnly,
ignoreTimezones,
})
const parsedTo = Helpers.stringifyDate(to, {
enableTime,
timeOnly,
ignoreTimezones,
})
const parsedTo = enableTime
? to.utc().format()
: Helpers.stringifyDate(to, {
enableTime,
timeOnly,
ignoreTimezones,
})
if (!editableFilter) return
editableFilter = sanitizeOperator({
...editableFilter,
value: { low: parsedFrom, high: parsedTo },
value: {
low: parsedFrom,
high: parsedTo,
},
})
}}
/>

View File

@ -96,6 +96,7 @@ export interface SDK {
ActionTypes: typeof ActionTypes
fetchDatasourceSchema: any
fetchDatasourceDefinition: (datasource: DataFetchDatasource) => Promise<Table>
getRelationshipSchemaAdditions: (schema: Record<string, any>) => Promise<any>
enrichButtonActions: any
generateGoldenSample: any
createContextStore: any

View File

@ -29,6 +29,7 @@ import { ActionTypes } from "./constants"
import {
fetchDatasourceSchema,
fetchDatasourceDefinition,
getRelationshipSchemaAdditions,
} from "./utils/schema"
import { getAPIKey } from "./utils/api.js"
import { enrichButtonActions } from "./utils/buttonActions.js"
@ -71,6 +72,7 @@ export default {
getAction,
fetchDatasourceSchema,
fetchDatasourceDefinition,
getRelationshipSchemaAdditions,
fetchData,
QueryUtils,
ContextScopes: Constants.ContextScopes,

View File

@ -121,6 +121,7 @@ export const getRelationshipSchemaAdditions = async (
relationshipAdditions[`${fieldKey}.${linkKey}`] = {
type: linkSchema[linkKey].type,
externalType: linkSchema[linkKey].externalType,
constraints: linkSchema[linkKey].constraints,
}
})
}

View File

@ -103,8 +103,6 @@ export const getValidOperatorsForType = (
ops = [Op.Equals, Op.NotEquals, Op.Empty, Op.NotEmpty, Op.In]
} else if (type === FieldType.BB_REFERENCE) {
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