Skip to content
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
2 changes: 1 addition & 1 deletion src/legacy/core_plugins/kibana/public/home/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,6 @@ let copiedLegacyCatalogue = false;
},
});
instance.start(npStart.core, {
data: npStart.plugins.data,
...npStart.plugins,
});
})();
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
UiSettingsState,
} from 'kibana/public';
import { UiStatsMetricType } from '@kbn/analytics';
import { FeatureCatalogueEntry } from '../../../../../plugins/home/public';
import { Environment, FeatureCatalogueEntry } from '../../../../../plugins/home/public';

export interface HomeKibanaServices {
indexPatternService: any;
Expand Down Expand Up @@ -61,6 +61,7 @@ export interface HomeKibanaServices {
shouldShowTelemetryOptIn: boolean;
docLinks: DocLinksStart;
addBasePath: (url: string) => string;
environment: Environment;
}

let services: HomeKibanaServices | null = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,19 @@ import { HashRouter as Router, Switch, Route, Redirect } from 'react-router-dom'
import { getTutorial } from '../load_tutorials';
import { replaceTemplateStrings } from './tutorial/replace_template_strings';
import { getServices } from '../../kibana_services';
// TODO This is going to be refactored soon
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { npSetup } from 'ui/new_platform';
export function HomeApp({ directories }) {
const {
getInjected,
savedObjectsClient,
getBasePath,
addBasePath,
environment,
telemetryOptInProvider: { setOptInNoticeSeen, getOptIn },
} = getServices();
const { cloud } = npSetup.plugins;
const isCloudEnabled = !!(cloud && cloud.isCloudEnabled);
const isCloudEnabled = environment.cloud;
const mlEnabled = environment.ml;
const apmUiEnabled = environment.apmUi;

const apmUiEnabled = getInjected('apmUiEnabled', true);
const mlEnabled = getInjected('mlEnabled', false);
const defaultAppId = getInjected('kbnDefaultAppId', 'discover');

const renderTutorialDirectory = props => {
Expand Down
13 changes: 10 additions & 3 deletions src/legacy/core_plugins/kibana/public/home/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ import { UiStatsMetricType } from '@kbn/analytics';
import { DataPublicPluginStart } from 'src/plugins/data/public';
import { setServices } from './kibana_services';
import { KibanaLegacySetup } from '../../../../../plugins/kibana_legacy/public';
import { FeatureCatalogueEntry } from '../../../../../plugins/home/public';
import {
Environment,
FeatureCatalogueEntry,
HomePublicPluginStart,
} from '../../../../../plugins/home/public';

export interface LegacyAngularInjectedDependencies {
telemetryOptInProvider: any;
Expand All @@ -32,6 +36,7 @@ export interface LegacyAngularInjectedDependencies {

export interface HomePluginStartDependencies {
data: DataPublicPluginStart;
home: HomePublicPluginStart;
}

export interface HomePluginSetupDependencies {
Expand Down Expand Up @@ -60,6 +65,7 @@ export interface HomePluginSetupDependencies {
export class HomePlugin implements Plugin {
private dataStart: DataPublicPluginStart | null = null;
private savedObjectsClient: any = null;
private environment: Environment | null = null;

setup(
core: CoreSetup,
Expand All @@ -86,6 +92,7 @@ export class HomePlugin implements Plugin {
addBasePath: core.http.basePath.prepend,
getBasePath: core.http.basePath.get,
indexPatternService: this.dataStart!.indexPatterns,
environment: this.environment!,
...angularDependencies,
});
const { renderApp } = await import('./np_ready/application');
Expand All @@ -94,8 +101,8 @@ export class HomePlugin implements Plugin {
});
}

start(core: CoreStart, { data }: HomePluginStartDependencies) {
// TODO is this really the right way? I though the app context would give us those
start(core: CoreStart, { data, home }: HomePluginStartDependencies) {
this.environment = home.environment.get();
this.dataStart = data;
this.savedObjectsClient = core.savedObjects.client;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import 'uiExports/docViews';
import 'uiExports/embeddableActions';
import 'uiExports/fieldFormatEditors';
import 'uiExports/fieldFormats';
import 'uiExports/home';
import 'uiExports/indexManagement';
import 'uiExports/inspectorViews';
import 'uiExports/savedObjectTypes';
Expand Down
3 changes: 3 additions & 0 deletions src/legacy/ui/public/new_platform/new_platform.karma_mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ export const npSetup = {
featureCatalogue: {
register: sinon.fake(),
},
environment: {
update: sinon.fake(),
},
},
},
};
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/home/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export {
HomePublicPluginSetup,
HomePublicPluginStart,
} from './plugin';
export { FeatureCatalogueEntry, FeatureCatalogueCategory } from './services';
export { FeatureCatalogueEntry, FeatureCatalogueCategory, Environment } from './services';
import { HomePublicPlugin } from './plugin';

export const plugin = () => new HomePublicPlugin();
3 changes: 3 additions & 0 deletions src/plugins/home/public/plugin.test.mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@
*/

import { featureCatalogueRegistryMock } from './services/feature_catalogue/feature_catalogue_registry.mock';
import { environmentServiceMock } from './services/environment/environment.mock';

export const registryMock = featureCatalogueRegistryMock.create();
export const environmentMock = environmentServiceMock.create();
jest.doMock('./services', () => ({
FeatureCatalogueRegistry: jest.fn(() => registryMock),
EnvironmentService: jest.fn(() => environmentMock),
}));
20 changes: 19 additions & 1 deletion src/plugins/home/public/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
* under the License.
*/

import { registryMock } from './plugin.test.mocks';
import { registryMock, environmentMock } from './plugin.test.mocks';
import { HomePublicPlugin } from './plugin';

describe('HomePublicPlugin', () => {
beforeEach(() => {
registryMock.setup.mockClear();
registryMock.start.mockClear();
environmentMock.setup.mockClear();
environmentMock.start.mockClear();
});

describe('setup', () => {
Expand All @@ -32,6 +34,12 @@ describe('HomePublicPlugin', () => {
expect(setup).toHaveProperty('featureCatalogue');
expect(setup.featureCatalogue).toHaveProperty('register');
});

test('wires up and returns environment service', async () => {
const setup = await new HomePublicPlugin().setup();
expect(setup).toHaveProperty('environment');
expect(setup.environment).toHaveProperty('update');
});
});

describe('start', () => {
Expand All @@ -45,5 +53,15 @@ describe('HomePublicPlugin', () => {
});
expect(start.featureCatalogue.get).toBeDefined();
});

test('wires up and returns environment service', async () => {
const service = new HomePublicPlugin();
await service.setup();
const start = await service.start({
application: { capabilities: { catalogue: {} } },
} as any);
expect(environmentMock.start).toHaveBeenCalled();
expect(start.environment.get).toBeDefined();
});
});
});
19 changes: 19 additions & 0 deletions src/plugins/home/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,22 @@

import { CoreStart, Plugin } from 'src/core/public';
import {
EnvironmentService,
EnvironmentServiceSetup,
EnvironmentServiceStart,
FeatureCatalogueRegistry,
FeatureCatalogueRegistrySetup,
FeatureCatalogueRegistryStart,
} from './services';

export class HomePublicPlugin implements Plugin<HomePublicPluginSetup, HomePublicPluginStart> {
private readonly featuresCatalogueRegistry = new FeatureCatalogueRegistry();
private readonly environmentService = new EnvironmentService();

public async setup() {
return {
featureCatalogue: { ...this.featuresCatalogueRegistry.setup() },
environment: { ...this.environmentService.setup() },
};
}

Expand All @@ -40,6 +45,7 @@ export class HomePublicPlugin implements Plugin<HomePublicPluginSetup, HomePubli
capabilities: core.application.capabilities,
}),
},
environment: { ...this.environmentService.start() },
};
}
}
Expand All @@ -50,12 +56,25 @@ export type FeatureCatalogueSetup = FeatureCatalogueRegistrySetup;
/** @public */
export type FeatureCatalogueStart = FeatureCatalogueRegistryStart;

/** @public */
export type EnvironmentSetup = EnvironmentServiceSetup;

/** @public */
export type EnvironmentStart = EnvironmentServiceStart;

/** @public */
export interface HomePublicPluginSetup {
featureCatalogue: FeatureCatalogueSetup;
/**
* The environment service is only available for a transition period and will
* be replaced by display specific extension points.
* @deprecated
*/
environment: EnvironmentSetup;
}

/** @public */
export interface HomePublicPluginStart {
featureCatalogue: FeatureCatalogueStart;
environment: EnvironmentStart;
}
54 changes: 54 additions & 0 deletions src/plugins/home/public/services/environment/environment.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* 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 {
EnvironmentService,
EnvironmentServiceSetup,
EnvironmentServiceStart,
} from './environment';

const createSetupMock = (): jest.Mocked<EnvironmentServiceSetup> => {
const setup = {
update: jest.fn(),
};
return setup;
};

const createStartMock = (): jest.Mocked<EnvironmentServiceStart> => {
const start = {
get: jest.fn(),
};
return start;
};

const createMock = (): jest.Mocked<PublicMethodsOf<EnvironmentService>> => {
const service = {
setup: jest.fn(),
start: jest.fn(),
};
service.setup.mockImplementation(createSetupMock);
service.start.mockImplementation(createStartMock);
return service;
};

export const environmentServiceMock = {
createSetup: createSetupMock,
createStart: createStartMock,
create: createMock,
};
47 changes: 47 additions & 0 deletions src/plugins/home/public/services/environment/environment.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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 { EnvironmentService } from './environment';

describe('EnvironmentService', () => {
describe('setup', () => {
test('allows multiple update calls', () => {
const setup = new EnvironmentService().setup();
expect(() => {
setup.update({ ml: true });
setup.update({ apmUi: true });
}).not.toThrow();
});
});

describe('start', () => {
test('returns default values', () => {
const service = new EnvironmentService();
expect(service.start().get()).toEqual({ ml: false, cloud: false, apmUi: false });
});

test('returns last state of update calls', () => {
const service = new EnvironmentService();
const setup = service.setup();
setup.update({ ml: true, cloud: true });
setup.update({ ml: false, apmUi: true });
expect(service.start().get()).toEqual({ ml: false, cloud: true, apmUi: true });
});
});
});
Loading