Skip to content

Commit

Permalink
fix: insights sticky header (#7607)
Browse files Browse the repository at this point in the history
Insights header should show below banners in insights v2
  • Loading branch information
Tymek authored Jul 17, 2024
1 parent 39f6cbd commit 6e4e58a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,15 @@ const BreadcrumbNav = () => {
item !== 'features2' &&
item !== 'create-toggle' &&
item !== 'settings' &&
item !== 'profile',
item !== 'profile' &&
item !== 'insights',
)
.map(decodeURI);

if (paths.length === 0) {
return null;
}

return (
<StyledBreadcrumbContainer>
<ConditionallyRender
Expand Down
42 changes: 32 additions & 10 deletions frontend/src/component/insights/Insights.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState, type VFC } from 'react';
import { useState, type FC } from 'react';
import { Box, styled } from '@mui/material';
import { ArrayParam, withDefault } from 'use-query-params';
import { usePersistentTableState } from 'hooks/usePersistentTableState';
Expand All @@ -12,9 +12,26 @@ import { useInsightsData } from './hooks/useInsightsData';
import { InsightsCharts } from './InsightsCharts';
import { LegacyInsightsCharts } from './LegacyInsightsCharts';
import { useUiFlag } from 'hooks/useUiFlag';
import { Sticky } from 'component/common/Sticky/Sticky';
import { InsightsFilters } from './InsightsFilters';
import { FilterItemParam } from '../../utils/serializeQueryParams';

const StyledWrapper = styled('div')(({ theme }) => ({
paddingTop: theme.spacing(1),
}));

const StickyContainer = styled(Sticky)(({ theme }) => ({
position: 'sticky',
top: 0,
zIndex: theme.zIndex.sticky,
padding: theme.spacing(2, 0),
background: theme.palette.background.application,
transition: 'padding 0.3s ease',
}));

/**
* @deprecated remove with insightsV2 flag
*/
const StickyWrapper = styled(Box, {
shouldForwardProp: (prop) => prop !== 'scrolled',
})<{ scrolled?: boolean }>(({ theme, scrolled }) => ({
Expand All @@ -34,7 +51,10 @@ const StyledProjectSelect = styled(ProjectSelect)(({ theme }) => ({
},
}));

const LegacyInsights = () => {
/**
* @deprecated remove with insightsV2 flag
*/
const LegacyInsights: FC = () => {
const [scrolled, setScrolled] = useState(false);
const { insights, loading, error } = useInsights();
const stateConfig = {
Expand Down Expand Up @@ -63,8 +83,8 @@ const LegacyInsights = () => {
}

return (
<>
<StickyWrapper scrolled={scrolled}>
<StyledWrapper>
<StickyContainer>
<InsightsHeader
actions={
<StyledProjectSelect
Expand All @@ -75,13 +95,13 @@ const LegacyInsights = () => {
/>
}
/>
</StickyWrapper>
</StickyContainer>
<LegacyInsightsCharts
loading={loading}
projects={projects}
{...insightsData}
/>
</>
</StyledWrapper>
);
};

Expand Down Expand Up @@ -116,8 +136,8 @@ const NewInsights = () => {
}

return (
<>
<StickyWrapper scrolled={scrolled}>
<StyledWrapper>
<StickyWrapper>
<InsightsHeader
actions={
<InsightsFilters state={state} onChange={setState} />
Expand All @@ -129,12 +149,14 @@ const NewInsights = () => {
projects={projects}
{...insightsData}
/>
</>
</StyledWrapper>
);
};

export const Insights: VFC = () => {
export const Insights: FC = () => {
const isInsightsV2Enabled = useUiFlag('insightsV2');

if (isInsightsV2Enabled) return <NewInsights />;

return <LegacyInsights />;
};
4 changes: 2 additions & 2 deletions frontend/src/component/insights/InsightsCharts.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { VFC } from 'react';
import type { FC } from 'react';
import { Box, styled } from '@mui/material';
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
import { Widget } from './components/Widget/Widget';
Expand Down Expand Up @@ -71,7 +71,7 @@ const ChartWidget = styled(Widget)(({ theme }) => ({
},
}));

export const InsightsCharts: VFC<IChartsProps> = ({
export const InsightsCharts: FC<IChartsProps> = ({
projects,
flags,
users,
Expand Down

0 comments on commit 6e4e58a

Please sign in to comment.