Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.x] Retain the original sample data interface #4530

Merged
merged 1 commit into from
Jul 9, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,21 @@ export interface SampleDatasetSchema<T = unknown> {
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<SavedObject<T>>;
savedObjects: Array<SavedObject<T>>;
getDataSourceIntegratedSavedObjects: (
dataSourceId?: string,
dataSourceTitle?: string
) => Array<SavedObject<T>>;
dataIndices: DataIndexSchema[];
status?: string | undefined;
statusMsg?: unknown;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/home/server/services/sample_data/routes/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading