-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remember tab choice between logs explorer and discover (#194930)
Closes #193321 ## Summary The PR adds the redirection point when "Discover" menu item is clicked on the sidenav in serverless (or solution nav on stateful). Based on what tab between "Discover" or "Logs Explorer" the user clicked recently, "Discover" will point to that app/tab. Previously, "Discover" would always point to "Logs Explorer" on serverless and to "Discover" on stateful. In order to implement this, a temporary app `last-used-logs-viewer` is registered in `observability-logs-explorer` plugin whose only job is to read the last stored value in local storage and perform the redirection. Doing the redirection from a temporary app should help prevent triggering unnecessary telemetry and history entries. And it should be fairly easy to undo once context aware redirection is in place. ~With this implementation, only the behavior of user clicking "Discover" on the sidenav and clicking the tabs is affected and any deeplinks from other apps or direct links should work as is.~ The tab choice will be updated even if the apps are visited via url. https://github.com/user-attachments/assets/8a0308db-9ddb-47b6-b1a5-8ed70662040d --------- Co-authored-by: kibanamachine <[email protected]>
- Loading branch information
1 parent
c53b2a8
commit fed9a19
Showing
14 changed files
with
287 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...bility_solution/observability_logs_explorer/public/applications/last_used_logs_viewer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React, { useEffect } from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import { useLocation } from 'react-router-dom'; | ||
import useLocalStorage from 'react-use/lib/useLocalStorage'; | ||
import { Router } from '@kbn/shared-ux-router'; | ||
import { | ||
OBSERVABILITY_LOGS_EXPLORER_APP_ID, | ||
OBS_LOGS_EXPLORER_LOGS_VIEWER_KEY, | ||
} from '@kbn/deeplinks-observability'; | ||
import { DISCOVER_APP_ID } from '@kbn/deeplinks-analytics'; | ||
import { AppMountParameters, CoreStart } from '@kbn/core/public'; | ||
|
||
export const renderLastUsedLogsViewerRedirect = ( | ||
core: CoreStart, | ||
appParams: AppMountParameters | ||
) => { | ||
ReactDOM.render( | ||
<Router history={appParams.history}> | ||
<LastUsedLogsViewerRedirect core={core} /> | ||
</Router>, | ||
appParams.element | ||
); | ||
|
||
return () => { | ||
ReactDOM.unmountComponentAtNode(appParams.element); | ||
}; | ||
}; | ||
|
||
export const LastUsedLogsViewerRedirect = ({ core }: { core: CoreStart }) => { | ||
const location = useLocation(); | ||
const path = `${location.pathname}${location.search}`; | ||
const [lastUsedLogsViewApp] = useLocalStorage< | ||
typeof DISCOVER_APP_ID | typeof OBSERVABILITY_LOGS_EXPLORER_APP_ID | ||
>(OBS_LOGS_EXPLORER_LOGS_VIEWER_KEY, OBSERVABILITY_LOGS_EXPLORER_APP_ID); | ||
|
||
if ( | ||
lastUsedLogsViewApp && | ||
lastUsedLogsViewApp !== DISCOVER_APP_ID && | ||
lastUsedLogsViewApp !== OBSERVABILITY_LOGS_EXPLORER_APP_ID | ||
) { | ||
throw new Error( | ||
`Invalid last used logs viewer app: "${lastUsedLogsViewApp}". Allowed values are "${DISCOVER_APP_ID}" and "${OBSERVABILITY_LOGS_EXPLORER_APP_ID}"` | ||
); | ||
} | ||
|
||
useEffect(() => { | ||
if (lastUsedLogsViewApp === DISCOVER_APP_ID) { | ||
core.application.navigateToApp(DISCOVER_APP_ID, { replace: true, path }); | ||
} | ||
|
||
if (lastUsedLogsViewApp === OBSERVABILITY_LOGS_EXPLORER_APP_ID) { | ||
core.application.navigateToApp(OBSERVABILITY_LOGS_EXPLORER_APP_ID, { replace: true, path }); | ||
} | ||
}, [core, path, lastUsedLogsViewApp]); | ||
|
||
return <></>; | ||
}; |
Oops, something went wrong.