Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.16] [Logs Explorer] Fix logs side nav default navigation (#198773) #198830

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
18 changes: 15 additions & 3 deletions x-pack/plugins/observability_solution/infra/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,16 @@ import {
MetricsExplorerLocatorParams,
ObservabilityTriggerId,
} from '@kbn/observability-shared-plugin/common';
import { BehaviorSubject, combineLatest, distinctUntilChanged, from, of, switchMap } from 'rxjs';
import { map } from 'rxjs';
import {
BehaviorSubject,
combineLatest,
distinctUntilChanged,
from,
of,
switchMap,
map,
firstValueFrom,
} from 'rxjs';
import type { EmbeddableApiContext } from '@kbn/presentation-publishing';
import { apiCanAddNewPanel } from '@kbn/presentation-containers';
import { IncompatibleActionError, ADD_PANEL_TRIGGER } from '@kbn/ui-actions-plugin/public';
Expand Down Expand Up @@ -237,8 +245,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