diff --git a/CHANGELOG.md b/CHANGELOG.md index b4f25f48f8ac..e5268edb22f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,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);