mirror of
https://github.com/inventree/InvenTree.git
synced 2025-07-09 22:45:06 +00:00
[UI] Allocation tweaks (#9970)
* Hide row actions if not in production * Refetch allocations on change
This commit is contained in:
@ -46,6 +46,7 @@ import {
|
|||||||
useCreateApiFormModal,
|
useCreateApiFormModal,
|
||||||
useEditApiFormModal
|
useEditApiFormModal
|
||||||
} from '../../hooks/UseForm';
|
} from '../../hooks/UseForm';
|
||||||
|
import useStatusCodes from '../../hooks/UseStatusCodes';
|
||||||
import { useStockAdjustActions } from '../../hooks/UseStockAdjustActions';
|
import { useStockAdjustActions } from '../../hooks/UseStockAdjustActions';
|
||||||
import { useTable } from '../../hooks/UseTable';
|
import { useTable } from '../../hooks/UseTable';
|
||||||
import { useUserState } from '../../states/UserState';
|
import { useUserState } from '../../states/UserState';
|
||||||
@ -152,6 +153,8 @@ export default function BuildOutputTable({
|
|||||||
return build.part ?? -1;
|
return build.part ?? -1;
|
||||||
}, [build.part]);
|
}, [build.part]);
|
||||||
|
|
||||||
|
const buildStatus = useStatusCodes({ modelType: ModelType.build });
|
||||||
|
|
||||||
// Fetch the test templates associated with the partId
|
// Fetch the test templates associated with the partId
|
||||||
const { data: testTemplates } = useQuery({
|
const { data: testTemplates } = useQuery({
|
||||||
queryKey: ['buildoutputtests', partId, build],
|
queryKey: ['buildoutputtests', partId, build],
|
||||||
@ -469,6 +472,8 @@ export default function BuildOutputTable({
|
|||||||
|
|
||||||
const rowActions = useCallback(
|
const rowActions = useCallback(
|
||||||
(record: any): RowAction[] => {
|
(record: any): RowAction[] => {
|
||||||
|
const production = build?.status == buildStatus.PRODUCTION;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
RowViewAction({
|
RowViewAction({
|
||||||
title: t`View Build Output`,
|
title: t`View Build Output`,
|
||||||
@ -480,18 +485,24 @@ export default function BuildOutputTable({
|
|||||||
title: t`Allocate`,
|
title: t`Allocate`,
|
||||||
tooltip: t`Allocate stock to build output`,
|
tooltip: t`Allocate stock to build output`,
|
||||||
color: 'blue',
|
color: 'blue',
|
||||||
hidden: !hasTrackedItems || !user.hasChangeRole(UserRoles.build),
|
hidden:
|
||||||
|
!production ||
|
||||||
|
!hasTrackedItems ||
|
||||||
|
!user.hasChangeRole(UserRoles.build),
|
||||||
icon: <InvenTreeIcon icon='plus' />,
|
icon: <InvenTreeIcon icon='plus' />,
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
setSelectedOutputs([record]);
|
setSelectedOutputs([record]);
|
||||||
openDrawer();
|
openAllocationDrawer();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: t`Deallocate`,
|
title: t`Deallocate`,
|
||||||
tooltip: t`Deallocate stock from build output`,
|
tooltip: t`Deallocate stock from build output`,
|
||||||
color: 'red',
|
color: 'red',
|
||||||
hidden: !hasTrackedItems || !user.hasChangeRole(UserRoles.build),
|
hidden:
|
||||||
|
!production ||
|
||||||
|
!hasTrackedItems ||
|
||||||
|
!user.hasChangeRole(UserRoles.build),
|
||||||
icon: <InvenTreeIcon icon='minus' />,
|
icon: <InvenTreeIcon icon='minus' />,
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
setSelectedOutputs([record]);
|
setSelectedOutputs([record]);
|
||||||
@ -548,7 +559,7 @@ export default function BuildOutputTable({
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
[user, partId, hasTrackedItems]
|
[buildStatus, user, partId, hasTrackedItems]
|
||||||
);
|
);
|
||||||
|
|
||||||
const tableColumns: TableColumn[] = useMemo(() => {
|
const tableColumns: TableColumn[] = useMemo(() => {
|
||||||
@ -650,8 +661,15 @@ export default function BuildOutputTable({
|
|||||||
trackedItems
|
trackedItems
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const [drawerOpen, { open: openDrawer, close: closeDrawer }] =
|
const [
|
||||||
useDisclosure(false);
|
allocationDrawerOpen,
|
||||||
|
{ open: openAllocationDrawer, close: closeAllocationDrawer }
|
||||||
|
] = useDisclosure(false);
|
||||||
|
|
||||||
|
const closeDrawer = useCallback(() => {
|
||||||
|
closeAllocationDrawer();
|
||||||
|
refetchTrackedItems();
|
||||||
|
}, [closeAllocationDrawer, refetchTrackedItems]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@ -666,7 +684,7 @@ export default function BuildOutputTable({
|
|||||||
<OutputAllocationDrawer
|
<OutputAllocationDrawer
|
||||||
build={build}
|
build={build}
|
||||||
output={selectedOutputs[0]}
|
output={selectedOutputs[0]}
|
||||||
opened={drawerOpen}
|
opened={allocationDrawerOpen}
|
||||||
close={closeDrawer}
|
close={closeDrawer}
|
||||||
/>
|
/>
|
||||||
<Stack gap='xs'>
|
<Stack gap='xs'>
|
||||||
@ -701,7 +719,7 @@ export default function BuildOutputTable({
|
|||||||
onRowClick: (record: any) => {
|
onRowClick: (record: any) => {
|
||||||
if (hasTrackedItems && !!record.serial) {
|
if (hasTrackedItems && !!record.serial) {
|
||||||
setSelectedOutputs([record]);
|
setSelectedOutputs([record]);
|
||||||
openDrawer();
|
openAllocationDrawer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
Reference in New Issue
Block a user