2
0
mirror of https://github.com/inventree/InvenTree.git synced 2026-07-04 06:00:38 +00:00

[Bug] Fix for build forms (#12081) (#12083)

* Bug fix for build forms

- Memoize outputs to prevent re-rendering reset issues

* Add playwright test

(cherry picked from commit 3dfd03fa89)

Co-authored-by: Oliver <oliver.henry.walters@gmail.com>
This commit is contained in:
github-actions[bot]
2026-06-04 22:25:12 +10:00
committed by GitHub
parent bcd70c7b0d
commit 00d99f65fa
2 changed files with 50 additions and 17 deletions
+32 -17
View File
@@ -344,16 +344,21 @@ export function useCompleteBuildOutputsForm({
);
}, [location, build.destination, build.part_detail]);
// Memoize the outputs once to avoid re-rendering issues
const buildOutputs = useMemo(() => {
return outputs.map((output: any) => {
return {
output: output.pk,
quantity: output.quantity
};
});
}, [outputs]);
const buildOutputCompleteFields: ApiFormFieldSet = useMemo(() => {
return {
outputs: {
field_type: 'table',
value: outputs.map((output: any) => {
return {
output: output.pk,
quantity: output.quantity
};
}),
value: buildOutputs,
modelRenderer: (row: TableFieldRowProps) => {
const record = outputs.find((output) => output.pk == row.item.output);
return (
@@ -421,16 +426,21 @@ export function useScrapBuildOutputsForm({
);
}, [location, build.destination, build.part_detail]);
// Memoize the outputs once to avoid re-rendering issues
const buildOutputs = useMemo(() => {
return outputs.map((output: any) => {
return {
output: output.pk,
quantity: output.quantity
};
});
}, [outputs]);
const buildOutputScrapFields: ApiFormFieldSet = useMemo(() => {
return {
outputs: {
field_type: 'table',
value: outputs.map((output: any) => {
return {
output: output.pk,
quantity: output.quantity
};
}),
value: buildOutputs,
modelRenderer: (row: TableFieldRowProps) => {
const record = outputs.find((output) => output.pk == row.item.output);
return (
@@ -487,15 +497,20 @@ export function useCancelBuildOutputsForm({
outputs: any[];
onFormSuccess: (response: any) => void;
}) {
// Memoize the outputs once to avoid re-rendering issues
const buildOutputs = useMemo(() => {
return outputs.map((output: any) => {
return {
output: output.pk
};
});
}, [outputs]);
const buildOutputCancelFields: ApiFormFieldSet = useMemo(() => {
return {
outputs: {
field_type: 'table',
value: outputs.map((output: any) => {
return {
output: output.pk
};
}),
value: buildOutputs,
modelRenderer: (row: TableFieldRowProps) => {
const record = outputs.find((output) => output.pk == row.item.output);
return (
@@ -327,6 +327,24 @@ test('Build Order - Build Outputs', async ({ browser }) => {
)
.waitFor();
await page.getByRole('cell', { name: 'Quantity: 16' }).waitFor();
// Adjust the quantity field - we will only 'partially' scrap this output
await page.getByRole('textbox', { name: 'number-field-quantity' }).fill('10');
// Next, adjust the "location" field - and check that the "quantity" field does not change
// Ref: https://github.com/inventree/InvenTree/pull/12081
await page
.getByRole('combobox', { name: 'related-field-location' })
.fill('factory');
await page.getByTitle('Factory/Mechanical Lab').click();
await page.waitForTimeout(250);
// Check the 'quantity' value again - it should not have changed
const quantityValue = await page
.getByRole('textbox', { name: 'number-field-quantity' })
.inputValue();
expect(quantityValue).toBe('10');
await page.getByRole('button', { name: 'Cancel', exact: true }).click();
});