From 1519828b741dba2bb0481676d2723466bb282ec8 Mon Sep 17 00:00:00 2001 From: SuZhou-Joe Date: Fri, 5 Jul 2024 18:27:15 +0800 Subject: [PATCH] feat: enable default route Signed-off-by: SuZhou-Joe --- common/constants/shared.ts | 4 +++ public/components/app.tsx | 3 ++ public/components/index.tsx | 4 ++- public/components/trace_analytics/home.tsx | 12 ++++++-- public/plugin.tsx | 33 ++++++++++++++-------- public/plugin_nav.tsx | 11 ++++++++ 6 files changed, 53 insertions(+), 14 deletions(-) diff --git a/common/constants/shared.ts b/common/constants/shared.ts index 616175c7c9..bafb5bf348 100644 --- a/common/constants/shared.ts +++ b/common/constants/shared.ts @@ -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; diff --git a/public/components/app.tsx b/public/components/app.tsx index 1b7150a8cf..6ddaf92534 100644 --- a/public/components/app.tsx +++ b/public/components/app.tsx @@ -35,6 +35,7 @@ interface ObservabilityAppDeps { dataSourceManagement: DataSourceManagementPluginSetup; setActionMenu: (menuMount: MountPoint | undefined) => void; savedObjectsMDSClient: CoreStart['savedObjects']; + defaultRoute?: string; } // for cypress to test redux store @@ -67,6 +68,7 @@ export const App = ({ setActionMenu, dataSourceEnabled, savedObjectsMDSClient, + defaultRoute, }: ObservabilityAppDeps) => { const { chrome, http, notifications, savedObjects: coreSavedObjects } = CoreStartProp; const parentBreadcrumb = { @@ -102,6 +104,7 @@ export const App = ({ dataSourceEnabled={dataSourceEnabled} setActionMenu={setActionMenu} savedObjectsMDSClient={savedObjectsMDSClient} + defaultRoute={defaultRoute} /> diff --git a/public/components/index.tsx b/public/components/index.tsx index b1ebf1211b..c6dff99e68 100644 --- a/public/components/index.tsx +++ b/public/components/index.tsx @@ -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; @@ -42,6 +43,7 @@ export const Observability = ( setActionMenu={setHeaderActionMenu} dataSourceEnabled={!!dataSource} savedObjectsMDSClient={savedObjectsMDSClient} + defaultRoute={defaultRoute} />, AppMountParametersProp.element ); diff --git a/public/components/trace_analytics/home.tsx b/public/components/trace_analytics/home.tsx index 391c97f236..d7ced3a35e 100644 --- a/public/components/trace_analytics/home.tsx +++ b/public/components/trace_analytics/home.tsx @@ -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, @@ -44,6 +44,7 @@ export interface TraceAnalyticsCoreDeps { dataSourceManagement: DataSourceManagementPluginSetup; setActionMenu: (menuMount: MountPoint | undefined) => void; savedObjectsMDSClient: SavedObjectsStart; + defaultRoute?: string; } interface HomeProps extends RouteComponentProps, TraceAnalyticsCoreDeps {} @@ -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( @@ -326,7 +328,7 @@ export const Home = (props: HomeProps) => { /> ( { /> )} /> + ( + + )} + /> {flyout} {spanFlyoutComponent} diff --git a/public/plugin.tsx b/public/plugin.tsx index 0db2caa21e..36ce2f340c 100644 --- a/public/plugin.tsx +++ b/public/plugin.tsx @@ -52,6 +52,8 @@ import { observabilityPanelsTitle, observabilityPanelsTitleForNav, observabilityPluginOrder, + observabilityServicesPluginOrder, + observabilityServicesTitle, observabilityTracesID, observabilityTracesPluginOrder, observabilityTracesTitle, @@ -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); @@ -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, ); }; @@ -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, diff --git a/public/plugin_nav.tsx b/public/plugin_nav.tsx index d7df3092bb..20bdd63fae 100644 --- a/public/plugin_nav.tsx +++ b/public/plugin_nav.tsx @@ -124,4 +124,15 @@ export function registerAllPluginNavGroups(core: CoreSetup