Skip to content

Commit

Permalink
[NP] Remove absoluteToParsedUrl & KibanaParsedUrl ref in kibana app (e…
Browse files Browse the repository at this point in the history
…lastic#61105) (elastic#61762)

* Remove absoluteToParsedUrl reference in dashboard

* Remove KibanaParsedUrl from visualize

* Fix tests

* Add tests

* Fix saved dashboard

* Fix empty line after resolving conflicts

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
sulemanof and elasticmachine committed Mar 30, 2020
1 parent e2e2a30 commit e146ae0
Show file tree
Hide file tree
Showing 15 changed files with 217 additions and 291 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
*/

export { npSetup, npStart } from 'ui/new_platform';
export { absoluteToParsedUrl } from 'ui/url/absolute_to_parsed_url';
export {
configureAppAngularModule,
migrateLegacyQuery,
Expand Down

This file was deleted.

100 changes: 0 additions & 100 deletions src/legacy/core_plugins/kibana/public/dashboard/np_ready/url_helper.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export interface VisualizeKibanaServices {
core: CoreStart;
data: DataPublicPluginStart;
embeddable: EmbeddableStart;
getBasePath: () => string;
indexPatterns: IndexPatternsContract;
localStorage: Storage;
navigation: NavigationStart;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
* directly where they are needed.
*/

export { absoluteToParsedUrl } from 'ui/url/absolute_to_parsed_url';
export { KibanaParsedUrl } from 'ui/url/kibana_parsed_url';
export { wrapInI18nContext } from 'ui/i18n';
export { DashboardConstants } from '../dashboard/np_ready/dashboard_constants';
export {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ import { EventEmitter } from 'events';

import React from 'react';
import { FormattedMessage } from '@kbn/i18n/react';
import { makeStateful, useVisualizeAppState } from './lib';
import { makeStateful, useVisualizeAppState, addEmbeddableToDashboardUrl } from './lib';
import { VisualizeConstants } from '../visualize_constants';
import { getEditBreadcrumbs } from '../breadcrumbs';

import { addHelpMenuToAppChrome } from '../help_menu/help_menu_util';
import { unhashUrl, removeQueryParam } from '../../../../../../../plugins/kibana_utils/public';
import { MarkdownSimple, toMountPoint } from '../../../../../../../plugins/kibana_react/public';
import { addFatalError, kbnBaseUrl } from '../../../../../../../plugins/kibana_legacy/public';
import { addFatalError } from '../../../../../../../plugins/kibana_legacy/public';
import {
SavedObjectSaveModal,
showSaveModal,
Expand All @@ -46,14 +46,7 @@ import {

import { initVisEditorDirective } from './visualization_editor';
import { initVisualizationDirective } from './visualization';
import {
VISUALIZE_EMBEDDABLE_TYPE,
subscribeWithScope,
absoluteToParsedUrl,
KibanaParsedUrl,
migrateLegacyQuery,
DashboardConstants,
} from '../../legacy_imports';
import { subscribeWithScope, migrateLegacyQuery, DashboardConstants } from '../../legacy_imports';

import { getServices } from '../../kibana_services';

Expand All @@ -79,7 +72,6 @@ function VisualizeAppController($scope, $route, $injector, $timeout, kbnUrlState
data: { query: queryService },
toastNotifications,
chrome,
getBasePath,
core: { docLinks, fatalErrors },
savedQueryService,
uiSettings,
Expand Down Expand Up @@ -653,29 +645,14 @@ function VisualizeAppController($scope, $route, $injector, $timeout, kbnUrlState
});

if ($scope.isAddToDashMode()) {
const savedVisualizationParsedUrl = new KibanaParsedUrl({
basePath: getBasePath(),
appId: kbnBaseUrl.slice('/app/'.length),
appPath: `${VisualizeConstants.EDIT_PATH}/${encodeURIComponent(savedVis.id)}`,
});
const appPath = `${VisualizeConstants.EDIT_PATH}/${encodeURIComponent(savedVis.id)}`;
// Manually insert a new url so the back button will open the saved visualization.
history.replace(savedVisualizationParsedUrl.appPath);
setActiveUrl(savedVisualizationParsedUrl.appPath);
history.replace(appPath);
setActiveUrl(appPath);

const lastDashboardAbsoluteUrl = chrome.navLinks.get('kibana:dashboard').url;
const dashboardParsedUrl = absoluteToParsedUrl(
lastDashboardAbsoluteUrl,
getBasePath()
);
dashboardParsedUrl.addQueryParameter(
DashboardConstants.ADD_EMBEDDABLE_TYPE,
VISUALIZE_EMBEDDABLE_TYPE
);
dashboardParsedUrl.addQueryParameter(
DashboardConstants.ADD_EMBEDDABLE_ID,
savedVis.id
);
history.push(dashboardParsedUrl.appPath);
const lastDashboardUrl = chrome.navLinks.get('kibana:dashboard').url;
const dashboardUrl = addEmbeddableToDashboardUrl(lastDashboardUrl, savedVis.id);
history.push(dashboardUrl);
} else if (savedVis.id === $route.current.params.id) {
chrome.docTitle.change(savedVis.lastSavedTitle);
chrome.setBreadcrumbs($injector.invoke(getEditBreadcrumbs));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@

export { useVisualizeAppState } from './visualize_app_state';
export { makeStateful } from './make_stateful';
export { addEmbeddableToDashboardUrl } from './url_helper';
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* 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 { addEmbeddableToDashboardUrl } from './url_helper';

jest.mock('../../../legacy_imports', () => ({
DashboardConstants: {
ADD_EMBEDDABLE_ID: 'addEmbeddableId',
ADD_EMBEDDABLE_TYPE: 'addEmbeddableType',
CREATE_NEW_DASHBOARD_URL: '/dashboard',
},
VISUALIZE_EMBEDDABLE_TYPE: 'visualization',
}));

describe('', () => {
it('addEmbeddableToDashboardUrl when dashboard is not saved', () => {
const id = '123eb456cd';
const url =
"/pep/app/kibana#/dashboard?_g=(refreshInterval:(pause:!t,value:0),time:(from:now-15m,to:now))&_a=(description:'',filters:!())";
expect(addEmbeddableToDashboardUrl(url, id)).toEqual(
`/dashboard?_a=%28description%3A%27%27%2Cfilters%3A%21%28%29%29&_g=%28refreshInterval%3A%28pause%3A%21t%2Cvalue%3A0%29%2Ctime%3A%28from%3Anow-15m%2Cto%3Anow%29%29&addEmbeddableId=${id}&addEmbeddableType=visualization`
);
});
it('addEmbeddableToDashboardUrl when dashboard is saved', () => {
const id = '123eb456cd';
const url =
"/pep/app/kibana#/dashboard/9b780cd0-3dd3-11e8-b2b9-5d5dc1715159?_g=(refreshInterval:(pause:!t,value:0),time:(from:now-15m,to:now))&_a=(description:'',filters:!())";
expect(addEmbeddableToDashboardUrl(url, id)).toEqual(
`/dashboard/9b780cd0-3dd3-11e8-b2b9-5d5dc1715159?_a=%28description%3A%27%27%2Cfilters%3A%21%28%29%29&_g=%28refreshInterval%3A%28pause%3A%21t%2Cvalue%3A0%29%2Ctime%3A%28from%3Anow-15m%2Cto%3Anow%29%29&addEmbeddableId=${id}&addEmbeddableType=visualization`
);
});
});
Loading

0 comments on commit e146ae0

Please sign in to comment.