Skip to content

Commit

Permalink
Use core navigation instead of hard coding URLs (#229) (#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
opensearch-trigger-bot[bot] committed Oct 19, 2023
1 parent 05548e4 commit 235680a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
5 changes: 3 additions & 2 deletions public/components/context_menu/context_menu_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@ 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('?'));
const reportSourceId = url.substr(url.lastIndexOf('/') + 1, url.length);
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);
Expand Down
15 changes: 15 additions & 0 deletions public/components/utils/application_service.ts
Original file line number Diff line number Diff line change
@@ -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,
};
2 changes: 2 additions & 0 deletions public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ReportsDashboardsPluginSetup, ReportsDashboardsPluginStart>
Expand Down Expand Up @@ -57,6 +58,7 @@ export class ReportsDashboardsPlugin
}

public start(core: CoreStart): ReportsDashboardsPluginStart {
applicationService.init(core.application);
return {};
}

Expand Down

0 comments on commit 235680a

Please sign in to comment.