Skip to content

Commit

Permalink
Fix undefined property access within StatusBarComposer component (#…
Browse files Browse the repository at this point in the history
…1018)

* Fix out of bounds array access in StatusBarComposer.

* rush change
  • Loading branch information
GerardasB authored Sep 10, 2024
1 parent c091fed commit c976f03
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
10 changes: 10 additions & 0 deletions common/changes/@itwin/appui-react/fix-999_2024-09-10-13-57.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@itwin/appui-react",
"comment": "Fix `undefined` property access within `StatusBarComposer` component.",
"type": "none"
}
],
"packageName": "@itwin/appui-react"
}
15 changes: 7 additions & 8 deletions ui/appui-react/src/appui-react/statusbar/StatusBarComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,10 @@ export function StatusBarComposer(props: StatusBarComposerProps) {
const combinedItems = combineItems(defaultItems, addonItems);
return sortItems(combinedItems);
}, [defaultItems, addonItems]);
const itemsNotInOverflow = React.useMemo(() => {
return statusBarItems.filter(
(item) => !isItemInOverflow(item.id, overflown)
);
const notOverflown = React.useMemo(() => {
return statusBarItems
.filter((item) => !isItemInOverflow(item.id, overflown))
.map((item) => item.id);
}, [overflown, statusBarItems]);

const calculateOverflow = React.useCallback(() => {
Expand Down Expand Up @@ -440,10 +440,9 @@ export function StatusBarComposer(props: StatusBarComposerProps) {
>
<StatusBarCornerComponentContext.Provider
value={
key === itemsNotInOverflow[0].id
key === notOverflown[0]
? "left-corner"
: (key ===
itemsNotInOverflow[itemsNotInOverflow.length - 1].id &&
: (key === notOverflown[notOverflown.length - 1] &&
overflown?.length === 0) ||
isItemInOverflow(key, overflown)
? "right-corner"
Expand All @@ -462,7 +461,7 @@ export function StatusBarComposer(props: StatusBarComposerProps) {
</DockedStatusBarEntry>
);
},
[handleEntryResize, itemsNotInOverflow, overflown]
[handleEntryResize, notOverflown, overflown]
);

const getSectionItems = React.useCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ import * as React from "react";
export const StatusBarCornerComponentContext = React.createContext<
"right-corner" | "left-corner" | undefined
>(undefined);
StatusBarCornerComponentContext.displayName =
"uifw:StatusBarCornerComponentContext";

0 comments on commit c976f03

Please sign in to comment.