-
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.
[Add panel flyout] Moving create new to the top of SavedObjectFinder (#…
…56428) * [Add panel flyout] Moving create new to the top of SavedObjectFinder * [Add panel flyout] Moving create new to the top of SavedObjectFinder * Fixing failing unit test * Readd missing test * [NP] Move saved object modal into new platform (#56383) * Move saved object modal into new platform * Fix TS * Revert "Fix TS" This reverts commit f2f9f5e. * Revert "Move saved object modal into new platform" This reverts commit d0f0ea6. # Conflicts: # src/legacy/core_plugins/kibana/public/discover/np_ready/angular/discover.js * Move save_object_save_modal * Move show_saved_object_save_modal.tsx * Move save_object_finder.tsx * Remove unused export * Pass I18nContext to showSaveModal * Update i18n ids * Fix map save * Refactoring * Load styles * Revert importing styles * Update snapshot * Update snapshot * Structural refactoring * Fix path Co-authored-by: Elastic Machine <[email protected]> * Applying PR comments Removing faulty rebase imports Fixing unresolved conflict Removing faulty merge files Removing faulty import Readd accidentally added file * Removing unnecessary eslint-ignore Co-authored-by: Maryia Lapata <[email protected]> Co-authored-by: Elastic Machine <[email protected]>
- Loading branch information
1 parent
696e46a
commit eab522d
Showing
6 changed files
with
201 additions
and
44 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
62 changes: 62 additions & 0 deletions
62
.../public/lib/panel/panel_header/panel_actions/add_panel/saved_object_finder_create_new.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,62 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
import React, { ReactElement, useState } from 'react'; | ||
import { EuiButton } from '@elastic/eui'; | ||
import { EuiContextMenuPanel } from '@elastic/eui'; | ||
import { EuiPopover } from '@elastic/eui'; | ||
import { FormattedMessage } from '@kbn/i18n/react'; | ||
|
||
interface Props { | ||
menuItems: ReactElement[]; | ||
} | ||
|
||
export function SavedObjectFinderCreateNew({ menuItems }: Props) { | ||
const [isCreateMenuOpen, setCreateMenuOpen] = useState(false); | ||
const toggleCreateMenu = () => { | ||
setCreateMenuOpen(!isCreateMenuOpen); | ||
}; | ||
const closeCreateMenu = () => { | ||
setCreateMenuOpen(false); | ||
}; | ||
return ( | ||
<EuiPopover | ||
id="createNew" | ||
button={ | ||
<EuiButton | ||
data-test-subj="createNew" | ||
iconType="arrowDown" | ||
iconSide="right" | ||
onClick={toggleCreateMenu} | ||
fill | ||
> | ||
<FormattedMessage | ||
id="embeddableApi.addPanel.createNewDefaultOption" | ||
defaultMessage="Create new" | ||
/> | ||
</EuiButton> | ||
} | ||
isOpen={isCreateMenuOpen} | ||
closePopover={closeCreateMenu} | ||
panelPaddingSize="none" | ||
anchorPosition="downRight" | ||
> | ||
<EuiContextMenuPanel items={menuItems} /> | ||
</EuiPopover> | ||
); | ||
} |
91 changes: 91 additions & 0 deletions
91
.../panel/panel_header/panel_actions/add_panel/tests/saved_object_finder_create_new.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,91 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
import React from 'react'; | ||
import { SavedObjectFinderCreateNew } from '../saved_object_finder_create_new'; | ||
import { shallow } from 'enzyme'; | ||
import { EuiButton, EuiContextMenuItem, EuiContextMenuPanel, EuiPopover } from '@elastic/eui'; | ||
import { mountWithIntl } from 'test_utils/enzyme_helpers'; | ||
|
||
describe('SavedObjectFinderCreateNew', () => { | ||
test('renders correctly with no items', () => { | ||
const wrapper = shallow(<SavedObjectFinderCreateNew menuItems={[]} />); | ||
expect(wrapper.find(EuiPopover).length).toEqual(1); | ||
const menuPanel = wrapper.find(EuiContextMenuPanel); | ||
expect(menuPanel.length).toEqual(1); | ||
const panelItems = menuPanel.prop('items'); | ||
if (panelItems) { | ||
expect(panelItems.length).toEqual(0); | ||
} else { | ||
fail('Expect paneltems to be defined'); | ||
} | ||
}); | ||
|
||
test('renders correctly with items', () => { | ||
const items = []; | ||
const onClick = jest.fn(); | ||
for (let i = 0; i < 3; i++) { | ||
items.push( | ||
<EuiContextMenuItem | ||
key={i + 1} | ||
data-test-subj={`item${i + 1}`} | ||
onClick={onClick} | ||
>{`item${i + 1}`}</EuiContextMenuItem> | ||
); | ||
} | ||
|
||
const wrapper = shallow(<SavedObjectFinderCreateNew menuItems={items} />); | ||
expect(wrapper.find(EuiPopover).length).toEqual(1); | ||
const menuPanel = wrapper.find(EuiContextMenuPanel); | ||
expect(menuPanel.length).toEqual(1); | ||
const paneltems = menuPanel.prop('items'); | ||
if (paneltems) { | ||
expect(paneltems.length).toEqual(3); | ||
expect(paneltems[0].key).toEqual('1'); | ||
expect(paneltems[1].key).toEqual('2'); | ||
expect(paneltems[2].key).toEqual('3'); | ||
} else { | ||
fail('Expect paneltems to be defined'); | ||
} | ||
}); | ||
|
||
test('clicking the button opens/closes the popover', () => { | ||
const items = []; | ||
const onClick = jest.fn(); | ||
for (let i = 0; i < 3; i++) { | ||
items.push( | ||
<EuiContextMenuItem | ||
key={i + 1} | ||
data-test-subj={`item${i + 1}`} | ||
onClick={onClick} | ||
>{`item${i + 1}`}</EuiContextMenuItem> | ||
); | ||
} | ||
|
||
const component = mountWithIntl(<SavedObjectFinderCreateNew menuItems={items} />); | ||
let popover = component.find(EuiPopover); | ||
expect(popover.prop('isOpen')).toBe(false); | ||
const button = component.find(EuiButton); | ||
button.simulate('click'); | ||
popover = component.find(EuiPopover); | ||
expect(popover.prop('isOpen')).toBe(true); | ||
button.simulate('click'); | ||
popover = component.find(EuiPopover); | ||
expect(popover.prop('isOpen')).toBe(false); | ||
}); | ||
}); |
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