Skip to content

Commit

Permalink
Merge pull request #1 from SuZhou-Joe/feature/enable_default_route
Browse files Browse the repository at this point in the history
feat: enable default route
  • Loading branch information
TackAdam authored Jul 5, 2024
2 parents bfa82c8 + 1519828 commit f5e26f3
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 14 deletions.
4 changes: 4 additions & 0 deletions common/constants/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ export const observabilityTracesID = 'observability-traces';
export const observabilityTracesTitle = 'Traces';
export const observabilityTracesPluginOrder = 5093;

export const observabilityServicesID = 'observability-services';
export const observabilityServicesTitle = 'Services';
export const observabilityServicesPluginOrder = 5092;

export const observabilityNotebookID = 'observability-notebooks';
export const observabilityNotebookTitle = 'Notebooks';
export const observabilityNotebookPluginOrder = 5094;
Expand Down
3 changes: 3 additions & 0 deletions public/components/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ interface ObservabilityAppDeps {
dataSourceManagement: DataSourceManagementPluginSetup;
setActionMenu: (menuMount: MountPoint | undefined) => void;
savedObjectsMDSClient: CoreStart['savedObjects'];
defaultRoute?: string;
}

// for cypress to test redux store
Expand Down Expand Up @@ -67,6 +68,7 @@ export const App = ({
setActionMenu,
dataSourceEnabled,
savedObjectsMDSClient,
defaultRoute,
}: ObservabilityAppDeps) => {
const { chrome, http, notifications, savedObjects: coreSavedObjects } = CoreStartProp;
const parentBreadcrumb = {
Expand Down Expand Up @@ -102,6 +104,7 @@ export const App = ({
dataSourceEnabled={dataSourceEnabled}
setActionMenu={setActionMenu}
savedObjectsMDSClient={savedObjectsMDSClient}
defaultRoute={defaultRoute}
/>
</MetricsListener>
</I18nProvider>
Expand Down
4 changes: 3 additions & 1 deletion public/components/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export const Observability = (
startPage: string,
dataSourcePluggables,
dataSourceManagement: DataSourceManagementPluginSetup,
savedObjectsMDSClient: CoreStart['savedObjects']
savedObjectsMDSClient: CoreStart['savedObjects'],
defaultRoute?: string,
) => {
const { setHeaderActionMenu } = AppMountParametersProp;
const { dataSource } = DepsStart;
Expand All @@ -42,6 +43,7 @@ export const Observability = (
setActionMenu={setHeaderActionMenu}
dataSourceEnabled={!!dataSource}
savedObjectsMDSClient={savedObjectsMDSClient}
defaultRoute={defaultRoute}
/>,
AppMountParametersProp.element
);
Expand Down
12 changes: 10 additions & 2 deletions public/components/trace_analytics/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { EuiGlobalToastList } from '@elastic/eui';
import { Toast } from '@elastic/eui/src/components/toast/global_toast_list';
import React, { ReactChild, useEffect, useState } from 'react';
import { HashRouter, Route, RouteComponentProps } from 'react-router-dom';
import { HashRouter, Route, RouteComponentProps, Redirect } from 'react-router-dom';
import {
ChromeBreadcrumb,
ChromeStart,
Expand Down Expand Up @@ -44,6 +44,7 @@ export interface TraceAnalyticsCoreDeps {
dataSourceManagement: DataSourceManagementPluginSetup;
setActionMenu: (menuMount: MountPoint | undefined) => void;
savedObjectsMDSClient: SavedObjectsStart;
defaultRoute?: string;
}

interface HomeProps extends RouteComponentProps, TraceAnalyticsCoreDeps {}
Expand Down Expand Up @@ -119,6 +120,7 @@ export const Home = (props: HomeProps) => {

const [dataSourceMDSId, setDataSourceMDSId] = useState([{ id: '', label: '' }]);
const [currentSelectedService, setCurrentSelectedService] = useState('');
const { defaultRoute = '/services' } = props;

useEffect(() => {
handleDataPrepperIndicesExistRequest(
Expand Down Expand Up @@ -326,7 +328,7 @@ export const Home = (props: HomeProps) => {
/>
<Route
exact
path={['/services', '/']}
path={['/services']}
render={(_routerProps) => (
<TraceSideBar>
<Services
Expand Down Expand Up @@ -364,6 +366,12 @@ export const Home = (props: HomeProps) => {
/>
)}
/>
<Route
path="/"
render={() => (
<Redirect to={defaultRoute} />
)}
/>
</HashRouter>
{flyout}
{spanFlyoutComponent}
Expand Down
33 changes: 22 additions & 11 deletions public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ import {
observabilityPanelsTitle,
observabilityPanelsTitleForNav,
observabilityPluginOrder,
observabilityServicesPluginOrder,
observabilityServicesTitle,
observabilityTracesID,
observabilityTracesPluginOrder,
observabilityTracesTitle,
Expand Down Expand Up @@ -269,7 +271,7 @@ export class ObservabilityPlugin
// prometheus: openSearchLocalDataSourcePluggable
};

const appMountWithStartPage = (startPage: string) => async (params: AppMountParameters) => {
const appMountWithStartPage = (startPage: string, defaultRoute?: string) => async (params: AppMountParameters) => {
const { Observability } = await import('./components/index');
const [coreStart, depsStart] = await core.getStartServices();
const dslService = new DSLService(coreStart.http);
Expand All @@ -288,7 +290,8 @@ export class ObservabilityPlugin
startPage,
dataSourcePluggables, // just pass down for now due to time constraint, later may better expose this as context
dataSourceManagement,
coreStart.savedObjects
coreStart.savedObjects,
defaultRoute,
);
};

Expand Down Expand Up @@ -326,15 +329,23 @@ export class ObservabilityPlugin

// NEEDS CORRECTION OR REFACTOR //ADAM
// The new-added applications need to be wrapped by a feature flag check.
// if (core.chrome.navGroup.getNavGroupEnabled()) {
// core.application.register({
// id: "observability-traces-nav",
// title: observabilityTracesTitle,
// order: observabilityTracesPluginOrder,
// category: DEFAULT_APP_CATEGORIES.investigate,
// mount: appMountWithStartPage('traces'),
// });
// }
if (core.chrome.navGroup.getNavGroupEnabled()) {
core.application.register({
id: "observability-traces-nav",
title: observabilityTracesTitle,
order: observabilityTracesPluginOrder,
category: DEFAULT_APP_CATEGORIES.investigate,
mount: appMountWithStartPage('traces', '/traces'),
});

core.application.register({
id: "observability-services-nav",
title: observabilityServicesTitle,
order: observabilityServicesPluginOrder,
category: DEFAULT_APP_CATEGORIES.investigate,
mount: appMountWithStartPage('traces', '/services'),
});
}

core.application.register({
id: observabilityNotebookID,
Expand Down
11 changes: 11 additions & 0 deletions public/plugin_nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,15 @@ export function registerAllPluginNavGroups(core: CoreSetup<AppPluginStartDepende
category: DEFAULT_APP_CATEGORIES.dashboardAndReport,
},
]);

core.chrome.navGroup.addNavLinksToGroup(DEFAULT_NAV_GROUPS.analytics, [
{
id: 'observability-traces-nav',
category: DEFAULT_APP_CATEGORIES.investigate,
},
{
id: 'observability-services-nav',
category: DEFAULT_APP_CATEGORIES.investigate,
},
]);
}

0 comments on commit f5e26f3

Please sign in to comment.