Skip to content

Commit

Permalink
Merge pull request #5313 from msupply-foundation/5250-gaps-improve-va…
Browse files Browse the repository at this point in the history
…lidation-on-packagingitem-variants(non-zero-input)

non zero input
  • Loading branch information
jmbrunskill authored Nov 5, 2024
2 parents 14dc2d7 + e5eda0c commit 47c68df
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ export const NumberInputCell = <T extends RecordWithId>({
TextInputProps,
width,
endAdornment,
error,
}: CellProps<T> &
NumericInputProps & {
id?: string;
TextInputProps?: StandardTextFieldProps;
endAdornment?: string;
error?: boolean;
}): React.ReactElement<CellProps<T>> => {
const [buffer, setBuffer] = useBufferState(column.accessor({ rowData }));
const updater = useDebounceCallback(column.setter, [column.setter], 250);
Expand Down Expand Up @@ -64,6 +66,7 @@ export const NumberInputCell = <T extends RecordWithId>({
value={buffer as number | undefined}
width={width}
endAdornment={endAdornment}
error={error}
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ export const ItemPackagingVariantsTable = ({
},
{
key: 'packSize',
Cell: update ? PackSizeInputCell : TooltipTextCell,
Cell: update ? NonZeroInputCell : TooltipTextCell,
label: 'label.pack-size',
setter: updatePackaging,
},
{
key: 'volumePerUnit',
Cell: update ? VolumeInputCell : TooltipTextCell,
Cell: update ? NonZeroInputCell : TooltipTextCell,
label: 'label.volume-per-unit',
setter: updatePackaging,
},
Expand All @@ -65,11 +65,11 @@ export const ItemPackagingVariantsTable = ({
};

// Input cells can't be defined inline, otherwise they lose focus on re-render
const VolumeInputCell = (props: CellProps<PackagingVariantFragment>) => (
<NumberInputCell decimalLimit={10} {...props} />
);

// Input cells can't be defined inline, otherwise they lose focus on re-render
const PackSizeInputCell = (props: CellProps<PackagingVariantFragment>) => (
<NumberInputCell min={0.0001} step={1} decimalLimit={10} {...props} />
const NonZeroInputCell = (props: CellProps<PackagingVariantFragment>) => (
<NumberInputCell
step={1}
decimalLimit={10}
error={props.column.accessor({ rowData: props.rowData }) === 0}
{...props}
/>
);
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,10 @@ const useUpsert = ({ itemId }: { itemId: string }) => {
};

function getIsComplete(draft: ItemVariantFragment) {
return !!draft.name;
return (
!!draft.name &&
draft.packagingVariants.every(
pv => pv.packSize !== 0 && pv.volumePerUnit !== 0
)
);
}

0 comments on commit 47c68df

Please sign in to comment.