Skip to content

Commit

Permalink
[Profiling] Preserve kuery filters when switching between Universal…
Browse files Browse the repository at this point in the history
… Profiling pages in new solution navigation (elastic#203545)

Closes elastic#197401

### Summary

This PR adds ability to preserve `kuery` filters when switching between
pages in Universal Profiling using `solution navigation`. The missing
filters were considered regression in comparison to `classic
navigation`.

### Testing

Expected behavior with **classic navigation** for comparison:
![Screen Recording 2024-12-10 at 14 40
26](https://github.com/user-attachments/assets/db066c2e-3a47-4ac1-9860-f00364716c19)

Before with **solution navigation**:
![Screen Recording 2024-12-10 at 14 50
21](https://github.com/user-attachments/assets/23481d63-37ee-4983-b8ef-5b3e6da2f55d)

After with **solution navigation**:
![Screen Recording 2024-12-10 at 14 45
30](https://github.com/user-attachments/assets/216b6c8d-bfb4-4f32-b4f8-40cf17f5847d)
  • Loading branch information
miloszmarcinkowski authored Dec 12, 2024
1 parent 748193d commit 881cdc1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import {
AppMountParameters,
AppUpdater,
CoreSetup,
CoreStart,
DEFAULT_APP_CATEGORIES,
Expand All @@ -15,7 +16,7 @@ import {
import { i18n } from '@kbn/i18n';
import { NavigationSection } from '@kbn/observability-shared-plugin/public';
import type { Location } from 'history';
import { BehaviorSubject, combineLatest, from, map } from 'rxjs';
import { BehaviorSubject, combineLatest, from, map, take } from 'rxjs';
import { OBLT_PROFILING_APP_ID } from '@kbn/deeplinks-observability';
import { registerEmbeddables } from './embeddables/register_embeddables';
import { getServices } from './services';
Expand Down Expand Up @@ -64,29 +65,47 @@ export class ProfilingPlugin
];

const kuerySubject = new BehaviorSubject<string>('');
const appUpdater$ = new BehaviorSubject<AppUpdater>(() => ({}));

const section$ = combineLatest([from(coreSetup.getStartServices()), kuerySubject]).pipe(
map(([[coreStart], kuery]) => {
if (coreStart.application.capabilities.profiling.show) {
const sections: NavigationSection[] = [
{
label: i18n.translate('xpack.profiling.navigation.sectionLabel', {
defaultMessage: 'Universal Profiling',
}),
entries: links.map((link) => {
return {
app: OBLT_PROFILING_APP_ID,
label: link.title,
path: `${link.path}?kuery=${kuery ?? ''}`,
matchPath: (path) => {
return path.startsWith(link.path);
},
};
}),
sortKey: 700,
},
];
return sections;
let isSidebarEnabled = true;
coreStart.chrome
.getChromeStyle$()
.pipe(take(1))
.subscribe((style) => (isSidebarEnabled = style === 'classic'));

if (isSidebarEnabled) {
// classic navigation
const sections: NavigationSection[] = [
{
label: i18n.translate('xpack.profiling.navigation.sectionLabel', {
defaultMessage: 'Universal Profiling',
}),
entries: links.map((link) => {
return {
app: OBLT_PROFILING_APP_ID,
label: link.title,
path: kuery ? `${link.path}?kuery=${kuery}` : link.path,
matchPath: (path) => {
return path.startsWith(link.path);
},
};
}),
sortKey: 700,
},
];
return sections;
} else {
// solution navigation
appUpdater$.next(() => ({
deepLinks: links.map((link) => ({
...link,
path: kuery ? `${link.path}?kuery=${encodeURIComponent(kuery)}` : link.path,
})),
}));
}
}
return [];
})
Expand All @@ -103,6 +122,7 @@ export class ProfilingPlugin
appRoute: '/app/profiling',
category: DEFAULT_APP_CATEGORIES.observability,
deepLinks: links,
updater$: appUpdater$,
async mount({ element, history, theme$, setHeaderActionMenu }: AppMountParameters) {
const [coreStart, pluginsStart] = await coreSetup.getStartServices();

Expand Down

0 comments on commit 881cdc1

Please sign in to comment.