diff --git a/x-pack/plugins/observability_ai_assistant/public/components/chat/chat_header.tsx b/x-pack/plugins/observability_ai_assistant/public/components/chat/chat_header.tsx index de8a80928207b..0dc37c7829482 100644 --- a/x-pack/plugins/observability_ai_assistant/public/components/chat/chat_header.tsx +++ b/x-pack/plugins/observability_ai_assistant/public/components/chat/chat_header.tsx @@ -73,14 +73,14 @@ export function ChatHeader({ const handleNavigateToConversations = () => { if (conversationId) { - router.navigateToConversationsApp('/conversations/{conversationId}', { + router.push('/conversations/{conversationId}', { path: { conversationId, }, query: {}, }); } else { - router.navigateToConversationsApp('/conversations/new', { path: {}, query: {} }); + router.push('/conversations/new', { path: {}, query: {} }); } }; diff --git a/x-pack/plugins/observability_ai_assistant/public/hooks/use_observability_ai_assistant_router.ts b/x-pack/plugins/observability_ai_assistant/public/hooks/use_observability_ai_assistant_router.ts index afdae21c91a8d..16e27d1f8505a 100644 --- a/x-pack/plugins/observability_ai_assistant/public/hooks/use_observability_ai_assistant_router.ts +++ b/x-pack/plugins/observability_ai_assistant/public/hooks/use_observability_ai_assistant_router.ts @@ -7,7 +7,6 @@ import { PathsOf, TypeAsArgs, TypeOf } from '@kbn/typed-react-router-config'; import { useMemo } from 'react'; -import { useHistory } from 'react-router-dom'; import { ObservabilityAIAssistantRouter, ObservabilityAIAssistantRoutes } from '../routes/config'; import { observabilityAIAssistantRouter } from '../routes/config'; import { useKibana } from './use_kibana'; @@ -21,15 +20,9 @@ interface StatefulObservabilityAIAssistantRouter extends ObservabilityAIAssistan path: T, ...params: TypeAsArgs> ): void; - navigateToConversationsApp>( - path: T, - ...params: TypeAsArgs> - ): void; } export function useObservabilityAIAssistantRouter(): StatefulObservabilityAIAssistantRouter { - const history = useHistory(); - const { services: { http, @@ -47,43 +40,16 @@ export function useObservabilityAIAssistantRouter(): StatefulObservabilityAIAssi ...observabilityAIAssistantRouter, push: (...args) => { const next = link(...args); - - history.push(next); - }, - navigateToConversationsApp: (path, ...args) => { - const [_, route, routeParam] = path.split('/'); - - const sanitized = routeParam.replace('{', '').replace('}', ''); - - const pathKey = args[0]?.path; - - if (typeof pathKey !== 'object') { - return; - } - - if (Object.keys(pathKey).length === 0) { - navigateToApp('observabilityAIAssistant', { - path: route, - }); - return; - } - - if (Object.keys(pathKey).length === 1) { - navigateToApp('observabilityAIAssistant', { - // @ts-expect-error - path: `${route}/${pathKey[sanitized]}`, - }); - return; - } + navigateToApp('observabilityAIAssistant', { path: next, replace: false }); }, replace: (path, ...args) => { const next = link(path, ...args); - history.replace(next); + navigateToApp('observabilityAIAssistant', { path: next, replace: true }); }, link: (path, ...args) => { return http.basePath.prepend('/app/observabilityAIAssistant' + link(path, ...args)); }, }), - [history, navigateToApp, http.basePath] + [navigateToApp, http.basePath] ); }