From ade6cfb878bdcbb0b44872d2941f312b3f65e8bd Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 2 Jul 2024 11:32:41 +1000 Subject: [PATCH] [PUI] Update table filters (#7544) * Update part table filters * Update stock location table filters * Update part category table filters --- src/frontend/src/tables/bom/BomTable.tsx | 5 +++ .../src/tables/part/PartCategoryTable.tsx | 5 +++ src/frontend/src/tables/part/PartTable.tsx | 37 +++++++++++++++---- .../src/tables/stock/StockLocationTable.tsx | 22 +++++++++-- 4 files changed, 58 insertions(+), 11 deletions(-) diff --git a/src/frontend/src/tables/bom/BomTable.tsx b/src/frontend/src/tables/bom/BomTable.tsx index 51b065d161..f9478e5e23 100644 --- a/src/frontend/src/tables/bom/BomTable.tsx +++ b/src/frontend/src/tables/bom/BomTable.tsx @@ -286,6 +286,11 @@ export function BomTable({ label: t`Inherited`, description: t`Show inherited items` }, + { + name: 'allow_variants', + label: t`Allow Variants`, + description: t`Show items which allow variant substitution` + }, { name: 'optional', label: t`Optional`, diff --git a/src/frontend/src/tables/part/PartCategoryTable.tsx b/src/frontend/src/tables/part/PartCategoryTable.tsx index 7f4de4fd86..76ccb257f8 100644 --- a/src/frontend/src/tables/part/PartCategoryTable.tsx +++ b/src/frontend/src/tables/part/PartCategoryTable.tsx @@ -64,6 +64,11 @@ export function PartCategoryTable({ parentId }: { parentId?: any }) { name: 'structural', label: t`Structural`, description: t`Show structural categories` + }, + { + name: 'starred', + label: t`Subscribed`, + description: t`Show categories to which the user is subscribed` } ]; }, []); diff --git a/src/frontend/src/tables/part/PartTable.tsx b/src/frontend/src/tables/part/PartTable.tsx index eb073e9763..47d0223a59 100644 --- a/src/frontend/src/tables/part/PartTable.tsx +++ b/src/frontend/src/tables/part/PartTable.tsx @@ -238,14 +238,37 @@ function partTableFilters(): TableFilter[] { { value: 'true', label: t`Virtual` }, { value: 'false', label: t`Not Virtual` } ] + }, + { + name: 'is_template', + label: t`Is Template`, + description: t`Filter by parts which are templates`, + type: 'boolean' + }, + { + name: 'has_pricing', + label: t`Has Pricing`, + description: t`Filter by parts which have pricing information`, + type: 'boolean' + }, + { + name: 'unallocated_stock', + label: t`Available Stock`, + description: t`Filter by parts which have available stock`, + type: 'boolean' + }, + { + name: 'starred', + label: t`Subscribed`, + description: t`Filter by parts to which the user is subscribed`, + type: 'boolean' + }, + { + name: 'stocktake', + label: t`Has Stocktake`, + description: t`Filter by parts which have stocktake information`, + type: 'boolean' } - // unallocated_stock - // starred - // stocktake - // is_template - // virtual - // has_pricing - // TODO: Any others from table_filters.js? ]; } diff --git a/src/frontend/src/tables/stock/StockLocationTable.tsx b/src/frontend/src/tables/stock/StockLocationTable.tsx index ceaf7ad3d4..f8bc23e4ec 100644 --- a/src/frontend/src/tables/stock/StockLocationTable.tsx +++ b/src/frontend/src/tables/stock/StockLocationTable.tsx @@ -6,6 +6,7 @@ import { ApiEndpoints } from '../../enums/ApiEndpoints'; import { ModelType } from '../../enums/ModelType'; import { UserRoles } from '../../enums/Roles'; import { stockLocationFields } from '../../forms/StockForms'; +import { useFilters } from '../../hooks/UseFilter'; import { useCreateApiFormModal, useEditApiFormModal @@ -26,6 +27,14 @@ export function StockLocationTable({ parentId }: { parentId?: any }) { const table = useTable('stocklocation'); const user = useUserState(); + const locationTypeFilters = useFilters({ + url: apiUrl(ApiEndpoints.stock_location_type_list), + transform: (item) => ({ + value: item.pk, + label: item.name + }) + }); + const tableFilters: TableFilter[] = useMemo(() => { return [ { @@ -35,21 +44,26 @@ export function StockLocationTable({ parentId }: { parentId?: any }) { }, { name: 'structural', - label: t`structural`, + label: t`Structural`, description: t`Show structural locations` }, { name: 'external', - label: t`external`, + label: t`External`, description: t`Show external locations` }, { name: 'has_location_type', label: t`Has location type` + }, + { + name: 'location_type', + label: t`Location Type`, + description: t`Filter by location type`, + choices: locationTypeFilters.choices } - // TODO: location_type ]; - }, []); + }, [locationTypeFilters.choices]); const tableColumns: TableColumn[] = useMemo(() => { return [