Skip to content

Commit

Permalink
Remove wrapped StyledPageTemplateComponent
Browse files Browse the repository at this point in the history
Since elastic#146212 we use a development build of React. This has surfaced
some existing problems in the `UptimePageTemplateComponent`, namely a
`useMemo` hook that was calling other hooks inside it by caching a
component.

The wrapped component seems to have some extra styling for mobile users.
For now we will remove this change to make the Uptime plugin work again
and tackle the issues with mobile rendering in a different PR.
  • Loading branch information
Alejandro Fernández Gómez committed Dec 27, 2022
1 parent d40b7fd commit e9611ca
Showing 1 changed file with 3 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
* 2.0.
*/

import React, { useEffect, useMemo } from 'react';
import styled from 'styled-components';
import React, { useEffect } from 'react';
import { EuiPageHeaderProps, EuiPageTemplateProps, useIsWithinMaxBreakpoint } from '@elastic/eui';
import { useKibana } from '@kbn/kibana-react-plugin/public';
import { useInspectorContext } from '@kbn/observability-plugin/public';
Expand All @@ -22,12 +21,6 @@ interface Props {
pageHeader?: EuiPageHeaderProps;
}

const mobileCenteredHeader = `
.euiPageHeaderContent > .euiFlexGroup > .euiFlexItem {
align-items: center;
}
`;

export const UptimePageTemplateComponent: React.FC<Props & EuiPageTemplateProps> = ({
path,
pageHeader,
Expand All @@ -37,18 +30,8 @@ export const UptimePageTemplateComponent: React.FC<Props & EuiPageTemplateProps>
const {
services: { observability },
} = useKibana<ClientPluginsStart>();
const isMobile = useIsWithinMaxBreakpoint('s');

const PageTemplateComponent = observability.navigation.PageTemplate;
const StyledPageTemplateComponent = useMemo(() => {
return styled(PageTemplateComponent)<{ isMobile: boolean }>`
.euiPageHeaderContent > .euiFlexGroup {
flex-wrap: wrap;
}
${(props) => (props.isMobile ? mobileCenteredHeader : '')}
`;
}, [PageTemplateComponent]);

const noDataConfig = useNoDataConfig();

Expand All @@ -69,8 +52,7 @@ export const UptimePageTemplateComponent: React.FC<Props & EuiPageTemplateProps>

return (
<>
<StyledPageTemplateComponent
isMobile={isMobile}
<PageTemplateComponent
pageHeader={pageHeader}
data-test-subj={noDataConfig ? 'data-missing' : undefined}
noDataConfig={isMainRoute && !loading ? noDataConfig : undefined}
Expand All @@ -84,7 +66,7 @@ export const UptimePageTemplateComponent: React.FC<Props & EuiPageTemplateProps>
>
{children}
</div>
</StyledPageTemplateComponent>
</PageTemplateComponent>
</>
);
};

0 comments on commit e9611ca

Please sign in to comment.