Skip to content

Commit

Permalink
[8.15] [Logs Explorer] Fix logs side nav default navigation (#198773) (
Browse files Browse the repository at this point in the history
…#198831)

# Backport

This will backport the following commits from `main` to `8.15`:
- [[Logs Explorer] Fix logs side nav default navigation
(#198773)](#198773)

<!--- Backport version: 8.9.8 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT
[{"author":{"name":"mohamedhamed-ahmed","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-11-04T17:06:13Z","message":"[Logs
Explorer] Fix logs side nav default navigation (#198773)\n\ncloses
https://github.com/elastic/kibana/issues/198766","sha":"0e4b9e0b60e5fe3346a5336b0f7ccca6e08b9eca","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:skip","v9.0.0","ci:project-deploy-observability","Team:obs-ux-logs","v8.15.0","v8.16.0","backport:version","v8.17.0"],"number":198773,"url":"https://github.com/elastic/kibana/pull/198773","mergeCommit":{"message":"[Logs
Explorer] Fix logs side nav default navigation (#198773)\n\ncloses
https://github.com/elastic/kibana/issues/198766","sha":"0e4b9e0b60e5fe3346a5336b0f7ccca6e08b9eca"}},"sourceBranch":"main","suggestedTargetBranches":["8.15","8.16","8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","labelRegex":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/198773","number":198773,"mergeCommit":{"message":"[Logs
Explorer] Fix logs side nav default navigation (#198773)\n\ncloses
https://github.com/elastic/kibana/issues/198766","sha":"0e4b9e0b60e5fe3346a5336b0f7ccca6e08b9eca"}},{"branch":"8.15","label":"v8.15.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.16","label":"v8.16.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.x","label":"v8.17.0","labelRegex":"^v8.17.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->
  • Loading branch information
mohamedhamed-ahmed authored Nov 5, 2024
1 parent 2469ffb commit 10f0172
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,13 @@
*/

import { History } from 'history';
import React, { useMemo } from 'react';
import ReactDOM from 'react-dom';
import useObservable from 'react-use/lib/useObservable';
import { map } from 'rxjs';
import { CoreStart } from '@kbn/core/public';
import React from 'react';
import ReactDOM from 'react-dom';
import { Router, Routes, Route } from '@kbn/shared-ux-router';
import { AppMountParameters, AppStatus } from '@kbn/core/public';
import { AppMountParameters } from '@kbn/core/public';
import { Storage } from '@kbn/kibana-utils-plugin/public';
import {
AllDatasetsLocatorParams,
ALL_DATASETS_LOCATOR_ID,
OBSERVABILITY_LOGS_EXPLORER_APP_ID,
} from '@kbn/deeplinks-observability';
import { AllDatasetsLocatorParams, ALL_DATASETS_LOCATOR_ID } from '@kbn/deeplinks-observability';
import { LinkToLogsPage } from '../pages/link_to/link_to_logs';
import { LogsPage } from '../pages/logs';
import { InfraClientStartDeps, InfraClientStartExports } from '../types';
Expand All @@ -30,6 +24,7 @@ export const renderApp = (
core: CoreStart,
plugins: InfraClientStartDeps,
pluginStart: InfraClientStartExports,
isLogsExplorerAccessible: boolean,
{ element, history, setHeaderActionMenu, theme$ }: AppMountParameters
) => {
const storage = new Storage(window.localStorage);
Expand All @@ -45,6 +40,7 @@ export const renderApp = (
pluginStart={pluginStart}
setHeaderActionMenu={setHeaderActionMenu}
theme$={theme$}
isLogsExplorerAccessible={isLogsExplorerAccessible}
/>,
element
);
Expand All @@ -62,26 +58,18 @@ const LogsApp: React.FC<{
setHeaderActionMenu: AppMountParameters['setHeaderActionMenu'];
storage: Storage;
theme$: AppMountParameters['theme$'];
}> = ({ core, history, pluginStart, plugins, setHeaderActionMenu, storage, theme$ }) => {
const {
capabilities: { logs },
applications$,
} = core.application;

const isLogsExplorerAppAccessible = useObservable(
useMemo(
() =>
applications$.pipe(
map(
(apps) =>
(apps.get(OBSERVABILITY_LOGS_EXPLORER_APP_ID)?.status ?? AppStatus.inaccessible) ===
AppStatus.accessible
)
),
[applications$]
),
false
);
isLogsExplorerAccessible: boolean;
}> = ({
core,
history,
pluginStart,
plugins,
setHeaderActionMenu,
storage,
theme$,
isLogsExplorerAccessible,
}) => {
const { logs } = core.application.capabilities;

return (
<CoreProviders core={core} pluginStart={pluginStart} plugins={plugins} theme$={theme$}>
Expand All @@ -98,7 +86,7 @@ const LogsApp: React.FC<{
toastsService={core.notifications.toasts}
>
<Routes>
{isLogsExplorerAppAccessible && (
{isLogsExplorerAccessible && (
<Route
path="/"
exact
Expand Down
7 changes: 6 additions & 1 deletion x-pack/plugins/observability_solution/infra/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
switchMap,
of,
distinctUntilChanged,
firstValueFrom,
} from 'rxjs';
import type { EmbeddableApiContext } from '@kbn/presentation-publishing';
import { apiCanAddNewPanel } from '@kbn/presentation-containers';
Expand Down Expand Up @@ -260,8 +261,12 @@ export class Plugin implements InfraClientPluginClass {
// mount callback should not use setup dependencies, get start dependencies instead
const [coreStart, plugins, pluginStart] = await core.getStartServices();

const isLogsExplorerAccessible = await firstValueFrom(
getLogsExplorerAccessible$(coreStart.application)
);

const { renderApp } = await import('./apps/logs_app');
return renderApp(coreStart, plugins, pluginStart, params);
return renderApp(coreStart, plugins, pluginStart, isLogsExplorerAccessible, params);
},
});
}
Expand Down

0 comments on commit 10f0172

Please sign in to comment.