mirror of
https://github.com/inventree/InvenTree.git
synced 2026-02-12 09:17:13 +00:00
[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
This commit is contained in:
@@ -16,10 +16,15 @@ import { useUserState } from '../states/UserState';
|
|||||||
/**
|
/**
|
||||||
* Field set for BomItem form
|
* Field set for BomItem form
|
||||||
*/
|
*/
|
||||||
export function bomItemFields(): ApiFormFieldSet {
|
export function bomItemFields({
|
||||||
|
showAssembly = false
|
||||||
|
}: {
|
||||||
|
showAssembly?: boolean;
|
||||||
|
}): ApiFormFieldSet {
|
||||||
return {
|
return {
|
||||||
part: {
|
part: {
|
||||||
hidden: true
|
disabled: true,
|
||||||
|
hidden: !showAssembly
|
||||||
},
|
},
|
||||||
sub_part: {
|
sub_part: {
|
||||||
filters: {
|
filters: {
|
||||||
|
|||||||
@@ -511,7 +511,7 @@ export function BomTable({
|
|||||||
const newBomItem = useCreateApiFormModal({
|
const newBomItem = useCreateApiFormModal({
|
||||||
url: ApiEndpoints.bom_list,
|
url: ApiEndpoints.bom_list,
|
||||||
title: t`Add BOM Item`,
|
title: t`Add BOM Item`,
|
||||||
fields: bomItemFields(),
|
fields: bomItemFields({}),
|
||||||
initialData: {
|
initialData: {
|
||||||
part: partId
|
part: partId
|
||||||
},
|
},
|
||||||
@@ -523,7 +523,7 @@ export function BomTable({
|
|||||||
url: ApiEndpoints.bom_list,
|
url: ApiEndpoints.bom_list,
|
||||||
pk: selectedBomItem.pk,
|
pk: selectedBomItem.pk,
|
||||||
title: t`Edit BOM Item`,
|
title: t`Edit BOM Item`,
|
||||||
fields: bomItemFields(),
|
fields: bomItemFields({}),
|
||||||
successMessage: t`BOM item updated`,
|
successMessage: t`BOM item updated`,
|
||||||
table: table
|
table: table
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,14 +1,18 @@
|
|||||||
import { t } from '@lingui/core/macro';
|
import { t } from '@lingui/core/macro';
|
||||||
import { Group, Text } from '@mantine/core';
|
import { Group, Text } from '@mantine/core';
|
||||||
import { useMemo } from 'react';
|
import { useCallback, useMemo, useState } from 'react';
|
||||||
|
|
||||||
import { ApiEndpoints } from '@lib/enums/ApiEndpoints';
|
import { ApiEndpoints } from '@lib/enums/ApiEndpoints';
|
||||||
import { ModelType } from '@lib/enums/ModelType';
|
import { ModelType } from '@lib/enums/ModelType';
|
||||||
import { apiUrl } from '@lib/functions/Api';
|
import { apiUrl } from '@lib/functions/Api';
|
||||||
|
import { RowEditAction, UserRoles } from '@lib/index';
|
||||||
import type { TableFilter } from '@lib/types/Filters';
|
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 { formatDecimal } from '../../defaults/formatters';
|
||||||
|
import { bomItemFields } from '../../forms/BomForms';
|
||||||
|
import { useEditApiFormModal } from '../../hooks/UseForm';
|
||||||
import { useTable } from '../../hooks/UseTable';
|
import { useTable } from '../../hooks/UseTable';
|
||||||
|
import { useUserState } from '../../states/UserState';
|
||||||
import {
|
import {
|
||||||
DescriptionColumn,
|
DescriptionColumn,
|
||||||
PartColumn,
|
PartColumn,
|
||||||
@@ -28,6 +32,8 @@ export function UsedInTable({
|
|||||||
}>) {
|
}>) {
|
||||||
const table = useTable('usedin');
|
const table = useTable('usedin');
|
||||||
|
|
||||||
|
const user = useUserState();
|
||||||
|
|
||||||
const tableColumns: TableColumn[] = useMemo(() => {
|
const tableColumns: TableColumn[] = useMemo(() => {
|
||||||
return [
|
return [
|
||||||
PartColumn({
|
PartColumn({
|
||||||
@@ -98,7 +104,39 @@ export function UsedInTable({
|
|||||||
];
|
];
|
||||||
}, [partId]);
|
}, [partId]);
|
||||||
|
|
||||||
|
const [selectedBomItem, setSelectedBomItem] = useState<any>({});
|
||||||
|
|
||||||
|
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 (
|
return (
|
||||||
|
<>
|
||||||
|
{editBomItem.modal}
|
||||||
<InvenTreeTable
|
<InvenTreeTable
|
||||||
url={apiUrl(ApiEndpoints.bom_list)}
|
url={apiUrl(ApiEndpoints.bom_list)}
|
||||||
tableState={table}
|
tableState={table}
|
||||||
@@ -110,10 +148,12 @@ export function UsedInTable({
|
|||||||
part_detail: true,
|
part_detail: true,
|
||||||
sub_part_detail: true
|
sub_part_detail: true
|
||||||
},
|
},
|
||||||
|
rowActions: rowActions,
|
||||||
tableFilters: tableFilters,
|
tableFilters: tableFilters,
|
||||||
modelType: ModelType.part,
|
modelType: ModelType.part,
|
||||||
modelField: 'part'
|
modelField: 'part'
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user