Skip to content

Commit

Permalink
Client: Fixed UI not handle empty filters properly
Browse files Browse the repository at this point in the history
  • Loading branch information
Donkie committed Sep 20, 2023
1 parent 556b80a commit f967aef
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 39 deletions.
2 changes: 1 addition & 1 deletion client/src/components/column.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export function FilteredQueryColumn<Obj>(props: FilteredQueryColumnProps<Obj>) {
}
filters.push({
text: "<empty>",
value: "",
value: "<empty>",
});

const typedFilters = typeFilters<Obj>(props.tableState.filters);
Expand Down
49 changes: 11 additions & 38 deletions client/src/components/dataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,49 +35,22 @@ const dataProvider = (
}

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 => {
if (!("field" in filter)) {
throw Error("Filter must be a LogicalFilter.")
}
const field = filter.field
const fieldValue = Array.isArray(filter.value) ? filter.value.join(",") : filter.value
if (fieldValue.length > 0) {
queryParams[field] = fieldValue
if (filter.value.length > 0) {
const filterValueArray = Array.isArray(filter.value) ? filter.value : [filter.value]

const filterValue = filterValueArray.map((value) => {
if (value === "<empty>") {
return ""
}
return value
}).join(",")

queryParams[field] = filterValue
}
});
}
Expand Down

0 comments on commit f967aef

Please sign in to comment.