Skip to content

Commit

Permalink
Move banner list under topbar (gravitational#36760)
Browse files Browse the repository at this point in the history
  • Loading branch information
avatus authored Jan 16, 2024
1 parent d749d69 commit b52dc61
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 47 deletions.
24 changes: 16 additions & 8 deletions web/packages/teleport/src/Main/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import React, {
useContext,
} from 'react';
import styled from 'styled-components';
import { Indicator } from 'design';
import { Box, Indicator } from 'design';
import { Failed } from 'design/CardError';

import useAttempt from 'shared/hooks/useAttemptNext';
Expand Down Expand Up @@ -170,23 +170,24 @@ export function Main(props: MainProps) {
: null
}
/>
<BannerList
banners={banners}
customBanners={props.customBanners}
billingBanners={featureFlags.billing && props.billingBanners}
onBannerDismiss={dismissAlert}
>
<Wrapper>
<MainContainer>
<Navigation />
<HorizontalSplit>
<ContentMinWidth>
<BannerList
banners={banners}
customBanners={props.customBanners}
billingBanners={featureFlags.billing && props.billingBanners}
onBannerDismiss={dismissAlert}
/>
<Suspense fallback={null}>
<FeatureRoutes lockedFeatures={ctx.lockedFeatures} />
</Suspense>
</ContentMinWidth>
</HorizontalSplit>
</MainContainer>
</BannerList>
</Wrapper>
{displayOnboardDiscover && (
<OnboardDiscover onClose={handleOnClose} onOnboard={handleOnboard} />
)}
Expand Down Expand Up @@ -306,3 +307,10 @@ export const StyledIndicator = styled(HorizontalSplit)`
align-items: center;
justify-content: center;
`;

const Wrapper = styled(Box)<{ hasDockedElement: boolean }>`
display: flex;
height: 100vh;
flex-direction: column;
width: ${p => (p.hasDockedElement ? 'calc(100vw - 520px)' : '100vw')};
`;
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,6 @@ describe('components/BannerList/Banner', () => {
expect(dismiss).toHaveBeenCalledWith('test-banner1');
});

it('supports rendering children', () => {
const message = 'That was easy';
render(
<BannerList banners={banners}>
<button>{message}</button>
</BannerList>
);
expect(screen.getByText(message)).toBeInTheDocument();
});

it('does not modify the provided banner list on hide', () => {
banners.pop();
render(<BannerList banners={banners} />);
Expand Down
31 changes: 2 additions & 29 deletions web/packages/teleport/src/components/BannerList/BannerList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,20 @@
*/

import React, { useEffect, useState } from 'react';
import styled from 'styled-components';

import { Box } from 'design';

import { MainContainer } from 'teleport/Main/MainContainer';

import { useLayout } from 'teleport/Main/LayoutContext';

import { Banner } from './Banner';

import type { Severity } from './Banner';
import type { ReactNode } from 'react';

export const BannerList = ({
banners = [],
children,
customBanners = [],
billingBanners = [],
onBannerDismiss = () => {},
}: Props) => {
const { hasDockedElement } = useLayout();

const [bannerData, setBannerData] = useState<{ [id: string]: BannerType }>(
{}
);
Expand All @@ -63,12 +55,7 @@ export const BannerList = ({
);

return (
<Wrapper
hasDockedElement={hasDockedElement}
bannerCount={
shownBanners.length + customBanners.length + billingBanners.length
}
>
<Box>
{shownBanners.map(banner => (
<Banner
message={banner.message}
Expand All @@ -81,26 +68,12 @@ export const BannerList = ({
))}
{customBanners}
{billingBanners}
{children}
</Wrapper>
</Box>
);
};

const Wrapper = styled(Box)<{ bannerCount: number; hasDockedElement: boolean }>`
display: flex;
height: 100vh;
flex-direction: column;
width: ${p => (p.hasDockedElement ? 'calc(100vw - 520px)' : '100vw')};
${MainContainer} {
flex: 1;
height: calc(100% - ${props => props.bannerCount * 38}px);
}
`;

type Props = {
banners: BannerType[];
children?: ReactNode;
customBanners?: ReactNode[];
onBannerDismiss?: (string) => void;
billingBanners?: ReactNode[];
Expand Down

0 comments on commit b52dc61

Please sign in to comment.