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

[NP] Move src/legacy/ui/public/notify/app_redirect to kibana_legacy #58127

Merged
merged 7 commits into from
Feb 25, 2020
6 changes: 4 additions & 2 deletions src/legacy/core_plugins/kibana/public/kibana.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import './management';
import './dev_tools';
import 'ui/agg_response';
import 'ui/agg_types';
import { showAppRedirectNotification } from 'ui/notify';
import { showAppRedirectNotification } from '../../../../plugins/kibana_legacy/public';
import 'leaflet';
import { localApplicationService } from './local_application_service';

Expand All @@ -68,4 +68,6 @@ routes.otherwise({
redirectTo: `/${config.defaultAppId || 'discover'}`,
});

uiModules.get('kibana').run(showAppRedirectNotification);
uiModules
.get('kibana')
.run($location => showAppRedirectNotification($location, npSetup.core.notifications.toasts));
1 change: 0 additions & 1 deletion src/legacy/ui/public/notify/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@

export { fatalError, addFatalErrorCallback } from './fatal_error';
export { toastNotifications } from './toasts';
export { addAppRedirectMessageToUrl, showAppRedirectNotification } from './app_redirect';
export { banners } from './banners';
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,12 @@
* under the License.
*/

import { ILocationService } from 'angular';
import { ToastsStart } from '../../../../../core/public';
import { addAppRedirectMessageToUrl, showAppRedirectNotification } from './app_redirect';

let isToastAdded = false;

jest.mock('../toasts', () => ({
toastNotifications: {
addDanger: () => {
isToastAdded = true;
},
},
}));
const toasts: ToastsStart = {} as ToastsStart;

describe('addAppRedirectMessageToUrl', () => {
test('adds a message to the URL', () => {
Expand All @@ -39,20 +34,29 @@ describe('addAppRedirectMessageToUrl', () => {
describe('showAppRedirectNotification', () => {
beforeEach(() => {
isToastAdded = false;
toasts.addDanger = (): any => {
isToastAdded = true;
};
});

test(`adds a toast when there's a message in the URL`, () => {
showAppRedirectNotification({
search: () => ({ app_redirect_message: 'redirect message' }),
});
showAppRedirectNotification(
{
search: () => ({ app_redirect_message: 'redirect message' }),
} as ILocationService,
toasts
);

expect(isToastAdded).toBe(true);
});

test(`doesn't add a toast when there's no message in the URL`, () => {
showAppRedirectNotification({
search: () => ({ app_redirect_message: '' }),
});
showAppRedirectNotification(
{
search: () => ({ app_redirect_message: '' }),
} as ILocationService,
toasts
);

expect(isToastAdded).toBe(false);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
* under the License.
*/

import { ILocationService } from 'angular';
import { modifyUrl } from '../../../../../core/utils';
import { toastNotifications } from '../toasts';
import { ToastsStart } from '../../../../../core/public';

const APP_REDIRECT_MESSAGE_PARAM = 'app_redirect_message';

export function addAppRedirectMessageToUrl(url, message) {
export function addAppRedirectMessageToUrl(url: string, message: string) {
return modifyUrl(url, urlParts => {
urlParts.hash = modifyUrl(urlParts.hash || '', hashParts => {
hashParts.query[APP_REDIRECT_MESSAGE_PARAM] = message;
Expand All @@ -32,7 +33,7 @@ export function addAppRedirectMessageToUrl(url, message) {

// If an app needs to redirect, e.g. due to an expired license, it can surface a message via
// the URL query params.
export function showAppRedirectNotification($location) {
export function showAppRedirectNotification($location: ILocationService, toasts: ToastsStart) {
const queryString = $location.search();

if (!queryString[APP_REDIRECT_MESSAGE_PARAM]) {
Expand All @@ -42,5 +43,5 @@ export function showAppRedirectNotification($location) {
const message = queryString[APP_REDIRECT_MESSAGE_PARAM];
$location.search(APP_REDIRECT_MESSAGE_PARAM, null);

toastNotifications.addDanger(message);
toasts.addDanger(message);
}
1 change: 1 addition & 0 deletions src/plugins/kibana_legacy/public/notify/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@
*/
export * from './toasts';
export * from './lib';
export { addAppRedirectMessageToUrl, showAppRedirectNotification } from './app_redirect';
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import 'plugins/kibana/dashboard/legacy';
import { npStart } from 'ui/new_platform';
import { localApplicationService } from 'plugins/kibana/local_application_service';

import { showAppRedirectNotification } from 'ui/notify';
import { showAppRedirectNotification } from '../../../../../src/plugins/kibana_legacy/public';
import { DashboardConstants, createDashboardEditUrl } from 'plugins/kibana/dashboard';

npStart.plugins.kibanaLegacy.dashboardConfig.turnHideWriteControlsOn();
Expand All @@ -51,7 +51,9 @@ chrome.setRootController('kibana', function() {
npStart.core.chrome.navLinks.showOnly('kibana:dashboard');
});

uiModules.get('kibana').run(showAppRedirectNotification);
uiModules
.get('kibana')
.run($location => showAppRedirectNotification($location, npStart.core.notifications.toasts));

/**
* If there is a configured `kibana.defaultAppId`, and it is a dashboard ID, we'll
Expand Down
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/graph/public/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
configureAppAngularModule,
createTopNavDirective,
createTopNavHelper,
addAppRedirectMessageToUrl,
} from './legacy_imports';
// @ts-ignore
import { initGraphApp } from './app';
Expand All @@ -37,6 +36,7 @@ import { checkLicense } from '../../../../plugins/graph/common/check_license';
import { NavigationPublicPluginStart as NavigationStart } from '../../../../../src/plugins/navigation/public';
import { createSavedWorkspacesLoader } from './services/persistence/saved_workspace_loader';
import { Storage } from '../../../../../src/plugins/kibana_utils/public';
import { addAppRedirectMessageToUrl } from '../../../../../src/plugins/kibana_legacy/public';

/**
* These are dependencies of the Graph app besides the base dependencies
Expand Down
2 changes: 0 additions & 2 deletions x-pack/legacy/plugins/graph/public/legacy_imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@ import 'ace';

// @ts-ignore
export { createTopNavDirective, createTopNavHelper } from 'ui/kbn_top_nav/kbn_top_nav';
// @ts-ignore
export { addAppRedirectMessageToUrl } from 'ui/notify';
export { configureAppAngularModule } from '../../../../../src/plugins/kibana_legacy/public';