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

[Serverless Chrome] Polish of home logo and project switcher #158523

Merged
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
2e904ff
[Serverless Chrome] Polish of home logo and project switcher
tsullivan Jun 6, 2023
8f785d1
declare validateChromeStyle before it is used
tsullivan Jun 6, 2023
f7f64f2
fix i18n in project switcher
tsullivan Jun 6, 2023
d3106b2
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Jun 6, 2023
e320e05
fix ts
tsullivan Jun 6, 2023
a1786f5
Merge branch 'main' into shared-ux/chrome/navigation-polish-ii
tsullivan Jun 7, 2023
f09ea54
Merge branch 'main' into shared-ux/chrome/navigation-polish-ii
tsullivan Jun 7, 2023
459c0de
Merge branch 'main' into shared-ux/chrome/navigation-polish-ii
tsullivan Jun 9, 2023
3328255
set security project home
tsullivan Jun 9, 2023
61834f6
ensure logo links have basepath and can be opened in new tab
tsullivan Jun 9, 2023
9290dda
debounce updates to the home icon/loading spinner
tsullivan Jun 9, 2023
6c428a4
Merge branch 'main' into shared-ux/chrome/navigation-polish-ii
tsullivan Jun 12, 2023
20263e7
update loading spinner debounce time
tsullivan Jun 12, 2023
3bbf1d6
Merge branch 'main' into shared-ux/chrome/navigation-polish-ii
tsullivan Jun 13, 2023
2fac0aa
fix misalignment of action menu
tsullivan Jun 13, 2023
2fba2ac
correction to observability landing page
tsullivan Jun 13, 2023
7328a7a
Merge branch 'main' into shared-ux/chrome/navigation-polish-ii
tsullivan Jun 13, 2023
4da4059
Revert project switcher
tsullivan Jun 13, 2023
c808a4b
restore cloud link
tsullivan Jun 13, 2023
b7e3731
Merge branch 'main' into shared-ux/chrome/navigation-polish-ii
tsullivan Jun 13, 2023
2d61cca
fix ts for removed homeRef prop
tsullivan Jun 13, 2023
3cdb41a
update test fixture
tsullivan Jun 13, 2023
cb5763f
update test fixture II
tsullivan Jun 14, 2023
3a68196
Merge branch 'main' into shared-ux/chrome/navigation-polish-ii
tsullivan Jun 14, 2023
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 @@ -9,7 +9,7 @@
import React from 'react';
import { FormattedMessage } from '@kbn/i18n-react';
import { BehaviorSubject, combineLatest, merge, type Observable, of, ReplaySubject } from 'rxjs';
import { flatMap, map, takeUntil } from 'rxjs/operators';
import { mergeMap, map, takeUntil } from 'rxjs/operators';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

flatMap is deprecated

import { parse } from 'url';
import { EuiLink } from '@elastic/eui';
import useObservable from 'react-use/lib/useObservable';
Expand Down Expand Up @@ -89,7 +89,7 @@ export class ChromeService {
// in the sense that the chrome UI should not be displayed until a non-chromeless app is mounting or mounted
of(true),
application.currentAppId$.pipe(
flatMap((appId) =>
mergeMap((appId) =>
application.applications$.pipe(
map((applications) => {
return !!appId && applications.has(appId) && !!applications.get(appId)!.chromeless;
Expand Down Expand Up @@ -177,25 +177,23 @@ export class ChromeService {
chromeStyle$.next(style);
};

const setProjectSideNavComponent = (component: ISideNavComponent | null) => {
const validateChromeStyle = () => {
const chromeStyle = chromeStyle$.getValue();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed the validation into a helper function

if (chromeStyle !== 'project') {
// Helps ensure callers go through the serverless plugin to get here.
throw new Error(
`Invalid ChromeStyle value of "${chromeStyle}". setProjectSideNavComponent requires ChromeStyle set to "project".`
`Invalid ChromeStyle value of "${chromeStyle}". This method requires ChromeStyle set to "project".`
);
}
};

const setProjectSideNavComponent = (component: ISideNavComponent | null) => {
validateChromeStyle();
projectNavigation.setProjectSideNavComponent(component);
};

const setProjectNavigation = (config: ChromeProjectNavigation) => {
const chromeStyle = chromeStyle$.getValue();
if (chromeStyle !== 'project') {
// Helps ensure callers go through the serverless plugin to get here.
throw new Error(
`Invalid ChromeStyle value of "${chromeStyle}". setProjectNavigation requires ChromeStyle set to "project".`
);
}
validateChromeStyle();
projectNavigation.setProjectNavigation(config);
};

Expand All @@ -206,6 +204,11 @@ export class ChromeService {
projectNavigation.setProjectBreadcrumbs(breadcrumbs, params);
};

const setProjectHome = (homeHref: string) => {
validateChromeStyle();
projectNavigation.setProjectHome(homeHref);
};

const isIE = () => {
const ua = window.navigator.userAgent;
const msie = ua.indexOf('MSIE '); // IE 10 or older
Expand Down Expand Up @@ -288,9 +291,14 @@ export class ChromeService {
breadcrumbs$={projectBreadcrumbs$.pipe(takeUntil(this.stop$))}
helpExtension$={helpExtension$.pipe(takeUntil(this.stop$))}
helpSupportUrl$={helpSupportUrl$.pipe(takeUntil(this.stop$))}
navControlsLeft$={navControls.getLeft$()}
navControlsCenter$={navControls.getCenter$()}
navControlsRight$={navControls.getRight$()}
loadingCount$={http.getLoadingCount$()}
homeHref$={projectNavigation.getProjectHome$()}
kibanaDocLink={docLinks.links.kibana.guide}
kibanaVersion={injectedMetadata.getKibanaVersion()}
prependBasePath={http.basePath.prepend}
>
{/* TODO: pass down the SideNavCompProps once they are defined */}
<SideNavComponent />
Expand Down Expand Up @@ -405,6 +413,7 @@ export class ChromeService {
setChromeStyle,
getChromeStyle$: () => chromeStyle$.pipe(takeUntil(this.stop$)),
project: {
setHome: setProjectHome,
setNavigation: setProjectNavigation,
setSideNavComponent: setProjectSideNavComponent,
setBreadcrumbs: setProjectBreadcrumbs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class ProjectNavigationService {
private customProjectSideNavComponent$ = new BehaviorSubject<{
current: SideNavComponent | null;
}>({ current: null });
private projectHome$ = new BehaviorSubject<string | undefined>(undefined);
private projectNavigation$ = new BehaviorSubject<ChromeProjectNavigation | undefined>(undefined);

private projectBreadcrumbs$ = new BehaviorSubject<{
Expand All @@ -40,6 +41,12 @@ export class ProjectNavigationService {
// 3. keep track of currently active link / path (path will be used to highlight the link in the sidenav and display part of the breadcrumbs)

return {
setProjectHome: (homeHref: string) => {
this.projectHome$.next(homeHref);
},
getProjectHome$: () => {
return this.projectHome$.asObservable();
},
setProjectNavigation: (projectNavigation: ChromeProjectNavigation) => {
this.projectNavigation$.next(projectNavigation);
},
Expand Down
22 changes: 15 additions & 7 deletions packages/core/chrome/core-chrome-browser-internal/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,34 +32,42 @@ export interface InternalChromeStart extends ChromeStart {

/**
* Used only by the serverless plugin to customize project-style chrome.
* Use {@link ServerlessPluginStart.setSideNavComponent} to set serverless navigation.
* @internal
*/
project: {
/**
* Sets the project home href string.
* @param homeHref
*
* Use {@link ServerlessPluginStart.setProjectHome} to set project home.
*/
setHome(homeHref: string): void;

/**
* Sets the project navigation config to be used for rendering project navigation.
* It is used for default project sidenav, project breadcrumbs, tracking active deep link.
* @param projectNavigation The project navigation config
*
* @remarks Has no effect if the chrome style is not `project`.
* Use {@link ServerlessPluginStart.setNavigation} to set project navigation config.
*/
setNavigation(projectNavigation: ChromeProjectNavigation): void;

/**
* Set custom project sidenav component to be used instead of the default project sidenav.
* @param getter A function returning a CustomNavigationComponent.
* This component will receive Chrome navigation state as props (not yet implemented)
* @param component A getter function returning a CustomNavigationComponent.
*
* @remarks This component will receive Chrome navigation state as props (not yet implemented)
*
* @remarks Has no effect if the chrome style is not `project`.
* Use {@link ServerlessPluginStart.setSideNavComponent} to set custom project navigation.
*/
setSideNavComponent(component: SideNavComponent | null): void;

/**
* Set project breadcrumbs
*
* @param breadcrumbs
* @param params.absolute If true, If true, the breadcrumbs will replace the defaults, otherwise they will be appended to the default ones. false by default.
*
* @remarks Has no effect if the chrome style is not `project` or if setNavigation was not called
* Use {@link ServerlessPluginStart.setBreadcrumbs} to set project breadcrumbs.
*/
setBreadcrumbs(
breadcrumbs: ChromeProjectBreadcrumb[] | ChromeProjectBreadcrumb,
Expand Down
Loading