mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-16 20:15:44 +00:00
Build category filter (#8940)
* Add 'category' filter to BuildList - Allows filtering by part category * Add filter element to build table * Bump API version
This commit is contained in:
@ -179,10 +179,17 @@ function FilterAddGroup({
|
||||
|
||||
// Determine the "type" of filter (default = boolean)
|
||||
const filterType: TableFilterType = useMemo(() => {
|
||||
return (
|
||||
availableFilters?.find((flt) => flt.name === selectedFilter)?.type ??
|
||||
'boolean'
|
||||
);
|
||||
const filter = availableFilters?.find((flt) => flt.name === selectedFilter);
|
||||
|
||||
if (filter?.type) {
|
||||
return filter.type;
|
||||
} else if (filter?.choices) {
|
||||
// If choices are provided, it is a choice filter
|
||||
return 'choice';
|
||||
} else {
|
||||
// Default fallback
|
||||
return 'boolean';
|
||||
}
|
||||
}, [selectedFilter]);
|
||||
|
||||
const setSelectedValue = useCallback(
|
||||
|
@ -8,7 +8,9 @@ import { ApiEndpoints } from '../../enums/ApiEndpoints';
|
||||
import { ModelType } from '../../enums/ModelType';
|
||||
import { UserRoles } from '../../enums/Roles';
|
||||
import { useBuildOrderFields } from '../../forms/BuildForms';
|
||||
import { shortenString } from '../../functions/tables';
|
||||
import {
|
||||
useFilters,
|
||||
useOwnerFilters,
|
||||
useProjectCodeFilters,
|
||||
useUserFilters
|
||||
@ -131,6 +133,17 @@ export function BuildOrderTable({
|
||||
const ownerFilters = useOwnerFilters();
|
||||
const userFilters = useUserFilters();
|
||||
|
||||
const categoryFilters = useFilters({
|
||||
url: apiUrl(ApiEndpoints.category_list),
|
||||
transform: (item) => ({
|
||||
value: item.pk,
|
||||
label: shortenString({
|
||||
str: item.pathstring,
|
||||
len: 50
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
const tableFilters: TableFilter[] = useMemo(() => {
|
||||
const filters: TableFilter[] = [
|
||||
OutstandingFilter(),
|
||||
@ -177,7 +190,13 @@ export function BuildOrderTable({
|
||||
description: t`Filter by user who issued this order`,
|
||||
choices: userFilters.choices
|
||||
},
|
||||
ResponsibleFilter({ choices: ownerFilters.choices })
|
||||
ResponsibleFilter({ choices: ownerFilters.choices }),
|
||||
{
|
||||
name: 'category',
|
||||
label: t`Category`,
|
||||
description: t`Filter by part category`,
|
||||
choices: categoryFilters.choices
|
||||
}
|
||||
];
|
||||
|
||||
// If we are filtering on a specific part, we can include the "include variants" filter
|
||||
@ -193,6 +212,7 @@ export function BuildOrderTable({
|
||||
return filters;
|
||||
}, [
|
||||
partId,
|
||||
categoryFilters.choices,
|
||||
projectCodeFilters.choices,
|
||||
ownerFilters.choices,
|
||||
userFilters.choices
|
||||
|
Reference in New Issue
Block a user