Skip to content

Commit

Permalink
Hide "location" column in certain conditions (#8587)
Browse files Browse the repository at this point in the history
  • Loading branch information
SchrodingersGat authored Nov 28, 2024
1 parent ced695b commit 390828d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/frontend/src/pages/build/BuildDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ export default function BuildDetail() {
<StockItemTable
allowAdd={false}
tableName='build-consumed'
showLocation={false}
params={{
consumed_by: id
}}
Expand Down
1 change: 1 addition & 0 deletions src/frontend/src/pages/company/CompanyDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ export default function CompanyDetail(props: Readonly<CompanyDetailProps>) {
<StockItemTable
allowAdd={false}
tableName='assigned-stock'
showLocation={false}
params={{ customer: company.pk }}
/>
) : (
Expand Down
25 changes: 23 additions & 2 deletions src/frontend/src/tables/stock/StockItemTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -215,6 +221,7 @@ function stockItemTableColumns(): TableColumn[] {
sortable: true
},
LocationColumn({
hidden: !showLocation,
accessor: 'location_detail'
}),
{
Expand All @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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({
Expand Down

0 comments on commit 390828d

Please sign in to comment.