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
7 changes: 6 additions & 1 deletion src/plugins/custom_integrations/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,19 @@ export const CATEGORY_DISPLAY = {

export type Category = keyof typeof CATEGORY_DISPLAY;

export interface CustomIntegrationIcon {
src: string;
type: 'eui' | 'svg';
}

export interface CustomIntegration {
id: string;
title: string;
description: string;
type: 'ui_link';
uiInternalPath: string;
isBeta: boolean;
icons: Array<{ src: string; type: string }>;
icons: CustomIntegrationIcon[];
categories: Category[];
shipper: string;
}
Expand Down
8 changes: 3 additions & 5 deletions src/plugins/custom_integrations/server/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@
* Side Public License, v 1.
*/

import type { MockedKeys } from '@kbn/utility-types/jest';

import { CustomIntegrationsPluginSetup } from '../server';

function createCustomIntegrationsSetup(): MockedKeys<CustomIntegrationsPluginSetup> {
const mock = {
function createCustomIntegrationsSetup(): jest.Mocked<CustomIntegrationsPluginSetup> {
const mock: jest.Mocked<CustomIntegrationsPluginSetup> = {
registerCustomIntegration: jest.fn(),
getAppendCustomIntegrations: jest.fn(),
};

return mock as MockedKeys<CustomIntegrationsPluginSetup>;
return mock;
}

export const customIntegrationsMock = {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion src/plugins/home/server/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ describe('HomeServerPlugin', () => {
homeServerPluginSetupDependenciesMock
);
expect(setup).toHaveProperty('sampleData');
expect(setup.sampleData).toHaveProperty('registerSampleDataset');
expect(setup.sampleData).toHaveProperty('getSampleDatasets');
expect(setup.sampleData).toHaveProperty('addSavedObjectsToSampleDataset');
expect(setup.sampleData).toHaveProperty('addAppLinksToSampleDataset');
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/home/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ export class HomeServerPlugin implements Plugin<HomeServerPluginSetup, HomeServe

return {
tutorials: { ...this.tutorialsRegistry.setup(core, plugins.customIntegrations) },
sampleData: { ...this.sampleDataRegistry.setup(core, plugins.usageCollection) },
sampleData: {
...this.sampleDataRegistry.setup(core, plugins.usageCollection, plugins.customIntegrations),
},
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@ export const ecommerceSpecProvider = function (): SampleDatasetSchema {
},
],
status: 'not_installed',
iconPath: '/plugins/home/assets/sample_data_resources/ecommerce/icon.svg',
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@ export const flightsSpecProvider = function (): SampleDatasetSchema {
},
],
status: 'not_installed',
iconPath: '/plugins/home/assets/sample_data_resources/flights/icon.svg',
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@ export const logsSpecProvider = function (): SampleDatasetSchema {
},
],
status: 'not_installed',
iconPath: '/plugins/home/assets/sample_data_resources/logs/icon.svg',
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { CoreSetup } from 'kibana/server';
import { CustomIntegrationsPluginSetup } from '../../../../../custom_integrations/server';
import { SampleDatasetSchema } from './sample_dataset_schema';
import { HOME_APP_BASE_PATH } from '../../../../common/constants';

export function registerSampleDatasetWithIntegration(
customIntegrations: CustomIntegrationsPluginSetup,
core: CoreSetup,
sampleDataset: SampleDatasetSchema
) {
customIntegrations.registerCustomIntegration({
id: sampleDataset.id,
title: sampleDataset.name,
description: sampleDataset.description,
uiInternalPath: `${HOME_APP_BASE_PATH}#/tutorial_directory/sampleData`,
isBeta: false,
icons: sampleDataset.iconPath
? [
{
type: 'svg',
src: core.http.basePath.prepend(sampleDataset.iconPath),
},
]
: [],
categories: ['sample_data'],
shipper: 'sample_data',
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export const sampleDataSchema = schema.object({
description: schema.string(),
previewImagePath: schema.string(),
darkPreviewImagePath: schema.maybe(schema.string()),
iconPath: schema.maybe(schema.string()), // relative path to icon. Used for display in the Fleet-integrations app

// saved object id of main dashboard for sample data set
overviewDashboard: schema.string(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {

const createSetupMock = (): jest.Mocked<SampleDataRegistrySetup> => {
const setup = {
registerSampleDataset: jest.fn(),
getSampleDatasets: jest.fn(),
addSavedObjectsToSampleDataset: jest.fn(),
addAppLinksToSampleDataset: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import type { MockedKeys } from '@kbn/utility-types/jest';
import { CoreSetup } from '../../../../../core/server';

import { CustomIntegrationsPluginSetup } from '../../../../custom_integrations/server';
import { customIntegrationsMock } from '../../../../custom_integrations/server/mocks';
import { SampleDataRegistry } from './sample_data_registry';
import { usageCollectionPluginMock } from '../../../../usage_collection/server/mocks';
import { UsageCollectionSetup } from '../../../../usage_collection/server/plugin';
import { coreMock } from '../../../../../core/server/mocks';

describe('SampleDataRegistry', () => {
let mockCoreSetup: MockedKeys<CoreSetup>;
let mockCustomIntegrationsPluginSetup: jest.Mocked<CustomIntegrationsPluginSetup>;
let mockUsageCollectionPluginSetup: MockedKeys<UsageCollectionSetup>;

beforeEach(() => {
mockCoreSetup = coreMock.createSetup();
mockCustomIntegrationsPluginSetup = customIntegrationsMock.createSetup();
mockUsageCollectionPluginSetup = usageCollectionPluginMock.createSetupContract();
});

describe('setup', () => {
test('should register the three sample datasets', () => {
const initContext = coreMock.createPluginInitializerContext();
const plugin = new SampleDataRegistry(initContext);
plugin.setup(
mockCoreSetup,
mockUsageCollectionPluginSetup,
mockCustomIntegrationsPluginSetup
);

const ids: string[] =
mockCustomIntegrationsPluginSetup.registerCustomIntegration.mock.calls.map((args) => {
return args[0].id;
});
expect(ids).toEqual(['flights', 'logs', 'ecommerce']);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,54 @@ import { createListRoute, createInstallRoute } from './routes';
import { UsageCollectionSetup } from '../../../../usage_collection/server';
import { makeSampleDataUsageCollector, usage } from './usage';
import { createUninstallRoute } from './routes/uninstall';

const flightsSampleDataset = flightsSpecProvider();
const logsSampleDataset = logsSpecProvider();
const ecommerceSampleDataset = ecommerceSpecProvider();
import { CustomIntegrationsPluginSetup } from '../../../../custom_integrations/server';
import { registerSampleDatasetWithIntegration } from './lib/register_with_integrations';

export class SampleDataRegistry {
constructor(private readonly initContext: PluginInitializerContext) {}
private readonly sampleDatasets: SampleDatasetSchema[] = [
flightsSampleDataset,
logsSampleDataset,
ecommerceSampleDataset,
];
private readonly sampleDatasets: SampleDatasetSchema[] = [];

private registerSampleDataSet(
specProvider: SampleDatasetProvider,
core: CoreSetup,
customIntegrations?: CustomIntegrationsPluginSetup
) {
let value: SampleDatasetSchema;
try {
value = sampleDataSchema.validate(specProvider());
} catch (error) {
throw new Error(`Unable to register sample dataset spec because it's invalid. ${error}`);
}

if (customIntegrations && core) {
registerSampleDatasetWithIntegration(customIntegrations, core, value);
}

public setup(core: CoreSetup, usageCollections: UsageCollectionSetup | undefined) {
const defaultIndexSavedObjectJson = value.savedObjects.find((savedObjectJson: any) => {
return savedObjectJson.type === 'index-pattern' && savedObjectJson.id === value.defaultIndex;
});
if (!defaultIndexSavedObjectJson) {
throw new Error(
`Unable to register sample dataset spec, defaultIndex: "${value.defaultIndex}" does not exist in savedObjects list.`
);
}

const dashboardSavedObjectJson = value.savedObjects.find((savedObjectJson: any) => {
return savedObjectJson.type === 'dashboard' && savedObjectJson.id === value.overviewDashboard;
});
if (!dashboardSavedObjectJson) {
throw new Error(
`Unable to register sample dataset spec, overviewDashboard: "${value.overviewDashboard}" does not exist in savedObject list.`
);
}
this.sampleDatasets.push(value);
}

public setup(
core: CoreSetup,
usageCollections: UsageCollectionSetup | undefined,
customIntegrations?: CustomIntegrationsPluginSetup
) {
if (usageCollections) {
makeSampleDataUsageCollector(usageCollections, this.initContext);
}
Expand All @@ -52,38 +86,11 @@ export class SampleDataRegistry {
);
createUninstallRoute(router, this.sampleDatasets, usageTracker);

return {
registerSampleDataset: (specProvider: SampleDatasetProvider) => {
let value: SampleDatasetSchema;
try {
value = sampleDataSchema.validate(specProvider());
} catch (error) {
throw new Error(`Unable to register sample dataset spec because it's invalid. ${error}`);
}

const defaultIndexSavedObjectJson = value.savedObjects.find((savedObjectJson: any) => {
return (
savedObjectJson.type === 'index-pattern' && savedObjectJson.id === value.defaultIndex
);
});
if (!defaultIndexSavedObjectJson) {
throw new Error(
`Unable to register sample dataset spec, defaultIndex: "${value.defaultIndex}" does not exist in savedObjects list.`
);
}
this.registerSampleDataSet(flightsSpecProvider, core, customIntegrations);
this.registerSampleDataSet(logsSpecProvider, core, customIntegrations);
this.registerSampleDataSet(ecommerceSpecProvider, core, customIntegrations);

const dashboardSavedObjectJson = value.savedObjects.find((savedObjectJson: any) => {
return (
savedObjectJson.type === 'dashboard' && savedObjectJson.id === value.overviewDashboard
);
});
if (!dashboardSavedObjectJson) {
throw new Error(
`Unable to register sample dataset spec, overviewDashboard: "${value.overviewDashboard}" does not exist in savedObject list.`
);
}
this.sampleDatasets.push(value);
},
return {
getSampleDatasets: () => this.sampleDatasets,

addSavedObjectsToSampleDataset: (id: string, savedObjects: SavedObject[]) => {
Expand Down
Loading