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

[Bug] Fix notebook routes for savedNotebook endpoints #2279

Merged
merged 2 commits into from
Dec 6, 2024
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
8 changes: 5 additions & 3 deletions public/components/notebooks/components/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,19 @@
if (this.props.dataSourceEnabled) {
// If `MDS` is enabled, only fetch from the first endpoint.
return this.props.http
.get(`${NOTEBOOKS_API_PREFIX}/savedNotebook/`)
.get(`${NOTEBOOKS_API_PREFIX}/savedNotebook`)
.then((savedNotebooksResponse) => {
this.setState({ data: savedNotebooksResponse.data });
})
.catch((err) => {
console.error('Issue in fetching the notebooks', err.body.message);
});
}
// If `MDS` is not enabled /savedNotebook/ API returns notebooks stored as saved objects, and the other one returns notebooks stored as observability objects.
// If `MDS` is not enabled /savedNotebook API returns notebooks stored as saved objects, and the other one returns notebooks stored as observability objects.
// ${NOTEBOOKS_API_PREFIX}/savedNotebook: this point to new notebooks saved in saved objects
// ${NOTEBOOKS_API_PREFIX}/: this point to old notebooks saved in observability index
return Promise.all([
this.props.http.get(`${NOTEBOOKS_API_PREFIX}/savedNotebook/`),
this.props.http.get(`${NOTEBOOKS_API_PREFIX}/savedNotebook`),
this.props.http.get(`${NOTEBOOKS_API_PREFIX}/`),
])
.then(([savedNotebooksResponse, secondResponse]) => {
Expand Down Expand Up @@ -154,7 +156,7 @@
};

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

Check warning on line 159 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 @@ -425,7 +427,7 @@
body: JSON.stringify({ visIds }),
})
.then((res) => {
const newData = res.body.map((notebook: any) => ({

Check warning on line 430 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 @@ -436,7 +438,7 @@
}));
});
this.setToast(`Sample notebooks successfully added.`);
} catch (err: any) {

Check warning on line 441 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
18 changes: 9 additions & 9 deletions public/components/notebooks/components/notebook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
*/

import {
EuiSmallButton,
EuiButtonGroup,
EuiButtonGroupOptionProps,
EuiButtonIcon,
EuiCallOut,
EuiCard,
EuiContextMenu,
Expand All @@ -19,18 +19,18 @@
EuiPageBody,
EuiPanel,
EuiPopover,
EuiSmallButton,
EuiSpacer,
EuiText,
EuiButtonIcon,
EuiTitle,
EuiToolTip,
} from '@elastic/eui';
import { FormattedMessage } from '@osd/i18n/react';
import CSS from 'csstype';
import moment from 'moment';
import queryString from 'query-string';
import React, { Component } from 'react';
import { RouteComponentProps } from 'react-router-dom';
import { FormattedMessage } from '@osd/i18n/react';
import {
ChromeBreadcrumb,
CoreStart,
Expand All @@ -43,6 +43,8 @@
import { UI_DATE_FORMAT } from '../../../../common/constants/shared';
import { ParaType } from '../../../../common/types/notebooks';
import { setNavBreadCrumbs } from '../../../../common/utils/set_nav_bread_crumbs';
import { HeaderControlledComponentsWrapper } from '../../../../public/plugin_helpers/plugin_headerControl';
import { coreRefs } from '../../../framework/core_refs';
import PPLService from '../../../services/requests/ppl';
import { GenerateReportLoadingModal } from './helpers/custom_modals/reporting_loading_modal';
import { defaultParagraphParser } from './helpers/default_parser';
Expand All @@ -54,8 +56,6 @@
generateInContextReport,
} from './helpers/reporting_context_menu_helper';
import { Paragraphs } from './paragraph_components/paragraphs';
import { HeaderControlledComponentsWrapper } from '../../../../public/plugin_helpers/plugin_headerControl';
import { coreRefs } from '../../../framework/core_refs';

const newNavigation = coreRefs.chrome?.navGroup.getNavGroupEnabled();

Expand All @@ -78,7 +78,7 @@
http: CoreStart['http'];
parentBreadcrumb: ChromeBreadcrumb;
setBreadcrumbs: (newBreadcrumbs: ChromeBreadcrumb[]) => void;
renameNotebook: (newNoteName: string, noteId: string) => Promise<any>;

Check warning on line 81 in public/components/notebooks/components/notebook.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
cloneNotebook: (newNoteName: string, noteId: string) => Promise<string>;
deleteNotebook: (noteList: string[], toastMessage?: string) => void;
setToast: (title: string, color?: string, text?: string) => void;
Expand All @@ -97,7 +97,7 @@
path: string;
dateCreated: string;
dateModified: string;
paragraphs: any; // notebook paragraphs fetched from API

Check warning on line 100 in public/components/notebooks/components/notebook.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
parsedPara: ParaType[]; // paragraphs parsed to a common format
vizPrefix: string; // prefix for visualizations in Zeppelin Adaptor
isAddParaPopoverOpen: boolean;
Expand Down Expand Up @@ -153,7 +153,7 @@
};

// parse paragraphs based on backend
parseParagraphs = (paragraphs: any[]): ParaType[] => {

Check warning on line 156 in public/components/notebooks/components/notebook.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
try {
const parsedPara = defaultParagraphParser(paragraphs);
parsedPara.forEach((para: ParaType) => {
Expand Down Expand Up @@ -416,7 +416,7 @@
};

return this.props.http
.post(`${NOTEBOOKS_API_PREFIX}/savedNotebook/paragraph/`, {
.post(`${NOTEBOOKS_API_PREFIX}/savedNotebook/paragraph`, {
body: JSON.stringify(addParaObj),
})
.then((res) => {
Expand Down Expand Up @@ -468,7 +468,7 @@
};

return this.props.http
.post(`${NOTEBOOKS_API_PREFIX}/savedNotebook/set_paragraphs/`, {
.post(`${NOTEBOOKS_API_PREFIX}/savedNotebook/set_paragraphs`, {
body: JSON.stringify(moveParaObj),
})
.then((_res) => this.setState({ paragraphs, parsedPara }))
Expand Down Expand Up @@ -499,7 +499,7 @@
noteId: this.props.openedNoteId,
};
this.props.http
.put(`${NOTEBOOKS_API_PREFIX}/savedNotebook/paragraph/clearall/`, {
.put(`${NOTEBOOKS_API_PREFIX}/savedNotebook/paragraph/clearall`, {
body: JSON.stringify(clearParaObj),
})
.then((res) => {
Expand Down Expand Up @@ -537,7 +537,7 @@
};
const isValid = isValidUUID(this.props.openedNoteId);
const route = isValid
? `${NOTEBOOKS_API_PREFIX}/savedNotebook/paragraph/update/run/`
? `${NOTEBOOKS_API_PREFIX}/savedNotebook/paragraph/update/run`
: `${NOTEBOOKS_API_PREFIX}/paragraph/update/run/`;
return this.props.http
.post(route, {
Expand Down Expand Up @@ -587,7 +587,7 @@
}
};

runForAllParagraphs = (reducer: (para: ParaType, _index: number) => Promise<any>) => {

Check warning on line 590 in public/components/notebooks/components/notebook.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
return this.state.parsedPara
.map((para: ParaType, _index: number) => () => reducer(para, _index))
.reduce((chain, func) => chain.then(func), Promise.resolve());
Expand Down Expand Up @@ -685,7 +685,7 @@
this.setState({ dataSourceMDSId: id, dataSourceMDSLabel: label });
};

loadQueryResultsFromInput = async (paragraph: any, dataSourceMDSId?: any) => {

Check warning on line 688 in public/components/notebooks/components/notebook.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type

Check warning on line 688 in public/components/notebooks/components/notebook.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
const queryType =
paragraph.input.inputText.substring(0, 4) === '%sql' ? 'sqlquery' : 'pplquery';
const query = {
Expand Down
10 changes: 5 additions & 5 deletions server/routes/notebooks/paraRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
context,
request,
response
): Promise<IOpenSearchDashboardsResponse<any | ResponseError>> => {

Check warning on line 49 in server/routes/notebooks/paraRouter.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
try {
const runResponse = await BACKEND.updateRunFetchParagraph(
context.observability_plugin.observabilityClient,
Expand Down Expand Up @@ -284,7 +284,7 @@

router.post(
{
path: `${NOTEBOOKS_API_PREFIX}/savedNotebook/paragraph/`,
path: `${NOTEBOOKS_API_PREFIX}/savedNotebook/paragraph`,
validate: {
body: schema.object({
noteId: schema.string(),
Expand Down Expand Up @@ -314,7 +314,7 @@
);
router.put(
{
path: `${NOTEBOOKS_API_PREFIX}/savedNotebook/paragraph/clearall/`,
path: `${NOTEBOOKS_API_PREFIX}/savedNotebook/paragraph/clearall`,
validate: {
body: schema.object({
noteId: schema.string(),
Expand Down Expand Up @@ -377,7 +377,7 @@

router.post(
{
path: `${NOTEBOOKS_API_PREFIX}/savedNotebook/paragraph/update/run/`,
path: `${NOTEBOOKS_API_PREFIX}/savedNotebook/paragraph/update/run`,
validate: {
body: schema.object({
noteId: schema.string(),
Expand Down Expand Up @@ -413,7 +413,7 @@

router.put(
{
path: `${NOTEBOOKS_API_PREFIX}/savedNotebook/paragraph/`,
path: `${NOTEBOOKS_API_PREFIX}/savedNotebook/paragraph`,
validate: {
body: schema.object({
noteId: schema.string(),
Expand Down Expand Up @@ -445,7 +445,7 @@
);
router.post(
{
path: `${NOTEBOOKS_API_PREFIX}/savedNotebook/set_paragraphs/`,
path: `${NOTEBOOKS_API_PREFIX}/savedNotebook/set_paragraphs`,
validate: {
body: schema.object({
noteId: schema.string(),
Expand Down
Loading