-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(app,components): implement ODD language setting toggle
adds the ODD language setting toggle to the robot settings page closes PLAT-506
- Loading branch information
1 parent
53f86a5
commit d5e9932
Showing
9 changed files
with
213 additions
and
29 deletions.
There are no files selected for viewing
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
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