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

[SharedUX] Removing TODOs from KibanaPageTemplate #141043

Merged
merged 12 commits into from
Sep 22, 2022
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import React, { FC } from 'react';
import React, { FC, useEffect, useState } from 'react';
import classNames from 'classnames';
import { EuiPageTemplate } from '@elastic/eui';

Expand Down Expand Up @@ -35,6 +35,18 @@ export const KibanaPageTemplateInner: FC<Props> = ({
}) => {
let header;

const [offset, setOffset] = useState<number | undefined>(undefined);
majagrubic marked this conversation as resolved.
Show resolved Hide resolved

useEffect(() => {
const kibanaChrome = document.querySelector('[data-test-subj="kibanaChrome"]') as HTMLElement;
majagrubic marked this conversation as resolved.
Show resolved Hide resolved
if (kibanaChrome) {
const kibanaChromeHeader = kibanaChrome.querySelector(
'[data-test-subj="headerGlobalNav"]'
) as HTMLElement;
setOffset(kibanaChromeHeader?.offsetTop + kibanaChromeHeader?.offsetHeight);
}
}, []);

if (isEmptyState && pageHeader && !children) {
const { iconType, pageTitle, description, rightSideItems } = pageHeader;
const title = pageTitle ? <h1>{pageTitle}</h1> : undefined;
Expand All @@ -54,15 +66,11 @@ export const KibanaPageTemplateInner: FC<Props> = ({

let sideBar;
if (pageSideBar) {
sideBar = (
<EuiPageTemplate.Sidebar
// TODO: Get `offset` from Kibana Chrome Header and pass directly to:
// sticky={{ offset }}
{...pageSideBarProps}
>
{pageSideBar}
</EuiPageTemplate.Sidebar>
);
const sideBarProps = { ...pageSideBarProps };
if (offset) {
sideBarProps.sticky = { offset };
}
sideBar = <EuiPageTemplate.Sidebar {...sideBarProps}>{pageSideBar}</EuiPageTemplate.Sidebar>;
}

const classes = getClasses(undefined, className);
Expand Down
1 change: 1 addition & 0 deletions packages/shared-ux/page/solution_nav/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ TYPES_DEPS = [
"//packages/kbn-i18n-react:npm_module_types",
"//packages/kbn-i18n:npm_module_types",
"//packages/shared-ux/avatar/solution:npm_module_types",
"//packages/shared-ux/page/kibana_template/types"
]

jsts_transpiler(
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
Copy link
Contributor

Choose a reason for hiding this comment

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

I need to remember to do this. I always forget...!

* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { css } from '@emotion/react';
import { euiCanAnimate, EuiThemeComputed } from '@elastic/eui';

export const WithSolutionNavStyles = (euiTheme: EuiThemeComputed<{}>) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I don't think this should start with a capital... it's not a React component, or a class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Happy to change it, but would prefer if we stayed consistent

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will merge this now, but lmk if you think it needs to be changed.

return css`
flex: 0 1 0%;
Copy link
Contributor

Choose a reason for hiding this comment

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

woohoo!!!

overflow: hidden;
${euiCanAnimate} {
transition: min-width ${euiTheme.animation.fast} ${euiTheme.animation.resistance};
}
`;
};
24 changes: 9 additions & 15 deletions packages/shared-ux/page/solution_nav/src/with_solution_nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,20 @@

import React, { ComponentType, ReactNode, useState } from 'react';
import classNames from 'classnames';
import {
useIsWithinBreakpoints,
useEuiTheme,
useIsWithinMinBreakpoint,
EuiPageSidebarProps,
} from '@elastic/eui';
import { SerializedStyles } from '@emotion/serialize';
import { KibanaPageTemplateProps } from '@kbn/shared-ux-page-kibana-template-types';
import { useIsWithinBreakpoints, useEuiTheme, useIsWithinMinBreakpoint } from '@elastic/eui';
import { SolutionNav, SolutionNavProps } from './solution_nav';

import './with_solution_nav.scss';
import { WithSolutionNavStyles } from './with_solution_nav.styles';

// https://reactjs.org/docs/higher-order-components.html#convention-wrap-the-display-name-for-easy-debugging
function getDisplayName(Component: ComponentType<any>) {
return Component.displayName || Component.name || 'UnnamedComponent';
}

// TODO: Would be nice to grab these from KibanaPageTemplate or vice-versa
interface TemplateProps {
pageSideBar?: ReactNode;
pageSideBarProps?: Partial<EuiPageSidebarProps>;
type TemplateProps = Pick<KibanaPageTemplateProps, 'pageSideBar' | 'pageSideBarProps'> & {
children?: ReactNode;
}
};

type Props<P> = P &
TemplateProps & {
Expand Down Expand Up @@ -58,8 +51,8 @@ export const withSolutionNav = <P extends TemplateProps>(WrappedComponent: Compo
const { canBeCollapsed = true } = solutionNav;
const isSidebarShrunk =
isMediumBreakpoint || (canBeCollapsed && isLargerBreakpoint && !isSideNavOpenOnDesktop);
const withSolutionNavStyles = WithSolutionNavStyles(euiTheme);
const sideBarClasses = classNames(
'kbnSolutionNav__sidebar',
'kbnStickyMenu',
{
'kbnSolutionNav__sidebar--shrink': isSidebarShrunk,
Expand All @@ -75,11 +68,12 @@ export const withSolutionNav = <P extends TemplateProps>(WrappedComponent: Compo
/>
);

const pageSideBarProps: TemplateProps['pageSideBarProps'] = {
const pageSideBarProps: TemplateProps['pageSideBarProps'] & { css: SerializedStyles } = {
paddingSize: 'none' as 'none',
...props.pageSideBarProps,
minWidth: isSidebarShrunk ? euiTheme.size.xxl : undefined,
className: sideBarClasses,
css: withSolutionNavStyles,
};

return (
Expand Down