diff --git a/src/legacy/core_plugins/kibana/public/home/sample_data_client.js b/src/legacy/core_plugins/kibana/public/home/sample_data_client.js index b585a6e123f4e9..eca88604a559da 100644 --- a/src/legacy/core_plugins/kibana/public/home/sample_data_client.js +++ b/src/legacy/core_plugins/kibana/public/home/sample_data_client.js @@ -19,7 +19,6 @@ import { getServices } from './kibana_services'; -const sampleDataUrlLP = '/api/sample_data_LP'; const sampleDataUrl = '/api/sample_data'; function clearIndexPatternsCache() { @@ -27,8 +26,7 @@ function clearIndexPatternsCache() { } export async function listSampleDataSets() { - return await getServices().http.get(sampleDataUrlLP); - // return await getServices().http.get(sampleDataUrl); + return await getServices().http.get(sampleDataUrl); } export async function installSampleDataSet(id, sampleDataDefaultIndex) { diff --git a/src/plugins/home/server/services/sample_data/data_sets/ecommerce/index.ts b/src/plugins/home/server/services/sample_data/data_sets/ecommerce/index.ts index 738dbbbb0ccc07..a461dd927ab2de 100644 --- a/src/plugins/home/server/services/sample_data/data_sets/ecommerce/index.ts +++ b/src/plugins/home/server/services/sample_data/data_sets/ecommerce/index.ts @@ -21,20 +21,25 @@ import path from 'path'; import { i18n } from '@kbn/i18n'; import { getSavedObjects } from './saved_objects'; import { fieldMappings } from './field_mappings'; -import { SampleDatasetSchema } from '../../lib/sample_dataset_registry_types'; +import { SampleDatasetSchema, AppLinkSchema } from '../../lib/sample_dataset_registry_types'; + +const ecommerceName = i18n.translate('server.sampleData.ecommerceSpecTitle', { + defaultMessage: 'Sample eCommerce orders', +}); +const ecommerceDescription = i18n.translate('server.sampleData.ecommerceSpecDescription', { + defaultMessage: 'Sample data, visualizations, and dashboards for tracking eCommerce orders.', +}); +const initialAppLinks = [] as AppLinkSchema[]; export const ecommerceSpecProvider = function(): SampleDatasetSchema { return { id: 'ecommerce', - name: i18n.translate('server.sampleData.ecommerceSpecTitle', { - defaultMessage: 'Sample eCommerce orders', - }), - description: i18n.translate('server.sampleData.ecommerceSpecDescription', { - defaultMessage: 'Sample data, visualizations, and dashboards for tracking eCommerce orders.', - }), + name: ecommerceName, + description: ecommerceDescription, previewImagePath: '/plugins/kibana/home/sample_data_resources/ecommerce/dashboard.png', darkPreviewImagePath: '/plugins/kibana/home/sample_data_resources/ecommerce/dashboard_dark.png', overviewDashboard: '722b74f0-b882-11e8-a6d9-e546fe2bba5f', + appLinks: initialAppLinks, defaultIndex: 'ff959d40-b880-11e8-a6d9-e546fe2bba5f', savedObjects: getSavedObjects(), dataIndices: [ @@ -47,5 +52,6 @@ export const ecommerceSpecProvider = function(): SampleDatasetSchema { preserveDayOfWeekTimeOfDay: true, }, ], + status: 'not_installed', }; }; diff --git a/src/plugins/home/server/services/sample_data/data_sets/flights/index.ts b/src/plugins/home/server/services/sample_data/data_sets/flights/index.ts index e9de1b2eb2cab0..207eb336ef58fd 100644 --- a/src/plugins/home/server/services/sample_data/data_sets/flights/index.ts +++ b/src/plugins/home/server/services/sample_data/data_sets/flights/index.ts @@ -21,20 +21,25 @@ import path from 'path'; import { i18n } from '@kbn/i18n'; import { getSavedObjects } from './saved_objects'; import { fieldMappings } from './field_mappings'; -import { SampleDatasetSchema } from '../../lib/sample_dataset_registry_types'; +import { SampleDatasetSchema, AppLinkSchema } from '../../lib/sample_dataset_registry_types'; + +const flightsName = i18n.translate('server.sampleData.flightsSpecTitle', { + defaultMessage: 'Sample flight data', +}); +const flightsDescription = i18n.translate('server.sampleData.flightsSpecDescription', { + defaultMessage: 'Sample data, visualizations, and dashboards for monitoring flight routes.', +}); +const initialAppLinks = [] as AppLinkSchema[]; export const flightsSpecProvider = function(): SampleDatasetSchema { return { id: 'flights', - name: i18n.translate('server.sampleData.flightsSpecTitle', { - defaultMessage: 'Sample flight data', - }), - description: i18n.translate('server.sampleData.flightsSpecDescription', { - defaultMessage: 'Sample data, visualizations, and dashboards for monitoring flight routes.', - }), + name: flightsName, + description: flightsDescription, previewImagePath: '/plugins/kibana/home/sample_data_resources/flights/dashboard.png', darkPreviewImagePath: '/plugins/kibana/home/sample_data_resources/flights/dashboard_dark.png', overviewDashboard: '7adfa750-4c81-11e8-b3d7-01146121b73d', + appLinks: initialAppLinks, defaultIndex: 'd3d7af60-4c81-11e8-b3d7-01146121b73d', savedObjects: getSavedObjects(), dataIndices: [ @@ -47,5 +52,6 @@ export const flightsSpecProvider = function(): SampleDatasetSchema { preserveDayOfWeekTimeOfDay: true, }, ], + status: 'not_installed', }; }; diff --git a/src/plugins/home/server/services/sample_data/data_sets/logs/index.ts b/src/plugins/home/server/services/sample_data/data_sets/logs/index.ts index 559c7b258eafda..7d038a70d00552 100644 --- a/src/plugins/home/server/services/sample_data/data_sets/logs/index.ts +++ b/src/plugins/home/server/services/sample_data/data_sets/logs/index.ts @@ -21,20 +21,25 @@ import path from 'path'; import { i18n } from '@kbn/i18n'; import { getSavedObjects } from './saved_objects'; import { fieldMappings } from './field_mappings'; -import { SampleDatasetSchema } from '../../lib/sample_dataset_registry_types'; +import { SampleDatasetSchema, AppLinkSchema } from '../../lib/sample_dataset_registry_types'; + +const logsName = i18n.translate('server.sampleData.logsSpecTitle', { + defaultMessage: 'Sample web logs', +}); +const logsDescription = i18n.translate('server.sampleData.logsSpecDescription', { + defaultMessage: 'Sample data, visualizations, and dashboards for monitoring web logs.', +}); +const initialAppLinks = [] as AppLinkSchema[]; export const logsSpecProvider = function(): SampleDatasetSchema { return { id: 'logs', - name: i18n.translate('server.sampleData.logsSpecTitle', { - defaultMessage: 'Sample web logs', - }), - description: i18n.translate('server.sampleData.logsSpecDescription', { - defaultMessage: 'Sample data, visualizations, and dashboards for monitoring web logs.', - }), + name: logsName, + description: logsDescription, previewImagePath: '/plugins/kibana/home/sample_data_resources/logs/dashboard.png', darkPreviewImagePath: '/plugins/kibana/home/sample_data_resources/logs/dashboard_dark.png', overviewDashboard: 'edf84fe0-e1a0-11e7-b6d5-4dc382ef7f5b', + appLinks: initialAppLinks, defaultIndex: '90943e30-9a47-11e8-b64d-95841ca0b247', savedObjects: getSavedObjects(), dataIndices: [ @@ -47,5 +52,6 @@ export const logsSpecProvider = function(): SampleDatasetSchema { preserveDayOfWeekTimeOfDay: true, }, ], + status: 'not_installed', }; }; diff --git a/src/plugins/home/server/services/sample_data/lib/sample_dataset_registry_types.ts b/src/plugins/home/server/services/sample_data/lib/sample_dataset_registry_types.ts index d071ce5622bcf8..cd7fb84ac6a84b 100644 --- a/src/plugins/home/server/services/sample_data/lib/sample_dataset_registry_types.ts +++ b/src/plugins/home/server/services/sample_data/lib/sample_dataset_registry_types.ts @@ -18,6 +18,11 @@ */ import { SavedObject } from 'src/core/server'; +export enum DatasetStatusTypes { + NOT_INSTALLED = 'not_installed', + INSTALLED = 'installed', + UNKNOWN = 'unknown', +} export interface SampleDatasetDashboardPanel { sampleDataId: string; dashboardId: string; @@ -58,8 +63,8 @@ export interface DataIndexSchema { export interface AppLinkSchema { path: string; - label: string; icon: string; + label: string; } export interface SampleDatasetSchema { @@ -80,7 +85,7 @@ export interface SampleDatasetSchema { // Should provide a nice demo of Kibana's functionality with the sample data set savedObjects: SavedObject[] | any[]; dataIndices: DataIndexSchema[]; - status?: unknown; + status?: string | undefined; statusMsg?: unknown; } diff --git a/src/plugins/home/server/services/sample_data/routes/list.ts b/src/plugins/home/server/services/sample_data/routes/list.ts index 98537fa7e7d19f..2c817c449bd720 100644 --- a/src/plugins/home/server/services/sample_data/routes/list.ts +++ b/src/plugins/home/server/services/sample_data/routes/list.ts @@ -26,35 +26,37 @@ const UNKNOWN = 'unknown'; export const createListRoute = (router: IRouter, sampleDatasets: SampleDatasetSchema[]) => { router.get({ path: '/api/sample_data', validate: false }, async (context, req, res) => { - const registeredSampleDatasets = sampleDatasets.map(dataset => { + const registeredSampleDatasets = sampleDatasets.map(sampleDataset => { return { - id: dataset.id, - name: dataset.name, - description: dataset.description, - oreviewImagePath: dataset.previewImagePath, - darkPreviewImagePath: dataset.darkPreviewImagePath, - overviewDashboard: dataset.overviewDashboard, - appLinks: dataset.appLinks, - defaultIndex: dataset.defaultIndex, - dataIndices: dataset.dataIndices.map(({ id }) => ({ id })), + id: sampleDataset.id, + name: sampleDataset.name, + description: sampleDataset.description, + previewImagePath: sampleDataset.previewImagePath, + darkPreviewImagePath: sampleDataset.darkPreviewImagePath, + overviewDashboard: sampleDataset.overviewDashboard, + appLinks: sampleDataset.appLinks, + defaultIndex: sampleDataset.defaultIndex, + dataIndices: sampleDataset.dataIndices.map(({ id }) => ({ id })), + status: sampleDataset.status, + statusMsg: sampleDataset.statusMsg, }; }); - const isInstalledPromises = sampleDatasets.map(async sampleDataset => { + const isInstalledPromises = registeredSampleDatasets.map(async sampleDataset => { for (let i = 0; i < sampleDataset.dataIndices.length; i++) { const dataIndexConfig = sampleDataset.dataIndices[i]; - const indexOfInterest = createIndexName(sampleDataset.id, dataIndexConfig.id); + const index = createIndexName(sampleDataset.id, dataIndexConfig.id); try { - // indexExists is either a true or false response from elasticsearch const indexExists = await context.core.elasticsearch.dataClient.callAsCurrentUser( 'indices.exists', - { index: indexOfInterest } + { index } ); if (!indexExists) { sampleDataset.status = NOT_INSTALLED; return; } + const { count } = await context.core.elasticsearch.dataClient.callAsCurrentUser('count', { - index: indexOfInterest, + index, }); if (count === 0) { sampleDataset.status = NOT_INSTALLED; @@ -63,6 +65,7 @@ export const createListRoute = (router: IRouter, sampleDatasets: SampleDatasetSc } catch (err) { sampleDataset.status = UNKNOWN; sampleDataset.statusMsg = err.message; + return; } } try { @@ -81,8 +84,8 @@ export const createListRoute = (router: IRouter, sampleDatasets: SampleDatasetSc sampleDataset.status = INSTALLED; }); - await Promise.all(isInstalledPromises); + await Promise.all(isInstalledPromises); return res.ok({ body: registeredSampleDatasets }); }); }; diff --git a/src/plugins/home/server/services/sample_data/sample_data_registry.ts b/src/plugins/home/server/services/sample_data/sample_data_registry.ts index ea999906c4231e..68e4e42df3a3e4 100644 --- a/src/plugins/home/server/services/sample_data/sample_data_registry.ts +++ b/src/plugins/home/server/services/sample_data/sample_data_registry.ts @@ -26,17 +26,10 @@ addSavedObjectsToSampleDataset DONE addAppLinksToSampleDataset DONE replacePanelInSampleDatasetDashboard DONE - During the start phase of the sample_data_registry, we expose the methods that use the setup methods: - `getSampleDataSets returns the array of sample data sets, similarly to - - Another question: - sample data is registered at the end of the file in src/legacy/server/sample_data/sample_data_mixin.js - Does this service need to do the registration itself? Yes, initialize the array with them! DONE - - TODO: createListRoute createInstallRoute + TODO: createUninstallRoute They go into the setup phase before the return methods. @@ -61,7 +54,6 @@ const ecommerceSampleDataset = ecommerceSpecProvider(); export class SampleDataRegistry { constructor(private readonly initContext: PluginInitializerContext) {} - // use initContext for the loggin in install route, e.g.: installRouteForGet(router, this.initContext.logger). private readonly sampleDatasets: SampleDatasetSchema[] = [ flightsSampleDataset, logsSampleDataset, @@ -163,7 +155,7 @@ export class SampleDataRegistry { const panels = JSON.parse(dashboard.attributes.panelsJSON); const panel = panels.find((panelItem: any) => { - return (panelItem.panelRefName = reference.name); + return panelItem.panelRefName === reference.name; }); if (!panel) { throw new Error(`Unable to find panel for reference: ${reference.name}`);