From 2f78f54c5bcb8321b13a2fe8aef07eb3762c47ed Mon Sep 17 00:00:00 2001 From: Joshua Li Date: Mon, 17 Apr 2023 16:15:05 -0700 Subject: [PATCH] Support new notebooks URL for reporting (#373) Signed-off-by: Joshua Li --- .../helpers/__tests__/legacy_route_helpers.test.ts | 8 ++++---- .../notebooks/components/helpers/legacy_route_helpers.ts | 8 ++++---- .../components/helpers/reporting_context_menu_helper.tsx | 3 +-- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/public/components/notebooks/components/helpers/__tests__/legacy_route_helpers.test.ts b/public/components/notebooks/components/helpers/__tests__/legacy_route_helpers.test.ts index c4d1a7855..c156d73e7 100644 --- a/public/components/notebooks/components/helpers/__tests__/legacy_route_helpers.test.ts +++ b/public/components/notebooks/components/helpers/__tests__/legacy_route_helpers.test.ts @@ -26,10 +26,10 @@ describe('Test legacy route helpers', () => { }, ] as Location[]; const expected = [ - '/app/observability-dashboards#/notebooks/GQ5icXwBJCegTOBKO4Um', - '/app/observability-dashboards#/notebooks/clPiPXwBEM7l9gC0xTpA?view=view_both', - `/testBasePath/app/observability-dashboards#/notebooks/GQ5icXwBJCegTOBKO4Um?_g=(time:(from:'2021-10-15T20:25:09.556Z',to:'2021-10-15T20:55:09.556Z'))&view=output_only&security_tenant=global`, - ] as RedirectProps['to'][]; + '/app/observability-notebooks#/GQ5icXwBJCegTOBKO4Um', + '/app/observability-notebooks#/clPiPXwBEM7l9gC0xTpA?view=view_both', + `/testBasePath/app/observability-notebooks#/GQ5icXwBJCegTOBKO4Um?_g=(time:(from:'2021-10-15T20:25:09.556Z',to:'2021-10-15T20:55:09.556Z'))&view=output_only&security_tenant=global`, + ] as Array; expect(locations.map((location) => convertLegacyNotebooksUrl(location))).toEqual(expected); }); }); diff --git a/public/components/notebooks/components/helpers/legacy_route_helpers.ts b/public/components/notebooks/components/helpers/legacy_route_helpers.ts index 8bda04cc5..1201d9f22 100644 --- a/public/components/notebooks/components/helpers/legacy_route_helpers.ts +++ b/public/components/notebooks/components/helpers/legacy_route_helpers.ts @@ -3,11 +3,11 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { observabilityID } from "../../../../../common/constants/shared"; +import { observabilityNotebookID } from '../../../../../common/constants/shared'; -export const convertLegacyNotebooksUrl = (location: Location)=> { - const pathname = location.pathname.replace('notebooks-dashboards', observabilityID); - const hash = `#/notebooks${location.hash.replace(/^#/, '')}${ +export const convertLegacyNotebooksUrl = (location: Location) => { + const pathname = location.pathname.replace('notebooks-dashboards', observabilityNotebookID); + const hash = `${location.hash}${ location.hash.includes('?') ? location.search.replace(/^\?/, '&') : location.search }`; return pathname + hash; diff --git a/public/components/notebooks/components/helpers/reporting_context_menu_helper.tsx b/public/components/notebooks/components/helpers/reporting_context_menu_helper.tsx index 1269d24c1..2f382519a 100644 --- a/public/components/notebooks/components/helpers/reporting_context_menu_helper.tsx +++ b/public/components/notebooks/components/helpers/reporting_context_menu_helper.tsx @@ -116,8 +116,7 @@ export const generateInContextReport = async ( toggleReportingLoadingModal(true); let baseUrl = location.pathname + - location.hash.replace(/\?view=(view_both|input_only|output_only)/, '') + - '?view=output_only'; + location.hash.replace(/view=(view_both|input_only|output_only)/, 'view=output_only'); // Add selected tenant info to url try { const tenant = await getTenantInfoIfExists();