diff --git a/public/components/notebooks/components/main.tsx b/public/components/notebooks/components/main.tsx index c8234699b1..9087289fd1 100644 --- a/public/components/notebooks/components/main.tsx +++ b/public/components/notebooks/components/main.tsx @@ -408,7 +408,7 @@ export class Main extends React.Component { }); await this.props.http .post(`${NOTEBOOKS_API_PREFIX}/note/savedNotebook/addSampleNotebooks`, { - body: JSON.stringify({ visIds }), + body: JSON.stringify({ visIds, dataSourceMDSId, dataSourceMDSLabel }), }) .then((res) => { const newData = res.body.map((notebook: any) => ({ diff --git a/server/adaptors/notebooks/saved_objects_notebooks_router.tsx b/server/adaptors/notebooks/saved_objects_notebooks_router.tsx index 6a941fbf9a..f881147de1 100644 --- a/server/adaptors/notebooks/saved_objects_notebooks_router.tsx +++ b/server/adaptors/notebooks/saved_objects_notebooks_router.tsx @@ -68,13 +68,31 @@ export function renameNotebook(noteBookObj: { name: string; noteId: string }) { export async function addSampleNotes( opensearchNotebooksClient: SavedObjectsClientContract, - visIds: string[] + visIds: string[], + dataSourceMDSId?: string, + dataSourceMDSLabel?: string ) { const notebooks = getSampleNotebooks(visIds); const sampleNotebooks = []; try { + // Without a stored binding, each code block's selector falls back to the default data + // source rather than the one the sample data was just installed against. for (const item of notebooks) { - const createdNotebooks = await opensearchNotebooksClient.create(NOTEBOOK_SAVED_OBJECT, item); + const notebook = { + ...item, + savedNotebook: { + ...item.savedNotebook, + paragraphs: item.savedNotebook.paragraphs.map((paragraph) => ({ + ...paragraph, + dataSourceMDSId: dataSourceMDSId ?? '', + dataSourceMDSLabel: dataSourceMDSLabel ?? '', + })), + }, + }; + const createdNotebooks = await opensearchNotebooksClient.create( + NOTEBOOK_SAVED_OBJECT, + notebook + ); sampleNotebooks.push({ dateCreated: createdNotebooks.attributes.savedNotebook.dateCreated, dateModified: createdNotebooks.attributes.savedNotebook.dateModified, diff --git a/server/routes/notebooks/noteRouter.ts b/server/routes/notebooks/noteRouter.ts index dac07d9448..c443d1877c 100644 --- a/server/routes/notebooks/noteRouter.ts +++ b/server/routes/notebooks/noteRouter.ts @@ -237,6 +237,8 @@ export function registerNoteRoute(router: IRouter) { validate: { body: schema.object({ visIds: schema.arrayOf(schema.string()), + dataSourceMDSId: schema.maybe(schema.string()), + dataSourceMDSLabel: schema.maybe(schema.string()), }), }, }, @@ -250,7 +252,9 @@ export function registerNoteRoute(router: IRouter) { try { const sampleNotebooks = await addSampleNotes( opensearchNotebooksClient, - request.body.visIds + request.body.visIds, + request.body.dataSourceMDSId, + request.body.dataSourceMDSLabel ); return response.ok({ body: sampleNotebooks,