Skip to content

Commit 3885e91

Browse files
kowalczyk-krzysztofkibanamachineangeles-mb
authored
[Chrome Next] Hide app menu separator when you only have static items (elastic#270618)
## Summary This PR removes the separator above `staticItems` when there are no regular items. <img width="273" height="147" alt="Screenshot 2026-05-22 at 19 03 26" src="https://github.com/user-attachments/assets/39da8872-5b66-4054-be27-1c2e4ca2fd4e" /> --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Ángeles Martínez Barrio <angeles.martinezbarrio@elastic.co>
1 parent 4d73eeb commit 3885e91

2 files changed

Lines changed: 33 additions & 16 deletions

File tree

src/core/packages/chrome/app-menu/core-chrome-app-menu-components/src/utils.test.tsx

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,22 @@ describe('utils', () => {
669669
expect(mainPanel?.['data-test-subj']).toBeUndefined(); // Main panel has no test ID by default
670670
});
671671

672-
it('should append staticItems after regular items in the main panel', () => {
672+
it('should not show a separator when only static items are present', () => {
673+
const items: AppMenuPopoverItem[] = [];
674+
const staticItems: AppMenuPopoverItem[] = [
675+
{ id: 'static1', label: 'Static 1', run: jest.fn(), order: 1 },
676+
{ id: 'static2', label: 'Static 2', run: jest.fn(), order: 2 },
677+
];
678+
679+
const panels = getPopoverPanels({ items, staticItems });
680+
681+
expect(panels).toHaveLength(1);
682+
const panelItems = panels[0].items as Array<{ key?: string; isSeparator?: boolean }>;
683+
expect(panelItems[0].isSeparator).not.toBe(true);
684+
expect(panelItems.map((i) => i.key)).toEqual(['static1', 'static2']);
685+
});
686+
687+
it('should add a separator between regular and static items', () => {
673688
const items: AppMenuPopoverItem[] = [
674689
{ id: '1', label: 'Item 1', run: jest.fn(), order: 2 },
675690
{ id: '2', label: 'Item 2', run: jest.fn(), order: 1 },
@@ -681,9 +696,9 @@ describe('utils', () => {
681696
const panels = getPopoverPanels({ items, staticItems });
682697

683698
expect(panels).toHaveLength(1);
684-
const panelItems = panels[0].items as Array<{ key?: string }>;
685-
// Regular items sorted by order: Item 2 (order 1), Item 1 (order 2), then static
686-
expect(panelItems.map((i) => i.key)).toEqual(['2', '1', 'static1']);
699+
const panelItems = panels[0].items as Array<{ key?: string; isSeparator?: boolean }>;
700+
expect(panelItems.map((i) => i.key)).toEqual(['2', '1', 'static-items-separator', 'static1']);
701+
expect(panelItems[2].isSeparator).toBe(true);
687702
});
688703

689704
it('should not re-sort staticItems together with regular items', () => {
@@ -854,27 +869,27 @@ describe('utils', () => {
854869
expect(result.every((item) => item.overflow === true)).toBe(true);
855870
});
856871

857-
it('should add separator "above" only to the first item', () => {
872+
it('should not add separator to items', () => {
858873
const items = [
859874
createStaticItem({ id: 'a', order: 1 }),
860875
createStaticItem({ id: 'b', order: 2 }),
861876
createStaticItem({ id: 'c', order: 3 }),
862877
];
863878
const result = processStaticItems(items);
864879

865-
expect(result[0].separator).toBe('above');
880+
expect(result[0].separator).toBeUndefined();
866881
expect(result[1].separator).toBeUndefined();
867882
expect(result[2].separator).toBeUndefined();
868883
});
869884

870-
it('should strip existing separator values from non-first items', () => {
885+
it('should strip existing separator values from items', () => {
871886
const items = [
872887
createStaticItem({ id: 'a', order: 1, separator: 'below' }),
873888
createStaticItem({ id: 'b', order: 2, separator: 'above' }),
874889
];
875890
const result = processStaticItems(items);
876891

877-
expect(result[0].separator).toBe('above');
892+
expect(result[0].separator).toBeUndefined();
878893
expect(result[1].separator).toBeUndefined();
879894
});
880895

@@ -889,15 +904,15 @@ describe('utils', () => {
889904
expect(result.map((item) => item.id)).toEqual(['a', 'b', 'c']);
890905
});
891906

892-
it('should add separator "above" to the first item after sorting', () => {
907+
it('should not add separator to the first item after sorting', () => {
893908
const items = [
894909
createStaticItem({ id: 'c', order: 3 }),
895910
createStaticItem({ id: 'a', order: 1 }),
896911
];
897912
const result = processStaticItems(items);
898913

899914
expect(result[0].id).toBe('a');
900-
expect(result[0].separator).toBe('above');
915+
expect(result[0].separator).toBeUndefined();
901916
});
902917
});
903918
});

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,9 @@ export const getAppMenuItems = ({
121121
};
122122

123123
export const processStaticItems = (staticItems?: AppMenuItemType[]): AppMenuItemType[] =>
124-
sortByOrder(staticItems ?? []).map(({ separator, ...item }, index) => ({
124+
sortByOrder(staticItems ?? []).map(({ separator, ...item }) => ({
125125
...item,
126126
overflow: true,
127-
...(index === 0 ? { separator: 'above' as const } : {}),
128127
}));
129128

130129
export const isDisabled = (disableButton: AppMenuItemCommon['disableButton']) =>
@@ -433,10 +432,13 @@ export const getPopoverPanels = ({
433432
const mainPanel = panels.find((panel) => panel.id === startPanelId);
434433

435434
if (staticPanel && mainPanel) {
436-
mainPanel.items = [
437-
...(mainPanel.items as EuiContextMenuPanelItemDescriptor[]),
438-
...(staticPanel.items as EuiContextMenuPanelItemDescriptor[]),
439-
];
435+
const mainItems = mainPanel.items as EuiContextMenuPanelItemDescriptor[];
436+
const staticPanelItems = staticPanel.items as EuiContextMenuPanelItemDescriptor[];
437+
438+
// Only add a separator between regular and static items
439+
const separator = mainItems.length > 0 ? [createSeparatorItem('static-items-separator')] : [];
440+
441+
mainPanel.items = [...mainItems, ...separator, ...staticPanelItems];
440442
panels.splice(panels.indexOf(staticPanel), 1);
441443
}
442444
}

0 commit comments

Comments
 (0)