Skip to content

Commit

Permalink
Retain the original sample data interface
Browse files Browse the repository at this point in the history
Signed-off-by: Kristen Tian <tyarong@amazon.com>
  • Loading branch information
kristenTian committed Jul 8, 2023
1 parent 24bde32 commit d9ea1f3
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 20 deletions.
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

0 comments on commit d9ea1f3

Please sign in to comment.