From 46e78297415690e781685bb5455d22401d3a2106 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 6 Dec 2024 18:02:54 +0000 Subject: [PATCH] [Bug] Fix notebook routes for savedNotebook endpoints (#2279) * Fix notebook routes to remove extra slash Signed-off-by: Shenoy Pratik * revert legacy notebook api route change Signed-off-by: Shenoy Pratik --------- Signed-off-by: Shenoy Pratik (cherry picked from commit 4f894deaab0d216d82adfff41c6382eb7bda3b94) Signed-off-by: github-actions[bot] --- .../components/notebooks/components/main.tsx | 8 +++++--- .../notebooks/components/notebook.tsx | 18 +++++++++--------- server/routes/notebooks/paraRouter.ts | 10 +++++----- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/public/components/notebooks/components/main.tsx b/public/components/notebooks/components/main.tsx index 70cab4c7f..2d0d34166 100644 --- a/public/components/notebooks/components/main.tsx +++ b/public/components/notebooks/components/main.tsx @@ -98,7 +98,7 @@ export class Main extends React.Component { 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 }); }) @@ -106,9 +106,11 @@ export class Main extends React.Component { 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]) => { diff --git a/public/components/notebooks/components/notebook.tsx b/public/components/notebooks/components/notebook.tsx index 92b675899..00ee14fda 100644 --- a/public/components/notebooks/components/notebook.tsx +++ b/public/components/notebooks/components/notebook.tsx @@ -4,9 +4,9 @@ */ import { - EuiSmallButton, EuiButtonGroup, EuiButtonGroupOptionProps, + EuiButtonIcon, EuiCallOut, EuiCard, EuiContextMenu, @@ -19,18 +19,18 @@ import { 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, @@ -43,6 +43,8 @@ import { CREATE_NOTE_MESSAGE, NOTEBOOKS_API_PREFIX } from '../../../../common/co 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'; @@ -54,8 +56,6 @@ import { 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(); @@ -416,7 +416,7 @@ export class Notebook extends Component { }; return this.props.http - .post(`${NOTEBOOKS_API_PREFIX}/savedNotebook/paragraph/`, { + .post(`${NOTEBOOKS_API_PREFIX}/savedNotebook/paragraph`, { body: JSON.stringify(addParaObj), }) .then((res) => { @@ -468,7 +468,7 @@ export class Notebook extends Component { }; 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 })) @@ -499,7 +499,7 @@ export class Notebook extends Component { 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) => { @@ -537,7 +537,7 @@ export class Notebook extends Component { }; 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, { diff --git a/server/routes/notebooks/paraRouter.ts b/server/routes/notebooks/paraRouter.ts index 16a3e3678..916c106b3 100644 --- a/server/routes/notebooks/paraRouter.ts +++ b/server/routes/notebooks/paraRouter.ts @@ -284,7 +284,7 @@ export function registerParaRoute(router: IRouter) { router.post( { - path: `${NOTEBOOKS_API_PREFIX}/savedNotebook/paragraph/`, + path: `${NOTEBOOKS_API_PREFIX}/savedNotebook/paragraph`, validate: { body: schema.object({ noteId: schema.string(), @@ -314,7 +314,7 @@ export function registerParaRoute(router: IRouter) { ); router.put( { - path: `${NOTEBOOKS_API_PREFIX}/savedNotebook/paragraph/clearall/`, + path: `${NOTEBOOKS_API_PREFIX}/savedNotebook/paragraph/clearall`, validate: { body: schema.object({ noteId: schema.string(), @@ -377,7 +377,7 @@ export function registerParaRoute(router: IRouter) { 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(), @@ -413,7 +413,7 @@ export function registerParaRoute(router: IRouter) { router.put( { - path: `${NOTEBOOKS_API_PREFIX}/savedNotebook/paragraph/`, + path: `${NOTEBOOKS_API_PREFIX}/savedNotebook/paragraph`, validate: { body: schema.object({ noteId: schema.string(), @@ -445,7 +445,7 @@ export function registerParaRoute(router: IRouter) { ); router.post( { - path: `${NOTEBOOKS_API_PREFIX}/savedNotebook/set_paragraphs/`, + path: `${NOTEBOOKS_API_PREFIX}/savedNotebook/set_paragraphs`, validate: { body: schema.object({ noteId: schema.string(),