2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-05-03 05:48:47 +00:00

Improve optional chaining checks (#8431)

- Fixes bug where part_detail is potentially undefined
This commit is contained in:
Oliver 2024-11-06 06:04:13 +11:00 committed by GitHub
parent 7b640a4f88
commit f470d30493
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 13 deletions

View File

@ -348,7 +348,8 @@ function LineItemFormRow({
if ( if (
!record.destination && !record.destination &&
!record.destination_detail && !record.destination_detail &&
location === record.part_detail.category_default_location record.part_detail &&
location === record.part_detail?.category_default_location
) { ) {
return t`Part category default location selected`; return t`Part category default location selected`;
} }
@ -511,8 +512,8 @@ function LineItemFormRow({
} }
/> />
<Flex style={{ marginBottom: '7px' }}> <Flex style={{ marginBottom: '7px' }}>
{(record.part_detail.default_location || {(record.part_detail?.default_location ||
record.part_detail.category_default_location) && ( record.part_detail?.category_default_location) && (
<ActionButton <ActionButton
icon={<InvenTreeIcon icon="default_location" />} icon={<InvenTreeIcon icon="default_location" />}
tooltip={t`Store at default location`} tooltip={t`Store at default location`}
@ -520,8 +521,8 @@ function LineItemFormRow({
props.changeFn( props.changeFn(
props.idx, props.idx,
'location', 'location',
record.part_detail.default_location ?? record.part_detail?.default_location ??
record.part_detail.category_default_location record.part_detail?.category_default_location
) )
} }
tooltipAlignment="top" tooltipAlignment="top"

View File

@ -325,14 +325,14 @@ function StockItemDefaultMove({
const { data } = useSuspenseQuery({ const { data } = useSuspenseQuery({
queryKey: [ queryKey: [
'location', 'location',
stockItem.part_detail.default_location ?? stockItem.part_detail?.default_location ??
stockItem.part_detail.category_default_location stockItem.part_detail?.category_default_location
], ],
queryFn: async () => { queryFn: async () => {
const url = apiUrl( const url = apiUrl(
ApiEndpoints.stock_location_list, ApiEndpoints.stock_location_list,
stockItem.part_detail.default_location ?? stockItem.part_detail?.default_location ??
stockItem.part_detail.category_default_location stockItem.part_detail?.category_default_location
); );
return api return api
@ -384,8 +384,8 @@ function moveToDefault(
children: <StockItemDefaultMove stockItem={stockItem} value={value} />, children: <StockItemDefaultMove stockItem={stockItem} value={value} />,
onConfirm: () => { onConfirm: () => {
if ( if (
stockItem.location === stockItem.part_detail.default_location || stockItem.location === stockItem.part_detail?.default_location ||
stockItem.location === stockItem.part_detail.category_default_location stockItem.location === stockItem.part_detail?.category_default_location
) { ) {
return; return;
} }
@ -400,8 +400,8 @@ function moveToDefault(
} }
], ],
location: location:
stockItem.part_detail.default_location ?? stockItem.part_detail?.default_location ??
stockItem.part_detail.category_default_location stockItem.part_detail?.category_default_location
}) })
.then((response) => { .then((response) => {
refresh(); refresh();