From 898d51547cb9dd3c47e31b029de36ef185be665a Mon Sep 17 00:00:00 2001 From: Derek Ho Date: Thu, 19 Oct 2023 16:02:09 -0400 Subject: [PATCH 1/3] Use application navigateToApp instead of window.location.assign Signed-off-by: Derek Ho --- .../context_menu/context_menu_helpers.js | 8 ++++++-- public/components/utils/application_service.ts | 15 +++++++++++++++ public/components/utils/settings_service.ts | 1 + public/plugin.ts | 2 ++ 4 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 public/components/utils/application_service.ts diff --git a/public/components/context_menu/context_menu_helpers.js b/public/components/context_menu/context_menu_helpers.js index 1a1e9959..d8d37284 100644 --- a/public/components/context_menu/context_menu_helpers.js +++ b/public/components/context_menu/context_menu_helpers.js @@ -13,6 +13,8 @@ import { } from './context_menu_ui'; import { timeRangeMatcher } from '../utils/utils'; import { unhashUrl } from '../../../../../src/plugins/opensearch_dashboards_utils/public'; +import { PLUGIN_ID } from '../../../common'; +import { applicationService } from '../utils/application_service'; const getReportSourceURL = (baseURI) => { const url = baseURI.substr(0, baseURI.indexOf('?')); @@ -20,8 +22,10 @@ const getReportSourceURL = (baseURI) => { return reportSourceId; }; -export const contextMenuViewReports = () => - window.location.assign('reports-dashboards#/'); +export const contextMenuViewReports = () => { + applicationService.getApplication().navigateToApp(PLUGIN_ID); + +} export const getTimeFieldsFromUrl = () => { const url = unhashUrl(window.location.href); diff --git a/public/components/utils/application_service.ts b/public/components/utils/application_service.ts new file mode 100644 index 00000000..b32862db --- /dev/null +++ b/public/components/utils/application_service.ts @@ -0,0 +1,15 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { ApplicationStart} from '../../../../../src/core/public'; + +let application: ApplicationStart + +export const applicationService = { + init: (applicationStart: ApplicationStart) => { + application = applicationStart + }, + getApplication: () => application, +}; diff --git a/public/components/utils/settings_service.ts b/public/components/utils/settings_service.ts index 4a15e831..ec8c85eb 100644 --- a/public/components/utils/settings_service.ts +++ b/public/components/utils/settings_service.ts @@ -33,4 +33,5 @@ export const uiSettingsService = { }; }, getHttpClient: () => http, + getApplication: () => application, }; diff --git a/public/plugin.ts b/public/plugin.ts index b91b6be1..c7e18f4b 100644 --- a/public/plugin.ts +++ b/public/plugin.ts @@ -18,6 +18,7 @@ import { i18n } from '@osd/i18n'; import './components/context_menu/context_menu'; import { PLUGIN_ID, PLUGIN_NAME } from '../common'; import { uiSettingsService } from './components/utils/settings_service'; +import { applicationService } from './components/utils/application_service'; export class ReportsDashboardsPlugin implements Plugin @@ -57,6 +58,7 @@ export class ReportsDashboardsPlugin } public start(core: CoreStart): ReportsDashboardsPluginStart { + applicationService.init(core.application); return {}; } From aa9c258f84fabde5c42c7bb92a276fb1e4824708 Mon Sep 17 00:00:00 2001 From: Derek Ho Date: Thu, 19 Oct 2023 16:05:54 -0400 Subject: [PATCH 2/3] Remove changes Signed-off-by: Derek Ho --- public/components/utils/settings_service.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/public/components/utils/settings_service.ts b/public/components/utils/settings_service.ts index ec8c85eb..4a15e831 100644 --- a/public/components/utils/settings_service.ts +++ b/public/components/utils/settings_service.ts @@ -33,5 +33,4 @@ export const uiSettingsService = { }; }, getHttpClient: () => http, - getApplication: () => application, }; From bcffed619cf93f812c9ccd2839f6527a2e21fa0d Mon Sep 17 00:00:00 2001 From: Derek Ho Date: Thu, 19 Oct 2023 16:08:04 -0400 Subject: [PATCH 3/3] Fix formatting Signed-off-by: Derek Ho --- public/components/context_menu/context_menu_helpers.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/public/components/context_menu/context_menu_helpers.js b/public/components/context_menu/context_menu_helpers.js index d8d37284..c0965d2e 100644 --- a/public/components/context_menu/context_menu_helpers.js +++ b/public/components/context_menu/context_menu_helpers.js @@ -22,10 +22,7 @@ const getReportSourceURL = (baseURI) => { return reportSourceId; }; -export const contextMenuViewReports = () => { - applicationService.getApplication().navigateToApp(PLUGIN_ID); - -} +export const contextMenuViewReports = () => applicationService.getApplication().navigateToApp(PLUGIN_ID); export const getTimeFieldsFromUrl = () => { const url = unhashUrl(window.location.href);