Skip to content

Commit f4d0e3d

Browse files
authored
Silence URL restore errors for Discover & Dashboards (#242788)
Silences the annoying URL restoration error notifications for Discover and Dashboards
1 parent 3cdecbf commit f4d0e3d

File tree

9 files changed

+14
-20
lines changed

9 files changed

+14
-20
lines changed

src/platform/plugins/shared/dashboard/public/dashboard_app/dashboard_app.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import { DASHBOARD_APP_LOCATOR } from '@kbn/deeplinks-analytics';
1111
import { useExecutionContext } from '@kbn/kibana-react-plugin/public';
12-
import { createKbnUrlStateStorage, withNotifyOnErrors } from '@kbn/kibana-utils-plugin/public';
12+
import { createKbnUrlStateStorage } from '@kbn/kibana-utils-plugin/public';
1313
import type { ViewMode } from '@kbn/presentation-publishing';
1414
import type { History } from 'history';
1515
import React, { useCallback, useEffect, useMemo, useState } from 'react';
@@ -117,7 +117,6 @@ export function DashboardApp({
117117
createKbnUrlStateStorage({
118118
history,
119119
useHash: coreServices.uiSettings.get('state:storeInSessionStorage'),
120-
...withNotifyOnErrors(coreServices.notifications.toasts),
121120
}),
122121
[history]
123122
);

src/platform/plugins/shared/dashboard/public/dashboard_app/dashboard_router.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
import type { AppMountParameters, CoreStart } from '@kbn/core/public';
11-
import { createKbnUrlStateStorage, withNotifyOnErrors } from '@kbn/kibana-utils-plugin/public';
11+
import { createKbnUrlStateStorage } from '@kbn/kibana-utils-plugin/public';
1212
import { KibanaRenderContextProvider } from '@kbn/react-kibana-context-render';
1313
import { Route, Routes } from '@kbn/shared-ux-router';
1414
import type { ParsedQuery } from 'query-string';
@@ -61,7 +61,6 @@ export async function mountApp({
6161
createKbnUrlStateStorage({
6262
history,
6363
useHash: coreServices.uiSettings.get('state:storeInSessionStorage'),
64-
...withNotifyOnErrors(coreServices.notifications.toasts),
6564
});
6665

6766
const redirect = (redirectTo: RedirectToProps) => {

src/platform/plugins/shared/discover/public/__mocks__/discover_state.mock.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
} from '../application/main/state_management/redux';
2424
import type { DiscoverServices, HistoryLocationState } from '../build_services';
2525
import type { IKbnUrlStateStorage } from '@kbn/kibana-utils-plugin/public';
26-
import { createKbnUrlStateStorage, withNotifyOnErrors } from '@kbn/kibana-utils-plugin/public';
26+
import { createKbnUrlStateStorage } from '@kbn/kibana-utils-plugin/public';
2727
import type { History } from 'history';
2828
import {
2929
getConnectedCustomizationService,
@@ -62,7 +62,7 @@ function createInternalStateStoreMock({
6262
useHash: storeInSessionStorage,
6363
history: services.history,
6464
useHashQuery: customizationContext.displayMode !== 'embedded',
65-
...(toasts && withNotifyOnErrors(toasts)),
65+
...toasts,
6666
});
6767
runtimeStateManager ??= createRuntimeStateManager();
6868
const tabsStorageManager = createTabsStorageManager({

src/platform/plugins/shared/discover/public/application/context/services/context_state.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import {
1717
createStateContainer,
1818
createKbnUrlStateStorage,
1919
syncStates,
20-
withNotifyOnErrors,
2120
} from '@kbn/kibana-utils-plugin/public';
2221

2322
import type { DataPublicPluginStart, FilterManager } from '@kbn/data-plugin/public';
@@ -155,7 +154,7 @@ export function getState({
155154
const stateStorage = createKbnUrlStateStorage({
156155
useHash: storeInSessionStorage,
157156
history,
158-
...(toasts && withNotifyOnErrors(toasts)),
157+
...toasts,
159158
});
160159

161160
const globalStateFromUrl = stateStorage.get<GlobalState>(GLOBAL_STATE_URL_KEY) as GlobalState;

src/platform/plugins/shared/discover/public/application/main/discover_main_route.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import { useHistory, useParams } from 'react-router-dom';
1111
import type { IKbnUrlStateStorage } from '@kbn/kibana-utils-plugin/public';
12-
import { createKbnUrlStateStorage, withNotifyOnErrors } from '@kbn/kibana-utils-plugin/public';
12+
import { createKbnUrlStateStorage } from '@kbn/kibana-utils-plugin/public';
1313
import { useEffect, useState } from 'react';
1414
import React from 'react';
1515
import useUnmount from 'react-use/lib/useUnmount';
@@ -74,7 +74,6 @@ export const DiscoverMainRoute = ({
7474
useHash: services.uiSettings.get('state:storeInSessionStorage'),
7575
history,
7676
useHashQuery: customizationContext.displayMode !== 'embedded',
77-
...withNotifyOnErrors(services.core.notifications.toasts),
7877
})
7978
);
8079
const { internalState, runtimeStateManager, searchSessionManager } = useStateManagers({

src/platform/plugins/shared/discover/public/application/main/state_management/discover_app_state_container.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import { createSearchSourceMock } from '@kbn/data-plugin/public/mocks';
1111
import { dataViewMock } from '@kbn/discover-utils/src/__mocks__';
1212
import type { IKbnUrlStateStorage } from '@kbn/kibana-utils-plugin/public';
13-
import { createKbnUrlStateStorage, withNotifyOnErrors } from '@kbn/kibana-utils-plugin/public';
13+
import { createKbnUrlStateStorage } from '@kbn/kibana-utils-plugin/public';
1414
import type { Filter } from '@kbn/es-query';
1515
import type { History } from 'history';
1616
import { discoverServiceMock } from '../../../__mocks__/services';
@@ -47,7 +47,7 @@ describe('Test discover app state container', () => {
4747
stateStorage = createKbnUrlStateStorage({
4848
useHash: storeInSessionStorage,
4949
history,
50-
...(toasts && withNotifyOnErrors(toasts)),
50+
...toasts,
5151
});
5252
tabsStorageManager = createTabsStorageManager({
5353
urlStateStorage: stateStorage,

src/platform/plugins/shared/kibana_utils/public/state_management/url/kbn_url_tracker.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ describe('kbnUrlTracker', () => {
123123
expect(getActiveNavLinkUrl()).toEqual('#/start/deep/path/3?unhashed');
124124
});
125125

126-
test('show warning and use hashed url if unhashing does not work', () => {
126+
test('warn in console and use hashed url if unhashing does not work', () => {
127+
const consoleWarnSpy = jest.spyOn(console, 'warn');
127128
(unhashUrl as jest.Mock).mockImplementation(() => {
128129
throw new Error('unhash broke');
129130
});
@@ -132,7 +133,8 @@ describe('kbnUrlTracker', () => {
132133
history.push('#/start/deep/path/2');
133134
urlTracker.appUnMounted();
134135
expect(getActiveNavLinkUrl()).toEqual('#/start/deep/path/2');
135-
expect(toastService.addDanger).toHaveBeenCalledWith('unhash broke');
136+
137+
expect(consoleWarnSpy).toHaveBeenCalledWith('unhash broke');
136138
});
137139

138140
test('change nav link back to default if app gets mounted again', () => {

src/platform/plugins/shared/kibana_utils/public/state_management/url/kbn_url_tracker.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ export function createKbnUrlTracker({
158158
try {
159159
urlWithStates = unhashUrl(urlWithHashes);
160160
} catch (e) {
161-
toastNotifications.addDanger(e.message);
161+
// eslint-disable-next-line no-console
162+
console.warn(e.message);
162163
}
163164

164165
previousActiveUrl = activeUrl;

src/platform/test/functional/apps/discover/group5/_shared_links.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
143143
await browser.get(currentUrl, false);
144144
const resolvedUrl = await browser.getCurrentUrl();
145145
expect(resolvedUrl).to.match(/discover/);
146-
const { title } = await toasts.getErrorByIndex(1, true);
147-
expect(title).to.contain(
148-
'Unable to completely restore the URL, be sure to use the share functionality.'
149-
);
150146
});
151-
await toasts.dismissAll();
152147
});
153148
});
154149
});

0 commit comments

Comments
 (0)