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

[6.x] Migrate reporting top nav to sharing context menu (#22596) #22949

Merged
merged 1 commit into from
Sep 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 7 additions & 9 deletions src/core_plugins/kibana/public/dashboard/dashboard_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import { showCloneModal } from './top_nav/show_clone_modal';
import { showSaveModal } from './top_nav/show_save_modal';
import { showAddPanel } from './top_nav/show_add_panel';
import { showOptionsPopover } from './top_nav/show_options_popover';
import { showShareContextMenu } from 'ui/share';
import { showShareContextMenu, ShareContextMenuExtensionsRegistryProvider } from 'ui/share';
import { migrateLegacyQuery } from 'ui/utils/migrateLegacyQuery';
import * as filterActions from 'ui/doc_table/actions/filter';
import { FilterManagerProvider } from 'ui/filter_manager';
Expand Down Expand Up @@ -86,6 +86,7 @@ app.directive('dashboardApp', function ($injector) {
const embeddableFactories = Private(EmbeddableFactoriesRegistryProvider);
const panelActionsRegistry = Private(ContextMenuActionsRegistryProvider);
const getUnhashableStates = Private(getUnhashableStatesProvider);
const shareContextMenuExtensions = Private(ShareContextMenuExtensionsRegistryProvider);

panelActionsStore.initializeFromRegistry(panelActionsRegistry);

Expand Down Expand Up @@ -133,14 +134,6 @@ app.directive('dashboardApp', function ($injector) {
dirty: !dash.id
};

this.getSharingTitle = () => {
return dash.title;
};

this.getSharingType = () => {
return 'dashboard';
};

dashboardStateManager.registerChangeListener(status => {
this.appStatus.dirty = status.dirty || !dash.id;
updateState();
Expand Down Expand Up @@ -409,6 +402,11 @@ app.directive('dashboardApp', function ($injector) {
getUnhashableStates,
objectId: dash.id,
objectType: 'dashboard',
shareContextMenuExtensions,
sharingData: {
title: dash.title,
},
isDirty: dashboardStateManager.getIsDirty(),
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,10 +470,10 @@ export class DashboardStateManager {
* @returns {boolean} True if the dashboard has changed since the last save (or, is new).
*/
getIsDirty(timeFilter) {
return this.isDirty ||
// Filter bar comparison is done manually (see cleanFiltersForComparison for the reason) and time picker
// changes are not tracked by the state monitor.
this.getFiltersChanged(timeFilter);
// Filter bar comparison is done manually (see cleanFiltersForComparison for the reason) and time picker
// changes are not tracked by the state monitor.
const hasTimeFilterChanged = timeFilter ? this.getFiltersChanged(timeFilter) : false;
return this.isDirty || hasTimeFilterChanged;
}

getPanels() {
Expand Down
27 changes: 14 additions & 13 deletions src/core_plugins/kibana/public/discover/controllers/discover.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import { recentlyAccessed } from 'ui/persisted_log';
import { getDocLink } from 'ui/documentation_links';
import '../components/fetch_error';
import { getPainlessError } from './get_painless_error';
import { showShareContextMenu } from 'ui/share';
import { showShareContextMenu, ShareContextMenuExtensionsRegistryProvider } from 'ui/share';
import { getUnhashableStatesProvider } from 'ui/state_management/state_hashing';
import { Inspector } from 'ui/inspector';
import { RequestAdapter } from 'ui/inspector/adapters';
Expand Down Expand Up @@ -162,6 +162,7 @@ function discoverController(
location: 'Discover'
});
const getUnhashableStates = Private(getUnhashableStatesProvider);
const shareContextMenuExtensions = Private(ShareContextMenuExtensionsRegistryProvider);
const inspectorAdapters = {
requests: new RequestAdapter()
};
Expand All @@ -179,6 +180,10 @@ function discoverController(
const savedSearch = $route.current.locals.savedSearch;
$scope.$on('$destroy', savedSearch.destroy);

const $appStatus = $scope.appStatus = this.appStatus = {
dirty: !savedSearch.id
};

$scope.topNavMenu = [{
key: 'new',
description: 'New Search',
Expand All @@ -198,13 +203,20 @@ function discoverController(
key: 'share',
description: 'Share Search',
testId: 'shareTopNavButton',
run: (menuItem, navController, anchorElement) => {
run: async (menuItem, navController, anchorElement) => {
const sharingData = await this.getSharingData();
showShareContextMenu({
anchorElement,
allowEmbed: false,
getUnhashableStates,
objectId: savedSearch.id,
objectType: 'search',
shareContextMenuExtensions,
sharingData: {
...sharingData,
title: savedSearch.title,
},
isDirty: $appStatus.dirty,
});
}
}, {
Expand Down Expand Up @@ -239,9 +251,6 @@ function discoverController(
docTitle.change(`Discover${pageTitleSuffix}`);

let stateMonitor;
const $appStatus = $scope.appStatus = this.appStatus = {
dirty: !savedSearch.id
};

const $state = $scope.state = new AppState(getStateDefaults());

Expand Down Expand Up @@ -306,14 +315,6 @@ function discoverController(
};
};

this.getSharingType = () => {
return 'search';
};

this.getSharingTitle = () => {
return savedSearch.title;
};

$scope.uiState = $state.makeStateful('uiState');

function getStateDefaults() {
Expand Down
1 change: 1 addition & 0 deletions src/core_plugins/kibana/public/kibana.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import 'uiExports/embeddableFactories';
import 'uiExports/inspectorViews';
import 'uiExports/search';
import 'uiExports/autocompleteProviders';
import 'uiExports/shareContextMenuExtensions';

import 'ui/autoload/all';
import './home';
Expand Down
26 changes: 13 additions & 13 deletions src/core_plugins/kibana/public/visualize/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import { migrateLegacyQuery } from 'ui/utils/migrateLegacyQuery';
import { recentlyAccessed } from 'ui/persisted_log';
import { timefilter } from 'ui/timefilter';
import { getVisualizeLoader } from '../../../../../ui/public/visualize/loader';
import { showShareContextMenu } from 'ui/share';
import { showShareContextMenu, ShareContextMenuExtensionsRegistryProvider } from 'ui/share';
import { getUnhashableStatesProvider } from 'ui/state_management/state_hashing';

uiRoutes
Expand Down Expand Up @@ -117,6 +117,7 @@ function VisEditor(
const docTitle = Private(DocTitleProvider);
const queryFilter = Private(FilterBarQueryFilterProvider);
const getUnhashableStates = Private(getUnhashableStatesProvider);
const shareContextMenuExtensions = Private(ShareContextMenuExtensionsRegistryProvider);

// Retrieve the resolved SavedVis instance.
const savedVis = $route.current.locals.savedVis;
Expand All @@ -138,6 +139,10 @@ function VisEditor(

$scope.vis = vis;

const $appStatus = this.appStatus = {
dirty: !savedVis.id
};

$scope.topNavMenu = [{
key: 'save',
description: 'Save Visualization',
Expand All @@ -156,12 +161,19 @@ function VisEditor(
description: 'Share Visualization',
testId: 'shareTopNavButton',
run: (menuItem, navController, anchorElement) => {
const hasUnappliedChanges = vis.dirty;
const hasUnsavedChanges = $appStatus.dirty;
showShareContextMenu({
anchorElement,
allowEmbed: true,
getUnhashableStates,
objectId: savedVis.id,
objectType: 'visualization',
shareContextMenuExtensions,
sharingData: {
title: savedVis.title,
},
isDirty: hasUnappliedChanges || hasUnsavedChanges,
});
}
}, {
Expand Down Expand Up @@ -190,18 +202,6 @@ function VisEditor(

let stateMonitor;

const $appStatus = this.appStatus = {
dirty: !savedVis.id
};

this.getSharingTitle = () => {
return savedVis.title;
};

this.getSharingType = () => {
return 'visualization';
};

if (savedVis.id) {
docTitle.change(savedVis.title);
}
Expand Down
1 change: 1 addition & 0 deletions src/ui/public/chrome/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ declare class Chrome {
public getBasePath(): string;
public getXsrfToken(): string;
public getKibanaVersion(): string;
public getUiSettingsClient(): any;
}

declare const chrome: Chrome;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

exports[`should only render permalink panel when there are no other panels 1`] = `
<EuiContextMenu
data-test-subj="shareContextMenu"
initialPanelId={1}
panels={
Array [
Object {
"content": <ShareUrlContent
"content": <UrlPanelContent
getUnhashableStates={[Function]}
objectType="dashboard"
/>,
Expand All @@ -20,19 +21,20 @@ exports[`should only render permalink panel when there are no other panels 1`] =

exports[`should render context menu panel when there are more than one panel 1`] = `
<EuiContextMenu
data-test-subj="shareContextMenu"
initialPanelId={3}
panels={
Array [
Object {
"content": <ShareUrlContent
"content": <UrlPanelContent
getUnhashableStates={[Function]}
objectType="dashboard"
/>,
"id": 1,
"title": "Permalink",
},
Object {
"content": <ShareUrlContent
"content": <UrlPanelContent
getUnhashableStates={[Function]}
isEmbedded={true}
objectType="dashboard"
Expand All @@ -44,11 +46,13 @@ exports[`should render context menu panel when there are more than one panel 1`]
"id": 3,
"items": Array [
Object {
"data-test-subj": "sharePanel-Embedcode",
"icon": "console",
"name": "Embed code",
"panel": 2,
},
Object {
"data-test-subj": "sharePanel-Permalinks",
"icon": "link",
"name": "Permalinks",
"panel": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`render 1`] = `
<EuiForm
className="shareUrlContentForm"
className="sharePanelContent"
data-test-subj="shareUrlForm"
>
<EuiFormRow
Expand Down Expand Up @@ -128,14 +128,15 @@ exports[`render 1`] = `
</EuiFormRow>
<EuiCopy
afterMessage="Copied"
anchorClassName="sharePanel__copyAnchor"
textToCopy="about:blank"
/>
</EuiForm>
`;

exports[`should enable saved object export option when objectId is provided 1`] = `
<EuiForm
className="shareUrlContentForm"
className="sharePanelContent"
data-test-subj="shareUrlForm"
>
<EuiFormRow
Expand Down Expand Up @@ -260,6 +261,7 @@ exports[`should enable saved object export option when objectId is provided 1`]
</EuiFormRow>
<EuiCopy
afterMessage="Copied"
anchorClassName="sharePanel__copyAnchor"
textToCopy="about:blank"
/>
</EuiForm>
Expand Down
Loading