From 0c0f5579e45606f612b72c0bfe6b8dbf362067a9 Mon Sep 17 00:00:00 2001 From: Kristen Tian Date: Fri, 7 Jul 2023 16:43:30 -0700 Subject: [PATCH] Retain the original sample data interface Signed-off-by: Kristen Tian --- CHANGELOG.md | 1 + .../sample_data/data_sets/ecommerce/index.ts | 9 ++++++--- .../services/sample_data/data_sets/flights/index.ts | 9 ++++++--- .../services/sample_data/data_sets/logs/index.ts | 9 ++++++--- .../sample_data/lib/sample_dataset_registry_types.ts | 12 +++++++++--- .../server/services/sample_data/routes/install.ts | 4 +++- .../home/server/services/sample_data/routes/list.ts | 4 ++-- .../server/services/sample_data/routes/uninstall.ts | 4 +++- .../services/sample_data/sample_data_registry.ts | 8 ++++---- 9 files changed, 40 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b5fc6207f49..54e6e37dfcfa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Cleanup unused url ([#3847](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3847)) - [Saved Objects Management] Fix relationships header overflow ([#4070](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4070)) - Update main menu to display 'Dashboards' for consistency ([#4453](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4453)) +- [Multiple DataSource] Retain the original sample data API ([#4526](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4526)) ### 🚞 Infrastructure 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 0321c428cf68..f7c80c5e63a8 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 @@ -53,10 +53,13 @@ export const ecommerceSpecProvider = function (): SampleDatasetSchema { description: ecommerceDescription, previewImagePath: '/plugins/home/assets/sample_data_resources/ecommerce/dashboard.png', darkPreviewImagePath: '/plugins/home/assets/sample_data_resources/ecommerce/dashboard_dark.png', - overviewDashboard: appendDataSourceId(DASHBOARD_ID), + overviewDashboard: DASHBOARD_ID, + getDataSourceIntegratedDashboard: appendDataSourceId(DASHBOARD_ID), appLinks: initialAppLinks, - defaultIndex: appendDataSourceId(DEFAULT_INDEX), - savedObjects: (dataSourceId?: string, dataSourceTitle?: string) => + defaultIndex: DEFAULT_INDEX, + getDataSourceIntegratedDefaultIndex: appendDataSourceId(DEFAULT_INDEX), + savedObjects: getSavedObjects(), + getDataSourceIntegratedSavedObjects: (dataSourceId?: string, dataSourceTitle?: string) => getSavedObjectsWithDataSource(getSavedObjects(), dataSourceId, dataSourceTitle), dataIndices: [ { 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 038744419f3e..d93fd4d052ee 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 @@ -53,10 +53,13 @@ export const flightsSpecProvider = function (): SampleDatasetSchema { description: flightsDescription, previewImagePath: '/plugins/home/assets/sample_data_resources/flights/dashboard.png', darkPreviewImagePath: '/plugins/home/assets/sample_data_resources/flights/dashboard_dark.png', - overviewDashboard: appendDataSourceId(DASHBOARD_ID), + overviewDashboard: DASHBOARD_ID, + getDataSourceIntegratedDashboard: appendDataSourceId(DASHBOARD_ID), appLinks: initialAppLinks, - defaultIndex: appendDataSourceId(DEFAULT_INDEX), - savedObjects: (dataSourceId?: string, dataSourceTitle?: string) => + defaultIndex: DEFAULT_INDEX, + getDataSourceIntegratedDefaultIndex: appendDataSourceId(DEFAULT_INDEX), + savedObjects: getSavedObjects(), + getDataSourceIntegratedSavedObjects: (dataSourceId?: string, dataSourceTitle?: string) => getSavedObjectsWithDataSource(getSavedObjects(), dataSourceId, dataSourceTitle), dataIndices: [ { 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 e4afabcdd212..63013b63354e 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 @@ -53,10 +53,13 @@ export const logsSpecProvider = function (): SampleDatasetSchema { description: logsDescription, previewImagePath: '/plugins/home/assets/sample_data_resources/logs/dashboard.png', darkPreviewImagePath: '/plugins/home/assets/sample_data_resources/logs/dashboard_dark.png', - overviewDashboard: appendDataSourceId(DASHBOARD_ID), + overviewDashboard: DASHBOARD_ID, + getDataSourceIntegratedDashboard: appendDataSourceId(DASHBOARD_ID), appLinks: initialAppLinks, - defaultIndex: appendDataSourceId(DEFAULT_INDEX), - savedObjects: (dataSourceId?: string, dataSourceTitle?: string) => + defaultIndex: DEFAULT_INDEX, + getDataSourceIntegratedDefaultIndex: appendDataSourceId(DEFAULT_INDEX), + savedObjects: getSavedObjects(), + getDataSourceIntegratedSavedObjects: (dataSourceId?: string, dataSourceTitle?: string) => getSavedObjectsWithDataSource(getSavedObjects(), dataSourceId, dataSourceTitle), dataIndices: [ { 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 76632ee4489d..3489b96bf751 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 @@ -87,15 +87,21 @@ export interface SampleDatasetSchema { darkPreviewImagePath: string; // saved object id of main dashboard for sample data set - overviewDashboard: (dataSourceId?: string) => string; + overviewDashboard: string; + getDataSourceIntegratedDashboard: (dataSourceId?: string) => string; appLinks: AppLinkSchema[]; // saved object id of default index-pattern for sample data set - defaultIndex: (dataSourceId?: string) => string; + defaultIndex: string; + getDataSourceIntegratedDefaultIndex: (dataSourceId?: string) => string; // OpenSearch Dashboards saved objects (index patter, visualizations, dashboard, ...) // Should provide a nice demo of OpenSearch Dashboards's functionality with the sample data set - savedObjects: (dataSourceId?: string, dataSourceTitle?: string) => Array>; + savedObjects: Array>; + getDataSourceIntegratedSavedObjects: ( + dataSourceId?: string, + dataSourceTitle?: string + ) => Array>; dataIndices: DataIndexSchema[]; status?: string | undefined; statusMsg?: unknown; diff --git a/src/plugins/home/server/services/sample_data/routes/install.ts b/src/plugins/home/server/services/sample_data/routes/install.ts index 3a321c3bdf0a..279357fc1977 100644 --- a/src/plugins/home/server/services/sample_data/routes/install.ts +++ b/src/plugins/home/server/services/sample_data/routes/install.ts @@ -198,7 +198,9 @@ export function createInstallRoute( } let createResults; - const savedObjectsList = sampleDataset.savedObjects(dataSourceId, dataSourceTitle); + const savedObjectsList = dataSourceId + ? sampleDataset.getDataSourceIntegratedSavedObjects(dataSourceId, dataSourceTitle) + : sampleDataset.savedObjects; try { createResults = await context.core.savedObjects.client.bulkCreate( 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 bc6fac2b76f3..0a42b073bde8 100644 --- a/src/plugins/home/server/services/sample_data/routes/list.ts +++ b/src/plugins/home/server/services/sample_data/routes/list.ts @@ -55,9 +55,9 @@ export const createListRoute = (router: IRouter, sampleDatasets: SampleDatasetSc description: sampleDataset.description, previewImagePath: sampleDataset.previewImagePath, darkPreviewImagePath: sampleDataset.darkPreviewImagePath, - overviewDashboard: sampleDataset.overviewDashboard(dataSourceId), + overviewDashboard: sampleDataset.getDataSourceIntegratedDashboard(dataSourceId), appLinks: sampleDataset.appLinks, - defaultIndex: sampleDataset.defaultIndex(dataSourceId), + defaultIndex: sampleDataset.getDataSourceIntegratedDefaultIndex(dataSourceId), dataIndices: sampleDataset.dataIndices.map(({ id }) => ({ id })), status: sampleDataset.status, statusMsg: sampleDataset.statusMsg, diff --git a/src/plugins/home/server/services/sample_data/routes/uninstall.ts b/src/plugins/home/server/services/sample_data/routes/uninstall.ts index 730de6afff30..d5a09ce56070 100644 --- a/src/plugins/home/server/services/sample_data/routes/uninstall.ts +++ b/src/plugins/home/server/services/sample_data/routes/uninstall.ts @@ -78,7 +78,9 @@ export function createUninstallRoute( } } - const savedObjectsList = sampleDataset.savedObjects(dataSourceId); + const savedObjectsList = dataSourceId + ? sampleDataset.getDataSourceIntegratedSavedObjects(dataSourceId) + : sampleDataset.savedObjects; const deletePromises = savedObjectsList.map(({ type, id }) => context.core.savedObjects.client.delete(type, id) 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 5f298fd86ef3..d90de532c339 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 @@ -84,23 +84,23 @@ export class SampleDataRegistry { } const defaultIndexSavedObjectJson = value.savedObjects.find((savedObjectJson: any) => { return ( - savedObjectJson.type === 'index-pattern' && savedObjectJson.id === value.defaultIndex() + 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.` + `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() + 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.` + `Unable to register sample dataset spec, overviewDashboard: "${value.overviewDashboard}" does not exist in savedObject list.` ); } this.sampleDatasets.push(value);