Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use embeddable registry in add panel #31400

Merged
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
658fd45
Prepare control flow to use embeddable factories in add panel
flash1293 Mar 4, 2019
d3b2759
Rewrite saved object finder and add tests
flash1293 Mar 4, 2019
501f38a
Fix usages of new saved object finder
flash1293 Mar 4, 2019
bcb630c
fix test failures
flash1293 Mar 5, 2019
7b2fee1
fix some functional tests and re-introduce makeUrl
flash1293 Mar 5, 2019
21736ae
fix tests
flash1293 Mar 5, 2019
0747c53
remove direct hrefs in saved_object_lists
flash1293 Mar 5, 2019
6acb88e
PR review fixes
flash1293 Mar 6, 2019
449f692
Merge remote-tracking branch 'upstream/master' into 27985/feature-emb…
flash1293 Mar 6, 2019
d024b52
update snapshot
flash1293 Mar 6, 2019
d8823cc
overwrite width of viz dialog
flash1293 Mar 6, 2019
b2b6a69
Merge remote-tracking branch 'upstream/master' into 27985/feature-emb…
flash1293 Mar 7, 2019
a4c2020
Update src/legacy/core_plugins/kibana/public/dashboard/top_nav/add_pa…
cchaos Mar 8, 2019
ad64368
Update src/legacy/core_plugins/kibana/public/discover/embeddable/sear…
cchaos Mar 8, 2019
e7fc388
Update src/legacy/core_plugins/kibana/public/discover/top_nav/open_se…
cchaos Mar 8, 2019
3dc0474
Update src/legacy/core_plugins/kibana/public/visualize/wizard/search_…
cchaos Mar 8, 2019
d9bd371
Update src/legacy/core_plugins/kibana/public/visualize/wizard/search_…
cchaos Mar 8, 2019
59f6a7e
Update src/legacy/core_plugins/kibana/public/visualize/wizard/search_…
cchaos Mar 8, 2019
f4934e5
fix tests
flash1293 Mar 8, 2019
b37ad87
review fixes #1
flash1293 Mar 8, 2019
d656671
review fixes #2
flash1293 Mar 8, 2019
df6dbf0
dont use classname in functional test
flash1293 Mar 8, 2019
bed5cba
remove call to action button prop
flash1293 Mar 8, 2019
360dac0
align buttons correctly
flash1293 Mar 8, 2019
0d1c865
fix tests
flash1293 Mar 8, 2019
09f39b6
remove debugging statement
flash1293 Mar 8, 2019
76a9bf0
Merge remote-tracking branch 'upstream/master' into 27985/feature-emb…
flash1293 Mar 8, 2019
0f0abbb
Update src/legacy/core_plugins/kibana/public/dashboard/top_nav/add_pa…
cchaos Mar 8, 2019
8a105ce
Update src/legacy/core_plugins/kibana/public/discover/top_nav/open_se…
cchaos Mar 8, 2019
4d35f31
Merge branch '27985/feature-embeddable-layer-add-panel' of github.com…
flash1293 Mar 8, 2019
6f7320e
review fixes #3
flash1293 Mar 8, 2019
b512467
improve filter behavior and enable it for search wizard
flash1293 Mar 8, 2019
c365aec
Merge remote-tracking branch 'upstream/master' into 27985/feature-emb…
flash1293 Mar 8, 2019
64a273e
adjust functional tests for new filter behavior
flash1293 Mar 8, 2019
1f49af1
Merge branch 'master' into pr/31400
timroes Mar 11, 2019
ac16449
Change translation id due to string change
timroes Mar 11, 2019
7ddce1d
Update Jest snapshot
timroes Mar 11, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ app.directive('dashboardApp', function ($injector) {
showNewVisModal(visTypes, { editorParams: [DashboardConstants.ADD_VISUALIZATION_TO_DASHBOARD_MODE_PARAM] });
};

showAddPanel(dashboardStateManager.addNewPanel, addNewVis, visTypes);
showAddPanel(dashboardStateManager.addNewPanel, addNewVis, embeddableFactories);
};
navActions[TopNavIds.OPTIONS] = (menuItem, navController, anchorElement) => {
showOptionsPopover({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,39 +23,16 @@ exports[`render 1`] = `
/>
</h1>
</EuiTitle>
<EuiTabs
expand={false}
size="m"
>
<EuiTab
data-test-subj="addVisualizationTab"
disabled={false}
isSelected={true}
key="vis"
onClick={[Function]}
>
Visualization
</EuiTab>
<EuiTab
data-test-subj="addSavedSearchTab"
disabled={false}
isSelected={false}
key="search"
onClick={[Function]}
>
Saved Search
</EuiTab>
</EuiTabs>
<EuiSpacer
size="s"
/>
<SavedObjectFinder
callToActionButton={
<EuiButton
<EuiButtonEmpty
color="primary"
data-test-subj="addNewSavedObjectLink"
fill={false}
iconSide="left"
iconType="plusInCircle"
onClick={[Function]}
type="button"
>
Expand All @@ -64,13 +41,12 @@ exports[`render 1`] = `
id="kbn.dashboard.topNav.addPanel.addNewVisualizationButtonLabel"
values={Object {}}
/>
</EuiButton>
</EuiButtonEmpty>
}
key="visSavedObjectFinder"
noItemsMessage="No matching visualizations found."
noItemsMessage="No matching objects found."
onChoose={[Function]}
savedObjectType="visualization"
visTypes={Object {}}
savedObjectMetaData={Array []}
showFilter={true}
/>
</EuiFlyoutBody>
</EuiFlyout>
Expand Down
163 changes: 46 additions & 117 deletions src/legacy/core_plugins/kibana/public/dashboard/top_nav/add_panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,109 +19,21 @@

import React from 'react';
import PropTypes from 'prop-types';
import { injectI18n, FormattedMessage } from '@kbn/i18n/react';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import { toastNotifications } from 'ui/notify';
import { SavedObjectFinder } from 'ui/saved_objects/components/saved_object_finder';

import {
EuiFlyout,
EuiFlyoutBody,
EuiButton,
EuiTabs,
EuiTab,
EuiButtonEmpty,
EuiSpacer,
EuiTitle,
} from '@elastic/eui';

const VIS_TAB_ID = 'vis';
const SAVED_SEARCH_TAB_ID = 'search';

class DashboardAddPanelUi extends React.Component {
constructor(props) {
super(props);

const addNewVisBtn = (
<EuiButton
onClick={this.props.addNewVis}
data-test-subj="addNewSavedObjectLink"
>
<FormattedMessage
id="kbn.dashboard.topNav.addPanel.addNewVisualizationButtonLabel"
defaultMessage="Add new Visualization"
/>
</EuiButton>
);

const tabs = [{
id: VIS_TAB_ID,
name: props.intl.formatMessage({
id: 'kbn.dashboard.topNav.addPanel.visualizationTabName',
defaultMessage: 'Visualization',
}),
dataTestSubj: 'addVisualizationTab',
toastDataTestSubj: 'addVisualizationToDashboardSuccess',
savedObjectFinder: (
<SavedObjectFinder
key="visSavedObjectFinder"
callToActionButton={addNewVisBtn}
onChoose={this.onAddPanel}
visTypes={this.props.visTypes}
noItemsMessage={props.intl.formatMessage({
id: 'kbn.dashboard.topNav.addPanel.visSavedObjectFinder.noMatchingVisualizationsMessage',
defaultMessage: 'No matching visualizations found.',
})}
savedObjectType="visualization"
/>
)
}, {
id: SAVED_SEARCH_TAB_ID,
name: props.intl.formatMessage({
id: 'kbn.dashboard.topNav.addPanel.savedSearchTabName',
defaultMessage: 'Saved Search',
}),
dataTestSubj: 'addSavedSearchTab',
toastDataTestSubj: 'addSavedSearchToDashboardSuccess',
savedObjectFinder: (
<SavedObjectFinder
key="searchSavedObjectFinder"
onChoose={this.onAddPanel}
noItemsMessage={props.intl.formatMessage({
id: 'kbn.dashboard.topNav.addPanel.searchSavedObjectFinder.noMatchingVisualizationsMessage',
defaultMessage: 'No matching saved searches found.',
})}
savedObjectType="search"
/>
)
}];

this.state = {
tabs: tabs,
selectedTab: tabs[0],
};
}

onSelectedTabChanged = tab => {
this.setState({
selectedTab: tab,
});
}

renderTabs() {
return this.state.tabs.map((tab) => {
return (
<EuiTab
onClick={() => this.onSelectedTabChanged(tab)}
isSelected={tab.id === this.state.selectedTab.id}
key={tab.id}
data-test-subj={tab.dataTestSubj}
>
{tab.name}
</EuiTab>
);
});
}

onAddPanel = (id, type) => {
export class DashboardAddPanel extends React.Component {
onAddPanel = (id, type, name) => {
this.props.addNewPanel(id, type);

// To avoid the clutter of having toast messages cover flyout
Expand All @@ -131,25 +43,37 @@ class DashboardAddPanelUi extends React.Component {
}

this.lastToast = toastNotifications.addSuccess({
title: this.props.intl.formatMessage({
id: 'kbn.dashboard.topNav.addPanel.selectedTabAddedToDashboardSuccessMessageTitle',
defaultMessage: '{selectedTabName} was added to your dashboard',
}, {
selectedTabName: this.state.selectedTab.name,
}),
'data-test-subj': this.state.selectedTab.toastDataTestSubj,
title: i18n.translate(
'kbn.dashboard.topNav.addPanel.savedObjectAddedToDashboardSuccessMessageTitle',
{
defaultMessage: '{savedObjectName} was added to your dashboard',
values: {
savedObjectName: name,
},
}
),
'data-test-subj': 'addObjectToDashboardSuccess',
});
}
};

render() {
return (
<EuiFlyout
ownFocus
onClose={this.props.onClose}
data-test-subj="dashboardAddPanel"
const addNewVisBtn = (
<EuiButtonEmpty
iconSide="left"
iconType="plusInCircle"
onClick={this.props.addNewVis}
data-test-subj="addNewSavedObjectLink"
>
<EuiFlyoutBody>
<FormattedMessage
id="kbn.dashboard.topNav.addPanel.addNewVisualizationButtonLabel"
defaultMessage="Add new Visualization"
flash1293 marked this conversation as resolved.
Show resolved Hide resolved
/>
</EuiButtonEmpty>
);

return (
<EuiFlyout ownFocus onClose={this.props.onClose} data-test-subj="dashboardAddPanel">
<EuiFlyoutBody>
<EuiTitle size="s">
flash1293 marked this conversation as resolved.
Show resolved Hide resolved
<h1>
<FormattedMessage
Expand All @@ -159,25 +83,30 @@ class DashboardAddPanelUi extends React.Component {
</h1>
</EuiTitle>

<EuiTabs>
{this.renderTabs()}
</EuiTabs>

<EuiSpacer size="s" />

{this.state.selectedTab.savedObjectFinder}

<SavedObjectFinder
onChoose={this.onAddPanel}
savedObjectMetaData={this.props.embeddableFactories
.filter(embeddableFactory => Boolean(embeddableFactory.savedObjectMetaData))
.map(({ savedObjectMetaData }) => savedObjectMetaData)}
showFilter={true}
callToActionButton={addNewVisBtn}
flash1293 marked this conversation as resolved.
Show resolved Hide resolved
noItemsMessage={i18n.translate(
'kbn.dashboard.topNav.addPanel.noMatchingObjectsMessage',
{
defaultMessage: 'No matching objects found.',
}
)}
/>
</EuiFlyoutBody>
</EuiFlyout>
);
}
}

DashboardAddPanelUi.propTypes = {
DashboardAddPanel.propTypes = {
onClose: PropTypes.func.isRequired,
visTypes: PropTypes.object.isRequired,
addNewPanel: PropTypes.func.isRequired,
addNewVis: PropTypes.func.isRequired,
};

export const DashboardAddPanel = injectI18n(DashboardAddPanelUi);
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import React from 'react';
import sinon from 'sinon';
import { shallowWithIntl } from 'test_utils/enzyme_helpers';
import { shallow } from 'enzyme';

import {
DashboardAddPanel,
Expand All @@ -38,11 +38,12 @@ beforeEach(() => {
});

test('render', () => {
const component = shallowWithIntl(<DashboardAddPanel.WrappedComponent
const component = shallow(<DashboardAddPanel
onClose={onClose}
visTypes={{}}
addNewPanel={() => {}}
addNewVis={() => {}}
embeddableFactories={[]}
/>);
expect(component).toMatchSnapshot();
});
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import ReactDOM from 'react-dom';

let isOpen = false;

export function showAddPanel(addNewPanel, addNewVis, visTypes) {
export function showAddPanel(addNewPanel, addNewVis, embeddableFactories) {
if (isOpen) {
return;
}
Expand All @@ -47,9 +47,9 @@ export function showAddPanel(addNewPanel, addNewVis, visTypes) {
<I18nContext>
<DashboardAddPanel
onClose={onClose}
visTypes={visTypes}
addNewPanel={addNewPanel}
addNewVis={addNewVisWithCleanup}
embeddableFactories={embeddableFactories}
/>
</I18nContext>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import 'ui/doc_table';

import { i18n } from '@kbn/i18n';
import { EmbeddableFactory } from 'ui/embeddable';
import {
EmbeddableInstanceConfiguration,
Expand All @@ -33,7 +34,17 @@ export class SearchEmbeddableFactory extends EmbeddableFactory {
private $rootScope: ng.IRootScopeService,
private searchLoader: SavedSearchLoader
) {
super({ name: 'search' });
super({
name: 'search',
savedObjectMetaData: {
name: i18n.translate('kbn.discover.savedSearch.savedObjectName', {
defaultMessage: 'Saved Search',
flash1293 marked this conversation as resolved.
Show resolved Hide resolved
}),
type: 'search',
getIconForSavedObject: () => 'search',
showSavedObject: () => true,
},
});
}

public getEditPath(panelId: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ exports[`render 1`] = `
/>
<SavedObjectFinder
callToActionButton={
<EuiButton
<EuiButtonEmpty
color="primary"
fill={false}
href="#/management/kibana/objects?_a=(tab:search)"
iconSide="left"
iconType="gear"
onClick={[Function]}
type="button"
>
Expand All @@ -41,9 +41,8 @@ exports[`render 1`] = `
id="kbn.discover.topNav.openSearchPanel.manageSearchesButtonLabel"
values={Object {}}
/>
</EuiButton>
</EuiButtonEmpty>
}
makeUrl={[Function]}
noItemsMessage={
<FormattedMessage
defaultMessage="No matching searches found."
Expand All @@ -52,7 +51,16 @@ exports[`render 1`] = `
/>
}
onChoose={[Function]}
savedObjectType="search"
savedObjectMetaData={
Array [
Object {
"getIconForSavedObject": [Function],
"name": "Search",
"showSavedObject": [Function],
"type": "search",
},
]
}
/>
</EuiFlyoutBody>
</EuiFlyout>
Expand Down
Loading