Skip to content

Commit

Permalink
Fix "Notifications is not set" errors. (#60473) (#60549)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeelmers committed Mar 18, 2020
1 parent 969c5de commit e207703
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 15 deletions.
18 changes: 11 additions & 7 deletions src/legacy/ui/public/new_platform/new_platform.karma_mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ import sinon from 'sinon';
import { getFieldFormatsRegistry } from '../../../../test_utils/public/stub_field_formats';
import { METRIC_TYPE } from '@kbn/analytics';
import {
setFieldFormats,
setIndexPatterns,
setQueryService,
setUiSettings,
setInjectedMetadata,
setFieldFormats,
setSearchService,
setHttp,
setNotifications,
setOverlays,
setQueryService,
setSearchService,
setUiSettings,
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
} from '../../../../plugins/data/public/services';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
Expand Down Expand Up @@ -477,11 +479,13 @@ export function __start__(coreStart) {

// Services that need to be set in the legacy platform since the legacy data plugin
// which previously provided them has been removed.
setHttp(npStart.core.http);
setNotifications(npStart.core.notifications);
setOverlays(npStart.core.overlays);
setUiSettings(npStart.core.uiSettings);
setQueryService(npStart.plugins.data.query);
setIndexPatterns(npStart.plugins.data.indexPatterns);
setFieldFormats(npStart.plugins.data.fieldFormats);
setIndexPatterns(npStart.plugins.data.indexPatterns);
setQueryService(npStart.plugins.data.query);
setSearchService(npStart.plugins.data.search);
setAggs(npStart.plugins.data.search.aggs);
setOverlays(npStart.core.overlays);
}
34 changes: 33 additions & 1 deletion src/legacy/ui/public/new_platform/new_platform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,19 @@
jest.mock('history');

import { setRootControllerMock, historyMock } from './new_platform.test.mocks';
import { legacyAppRegister, __reset__, __setup__ } from './new_platform';
import {
legacyAppRegister,
__reset__,
__setup__,
__start__,
PluginsSetup,
PluginsStart,
} from './new_platform';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import * as dataServices from '../../../../plugins/data/public/services';
import { LegacyCoreSetup, LegacyCoreStart } from '../../../../core/public';
import { coreMock } from '../../../../core/public/mocks';
import { npSetup, npStart } from './__mocks__';

describe('ui/new_platform', () => {
describe('legacyAppRegister', () => {
Expand Down Expand Up @@ -108,4 +119,25 @@ describe('ui/new_platform', () => {
expect(unmountMock).toHaveBeenCalled();
});
});

describe('service getters', () => {
const services: Record<string, Function> = dataServices;
const getters = Object.keys(services).filter(k => k.substring(0, 3) === 'get');

getters.forEach(g => {
it(`sets a value for ${g}`, () => {
__reset__();
__setup__(
(coreMock.createSetup() as unknown) as LegacyCoreSetup,
(npSetup.plugins as unknown) as PluginsSetup
);
__start__(
(coreMock.createStart() as unknown) as LegacyCoreStart,
(npStart.plugins as unknown) as PluginsStart
);

expect(services[g]()).toBeDefined();
});
});
});
});
18 changes: 11 additions & 7 deletions src/legacy/ui/public/new_platform/new_platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ import {
} from '../../../../core/public';
import { Plugin as DataPlugin } from '../../../../plugins/data/public';
import {
setFieldFormats,
setIndexPatterns,
setQueryService,
setUiSettings,
setInjectedMetadata,
setFieldFormats,
setSearchService,
setHttp,
setNotifications,
setOverlays,
setQueryService,
setSearchService,
setUiSettings,
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
} from '../../../../plugins/data/public/services';
import { Plugin as ExpressionsPlugin } from '../../../../plugins/expressions/public';
Expand Down Expand Up @@ -141,12 +143,14 @@ export function __start__(coreStart: LegacyCoreStart, plugins: PluginsStart) {

// Services that need to be set in the legacy platform since the legacy data plugin
// which previously provided them has been removed.
setHttp(npStart.core.http);
setNotifications(npStart.core.notifications);
setOverlays(npStart.core.overlays);
setUiSettings(npStart.core.uiSettings);
setQueryService(npStart.plugins.data.query);
setIndexPatterns(npStart.plugins.data.indexPatterns);
setFieldFormats(npStart.plugins.data.fieldFormats);
setIndexPatterns(npStart.plugins.data.indexPatterns);
setQueryService(npStart.plugins.data.query);
setSearchService(npStart.plugins.data.search);
setOverlays(npStart.core.overlays);
}

/** Flag used to ensure `legacyAppRegister` is only called once. */
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/data/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { createIndexPatternSelect } from './ui/index_pattern_select';
import { IndexPatternsService } from './index_patterns';
import {
setFieldFormats,
setHttp,
setIndexPatterns,
setInjectedMetadata,
setNotifications,
Expand Down Expand Up @@ -128,6 +129,7 @@ export class DataPublicPlugin implements Plugin<DataPublicPluginSetup, DataPubli

public start(core: CoreStart, { uiActions }: DataStartDependencies): DataPublicPluginStart {
const { uiSettings, http, notifications, savedObjects, overlays } = core;
setHttp(http);
setNotifications(notifications);
setOverlays(overlays);
setUiSettings(uiSettings);
Expand Down

0 comments on commit e207703

Please sign in to comment.