-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(app): implement ODD choose language screen, app language toggles (…
…#16573) # Overview implements the choose language screen that will be the first step of the ODD unboxing flow. migration of the unboxing flow route config value from '/welcome' to '/choose-langauge' will happen in a future PR removing the localization feature flag. the screen can be tested locally by manually editing `unfinishedUnboxingFlowRoute` in `config.json` and commenting out the line `dev-shell-odd: export OT_APP_ON_DEVICE_DISPLAY_SETTINGS__UNFINISHED_UNBOXING_FLOW_ROUTE := 0` in the app makefile. implements the language setting hi-fi designs on desktop and ODD. closes PLAT-537, PLAT-506 <img width="1136" alt="Screen Shot 2024-10-22 at 5 06 03 PM" src="https://github.com/user-attachments/assets/0222b95f-e260-4ec5-a472-9e3645d38d54"> <img width="1136" alt="Screen Shot 2024-10-22 at 5 06 15 PM" src="https://github.com/user-attachments/assets/a82573f3-0446-4ac1-a624-9a680194c9b6"> <img width="1136" alt="Screen Shot 2024-10-24 at 3 05 24 PM" src="https://github.com/user-attachments/assets/8ac6a54d-b842-41ca-828a-4e0f28293cfe"> <img width="1136" alt="Screen Shot 2024-10-24 at 3 05 29 PM" src="https://github.com/user-attachments/assets/f1aee946-955f-4ce8-99aa-1b3da3e00815"> ## Test Plan and Hands on Testing added unit tests for the screen and toggles, verified all behavior ## Changelog - Implements ODD Choose Language screen - Implements ODD language setting toggle ## Review requests check out the screens and toggles ## Risk assessment low, screen not active until config migrated, toggles behind feature flag
- Loading branch information
1 parent
025d5e1
commit d96e2b6
Showing
21 changed files
with
486 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
app/src/organisms/ODD/RobotSettingsDashboard/LanguageSetting.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import * as React from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
import { useDispatch, useSelector } from 'react-redux' | ||
import styled from 'styled-components' | ||
|
||
import { | ||
BORDERS, | ||
COLORS, | ||
CURSOR_POINTER, | ||
DIRECTION_COLUMN, | ||
Flex, | ||
SPACING, | ||
StyledText, | ||
} from '@opentrons/components' | ||
|
||
import { LANGUAGES } from '/app/i18n' | ||
import { ChildNavigation } from '/app/organisms/ODD/ChildNavigation' | ||
import { getAppLanguage, updateConfigValue } from '/app/redux/config' | ||
|
||
import type { Dispatch } from '/app/redux/types' | ||
import type { SetSettingOption } from './types' | ||
|
||
interface LabelProps { | ||
isSelected?: boolean | ||
} | ||
|
||
const SettingButton = styled.input` | ||
display: none; | ||
` | ||
|
||
const SettingButtonLabel = styled.label<LabelProps>` | ||
padding: ${SPACING.spacing24}; | ||
border-radius: ${BORDERS.borderRadius16}; | ||
cursor: ${CURSOR_POINTER}; | ||
background: ${({ isSelected }) => | ||
isSelected === true ? COLORS.blue50 : COLORS.blue35}; | ||
color: ${({ isSelected }) => isSelected === true && COLORS.white}; | ||
` | ||
|
||
interface LanguageSettingProps { | ||
setCurrentOption: SetSettingOption | ||
} | ||
|
||
export function LanguageSetting({ | ||
setCurrentOption, | ||
}: LanguageSettingProps): JSX.Element { | ||
const { t } = useTranslation('app_settings') | ||
const dispatch = useDispatch<Dispatch>() | ||
|
||
const appLanguage = useSelector(getAppLanguage) | ||
|
||
const handleChange = (event: React.ChangeEvent<HTMLInputElement>): void => { | ||
dispatch(updateConfigValue('language.appLanguage', event.target.value)) | ||
} | ||
|
||
return ( | ||
<Flex flexDirection={DIRECTION_COLUMN}> | ||
<ChildNavigation | ||
header={t('language')} | ||
onClickBack={() => { | ||
setCurrentOption(null) | ||
}} | ||
/> | ||
<Flex | ||
flexDirection={DIRECTION_COLUMN} | ||
gridGap={SPACING.spacing8} | ||
marginTop="7.75rem" | ||
padding={`${SPACING.spacing16} ${SPACING.spacing40} ${SPACING.spacing40} ${SPACING.spacing40}`} | ||
> | ||
{LANGUAGES.map(lng => ( | ||
<React.Fragment key={`language_setting_${lng.name}`}> | ||
<SettingButton | ||
id={lng.name} | ||
type="radio" | ||
value={lng.value} | ||
checked={lng.value === appLanguage} | ||
onChange={handleChange} | ||
/> | ||
<SettingButtonLabel | ||
htmlFor={lng.name} | ||
isSelected={lng.value === appLanguage} | ||
> | ||
<StyledText oddStyle="level4HeaderSemiBold"> | ||
{lng.name} | ||
</StyledText> | ||
</SettingButtonLabel> | ||
</React.Fragment> | ||
))} | ||
</Flex> | ||
</Flex> | ||
) | ||
} |
60 changes: 60 additions & 0 deletions
60
app/src/organisms/ODD/RobotSettingsDashboard/__tests__/LanguageSetting.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import type * as React from 'react' | ||
import { fireEvent, screen } from '@testing-library/react' | ||
import { describe, it, expect, vi, beforeEach } from 'vitest' | ||
import '@testing-library/jest-dom/vitest' | ||
|
||
import { | ||
i18n, | ||
US_ENGLISH_DISPLAY_NAME, | ||
US_ENGLISH, | ||
SIMPLIFIED_CHINESE_DISPLAY_NAME, | ||
SIMPLIFIED_CHINESE, | ||
} from '/app/i18n' | ||
import { getAppLanguage, updateConfigValue } from '/app/redux/config' | ||
import { renderWithProviders } from '/app/__testing-utils__' | ||
|
||
import { LanguageSetting } from '../LanguageSetting' | ||
|
||
vi.mock('/app/redux/config') | ||
|
||
const mockSetCurrentOption = vi.fn() | ||
|
||
const render = (props: React.ComponentProps<typeof LanguageSetting>) => { | ||
return renderWithProviders(<LanguageSetting {...props} />, { | ||
i18nInstance: i18n, | ||
}) | ||
} | ||
|
||
describe('LanguageSetting', () => { | ||
let props: React.ComponentProps<typeof LanguageSetting> | ||
beforeEach(() => { | ||
props = { | ||
setCurrentOption: mockSetCurrentOption, | ||
} | ||
vi.mocked(getAppLanguage).mockReturnValue(US_ENGLISH) | ||
}) | ||
|
||
it('should render text and buttons', () => { | ||
render(props) | ||
screen.getByText('Language') | ||
screen.getByText(US_ENGLISH_DISPLAY_NAME) | ||
screen.getByText(SIMPLIFIED_CHINESE_DISPLAY_NAME) | ||
}) | ||
|
||
it('should call mock function when tapping a language button', () => { | ||
render(props) | ||
const button = screen.getByText(SIMPLIFIED_CHINESE_DISPLAY_NAME) | ||
fireEvent.click(button) | ||
expect(updateConfigValue).toHaveBeenCalledWith( | ||
'language.appLanguage', | ||
SIMPLIFIED_CHINESE | ||
) | ||
}) | ||
|
||
it('should call mock function when tapping back button', () => { | ||
render(props) | ||
const button = screen.getByRole('button') | ||
fireEvent.click(button) | ||
expect(props.setCurrentOption).toHaveBeenCalled() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.