[Serverless] Chrome UI fixes (#164030)

This commit is contained in:
Sébastien Loix 2023-08-16 22:21:59 +01:00 committed by GitHub
parent 0d74544d00
commit 1b6430ece4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 13 deletions

View file

@ -16,6 +16,8 @@ import {
EuiIcon, EuiIcon,
EuiLoadingSpinner, EuiLoadingSpinner,
htmlIdGenerator, htmlIdGenerator,
useEuiTheme,
EuiThemeComputed,
} from '@elastic/eui'; } from '@elastic/eui';
import { css } from '@emotion/react'; import { css } from '@emotion/react';
import type { InternalApplicationStart } from '@kbn/core-application-browser-internal'; import type { InternalApplicationStart } from '@kbn/core-application-browser-internal';
@ -46,12 +48,12 @@ import { ScreenReaderRouteAnnouncements, SkipToMainContent } from '../header/scr
import { AppMenuBar } from './app_menu'; import { AppMenuBar } from './app_menu';
import { ProjectNavigation } from './navigation'; import { ProjectNavigation } from './navigation';
const headerCss = { const getHeaderCss = ({ size }: EuiThemeComputed) => ({
logo: { logo: {
container: css` container: css`
display: inline-block; display: inline-block;
min-width: 56px; /* 56 = 40 + 8 + 8 */ min-width: 56px; /* 56 = 40 + 8 + 8 */
padding: 0 8px; padding: 0 ${size.s};
cursor: pointer; cursor: pointer;
`, `,
logo: css` logo: css`
@ -68,9 +70,12 @@ const headerCss = {
toggleNavButton: css` toggleNavButton: css`
border-right: 1px solid #d3dae6; border-right: 1px solid #d3dae6;
margin-left: -1px; margin-left: -1px;
padding-right: ${size.xs};
`, `,
}, },
}; });
type HeaderCss = ReturnType<typeof getHeaderCss>;
const headerStrings = { const headerStrings = {
logo: { logo: {
@ -114,16 +119,17 @@ export interface Props {
const LOCAL_STORAGE_IS_OPEN_KEY = 'PROJECT_NAVIGATION_OPEN' as const; const LOCAL_STORAGE_IS_OPEN_KEY = 'PROJECT_NAVIGATION_OPEN' as const;
const LOADING_DEBOUNCE_TIME = 80; const LOADING_DEBOUNCE_TIME = 80;
const Logo = ( type LogoProps = Pick<Props, 'application' | 'homeHref$' | 'loadingCount$' | 'prependBasePath'> & {
props: Pick<Props, 'application' | 'homeHref$' | 'loadingCount$' | 'prependBasePath'> logoCss: HeaderCss['logo'];
) => { };
const Logo = (props: LogoProps) => {
const loadingCount = useObservable( const loadingCount = useObservable(
props.loadingCount$.pipe(debounceTime(LOADING_DEBOUNCE_TIME)), props.loadingCount$.pipe(debounceTime(LOADING_DEBOUNCE_TIME)),
0 0
); );
const homeHref = useObservable(props.homeHref$, '/app/home'); const homeHref = useObservable(props.homeHref$, '/app/home');
const { logo } = headerCss;
let fullHref: string | undefined; let fullHref: string | undefined;
if (homeHref) { if (homeHref) {
@ -141,18 +147,18 @@ const Logo = (
); );
return ( return (
<span css={logo.container} data-test-subj="nav-header-logo"> <span css={props.logoCss.container} data-test-subj="nav-header-logo">
{loadingCount === 0 ? ( {loadingCount === 0 ? (
<EuiHeaderLogo <EuiHeaderLogo
iconType="logoElastic" iconType="logoElastic"
onClick={navigateHome} onClick={navigateHome}
href={fullHref} href={fullHref}
css={logo} css={props.logoCss}
data-test-subj="globalLoadingIndicator-hidden" data-test-subj="globalLoadingIndicator-hidden"
aria-label={headerStrings.logo.ariaLabel} aria-label={headerStrings.logo.ariaLabel}
/> />
) : ( ) : (
<a onClick={navigateHome} href={fullHref} css={logo.spinner}> <a onClick={navigateHome} href={fullHref} css={props.logoCss.spinner}>
<EuiLoadingSpinner <EuiLoadingSpinner
size="l" size="l"
aria-hidden={false} aria-hidden={false}
@ -178,6 +184,9 @@ export const ProjectHeader = ({
const toggleCollapsibleNavRef = createRef<HTMLButtonElement & { euiAnimate: () => void }>(); const toggleCollapsibleNavRef = createRef<HTMLButtonElement & { euiAnimate: () => void }>();
const headerActionMenuMounter = useHeaderActionMenuMounter(observables.actionMenu$); const headerActionMenuMounter = useHeaderActionMenuMounter(observables.actionMenu$);
const projectsUrl = useObservable(observables.projectsUrl$); const projectsUrl = useObservable(observables.projectsUrl$);
const { euiTheme } = useEuiTheme();
const headerCss = getHeaderCss(euiTheme);
const { logo: logoCss } = headerCss;
return ( return (
<> <>
@ -228,6 +237,7 @@ export const ProjectHeader = ({
application={application} application={application}
homeHref$={observables.homeHref$} homeHref$={observables.homeHref$}
loadingCount$={observables.loadingCount$} loadingCount$={observables.loadingCount$}
logoCss={logoCss}
/> />
</EuiHeaderSectionItem> </EuiHeaderSectionItem>

View file

@ -25,11 +25,13 @@ jest.mock('../../dashboard_listing/dashboard_listing', () => {
}); });
import { DashboardAppNoDataPage } from '../no_data/dashboard_app_no_data'; import { DashboardAppNoDataPage } from '../no_data/dashboard_app_no_data';
const mockIsDashboardAppInNoDataState = jest.fn().mockResolvedValue(false);
jest.mock('../no_data/dashboard_app_no_data', () => { jest.mock('../no_data/dashboard_app_no_data', () => {
const originalModule = jest.requireActual('../no_data/dashboard_app_no_data'); const originalModule = jest.requireActual('../no_data/dashboard_app_no_data');
return { return {
__esModule: true, __esModule: true,
...originalModule, ...originalModule,
isDashboardAppInNoDataState: () => mockIsDashboardAppInNoDataState(),
DashboardAppNoDataPage: jest.fn().mockReturnValue(null), DashboardAppNoDataPage: jest.fn().mockReturnValue(null),
}; };
}); });
@ -53,6 +55,7 @@ function mountWith({ props: incomingProps }: { props?: DashboardListingPageProps
} }
test('renders analytics no data page when the user has no data view', async () => { test('renders analytics no data page when the user has no data view', async () => {
mockIsDashboardAppInNoDataState.mockResolvedValueOnce(true);
pluginServices.getServices().data.dataViews.hasData.hasUserDataView = jest pluginServices.getServices().data.dataViews.hasData.hasUserDataView = jest
.fn() .fn()
.mockResolvedValue(false); .mockResolvedValue(false);

View file

@ -42,12 +42,12 @@ export const DashboardListingPage = ({
dashboardContentManagement: { findDashboards }, dashboardContentManagement: { findDashboards },
} = pluginServices.getServices(); } = pluginServices.getServices();
const [showNoDataPage, setShowNoDataPage] = useState<boolean>(false); const [showNoDataPage, setShowNoDataPage] = useState<boolean | undefined>();
useEffect(() => { useEffect(() => {
let isMounted = true; let isMounted = true;
(async () => { (async () => {
const isInNoDataState = await isDashboardAppInNoDataState(); const isInNoDataState = await isDashboardAppInNoDataState();
if (isInNoDataState && isMounted) setShowNoDataPage(true); setShowNoDataPage(isInNoDataState && isMounted);
})(); })();
return () => { return () => {
isMounted = false; isMounted = false;
@ -92,6 +92,10 @@ export const DashboardListingPage = ({
const titleFilter = title ? `${title}` : ''; const titleFilter = title ? `${title}` : '';
if (showNoDataPage === undefined) {
return null;
}
return ( return (
<> <>
{showNoDataPage && ( {showNoDataPage && (

View file

@ -268,7 +268,7 @@ export const SearchBar: FC<SearchBarProps> = (opts) => {
if (chromeStyle === 'project' && !isVisible) { if (chromeStyle === 'project' && !isVisible) {
return ( return (
<EuiButtonIcon <EuiHeaderSectionItemButton
aria-label={i18nStrings.showSearchAriaText} aria-label={i18nStrings.showSearchAriaText}
buttonRef={visibilityButtonRef} buttonRef={visibilityButtonRef}
color="text" color="text"