Skip to content

Commit 705eb42

Browse files
[Chrome Next] Split static items into global and app specific (elastic#268077)
## Summary This PR introduces `global` property to static items to distinguish global items from app specific items.
1 parent 92d6015 commit 705eb42

4 files changed

Lines changed: 22 additions & 5 deletions

File tree

src/core/packages/chrome/app-menu/core-chrome-app-menu-components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export type {
2222
AppMenuPrimaryActionItem,
2323
AppMenuPopoverItem,
2424
AppMenuSplitButtonProps,
25+
AppMenuStaticItem,
2526
} from './src';
2627

2728
export { APP_MENU_ITEM_LIMIT } from './src';

src/core/packages/chrome/app-menu/core-chrome-app-menu-components/src/components/app_menu.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { getAppMenuItems, processStaticItems } from '../utils';
1313
import { AppMenuActionButton } from './app_menu_action_button';
1414
import { AppMenuItem } from './app_menu_item';
1515
import { AppMenuOverflowButton } from './app_menu_overflow_button';
16-
import type { AppMenuConfig, AppMenuItemType } from '../types';
16+
import type { AppMenuConfig, AppMenuStaticItem } from '../types';
1717

1818
export interface AppMenuItemsProps {
1919
config?: AppMenuConfig;
@@ -27,7 +27,7 @@ export interface AppMenuItemsProps {
2727
/**
2828
* Static items that always appear at the end of the overflow menu.
2929
*/
30-
staticItems?: AppMenuItemType[];
30+
staticItems?: AppMenuStaticItem[];
3131
}
3232

3333
const hasNoItems = (config: AppMenuConfig) => !config.items?.length && !config?.primaryActionItem;
@@ -42,9 +42,16 @@ export const AppMenuComponent = ({
4242
const isBetweenMandXlBreakpoint = useIsWithinBreakpoints(['m', 'l']);
4343
const isAboveXlBreakpoint = useIsWithinBreakpoints(['xl']);
4444

45-
const hasStaticItems = !!staticItems?.length;
45+
/**
46+
* Global static items are registered once, usually before
47+
* an application is mounted, and this can cause flickering when
48+
* the app menu is first rendered without app specific config.
49+
* If only global static items are present, we don't want to render
50+
* the app menu.
51+
*/
52+
const hasNonGlobalStaticItems = !!staticItems?.length && staticItems.some((item) => !item.global);
4653

47-
if ((!config || hasNoItems(config)) && !hasStaticItems) {
54+
if ((!config || hasNoItems(config)) && !hasNonGlobalStaticItems) {
4855
return null;
4956
}
5057

@@ -68,7 +75,7 @@ export const AppMenuComponent = ({
6875
shouldOverflow: shouldOverflowBase,
6976
} = getAppMenuItems({
7077
config,
71-
hasStaticItems,
78+
hasStaticItems: hasNonGlobalStaticItems,
7279
});
7380

7481
const processedStaticItems = processStaticItems(staticItems);

src/core/packages/chrome/app-menu/core-chrome-app-menu-components/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export type {
2222
AppMenuPrimaryActionItem,
2323
AppMenuPopoverItem,
2424
AppMenuSplitButtonProps,
25+
AppMenuStaticItem,
2526
} from './types';
2627

2728
export { APP_MENU_ITEM_LIMIT, DEFAULT_POPOVER_WIDTH } from './constants';

src/core/packages/chrome/app-menu/core-chrome-app-menu-components/src/types.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,14 @@ export type AppMenuItemType = AppMenuItemCommon & {
229229
separator?: 'above' | 'below';
230230
};
231231

232+
export type AppMenuStaticItem = AppMenuItemType & {
233+
/**
234+
* Global static items are singleton items that are registered once
235+
* and are shared across all app menus.
236+
*/
237+
global?: boolean;
238+
};
239+
232240
/**
233241
* Popover item type for use in `items` arrays.
234242
*/

0 commit comments

Comments
 (0)