From e963b8219bdd794d204db89602eb8dfa58c750bc Mon Sep 17 00:00:00 2001 From: Oliver Date: Wed, 11 Feb 2026 21:46:54 +1100 Subject: [PATCH] [UI] Edit BOM item from "Used In" table (#11286) - Allows editing BOM item from the "used in" table - Useful for editing from the context of the component / subassembly --- src/frontend/src/forms/BomForms.tsx | 9 ++- src/frontend/src/tables/bom/BomTable.tsx | 4 +- src/frontend/src/tables/bom/UsedInTable.tsx | 76 ++++++++++++++++----- 3 files changed, 67 insertions(+), 22 deletions(-) diff --git a/src/frontend/src/forms/BomForms.tsx b/src/frontend/src/forms/BomForms.tsx index ce573186a0..d512c66428 100644 --- a/src/frontend/src/forms/BomForms.tsx +++ b/src/frontend/src/forms/BomForms.tsx @@ -16,10 +16,15 @@ import { useUserState } from '../states/UserState'; /** * Field set for BomItem form */ -export function bomItemFields(): ApiFormFieldSet { +export function bomItemFields({ + showAssembly = false +}: { + showAssembly?: boolean; +}): ApiFormFieldSet { return { part: { - hidden: true + disabled: true, + hidden: !showAssembly }, sub_part: { filters: { diff --git a/src/frontend/src/tables/bom/BomTable.tsx b/src/frontend/src/tables/bom/BomTable.tsx index 808ac1e9eb..6fdec77f7d 100644 --- a/src/frontend/src/tables/bom/BomTable.tsx +++ b/src/frontend/src/tables/bom/BomTable.tsx @@ -511,7 +511,7 @@ export function BomTable({ const newBomItem = useCreateApiFormModal({ url: ApiEndpoints.bom_list, title: t`Add BOM Item`, - fields: bomItemFields(), + fields: bomItemFields({}), initialData: { part: partId }, @@ -523,7 +523,7 @@ export function BomTable({ url: ApiEndpoints.bom_list, pk: selectedBomItem.pk, title: t`Edit BOM Item`, - fields: bomItemFields(), + fields: bomItemFields({}), successMessage: t`BOM item updated`, table: table }); diff --git a/src/frontend/src/tables/bom/UsedInTable.tsx b/src/frontend/src/tables/bom/UsedInTable.tsx index c86e9e0f5c..d2e4481d14 100644 --- a/src/frontend/src/tables/bom/UsedInTable.tsx +++ b/src/frontend/src/tables/bom/UsedInTable.tsx @@ -1,14 +1,18 @@ import { t } from '@lingui/core/macro'; import { Group, Text } from '@mantine/core'; -import { useMemo } from 'react'; +import { useCallback, useMemo, useState } from 'react'; import { ApiEndpoints } from '@lib/enums/ApiEndpoints'; import { ModelType } from '@lib/enums/ModelType'; import { apiUrl } from '@lib/functions/Api'; +import { RowEditAction, UserRoles } from '@lib/index'; import type { TableFilter } from '@lib/types/Filters'; -import type { TableColumn } from '@lib/types/Tables'; +import type { RowAction, TableColumn } from '@lib/types/Tables'; import { formatDecimal } from '../../defaults/formatters'; +import { bomItemFields } from '../../forms/BomForms'; +import { useEditApiFormModal } from '../../hooks/UseForm'; import { useTable } from '../../hooks/UseTable'; +import { useUserState } from '../../states/UserState'; import { DescriptionColumn, PartColumn, @@ -28,6 +32,8 @@ export function UsedInTable({ }>) { const table = useTable('usedin'); + const user = useUserState(); + const tableColumns: TableColumn[] = useMemo(() => { return [ PartColumn({ @@ -98,22 +104,56 @@ export function UsedInTable({ ]; }, [partId]); + const [selectedBomItem, setSelectedBomItem] = useState({}); + + const editBomItem = useEditApiFormModal({ + url: ApiEndpoints.bom_list, + pk: selectedBomItem.pk, + title: t`Edit BOM Item`, + fields: bomItemFields({ + showAssembly: true + }), + successMessage: t`BOM item updated`, + table: table + }); + + const rowActions = useCallback( + (record: any): RowAction[] => { + const locked = record.part_detail?.locked; + + return [ + RowEditAction({ + hidden: locked || !user.hasChangeRole(UserRoles.part), + onClick: () => { + setSelectedBomItem(record); + editBomItem.open(); + } + }) + ]; + }, + [user] + ); + return ( - + <> + {editBomItem.modal} + + ); }