-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(app): factory mode desktop toggle (#14911)
- Loading branch information
1 parent
8cc2fc7
commit dfb572c
Showing
8 changed files
with
255 additions
and
10 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
168 changes: 168 additions & 0 deletions
168
.../organisms/Devices/RobotSettings/AdvancedTab/AdvancedTabSlideouts/FactoryModeSlideout.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,168 @@ | ||
import * as React from 'react' | ||
import { useDispatch } from 'react-redux' | ||
import { useForm, Controller } from 'react-hook-form' | ||
import { useTranslation } from 'react-i18next' | ||
|
||
import { | ||
ALIGN_CENTER, | ||
COLORS, | ||
DIRECTION_COLUMN, | ||
Flex, | ||
PrimaryButton, | ||
SPACING, | ||
StyledText, | ||
TYPOGRAPHY, | ||
} from '@opentrons/components' | ||
import { useRobotSettingsQuery } from '@opentrons/react-api-client' | ||
|
||
import { ToggleButton } from '../../../../../atoms/buttons' | ||
import { InputField } from '../../../../../atoms/InputField' | ||
import { MultiSlideout } from '../../../../../atoms/Slideout/MultiSlideout' | ||
import { restartRobot } from '../../../../../redux/robot-admin' | ||
import { updateSetting } from '../../../../../redux/robot-settings' | ||
|
||
import type { RobotSettingsField } from '@opentrons/api-client' | ||
import type { Dispatch } from '../../../../../redux/types' | ||
|
||
interface FactoryModeSlideoutProps { | ||
isExpanded: boolean | ||
onCloseClick: () => void | ||
robotName: string | ||
} | ||
|
||
interface FormValues { | ||
passwordInput: string | ||
} | ||
|
||
export function FactoryModeSlideout({ | ||
isExpanded, | ||
onCloseClick, | ||
robotName, | ||
}: FactoryModeSlideoutProps): JSX.Element { | ||
const { t } = useTranslation(['device_settings', 'shared', 'branded']) | ||
|
||
const dispatch = useDispatch<Dispatch>() | ||
|
||
const { settings } = useRobotSettingsQuery().data ?? {} | ||
const oemModeSetting = (settings ?? []).find( | ||
(setting: RobotSettingsField) => setting?.id === 'enableOEMMode' | ||
) | ||
const isOEMMode = oemModeSetting?.value ?? null | ||
|
||
const [currentStep, setCurrentStep] = React.useState<number>(1) | ||
const [toggleValue, setToggleValue] = React.useState<boolean>(false) | ||
|
||
const { | ||
handleSubmit, | ||
control, | ||
formState: { errors }, | ||
trigger, | ||
} = useForm({ | ||
defaultValues: { | ||
passwordInput: '', | ||
}, | ||
}) | ||
const onSubmit = (data: FormValues): void => { | ||
setCurrentStep(2) | ||
} | ||
|
||
const handleSubmitFactoryPassword = (): void => { | ||
// TODO: validation and errors: PLAT-281 | ||
void handleSubmit(onSubmit)() | ||
} | ||
|
||
const handleToggleClick: React.MouseEventHandler<Element> = () => { | ||
setToggleValue(toggleValue => !toggleValue) | ||
} | ||
|
||
const handleCompleteClick: React.MouseEventHandler<Element> = () => { | ||
dispatch(updateSetting(robotName, 'enableOEMMode', toggleValue)) | ||
dispatch(restartRobot(robotName)) | ||
onCloseClick() | ||
} | ||
|
||
React.useEffect(() => { | ||
// initialize local state to OEM mode value | ||
if (isOEMMode != null) { | ||
setToggleValue(isOEMMode) | ||
} | ||
}, [isOEMMode]) | ||
|
||
return ( | ||
<MultiSlideout | ||
title={currentStep === 1 ? t('enter_password') : t('manage_oem_settings')} | ||
maxSteps={2} | ||
currentStep={currentStep} | ||
onCloseClick={onCloseClick} | ||
isExpanded={isExpanded} | ||
footer={ | ||
<> | ||
{currentStep === 1 ? ( | ||
<PrimaryButton onClick={handleSubmitFactoryPassword} width="100%"> | ||
{t('shared:next')} | ||
</PrimaryButton> | ||
) : null} | ||
{currentStep === 2 ? ( | ||
<PrimaryButton onClick={handleCompleteClick} width="100%"> | ||
{t('complete_and_restart_robot')} | ||
</PrimaryButton> | ||
) : null} | ||
</> | ||
} | ||
> | ||
{currentStep === 1 ? ( | ||
<Flex flexDirection={DIRECTION_COLUMN}> | ||
<Controller | ||
control={control} | ||
name="passwordInput" | ||
render={({ field, fieldState }) => ( | ||
<InputField | ||
id="passwordInput" | ||
name="passwordInput" | ||
type="text" | ||
onChange={(e: React.ChangeEvent<HTMLInputElement>) => { | ||
field.onChange(e) | ||
trigger('passwordInput') | ||
}} | ||
value={field.value} | ||
error={fieldState.error?.message && ' '} | ||
onBlur={field.onBlur} | ||
title={t('enter_factory_password')} | ||
/> | ||
)} | ||
/> | ||
{errors.passwordInput != null ? ( | ||
<StyledText | ||
as="label" | ||
color={COLORS.red50} | ||
marginTop={SPACING.spacing4} | ||
> | ||
{errors.passwordInput.message} | ||
</StyledText> | ||
) : null} | ||
</Flex> | ||
) : null} | ||
{currentStep === 2 ? ( | ||
<Flex flexDirection={DIRECTION_COLUMN}> | ||
<StyledText | ||
css={TYPOGRAPHY.pSemiBold} | ||
paddingBottom={SPACING.spacing4} | ||
> | ||
{t('oem_mode')} | ||
</StyledText> | ||
<Flex alignItems={ALIGN_CENTER} gridGap={SPACING.spacing6}> | ||
<ToggleButton | ||
label="oem_mode_toggle" | ||
toggledOn={toggleValue} | ||
onClick={handleToggleClick} | ||
/> | ||
<StyledText as="p" marginBottom={SPACING.spacing4}> | ||
{toggleValue ? t('on') : t('off')} | ||
</StyledText> | ||
</Flex> | ||
<StyledText as="p">{t('branded:oem_mode_description')}</StyledText> | ||
</Flex> | ||
) : null} | ||
</MultiSlideout> | ||
) | ||
} |
50 changes: 50 additions & 0 deletions
50
app/src/organisms/Devices/RobotSettings/AdvancedTab/FactoryMode.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,50 @@ | ||
import * as React from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
|
||
import { | ||
ALIGN_CENTER, | ||
Box, | ||
Flex, | ||
JUSTIFY_SPACE_BETWEEN, | ||
SPACING_AUTO, | ||
SPACING, | ||
StyledText, | ||
TYPOGRAPHY, | ||
} from '@opentrons/components' | ||
|
||
import { TertiaryButton } from '../../../../atoms/buttons' | ||
|
||
interface FactoryModeProps { | ||
isRobotBusy: boolean | ||
setShowFactoryModeSlideout: React.Dispatch<React.SetStateAction<boolean>> | ||
} | ||
|
||
export function FactoryMode({ | ||
isRobotBusy, | ||
setShowFactoryModeSlideout, | ||
}: FactoryModeProps): JSX.Element { | ||
const { t } = useTranslation('device_settings') | ||
|
||
return ( | ||
<Flex | ||
alignItems={ALIGN_CENTER} | ||
justifyContent={JUSTIFY_SPACE_BETWEEN} | ||
marginTop={SPACING.spacing24} | ||
> | ||
<Box width="70%"> | ||
<StyledText as="p" fontWeight={TYPOGRAPHY.fontWeightSemiBold}> | ||
{t('factory_mode')} | ||
</StyledText> | ||
</Box> | ||
<TertiaryButton | ||
disabled={isRobotBusy} | ||
marginLeft={SPACING_AUTO} | ||
onClick={() => { | ||
setShowFactoryModeSlideout(true) | ||
}} | ||
> | ||
{t('setup_mode')} | ||
</TertiaryButton> | ||
</Flex> | ||
) | ||
} |
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