Skip to content

Commit

Permalink
🔧 Refactor some components and improve styling
Browse files Browse the repository at this point in the history
  • Loading branch information
emilijadunoska committed Aug 6, 2024
1 parent 5e64ff9 commit 7a943cc
Show file tree
Hide file tree
Showing 13 changed files with 295 additions and 193 deletions.
3 changes: 2 additions & 1 deletion frontend/locales/de-onboarding.json5
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
congrats: 'Herzlichen Glückwunsch!',
congratsContent: 'Sie haben die Touren erfolgreich abgeschlossen. Sie können eine Tour jederzeit wiederholen, indem Sie auf die Chips unten klicken.',
getStarted: 'Starten Sie mit ESID',
getStartedContent: 'Wählen Sie eine der untenstehenden Touren aus, um jede Funktion im Detail zu erkunden und zu verstehen.',
getStartedContent: 'Um Ihnen zu helfen, sich mit ESID vertraut zu machen, haben wir mehrere Onboarding-Touren vorbereitet. Wählen Sie eine Tour aus, um die wichtigsten Merkmale und Funktionen in Ihrem eigenen Tempo zu erkunden. ',
completed: 'abgeschlossen',
next: 'Weiter',
back: 'Zurück',
skip: 'Überspringen',
Expand Down
7 changes: 4 additions & 3 deletions frontend/locales/en-onboarding.json5
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@
toolTipText: 'This is the floating button for help.',
congrats: 'Congratulations!',
congratsContent: 'You have successfully completed the tours. You can retake a tour anytime by clicking on the chips below.',
getStarted: 'Get started with ESID',
getStartedContent: 'Select any tour below to explore and understand each feature in detail.',
getStarted: 'Welcome to ESID',
getStartedContent: "To help you get familiar with ESID, we've prepared several onboarding tours. Select a tour to explore key features and functionalities at your own pace.",
completed: 'completed',
next: 'Next',
back: 'Back',
skip: 'Skip',
Expand Down Expand Up @@ -151,7 +152,7 @@
},
},
filter: {
title: 'Filter',
title: 'Filters',
steps: {
step1: {
target: '#manage-filters-button',
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {I18nextProvider, useTranslation} from 'react-i18next';
import i18n from './util/i18n';
import {MUILocalization} from './components/shared/MUILocalization';
import {DataProvider} from 'DataContext';
import WelcomeModal from './components/OnboardingComponents/WelcomeModal';
import WelcomeDialog from './components/OnboardingComponents/WelcomeDialog';

import AuthProvider from './components/AuthProvider';
/**
Expand All @@ -38,7 +38,7 @@ export default function App(): JSX.Element {
<MUILocalization>
<DataProvider>
<Initializer />
<WelcomeModal />
<WelcomeDialog />
<Box id='app' display='flex' flexDirection='column' sx={{height: '100%', width: '100%'}}>
<TopBar />
<Box
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {Provider} from 'react-redux';
import {Store} from '../../../store';
import {I18nextProvider} from 'react-i18next';
import i18n from '../../../util/i18nForTests';
import TourChips from '../../../components/OnboardingComponents/TourComponents/TourChips';
import TourChips from '../../../components/OnboardingComponents/TourComponents/TourChipsList';
import {TourType} from 'types/tours';

describe('TourChips', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import {I18nextProvider} from 'react-i18next';
import i18n from '../../../util/i18nForTests';
import {Provider} from 'react-redux';
import React from 'react';
import WelcomeModal from '../../../components/OnboardingComponents/WelcomeModal';
import WelcomeDialog from '../../../components/OnboardingComponents/WelcomeDialog';
import {setTourCompleted} from '../../../store/UserOnboardingSlice';

describe('WelcomeModal', () => {
describe('WelcomeDialog', () => {
const renderComponent = () => {
render(
<Provider store={Store}>
<I18nextProvider i18n={i18n}>
<WelcomeModal />
<WelcomeDialog />
</I18nextProvider>
</Provider>
);
Expand Down
73 changes: 20 additions & 53 deletions frontend/src/components/OnboardingComponents/InfoButton.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
// SPDX-FileCopyrightText: 2024 German Aerospace Center (DLR)
// SPDX-License-Identifier: Apache-2.0

import React, {useState} from 'react';
import Popover from '@mui/material/Popover';
import React, {useMemo, useState} from 'react';
import Tooltip from '@mui/material/Tooltip';
import Box from '@mui/material/Box';
import {useAppSelector, useAppDispatch} from '../../store/hooks';
import {setShowTooltip, setShowPopover} from '../../store/UserOnboardingSlice';
import IconButton from '@mui/material/IconButton';
import InfoOutlinedIcon from '@mui/icons-material/InfoOutlined';
import TourChips from './TourComponents/TourChips';
import CloseIcon from '@mui/icons-material/Close';
import Typography from '@mui/material/Typography';
import {useTranslation} from 'react-i18next';
import TopBarPopover from './TopBarPopover';

/**
* this component is an information button in the top bar that opens a popover, which contains the onboarding tours which the user can take
*/
export default function InfoButton() {
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
const dispatch = useAppDispatch();
const {t: tOnboarding} = useTranslation('onboarding');

const showTooltip = useAppSelector((state) => state.userOnboarding.showTooltip);
const showPopover = useAppSelector((state) => state.userOnboarding.showPopover);
const allToursCompleted = useAppSelector((state) => state.userOnboarding.allToursCompleted);
const {t: tOnboarding} = useTranslation('onboarding');
const tours = useAppSelector((state) => state.userOnboarding.tours);

const dispatch = useAppDispatch();
/**
* this use memo is to calculate the total number of tours and the number of completed tours for the popover progress bar
**/
const [totalTours, completedTours] = useMemo(() => {
const total = Object.keys(tours).length;
const completed = Object.values(tours).filter(Boolean).length;
return [total, completed];
}, [tours]);

const handlePopoverOpen = (event: React.MouseEvent<HTMLElement>) => {
setAnchorEl(event.currentTarget);
Expand Down Expand Up @@ -71,53 +77,14 @@ export default function InfoButton() {
</IconButton>
</Tooltip>
{showPopover && (
<Popover
aria-label='popover'
data-testid='popover-testid'
open={true}
<TopBarPopover
anchorEl={anchorEl}
open={showPopover}
onClose={handlePopoverClose}
anchorOrigin={{
vertical: 'top',
horizontal: 'right',
}}
>
<Box position='relative' p={4}>
{allToursCompleted ? (
<>
<Typography variant='h2' align='center' gutterBottom>
{tOnboarding(`congrats`)}
</Typography>
<Typography variant='body1' align='center' gutterBottom>
{tOnboarding(`congratsContent`)}
</Typography>
</>
) : (
<>
<Typography variant='h2' align='center' gutterBottom>
{tOnboarding(`getStarted`)}
</Typography>
<Typography variant='body1' align='center' gutterBottom>
{tOnboarding(`getStartedContent`)}
</Typography>
</>
)}

<IconButton
aria-label='close-info-button'
onClick={handlePopoverClose}
sx={{
position: 'absolute',
right: 8,
top: 8,
}}
>
<CloseIcon />
</IconButton>
<TourChips />
<Box mt={4}></Box>
</Box>
</Popover>
allToursCompleted={allToursCompleted || false}
completedTours={completedTours}
totalTours={totalTours}
/>
)}
</>
);
Expand Down
109 changes: 109 additions & 0 deletions frontend/src/components/OnboardingComponents/TopBarPopover.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// SPDX-FileCopyrightText: 2024 German Aerospace Center (DLR)
// SPDX-License-Identifier: Apache-2.0

import React, {useMemo} from 'react';
import Popover from '@mui/material/Popover';
import Box from '@mui/material/Box';
import IconButton from '@mui/material/IconButton';
import Typography from '@mui/material/Typography';
import CloseIcon from '@mui/icons-material/Close';
import {useTranslation} from 'react-i18next';
import TourChips from './TourComponents/TourChipsList';
import LinearProgress from '@mui/material/LinearProgress';

interface TopBarPopoverProps {
anchorEl: HTMLElement | null;
open: boolean;
onClose: () => void;
allToursCompleted: boolean;
completedTours: number;
totalTours: number;
}

/**
* This component is a popover that contains the onboarding tours which the user can take, it is rendered when the user clicks the information button in the top bar
*/
const TopBarPopover: React.FC<TopBarPopoverProps> = ({
anchorEl,
open,
onClose,
allToursCompleted,
completedTours,
totalTours,
}) => {
const {t: tOnboarding} = useTranslation('onboarding');

/**
* this use memo is to calculate the completion percentage of the tours for the progress bar
*/
const completionPercentage = useMemo(() => {
return totalTours > 0 ? (completedTours / totalTours) * 100 : 0;
}, [completedTours, totalTours]);

return (
<Popover
aria-label='popover'
data-testid='popover-testid'
open={open}
anchorEl={anchorEl}
onClose={onClose}
anchorOrigin={{
vertical: 'top',
horizontal: 'right',
}}
sx={{
'& .MuiPopover-paper': {
width: 600,
height: 370,
},
}}
>
<Box position='relative' p={4}>
<Box>
<Typography variant='h2' align='left' gutterBottom>
{allToursCompleted ? tOnboarding('congrats') : tOnboarding('getStarted')}
</Typography>
</Box>
<Box mt={2}>
<Typography variant='body1' align='left' gutterBottom sx={{color: 'GrayText'}}>
{allToursCompleted ? tOnboarding('congratsContent') : tOnboarding('getStartedContent')}
</Typography>
</Box>
<IconButton
aria-label='close-info-button'
onClick={onClose}
sx={{
position: 'absolute',
right: 8,
top: 8,
}}
>
<CloseIcon />
</IconButton>
<Box mt={4}>
<TourChips />
</Box>
<Box mt={4}>
<LinearProgress
variant='determinate'
value={completionPercentage}
sx={{
height: 10,
borderRadius: 5,
backgroundColor: '#e0e0e0',
'& .MuiLinearProgress-bar': {
borderRadius: 5,
backgroundColor: 'primary',
},
}}
/>
<Typography variant='body2' align='left' sx={{color: 'GrayText', mt: 1}}>
{Math.round(completionPercentage)}% {tOnboarding('completed')}
</Typography>
</Box>
</Box>
</Popover>
);
};

export default TopBarPopover;
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// SPDX-FileCopyrightText: 2024 German Aerospace Center (DLR)
// SPDX-License-Identifier: Apache-2.0

import React from 'react';
import Chip from '@mui/material/Chip';
import {useTheme} from '@mui/material/styles';
import {TourType} from '../../../types/tours';

interface TourChipProps {
icon: React.ReactElement;
tourType: TourType;
label: string;
color: 'default' | 'primary';
onClick: (tour: TourType) => void;
}

/**
* This component is a chip that represents a tour that the user can take
*/
const TourChip: React.FC<TourChipProps> = ({icon, tourType, label, color, onClick}) => {
const theme = useTheme();
return (
<Chip
icon={icon}
label={label}
variant='outlined'
color={color}
onClick={() => onClick(tourType)}
sx={{
fontSize: theme.typography.listElement.fontSize,
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
justifyContent: 'left',
padding: '0 8px',
'& .MuiChip-label': {
padding: '0 8px',
},
}}
/>
);
};

export default TourChip;
Loading

0 comments on commit 7a943cc

Please sign in to comment.