Client: Fixed UI not handle empty filters properly
This commit is contained in:
@@ -130,7 +130,7 @@ export function FilteredQueryColumn<Obj>(props: FilteredQueryColumnProps<Obj>) {
|
|||||||
}
|
}
|
||||||
filters.push({
|
filters.push({
|
||||||
text: "<empty>",
|
text: "<empty>",
|
||||||
value: "",
|
value: "<empty>",
|
||||||
});
|
});
|
||||||
|
|
||||||
const typedFilters = typeFilters<Obj>(props.tableState.filters);
|
const typedFilters = typeFilters<Obj>(props.tableState.filters);
|
||||||
|
|||||||
@@ -35,49 +35,22 @@ const dataProvider = (
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (filters && filters.length > 0) {
|
if (filters && filters.length > 0) {
|
||||||
// Pre-process the filters and handle the special case where we want to split the filament name into vendor and filament name
|
|
||||||
if (resource === "spool") {
|
|
||||||
filters = structuredClone(filters)
|
|
||||||
|
|
||||||
for (let i = 0; i < filters.length; i++) {
|
|
||||||
const filter = filters[i]
|
|
||||||
if (("field" in filter) && filter.field === "filament.name") {
|
|
||||||
const filamentNames: string[] = []
|
|
||||||
const vendorNames: string[] = []
|
|
||||||
if (Array.isArray(filter.value)) {
|
|
||||||
filter.value.forEach((value: string) => {
|
|
||||||
const split = value.split(" - ")
|
|
||||||
if (split.length === 1) {
|
|
||||||
filamentNames.push(split[0])
|
|
||||||
} else {
|
|
||||||
vendorNames.push(split[0])
|
|
||||||
filamentNames.push(split[1])
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
filamentNames.push(filter.value.split(" - ")[1])
|
|
||||||
vendorNames.push(filter.value.split(" - ")[0])
|
|
||||||
}
|
|
||||||
filter.value = filamentNames
|
|
||||||
|
|
||||||
filters.push({
|
|
||||||
field: "vendor.name",
|
|
||||||
operator: "in",
|
|
||||||
value: vendorNames,
|
|
||||||
})
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
filters.forEach(filter => {
|
filters.forEach(filter => {
|
||||||
if (!("field" in filter)) {
|
if (!("field" in filter)) {
|
||||||
throw Error("Filter must be a LogicalFilter.")
|
throw Error("Filter must be a LogicalFilter.")
|
||||||
}
|
}
|
||||||
const field = filter.field
|
const field = filter.field
|
||||||
const fieldValue = Array.isArray(filter.value) ? filter.value.join(",") : filter.value
|
if (filter.value.length > 0) {
|
||||||
if (fieldValue.length > 0) {
|
const filterValueArray = Array.isArray(filter.value) ? filter.value : [filter.value]
|
||||||
queryParams[field] = fieldValue
|
|
||||||
|
const filterValue = filterValueArray.map((value) => {
|
||||||
|
if (value === "<empty>") {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return value
|
||||||
|
}).join(",")
|
||||||
|
|
||||||
|
queryParams[field] = filterValue
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user