Skip to content

Commit

Permalink
[Logs Explorer] Fix logs side nav default navigation (#198773)
Browse files Browse the repository at this point in the history
closes #198766
  • Loading branch information
mohamedhamed-ahmed authored Nov 4, 2024
1 parent cfbf935 commit 0e4b9e0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,13 @@
*/

import { History } from 'history';
import { AppStatus, CoreStart } from '@kbn/core/public';
import React, { useMemo } from 'react';
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 } 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 useObservable from 'react-use/lib/useObservable';
import { map } from 'rxjs';
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,24 +58,19 @@ const LogsApp: React.FC<{
setHeaderActionMenu: AppMountParameters['setHeaderActionMenu'];
storage: Storage;
theme$: AppMountParameters['theme$'];
}> = ({ core, history, pluginStart, plugins, setHeaderActionMenu, storage, theme$ }) => {
isLogsExplorerAccessible: boolean;
}> = ({
core,
history,
pluginStart,
plugins,
setHeaderActionMenu,
storage,
theme$,
isLogsExplorerAccessible,
}) => {
const { logs } = core.application.capabilities;

const isLogsExplorerAppAccessible = useObservable(
useMemo(
() =>
core.application.applications$.pipe(
map(
(apps) =>
(apps.get(OBSERVABILITY_LOGS_EXPLORER_APP_ID)?.status ?? AppStatus.inaccessible) ===
AppStatus.accessible
)
),
[core.application.applications$]
),
false
);

return (
<CoreProviders core={core} pluginStart={pluginStart} plugins={plugins} theme$={theme$}>
<CommonInfraProviders
Expand All @@ -95,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 @@ -29,6 +29,7 @@ import {
of,
switchMap,
map,
firstValueFrom,
} from 'rxjs';
import type { EmbeddableApiContext } from '@kbn/presentation-publishing';
import { apiCanAddNewPanel } from '@kbn/presentation-containers';
Expand Down Expand Up @@ -231,8 +232,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 0e4b9e0

Please sign in to comment.