From 390828d166231f10743eb7f8233747795434e250 Mon Sep 17 00:00:00 2001 From: Oliver Date: Fri, 29 Nov 2024 10:45:24 +1100 Subject: [PATCH] Hide "location" column in certain conditions (#8587) --- src/frontend/src/pages/build/BuildDetail.tsx | 1 + .../src/pages/company/CompanyDetail.tsx | 1 + .../src/tables/stock/StockItemTable.tsx | 25 +++++++++++++++++-- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/frontend/src/pages/build/BuildDetail.tsx b/src/frontend/src/pages/build/BuildDetail.tsx index 19c9fd7217..a2de259fdc 100644 --- a/src/frontend/src/pages/build/BuildDetail.tsx +++ b/src/frontend/src/pages/build/BuildDetail.tsx @@ -313,6 +313,7 @@ export default function BuildDetail() { ) { ) : ( diff --git a/src/frontend/src/tables/stock/StockItemTable.tsx b/src/frontend/src/tables/stock/StockItemTable.tsx index 587ef88001..d9dfc20cf4 100644 --- a/src/frontend/src/tables/stock/StockItemTable.tsx +++ b/src/frontend/src/tables/stock/StockItemTable.tsx @@ -42,7 +42,13 @@ import { TableHoverCard } from '../TableHoverCard'; /** * Construct a list of columns for the stock item table */ -function stockItemTableColumns(): TableColumn[] { +function stockItemTableColumns({ + showLocation, + showPricing +}: { + showLocation: boolean; + showPricing: boolean; +}): TableColumn[] { return [ { accessor: 'part', @@ -215,6 +221,7 @@ function stockItemTableColumns(): TableColumn[] { sortable: true }, LocationColumn({ + hidden: !showLocation, accessor: 'location_detail' }), { @@ -239,6 +246,7 @@ function stockItemTableColumns(): TableColumn[] { title: t`Unit Price`, sortable: true, switchable: true, + hidden: !showPricing, render: (record: any) => formatCurrency(record.purchase_price, { currency: record.purchase_price_currency @@ -248,6 +256,7 @@ function stockItemTableColumns(): TableColumn[] { accessor: 'stock_value', title: t`Stock Value`, sortable: false, + hidden: !showPricing, render: (record: any) => { const min_price = record.purchase_price || record.part_detail?.pricing_min; @@ -466,10 +475,14 @@ function stockItemTableFilters({ export function StockItemTable({ params = {}, allowAdd = false, + showLocation = true, + showPricing = true, tableName = 'stockitems' }: Readonly<{ params?: any; allowAdd?: boolean; + showLocation?: boolean; + showPricing?: boolean; tableName: string; }>) { const table = useTable(tableName); @@ -482,7 +495,15 @@ export function StockItemTable({ [settings] ); - const tableColumns = useMemo(() => stockItemTableColumns(), []); + const tableColumns = useMemo( + () => + stockItemTableColumns({ + showLocation: showLocation ?? true, + showPricing: showPricing ?? true + }), + [showLocation, showPricing] + ); + const tableFilters = useMemo( () => stockItemTableFilters({