Skip to content

Commit

Permalink
feat(suite): display the left menu sidebar in welcome state
Browse files Browse the repository at this point in the history
  • Loading branch information
vojtatranta committed Feb 14, 2025
1 parent 2ed5096 commit aa4dc57
Show file tree
Hide file tree
Showing 11 changed files with 137 additions and 170 deletions.
4 changes: 2 additions & 2 deletions packages/suite-desktop-core/e2e/support/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ export const expectBridgeToBeStopped = async (request: APIRequestContext) => {
}).rejects.toThrow('ECONNREFUSED');
};

// We wait for `@welcome/title` or `@dashboard/graph` since
// We wait for `@welcome-layout/body` or `@dashboard/graph` since
// one or the other will be display depending on the state of the app
// due to previously run tests. And both means the same for the porpoise of this test.
// Bridge should be ready to check `/status` endpoint.
export const waitForAppToBeInitialized = async (suite: any) =>
await Promise.race([
expect(suite.window.getByTestId('@welcome/title')).toBeVisible(),
expect(suite.window.getByTestId('@welcome-layout/body')).toBeVisible(),
expect(suite.window.getByTestId('@dashboard/graph')).toBeVisible(),
]);
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class OnboardingActions {
readonly pin: PinActions;
readonly tutorial: TutorialActions;

readonly welcomeTitle: Locator;
readonly welcomeBody: Locator;
readonly onboardingContinueButton: Locator;
readonly onboardingViewOnlySkipButton: Locator;
readonly onboardingViewOnlyEnableButton: Locator;
Expand Down Expand Up @@ -52,7 +52,7 @@ export class OnboardingActions {
this.tutorial = new TutorialActions(page);
this.pin = new PinActions(page);

this.welcomeTitle = this.page.getByTestId('@welcome/title');
this.welcomeBody = this.page.getByTestId('@welcome-layout/body');
this.onboardingContinueButton = this.page.getByTestId('@onboarding/exit-app-button');
this.onboardingViewOnlySkipButton = this.page.getByTestId('@onboarding/viewOnly/skip');
this.onboardingViewOnlyEnableButton = this.page.getByTestId('@onboarding/viewOnly/enable');
Expand Down Expand Up @@ -83,7 +83,7 @@ export class OnboardingActions {

@step()
async verifySuiteIsLoaded() {
await expect(this.welcomeTitle, 'expect Suite to load in under 30s').toBeVisible({
await expect(this.welcomeBody, 'expect Suite to load in under 30s').toBeVisible({
timeout: 30_000,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class SettingsActions {
'@settings/early-access-confirm-button',
);
this.earlyAccessSkipButton = this.page.getByTestId('@settings/early-access-skip-button');
this.settingsCloseButton = this.page.getByTestId('@settings/menu/close');
this.settingsCloseButton = this.page.getByTestId('@suite/menu/suite-start');
this.modal = this.page.getByTestId('@modal');
this.modalCloseButton = this.page.getByTestId('@modal/close-button');
this.deviceLabelInput = this.page.getByTestId('@settings/device/label-input');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ test.describe.skip('Tor loading screen', { tag: ['@group=suite', '@desktopOnly']
state: 'visible',
});

await suite.window.waitForSelector('[data-testid="@welcome/title"]', { timeout });
await suite.window.waitForSelector('[data-testid="@welcome-layout/body"]', { timeout });

suite.electronApp.close();
});
Expand Down Expand Up @@ -83,7 +83,7 @@ test.describe.skip('Tor loading screen', { tag: ['@group=suite', '@desktopOnly']
state: 'visible',
});

await suite.window.waitForSelector('[data-testid="@welcome/title"]', { timeout });
await suite.window.waitForSelector('[data-testid="@welcome-layout/body"]', { timeout });
networkAnalyzer.stop();
const requests = networkAnalyzer.getRequests();
requests.forEach(request => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as envUtils from '@trezor/env-utils';
import { DeepPartial } from '@trezor/type-utils';

import { desktopUpdateInitialState } from 'src/reducers/suite/desktopUpdateReducer';
import { configureStore } from 'src/support/tests/configureStore';
import { findByTestId, renderWithProviders } from 'src/support/tests/hooksHelper';

Expand Down Expand Up @@ -85,7 +86,9 @@ const getInitialState = ({ suite, router, device }: any = {}) => ({
discovery: [],
accountSearch: {},
settings: {},
blockchain: {},
},
desktopUpdate: desktopUpdateInitialState,
router: {
app: 'suite-index',
loaded: true,
Expand Down
65 changes: 33 additions & 32 deletions packages/suite/src/components/suite/layouts/LoggedOutLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ReactNode, useRef, useState } from 'react';

import { ElevationContext, ElevationUp, NewModal } from '@trezor/components';
import { ElevationContext, ElevationDown, ElevationUp, NewModal } from '@trezor/components';

import { GuideButton, GuideRouter } from 'src/components/guide';
import { useLayoutSize } from 'src/hooks/suite';
Expand All @@ -10,7 +10,6 @@ import { LayoutContext, LayoutContextPayload } from 'src/support/suite/LayoutCon
import { ModalContextProvider } from 'src/support/suite/ModalContext';

import { Metadata } from '../Metadata';
import { TrafficLightOffset } from '../TrafficLightOffset';
import {
AppWrapper,
Body,
Expand All @@ -19,6 +18,7 @@ import {
PageWrapper,
Wrapper,
} from './SuiteLayout/SuiteLayout';
import { LoggedOutSidebar } from './WelcomeLayout/WelcomeLayout';
import { ModalSwitcher } from '../modals/ModalSwitcher/ModalSwitcher';

interface LoggedOutLayout {
Expand All @@ -36,38 +36,39 @@ export const LoggedOutLayout = ({ children }: LoggedOutLayout) => {

return (
<ElevationContext baseElevation={-1}>
<TrafficLightOffset>
<Wrapper ref={wrapperRef} data-testid="@logged-out-layout">
<PageWrapper>
<NewModal.Provider>
<ModalContextProvider>
<Metadata title={title} />
<ModalSwitcher />
<Wrapper ref={wrapperRef} data-testid="@logged-out-layout">
<PageWrapper>
<NewModal.Provider>
<ModalContextProvider>
<Metadata title={title} />
<ModalSwitcher />

<LayoutContext.Provider value={setLayoutPayload}>
<Body data-testid="@suite-layout/body">
<Columns>
<AppWrapper
data-testid="@app"
ref={scrollRef}
id="layout-scroll"
>
{layoutHeader}
<ElevationUp>
<ContentWrapper>{children}</ContentWrapper>
</ElevationUp>
</AppWrapper>
</Columns>
</Body>
</LayoutContext.Provider>
<LayoutContext.Provider value={setLayoutPayload}>
<Body data-testid="@suite-layout/body">
<Columns>
<ElevationDown>
<LoggedOutSidebar />
</ElevationDown>
<AppWrapper
data-testid="@app"
ref={scrollRef}
id="layout-scroll"
>
{layoutHeader}
<ElevationUp>
<ContentWrapper>{children}</ContentWrapper>
</ElevationUp>
</AppWrapper>
</Columns>
</Body>
</LayoutContext.Provider>

{!isMobileLayout && <GuideButton />}
</ModalContextProvider>
</NewModal.Provider>
</PageWrapper>
<GuideRouter />
</Wrapper>
</TrafficLightOffset>
{!isMobileLayout && <GuideButton />}
</ModalContextProvider>
</NewModal.Provider>
</PageWrapper>
<GuideRouter />
</Wrapper>
</ElevationContext>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import { FC } from 'react';

import styled from 'styled-components';

import { Route } from '@suite-common/suite-types';
import { spacingsPx } from '@trezor/theme';

import { NavigationItem, NavigationItemProps } from './NavigationItem';
import { NotificationDropdown } from './NotificationDropdown';
import { useResponsiveContext } from '../../../../../support/suite/ResponsiveContext';

const Nav = styled.nav<{ $isSidebarCollapsed: boolean }>`
export const Nav = styled.nav<{ $isSidebarCollapsed: boolean }>`
display: flex;
flex-direction: column;
gap: ${spacingsPx.xxs};
Expand All @@ -18,6 +19,13 @@ const Nav = styled.nav<{ $isSidebarCollapsed: boolean }>`
${({ $isSidebarCollapsed }) => $isSidebarCollapsed && `align-items: center;`}
`;

export const SETTINGS_ROUTES: Route['name'][] = [
'settings-index',
'settings-device',
'settings-coins',
'settings-debug',
] as const;

const navItems: Array<NavigationItemProps & { CustomComponent?: FC<NavigationItemProps> }> = [
{
nameId: 'TR_DASHBOARD',
Expand All @@ -34,7 +42,7 @@ const navItems: Array<NavigationItemProps & { CustomComponent?: FC<NavigationIte
nameId: 'TR_SETTINGS',
icon: 'gearSix',
goToRoute: 'settings-index',
routes: ['settings-index', 'settings-device', 'settings-coins', 'settings-debug'],
routes: SETTINGS_ROUTES,
'data-testid': '@suite/menu/settings',
},
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { DebugAndExperimental } from './DebugAndExperimental';
import { HideBalances } from './HideBalances';
import { Tor } from './Tor';
import { UpdateStatusActionBarIcon } from './Update/UpdateStatusActionBarIcon';
import { useResponsiveContext } from '../../../../../../support/suite/ResponsiveContext';

const ActionsContainer = styled.div<{ $isSidebarCollapsed: boolean }>`
display: flex;
Expand All @@ -25,21 +24,21 @@ const ActionsContainer = styled.div<{ $isSidebarCollapsed: boolean }>`
`;

type QuickActionsProps = {
showUpdateBannerNotification: boolean;
isSidebarCollapsed: boolean;
showUpdateBannerNotification?: boolean;
};

export const QuickActions = ({ showUpdateBannerNotification }: QuickActionsProps) => {
const { isSidebarCollapsed } = useResponsiveContext();

return (
<ActionsContainer $isSidebarCollapsed={isSidebarCollapsed}>
<UpdateStatusActionBarIcon
showUpdateBannerNotification={showUpdateBannerNotification}
/>
<DebugAndExperimental />
<CustomBackend />
<Tor />
<HideBalances />
</ActionsContainer>
);
};
export const QuickActions = ({
isSidebarCollapsed,
showUpdateBannerNotification,
}: QuickActionsProps) => (
<ActionsContainer $isSidebarCollapsed={isSidebarCollapsed}>
<UpdateStatusActionBarIcon
showUpdateBannerNotification={Boolean(showUpdateBannerNotification)}
/>
<DebugAndExperimental />
<CustomBackend />
<Tor />
<HideBalances />
</ActionsContainer>
);
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ const Content = styled.div`
flex-direction: column;
`;

export const SIDEBAR_MIN_WIDTH = 84;

export const Sidebar = () => {
const [closedNotificationDevice, setClosedNotificationDevice] = useState(false);
const [closedNotificationSuite, setClosedNotificationSuite] = useState(false);
Expand Down Expand Up @@ -75,7 +77,7 @@ export const Sidebar = () => {
<ResizableBox
directions={['right']}
width={sidebarWidth}
minWidth={84}
minWidth={SIDEBAR_MIN_WIDTH}
maxWidth={600}
zIndex={zIndices.draggableComponent}
updateHeightOnWindowResize
Expand All @@ -100,6 +102,7 @@ export const Sidebar = () => {
)}

<QuickActions
isSidebarCollapsed={isSidebarCollapsed}
showUpdateBannerNotification={showUpdateBannerNotification}
/>
</Content>
Expand Down
Loading

0 comments on commit aa4dc57

Please sign in to comment.