mirror of
https://github.com/inventree/InvenTree.git
synced 2026-06-06 00:44:25 +00:00
[Bug] Fix for build forms (#12081)
* Bug fix for build forms - Memoize outputs to prevent re-rendering reset issues * Add playwright test
This commit is contained in:
@@ -343,16 +343,21 @@ export function useCompleteBuildOutputsForm({
|
|||||||
);
|
);
|
||||||
}, [location, build.destination, build.part_detail]);
|
}, [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(() => {
|
const buildOutputCompleteFields: ApiFormFieldSet = useMemo(() => {
|
||||||
return {
|
return {
|
||||||
outputs: {
|
outputs: {
|
||||||
field_type: 'table',
|
field_type: 'table',
|
||||||
value: outputs.map((output: any) => {
|
value: buildOutputs,
|
||||||
return {
|
|
||||||
output: output.pk,
|
|
||||||
quantity: output.quantity
|
|
||||||
};
|
|
||||||
}),
|
|
||||||
modelRenderer: (row: TableFieldRowProps) => {
|
modelRenderer: (row: TableFieldRowProps) => {
|
||||||
const record = outputs.find((output) => output.pk == row.item.output);
|
const record = outputs.find((output) => output.pk == row.item.output);
|
||||||
return (
|
return (
|
||||||
@@ -420,16 +425,21 @@ export function useScrapBuildOutputsForm({
|
|||||||
);
|
);
|
||||||
}, [location, build.destination, build.part_detail]);
|
}, [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(() => {
|
const buildOutputScrapFields: ApiFormFieldSet = useMemo(() => {
|
||||||
return {
|
return {
|
||||||
outputs: {
|
outputs: {
|
||||||
field_type: 'table',
|
field_type: 'table',
|
||||||
value: outputs.map((output: any) => {
|
value: buildOutputs,
|
||||||
return {
|
|
||||||
output: output.pk,
|
|
||||||
quantity: output.quantity
|
|
||||||
};
|
|
||||||
}),
|
|
||||||
modelRenderer: (row: TableFieldRowProps) => {
|
modelRenderer: (row: TableFieldRowProps) => {
|
||||||
const record = outputs.find((output) => output.pk == row.item.output);
|
const record = outputs.find((output) => output.pk == row.item.output);
|
||||||
return (
|
return (
|
||||||
@@ -486,15 +496,20 @@ export function useCancelBuildOutputsForm({
|
|||||||
outputs: any[];
|
outputs: any[];
|
||||||
onFormSuccess: (response: any) => void;
|
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(() => {
|
const buildOutputCancelFields: ApiFormFieldSet = useMemo(() => {
|
||||||
return {
|
return {
|
||||||
outputs: {
|
outputs: {
|
||||||
field_type: 'table',
|
field_type: 'table',
|
||||||
value: outputs.map((output: any) => {
|
value: buildOutputs,
|
||||||
return {
|
|
||||||
output: output.pk
|
|
||||||
};
|
|
||||||
}),
|
|
||||||
modelRenderer: (row: TableFieldRowProps) => {
|
modelRenderer: (row: TableFieldRowProps) => {
|
||||||
const record = outputs.find((output) => output.pk == row.item.output);
|
const record = outputs.find((output) => output.pk == row.item.output);
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -379,6 +379,24 @@ test('Build Order - Build Outputs', async ({ browser }) => {
|
|||||||
)
|
)
|
||||||
.waitFor();
|
.waitFor();
|
||||||
await page.getByRole('cell', { name: 'Quantity: 16' }).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();
|
await page.getByRole('button', { name: 'Cancel', exact: true }).click();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user