Skip to content

Commit

Permalink
Improve optional chaining checks
Browse files Browse the repository at this point in the history
- Fixes bug where part_detail is potentially undefined
  • Loading branch information
SchrodingersGat committed Nov 5, 2024
1 parent 56bd66d commit 242c773
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
11 changes: 6 additions & 5 deletions src/frontend/src/forms/PurchaseOrderForms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,8 @@ function LineItemFormRow({
if (
!record.destination &&
!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`;
}
Expand Down Expand Up @@ -511,17 +512,17 @@ function LineItemFormRow({
}
/>
<Flex style={{ marginBottom: '7px' }}>
{(record.part_detail.default_location ||
record.part_detail.category_default_location) && (
{(record.part_detail?.default_location ||
record.part_detail?.category_default_location) && (
<ActionButton
icon={<InvenTreeIcon icon="default_location" />}
tooltip={t`Store at default location`}
onClick={() =>
props.changeFn(
props.idx,
'location',
record.part_detail.default_location ??
record.part_detail.category_default_location
record.part_detail?.default_location ??
record.part_detail?.category_default_location
)
}
tooltipAlignment="top"
Expand Down
16 changes: 8 additions & 8 deletions src/frontend/src/forms/StockForms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -325,14 +325,14 @@ function StockItemDefaultMove({
const { data } = useSuspenseQuery({
queryKey: [
'location',
stockItem.part_detail.default_location ??
stockItem.part_detail.category_default_location
stockItem.part_detail?.default_location ??
stockItem.part_detail?.category_default_location
],
queryFn: async () => {
const url = apiUrl(
ApiEndpoints.stock_location_list,
stockItem.part_detail.default_location ??
stockItem.part_detail.category_default_location
stockItem.part_detail?.default_location ??
stockItem.part_detail?.category_default_location
);

return api
Expand Down Expand Up @@ -384,8 +384,8 @@ function moveToDefault(
children: <StockItemDefaultMove stockItem={stockItem} value={value} />,
onConfirm: () => {
if (
stockItem.location === stockItem.part_detail.default_location ||
stockItem.location === stockItem.part_detail.category_default_location
stockItem.location === stockItem.part_detail?.default_location ||
stockItem.location === stockItem.part_detail?.category_default_location
) {
return;
}
Expand All @@ -400,8 +400,8 @@ function moveToDefault(
}
],
location:
stockItem.part_detail.default_location ??
stockItem.part_detail.category_default_location
stockItem.part_detail?.default_location ??
stockItem.part_detail?.category_default_location
})
.then((response) => {
refresh();
Expand Down

0 comments on commit 242c773

Please sign in to comment.