Skip to content

Commit 7ea2758

Browse files
sorenlouvfkanout
authored andcommitted
[Obs AI Assistant] Simplify routing (elastic#176569)
Minor simplification to how we link into the conversation app
1 parent f50602c commit 7ea2758

File tree

2 files changed

+5
-39
lines changed

2 files changed

+5
-39
lines changed

x-pack/plugins/observability_ai_assistant/public/components/chat/chat_header.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@ export function ChatHeader({
7373

7474
const handleNavigateToConversations = () => {
7575
if (conversationId) {
76-
router.navigateToConversationsApp('/conversations/{conversationId}', {
76+
router.push('/conversations/{conversationId}', {
7777
path: {
7878
conversationId,
7979
},
8080
query: {},
8181
});
8282
} else {
83-
router.navigateToConversationsApp('/conversations/new', { path: {}, query: {} });
83+
router.push('/conversations/new', { path: {}, query: {} });
8484
}
8585
};
8686

x-pack/plugins/observability_ai_assistant/public/hooks/use_observability_ai_assistant_router.ts

+3-37
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import { PathsOf, TypeAsArgs, TypeOf } from '@kbn/typed-react-router-config';
99
import { useMemo } from 'react';
10-
import { useHistory } from 'react-router-dom';
1110
import { ObservabilityAIAssistantRouter, ObservabilityAIAssistantRoutes } from '../routes/config';
1211
import { observabilityAIAssistantRouter } from '../routes/config';
1312
import { useKibana } from './use_kibana';
@@ -21,15 +20,9 @@ interface StatefulObservabilityAIAssistantRouter extends ObservabilityAIAssistan
2120
path: T,
2221
...params: TypeAsArgs<TypeOf<ObservabilityAIAssistantRoutes, T>>
2322
): void;
24-
navigateToConversationsApp<T extends PathsOf<ObservabilityAIAssistantRoutes>>(
25-
path: T,
26-
...params: TypeAsArgs<TypeOf<ObservabilityAIAssistantRoutes, T>>
27-
): void;
2823
}
2924

3025
export function useObservabilityAIAssistantRouter(): StatefulObservabilityAIAssistantRouter {
31-
const history = useHistory();
32-
3326
const {
3427
services: {
3528
http,
@@ -47,43 +40,16 @@ export function useObservabilityAIAssistantRouter(): StatefulObservabilityAIAssi
4740
...observabilityAIAssistantRouter,
4841
push: (...args) => {
4942
const next = link(...args);
50-
51-
history.push(next);
52-
},
53-
navigateToConversationsApp: (path, ...args) => {
54-
const [_, route, routeParam] = path.split('/');
55-
56-
const sanitized = routeParam.replace('{', '').replace('}', '');
57-
58-
const pathKey = args[0]?.path;
59-
60-
if (typeof pathKey !== 'object') {
61-
return;
62-
}
63-
64-
if (Object.keys(pathKey).length === 0) {
65-
navigateToApp('observabilityAIAssistant', {
66-
path: route,
67-
});
68-
return;
69-
}
70-
71-
if (Object.keys(pathKey).length === 1) {
72-
navigateToApp('observabilityAIAssistant', {
73-
// @ts-expect-error
74-
path: `${route}/${pathKey[sanitized]}`,
75-
});
76-
return;
77-
}
43+
navigateToApp('observabilityAIAssistant', { path: next, replace: false });
7844
},
7945
replace: (path, ...args) => {
8046
const next = link(path, ...args);
81-
history.replace(next);
47+
navigateToApp('observabilityAIAssistant', { path: next, replace: true });
8248
},
8349
link: (path, ...args) => {
8450
return http.basePath.prepend('/app/observabilityAIAssistant' + link(path, ...args));
8551
},
8652
}),
87-
[history, navigateToApp, http.basePath]
53+
[navigateToApp, http.basePath]
8854
);
8955
}

0 commit comments

Comments
 (0)