-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Embeddable Rebuild] Support grouping in ADD_PANEL_TRIGGER (#179872)
## Summary Resolves #179565 Adds support for the `grouping` property in actions assigned to the `ADD_PANEL_TRIGGER` trigger. In the "Add panel" context menu, groups from the embeddable factories and `ADD_PANEL_TRIGGER` actions are merged, allowing us to group legacy embeddables with the react ones. ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios
- Loading branch information
Showing
4 changed files
with
376 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
148 changes: 148 additions & 0 deletions
148
src/plugins/dashboard/public/dashboard_app/top_nav/editor_menu.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { EmbeddableFactory } from '@kbn/embeddable-plugin/public'; | ||
import { PresentationContainer } from '@kbn/presentation-containers'; | ||
import { GroupedAddPanelActions } from './add_panel_action_menu_items'; | ||
import { | ||
FactoryGroup, | ||
mergeGroupedItemsProvider, | ||
getEmbeddableFactoryMenuItemProvider, | ||
} from './editor_menu'; | ||
|
||
describe('mergeGroupedItemsProvider', () => { | ||
const mockApi = { addNewPanel: jest.fn() } as unknown as jest.Mocked<PresentationContainer>; | ||
const closePopoverSpy = jest.fn(); | ||
|
||
const getEmbeddableFactoryMenuItem = getEmbeddableFactoryMenuItemProvider( | ||
mockApi, | ||
closePopoverSpy | ||
); | ||
|
||
const mockFactory = { | ||
id: 'factory1', | ||
type: 'mockFactory', | ||
getDisplayName: () => 'Factory 1', | ||
getDescription: () => 'Factory 1 description', | ||
getIconType: () => 'icon1', | ||
} as unknown as EmbeddableFactory; | ||
|
||
const factoryGroupMap = { | ||
group1: { | ||
panelId: 'panel1', | ||
appName: 'App 1', | ||
icon: 'icon1', | ||
factories: [mockFactory], | ||
}, | ||
} as unknown as Record<string, FactoryGroup>; | ||
|
||
const groupedAddPanelAction = { | ||
group1: { | ||
id: 'panel2', | ||
title: 'Panel 2', | ||
icon: 'icon2', | ||
items: [ | ||
{ | ||
id: 'addPanelActionId', | ||
}, | ||
], | ||
}, | ||
} as unknown as Record<string, GroupedAddPanelActions>; | ||
|
||
it('should merge factoryGroupMap and groupedAddPanelAction correctly', () => { | ||
const [initialPanelGroups, additionalPanels] = mergeGroupedItemsProvider( | ||
getEmbeddableFactoryMenuItem | ||
)(factoryGroupMap, groupedAddPanelAction); | ||
|
||
expect(initialPanelGroups).toEqual([ | ||
{ | ||
'data-test-subj': 'dashboardEditorMenu-group1Group', | ||
name: 'App 1', | ||
icon: 'icon1', | ||
panel: 'panel1', | ||
}, | ||
]); | ||
|
||
expect(additionalPanels).toEqual([ | ||
{ | ||
id: 'panel1', | ||
title: 'App 1', | ||
items: [ | ||
{ | ||
icon: 'icon1', | ||
name: 'Factory 1', | ||
toolTipContent: 'Factory 1 description', | ||
'data-test-subj': 'createNew-mockFactory', | ||
onClick: expect.any(Function), | ||
}, | ||
{ | ||
id: 'addPanelActionId', | ||
}, | ||
], | ||
}, | ||
]); | ||
}); | ||
|
||
it('should handle missing factoryGroup correctly', () => { | ||
const [initialPanelGroups, additionalPanels] = mergeGroupedItemsProvider( | ||
getEmbeddableFactoryMenuItem | ||
)({}, groupedAddPanelAction); | ||
|
||
expect(initialPanelGroups).toEqual([ | ||
{ | ||
'data-test-subj': 'dashboardEditorMenu-group1Group', | ||
name: 'Panel 2', | ||
icon: 'icon2', | ||
panel: 'panel2', | ||
}, | ||
]); | ||
|
||
expect(additionalPanels).toEqual([ | ||
{ | ||
id: 'panel2', | ||
title: 'Panel 2', | ||
items: [ | ||
{ | ||
id: 'addPanelActionId', | ||
}, | ||
], | ||
}, | ||
]); | ||
}); | ||
|
||
it('should handle missing groupedAddPanelAction correctly', () => { | ||
const [initialPanelGroups, additionalPanels] = mergeGroupedItemsProvider( | ||
getEmbeddableFactoryMenuItem | ||
)(factoryGroupMap, {}); | ||
|
||
expect(initialPanelGroups).toEqual([ | ||
{ | ||
'data-test-subj': 'dashboardEditorMenu-group1Group', | ||
name: 'App 1', | ||
icon: 'icon1', | ||
panel: 'panel1', | ||
}, | ||
]); | ||
|
||
expect(additionalPanels).toEqual([ | ||
{ | ||
id: 'panel1', | ||
title: 'App 1', | ||
items: [ | ||
{ | ||
icon: 'icon1', | ||
name: 'Factory 1', | ||
toolTipContent: 'Factory 1 description', | ||
'data-test-subj': 'createNew-mockFactory', | ||
onClick: expect.any(Function), | ||
}, | ||
], | ||
}, | ||
]); | ||
}); | ||
}); |
Oops, something went wrong.