Skip to content

Commit 3787640

Browse files
AppMenu changes for DnD
1 parent 9848945 commit 3787640

30 files changed

Lines changed: 320 additions & 581 deletions

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

Lines changed: 80 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,86 @@ type Story = StoryObj<AppMenuWrapperProps>;
5454

5555
const dashboardEditModeConfig: AppMenuConfig = {
5656
items: [
57+
{
58+
id: 'add',
59+
order: 0,
60+
label: 'add',
61+
testId: 'addButton',
62+
iconType: 'plus',
63+
popoverWidth: 200,
64+
items: [
65+
{
66+
run: () => action('create-visualization-clicked'),
67+
order: 1,
68+
id: 'createVisualization',
69+
label: 'Visualization',
70+
iconType: 'lensApp',
71+
testId: 'createNewVisButton',
72+
},
73+
{
74+
run: () => action('new-panel-clicked'),
75+
id: 'newPanel',
76+
order: 2,
77+
label: 'New panel',
78+
iconType: 'plusCircle',
79+
testId: 'openAddPanelFlyoutButton',
80+
},
81+
{
82+
run: () => action('add-section-clicked'),
83+
id: 'collapsibleSection',
84+
order: 3,
85+
label: 'Collapsible section',
86+
iconType: 'section',
87+
testId: 'addCollapsibleSectionButton',
88+
},
89+
{
90+
id: 'controls',
91+
order: 4,
92+
label: 'Controls',
93+
iconType: 'controls',
94+
testId: 'controls-menu-button',
95+
items: [
96+
{
97+
run: () => action('control-clicked'),
98+
id: 'control',
99+
order: 1,
100+
label: 'control',
101+
testId: 'controlButton',
102+
},
103+
{
104+
run: () => action('variable-control-clicked'),
105+
id: 'variableControl',
106+
order: 2,
107+
label: 'variable control',
108+
testId: 'variableControlButton',
109+
},
110+
{
111+
run: () => action('time-slider-control-clicked'),
112+
id: 'timeSliderControl',
113+
order: 3,
114+
label: 'time slider control',
115+
testId: 'timeSliderControlButton',
116+
},
117+
{
118+
run: () => action('setting-clicked'),
119+
id: 'settings',
120+
order: 4,
121+
label: 'settings',
122+
testId: 'settingButton',
123+
separator: 'above',
124+
},
125+
],
126+
},
127+
{
128+
run: () => action('add-from-library-clicked'),
129+
id: 'fromLibrary',
130+
order: 5,
131+
label: 'From library',
132+
iconType: 'folderOpen',
133+
testId: 'addFromLibraryButton',
134+
},
135+
],
136+
},
57137
{
58138
run: action('exit-edit-clicked'),
59139
id: 'exitEdit',
@@ -121,87 +201,6 @@ const dashboardEditModeConfig: AppMenuConfig = {
121201
iconType: 'backgroundTask',
122202
},
123203
],
124-
secondaryActionItem: {
125-
id: 'add',
126-
label: 'add',
127-
testId: 'addButton',
128-
iconType: 'plusCircle',
129-
color: 'success',
130-
minWidth: false,
131-
popoverWidth: 200,
132-
items: [
133-
{
134-
run: () => action('create-visualization-clicked'),
135-
order: 1,
136-
id: 'createVisualization',
137-
label: 'Visualization',
138-
iconType: 'lensApp',
139-
testId: 'createNewVisButton',
140-
},
141-
{
142-
run: () => action('new-panel-clicked'),
143-
id: 'newPanel',
144-
order: 2,
145-
label: 'New panel',
146-
iconType: 'plusCircle',
147-
testId: 'openAddPanelFlyoutButton',
148-
},
149-
{
150-
run: () => action('add-section-clicked'),
151-
id: 'collapsibleSection',
152-
order: 3,
153-
label: 'Collapsible section',
154-
iconType: 'section',
155-
testId: 'addCollapsibleSectionButton',
156-
},
157-
{
158-
id: 'controls',
159-
order: 4,
160-
label: 'Controls',
161-
iconType: 'controls',
162-
testId: 'controls-menu-button',
163-
items: [
164-
{
165-
run: () => action('control-clicked'),
166-
id: 'control',
167-
order: 1,
168-
label: 'control',
169-
testId: 'controlButton',
170-
},
171-
{
172-
run: () => action('variable-control-clicked'),
173-
id: 'variableControl',
174-
order: 2,
175-
label: 'variable control',
176-
testId: 'variableControlButton',
177-
},
178-
{
179-
run: () => action('time-slider-control-clicked'),
180-
id: 'timeSliderControl',
181-
order: 3,
182-
label: 'time slider control',
183-
testId: 'timeSliderControlButton',
184-
},
185-
{
186-
run: () => action('setting-clicked'),
187-
id: 'settings',
188-
order: 4,
189-
label: 'settings',
190-
testId: 'settingButton',
191-
separator: 'above',
192-
},
193-
],
194-
},
195-
{
196-
run: () => action('add-from-library-clicked'),
197-
id: 'fromLibrary',
198-
order: 5,
199-
label: 'From library',
200-
iconType: 'folderOpen',
201-
testId: 'addFromLibraryButton',
202-
},
203-
],
204-
},
205204
primaryActionItem: {
206205
run: action('save-clicked'),
207206
id: 'save',

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ export type {
1919
AppMenuRunActionParams,
2020
AppMenuConfig,
2121
AppMenuItemType,
22-
AppMenuSecondaryActionItem,
2322
AppMenuPrimaryActionItem,
2423
AppMenuPopoverItem,
2524
AppMenuSplitButtonProps,

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

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -89,43 +89,6 @@ describe('AppMenu', () => {
8989

9090
expect(screen.getByText('Save')).toBeInTheDocument();
9191
});
92-
93-
it('should render secondary action item', () => {
94-
const configWithSecondary: AppMenuConfig = {
95-
secondaryActionItem: {
96-
id: 'cancel',
97-
label: 'Cancel',
98-
run: jest.fn(),
99-
iconType: 'cross',
100-
},
101-
};
102-
103-
render(<AppMenuComponent config={configWithSecondary} />);
104-
105-
expect(screen.getByText('Cancel')).toBeInTheDocument();
106-
});
107-
108-
it('should render both primary and secondary action items', () => {
109-
const configWithBoth: AppMenuConfig = {
110-
primaryActionItem: {
111-
id: 'save',
112-
label: 'Save',
113-
run: jest.fn(),
114-
iconType: 'save',
115-
},
116-
secondaryActionItem: {
117-
id: 'cancel',
118-
label: 'Cancel',
119-
run: jest.fn(),
120-
iconType: 'cross',
121-
},
122-
};
123-
124-
render(<AppMenuComponent config={configWithBoth} />);
125-
126-
expect(screen.getByText('Save')).toBeInTheDocument();
127-
expect(screen.getByText('Cancel')).toBeInTheDocument();
128-
});
12992
});
13093

13194
describe('responsive behavior', () => {

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

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ export interface AppMenuItemsProps {
2626
isCollapsed?: boolean;
2727
}
2828

29-
const hasNoItems = (config: AppMenuConfig) =>
30-
!config.items?.length && !config?.primaryActionItem && !config?.secondaryActionItem;
29+
const hasNoItems = (config: AppMenuConfig) => !config.items?.length && !config?.primaryActionItem;
3130

3231
export const AppMenuComponent = ({
3332
config,
@@ -43,7 +42,6 @@ export const AppMenuComponent = ({
4342
}
4443

4544
const primaryActionItem = config?.primaryActionItem;
46-
const secondaryActionItem = config?.secondaryActionItem;
4745
const showMoreButtonId = 'show-more';
4846

4947
const headerLinksProps = {
@@ -76,22 +74,10 @@ export const AppMenuComponent = ({
7674
/>
7775
) : undefined;
7876

79-
const secondaryActionComponent = secondaryActionItem ? (
80-
<AppMenuActionButton
81-
{...secondaryActionItem}
82-
isPopoverOpen={openPopoverId === secondaryActionItem.id}
83-
onPopoverToggle={() => {
84-
handlePopoverToggle(secondaryActionItem.id);
85-
}}
86-
onPopoverClose={handleOnPopoverClose}
87-
/>
88-
) : undefined;
89-
9077
const collapsedComponent = (
9178
<AppMenuOverflowButton
9279
items={[...displayedItems, ...overflowItems]}
9380
isPopoverOpen={openPopoverId === showMoreButtonId}
94-
secondaryActionItem={secondaryActionItem}
9581
primaryActionItem={primaryActionItem}
9682
onPopoverToggle={() => handlePopoverToggle(showMoreButtonId)}
9783
onPopoverClose={handleOnPopoverClose}
@@ -111,7 +97,6 @@ export const AppMenuComponent = ({
11197
onPopoverToggle={() => handlePopoverToggle(showMoreButtonId)}
11298
onPopoverClose={handleOnPopoverClose}
11399
/>
114-
{secondaryActionComponent}
115100
{primaryActionComponent}
116101
</EuiHeaderLinks>
117102
);
@@ -138,7 +123,6 @@ export const AppMenuComponent = ({
138123
onPopoverClose={handleOnPopoverClose}
139124
/>
140125
)}
141-
{secondaryActionComponent}
142126
{primaryActionComponent}
143127
</EuiHeaderLinks>
144128
);

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

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -110,28 +110,6 @@ describe('AppMenuActionButton', () => {
110110
expect(defaultProps.run).not.toHaveBeenCalled();
111111
});
112112

113-
it('should toggle popover when button with items is clicked', async () => {
114-
const user = userEvent.setup();
115-
const secondaryActionProps = {
116-
label: 'options',
117-
id: 'optionsButton',
118-
iconType: 'gear',
119-
isPopoverOpen: false,
120-
onPopoverToggle: jest.fn(),
121-
onPopoverClose: jest.fn(),
122-
items: [
123-
{ id: 'item1', label: 'Item 1', run: jest.fn(), order: 1 },
124-
{ id: 'item2', label: 'Item 2', run: jest.fn(), order: 2 },
125-
],
126-
};
127-
128-
render(<AppMenuActionButton {...secondaryActionProps} testId="test-action-button" />);
129-
130-
await user.click(screen.getByTestId('test-action-button'));
131-
132-
expect(secondaryActionProps.onPopoverToggle).toHaveBeenCalledTimes(1);
133-
});
134-
135113
it('should toggle popover when split button with items is clicked', async () => {
136114
const user = userEvent.setup();
137115
const splitButtonPropsWithItems = {

0 commit comments

Comments
 (0)