Skip to content
Open
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
2 changes: 1 addition & 1 deletion public/components/notebooks/components/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
};

// Renames an existing notebook
renameNotebook = async (editedNoteName: string, editedNoteID: string): Promise<any> => {

Check warning on line 143 in public/components/notebooks/components/main.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
if (editedNoteName.length >= 50 || editedNoteName.length === 0) {
this.setToast('Invalid notebook name', 'danger');
return;
Expand Down Expand Up @@ -408,10 +408,10 @@
});
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) => ({

Check warning on line 414 in public/components/notebooks/components/main.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
path: notebook.name,
id: notebook.id,
dateCreated: notebook.dateCreated,
Expand All @@ -422,7 +422,7 @@
}));
});
this.setToast(`Sample notebooks successfully added.`);
} catch (err: any) {

Check warning on line 425 in public/components/notebooks/components/main.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
this.setToast('Error adding sample notebooks.', 'danger');
console.error(err.body.message);
} finally {
Expand Down
22 changes: 20 additions & 2 deletions server/adaptors/notebooks/saved_objects_notebooks_router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 5 additions & 1 deletion server/routes/notebooks/noteRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
context,
request,
response
): Promise<IOpenSearchDashboardsResponse<any | ResponseError>> => {

Check warning on line 33 in server/routes/notebooks/noteRouter.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
const opensearchNotebooksClient: SavedObjectsClientContract =
context.core.savedObjects.client;
try {
Expand Down Expand Up @@ -67,7 +67,7 @@
context,
request,
response
): Promise<IOpenSearchDashboardsResponse<any | ResponseError>> => {

Check warning on line 70 in server/routes/notebooks/noteRouter.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
const opensearchNotebooksClient: SavedObjectsClientContract =
context.core.savedObjects.client;
let notebooksData;
Expand Down Expand Up @@ -101,7 +101,7 @@
context,
request,
response
): Promise<IOpenSearchDashboardsResponse<any | ResponseError>> => {

Check warning on line 104 in server/routes/notebooks/noteRouter.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
const opensearchNotebooksClient: SavedObjectsClientContract =
context.core.savedObjects.client;
try {
Expand Down Expand Up @@ -135,7 +135,7 @@
context,
request,
response
): Promise<IOpenSearchDashboardsResponse<any | ResponseError>> => {

Check warning on line 138 in server/routes/notebooks/noteRouter.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
const opensearchNotebooksClient: SavedObjectsClientContract =
context.core.savedObjects.client;
try {
Expand Down Expand Up @@ -176,7 +176,7 @@
context,
request,
response
): Promise<IOpenSearchDashboardsResponse<any | ResponseError>> => {

Check warning on line 179 in server/routes/notebooks/noteRouter.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
const opensearchNotebooksClient: SavedObjectsClientContract =
context.core.savedObjects.client;
try {
Expand Down Expand Up @@ -211,7 +211,7 @@
context,
request,
response
): Promise<IOpenSearchDashboardsResponse<any | ResponseError>> => {

Check warning on line 214 in server/routes/notebooks/noteRouter.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
const opensearchNotebooksClient: SavedObjectsClientContract =
context.core.savedObjects.client;

Expand All @@ -237,6 +237,8 @@
validate: {
body: schema.object({
visIds: schema.arrayOf(schema.string()),
dataSourceMDSId: schema.maybe(schema.string()),
dataSourceMDSLabel: schema.maybe(schema.string()),
}),
},
},
Expand All @@ -244,13 +246,15 @@
context,
request,
response
): Promise<IOpenSearchDashboardsResponse<any | ResponseError>> => {

Check warning on line 249 in server/routes/notebooks/noteRouter.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
const opensearchNotebooksClient: SavedObjectsClientContract =
context.core.savedObjects.client;
try {
const sampleNotebooks = await addSampleNotes(
opensearchNotebooksClient,
request.body.visIds
request.body.visIds,
request.body.dataSourceMDSId,
request.body.dataSourceMDSLabel
);
return response.ok({
body: sampleNotebooks,
Expand Down
Loading