Skip to content

Commit

Permalink
Refactor retrieval of first and last panel items
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronrobertshaw committed Jan 10, 2022
1 parent cdf668a commit 5bc8da0
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions packages/components/src/tools-panel/tools-panel/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,23 +232,21 @@ export function useToolsPanel(

// Assist ItemGroup styling when there are potentially hidden placeholder
// items by identifying first & last items that are toggled on for display.
const getFirstItem = () => {
const getFirstVisibleItemLabel = ( items: ToolsPanelItem[] ) => {
const optionalItems = menuItems.optional || {};
const firstItem = panelItems.find(
const firstItem = items.find(
( item ) => item.isShownByDefault || !! optionalItems[ item.label ]
);

return firstItem?.label;
};

const getLastItem = () => {
const reversedPanelItems = [ ...panelItems ].reverse();
const optionalItems = menuItems.optional || {};
const lastItem = reversedPanelItems.find(
( item ) => item.isShownByDefault || !! optionalItems[ item.label ]
);
const getFirstItem = () => {
return getFirstVisibleItemLabel( panelItems );
};

return lastItem?.label;
const getLastItem = () => {
return getFirstVisibleItemLabel( [ ...panelItems ].reverse() );
};

const panelContext = {
Expand Down

0 comments on commit 5bc8da0

Please sign in to comment.