-
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): add ODD analytics setting screen (#13525)
adds a robot settings privacy screen to change analytics settings and an opt in modal at the end of unboxing flow to follow the welcome modal closes RAUT-660
- Loading branch information
1 parent
6481d14
commit 9cd9b6b
Showing
16 changed files
with
439 additions
and
72 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import * as React from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
import { useDispatch, useSelector } from 'react-redux' | ||
|
||
import { | ||
Flex, | ||
SPACING, | ||
DIRECTION_COLUMN, | ||
TYPOGRAPHY, | ||
} from '@opentrons/components' | ||
|
||
import { StyledText } from '../../atoms/text' | ||
import { ChildNavigation } from '../../organisms/ChildNavigation' | ||
import { ROBOT_ANALYTICS_SETTING_ID } from '../../pages/OnDeviceDisplay/RobotDashboard/AnalyticsOptInModal' | ||
import { RobotSettingButton } from '../../pages/OnDeviceDisplay/RobotSettingsDashboard/RobotSettingButton' | ||
import { OnOffToggle } from '../../pages/OnDeviceDisplay/RobotSettingsDashboard/RobotSettingsList' | ||
import { | ||
getAnalyticsOptedIn, | ||
toggleAnalyticsOptedIn, | ||
} from '../../redux/analytics' | ||
import { getRobotSettings, updateSetting } from '../../redux/robot-settings' | ||
|
||
import type { Dispatch, State } from '../../redux/types' | ||
import type { SetSettingOption } from '../../pages/OnDeviceDisplay/RobotSettingsDashboard' | ||
|
||
interface PrivacyProps { | ||
robotName: string | ||
setCurrentOption: SetSettingOption | ||
} | ||
|
||
export function Privacy({ | ||
robotName, | ||
setCurrentOption, | ||
}: PrivacyProps): JSX.Element { | ||
const { t } = useTranslation('app_settings') | ||
const dispatch = useDispatch<Dispatch>() | ||
|
||
const allRobotSettings = useSelector((state: State) => | ||
getRobotSettings(state, robotName) | ||
) | ||
|
||
const appAnalyticsOptedIn = useSelector(getAnalyticsOptedIn) | ||
|
||
const isRobotAnalyticsDisabled = | ||
allRobotSettings.find(({ id }) => id === ROBOT_ANALYTICS_SETTING_ID) | ||
?.value ?? false | ||
|
||
return ( | ||
<Flex flexDirection={DIRECTION_COLUMN}> | ||
<ChildNavigation | ||
header={t('app_settings:privacy')} | ||
onClickBack={() => setCurrentOption(null)} | ||
/> | ||
<Flex | ||
flexDirection={DIRECTION_COLUMN} | ||
gridGap={SPACING.spacing24} | ||
paddingX={SPACING.spacing40} | ||
marginTop="7.75rem" | ||
> | ||
<StyledText | ||
fontSize={TYPOGRAPHY.fontSize28} | ||
lineHeight={TYPOGRAPHY.lineHeight36} | ||
fontWeight={TYPOGRAPHY.fontWeightRegular} | ||
> | ||
{t('opentrons_cares_about_privacy')} | ||
</StyledText> | ||
<Flex flexDirection={DIRECTION_COLUMN}> | ||
<RobotSettingButton | ||
settingName={t('share_robot_logs')} | ||
settingInfo={t('share_robot_logs_description')} | ||
dataTestId="RobotSettingButton_share_analytics" | ||
rightElement={<OnOffToggle isOn={!isRobotAnalyticsDisabled} />} | ||
onClick={() => | ||
dispatch( | ||
updateSetting( | ||
robotName, | ||
ROBOT_ANALYTICS_SETTING_ID, | ||
!isRobotAnalyticsDisabled | ||
) | ||
) | ||
} | ||
/> | ||
<RobotSettingButton | ||
settingName={t('share_display_usage')} | ||
settingInfo={t('share_display_usage_description')} | ||
dataTestId="RobotSettingButton_share_app_analytics" | ||
rightElement={<OnOffToggle isOn={appAnalyticsOptedIn} />} | ||
onClick={() => dispatch(toggleAnalyticsOptedIn())} | ||
/> | ||
</Flex> | ||
</Flex> | ||
</Flex> | ||
) | ||
} |
73 changes: 73 additions & 0 deletions
73
app/src/organisms/RobotSettingsDashboard/__tests__/Privacy.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,73 @@ | ||
import * as React from 'react' | ||
|
||
import { renderWithProviders } from '@opentrons/components' | ||
|
||
import { i18n } from '../../../i18n' | ||
import { toggleAnalyticsOptedIn } from '../../../redux/analytics' | ||
import { getRobotSettings, updateSetting } from '../../../redux/robot-settings' | ||
|
||
import { Privacy } from '../Privacy' | ||
|
||
jest.mock('../../../redux/analytics') | ||
jest.mock('../../../redux/robot-settings') | ||
|
||
const mockGetRobotSettings = getRobotSettings as jest.MockedFunction< | ||
typeof getRobotSettings | ||
> | ||
const mockUpdateSetting = updateSetting as jest.MockedFunction< | ||
typeof updateSetting | ||
> | ||
const mockToggleAnalyticsOptedIn = toggleAnalyticsOptedIn as jest.MockedFunction< | ||
typeof toggleAnalyticsOptedIn | ||
> | ||
|
||
const render = (props: React.ComponentProps<typeof Privacy>) => { | ||
return renderWithProviders(<Privacy {...props} />, { | ||
i18nInstance: i18n, | ||
}) | ||
} | ||
|
||
describe('Privacy', () => { | ||
let props: React.ComponentProps<typeof Privacy> | ||
beforeEach(() => { | ||
props = { | ||
robotName: 'Otie', | ||
setCurrentOption: jest.fn(), | ||
} | ||
mockGetRobotSettings.mockReturnValue([]) | ||
}) | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks() | ||
}) | ||
|
||
it('should render text and buttons', () => { | ||
const [{ getByText }] = render(props) | ||
getByText('Privacy') | ||
getByText( | ||
'Opentrons cares about your privacy. We anonymize all data and only use it to improve our products.' | ||
) | ||
getByText('Share robot logs') | ||
getByText('Data on actions the robot does, like running protocols.') | ||
getByText('Share display usage') | ||
getByText('Data on how you interact with the touchscreen on Flex.') | ||
}) | ||
|
||
it('should toggle display usage sharing on click', () => { | ||
const [{ getByText }] = render(props) | ||
|
||
getByText('Share display usage').click() | ||
expect(mockToggleAnalyticsOptedIn).toBeCalled() | ||
}) | ||
|
||
it('should toggle robot logs sharing on click', () => { | ||
const [{ getByText }] = render(props) | ||
|
||
getByText('Share robot logs').click() | ||
expect(mockUpdateSetting).toBeCalledWith( | ||
'Otie', | ||
'disableLogAggregation', | ||
true | ||
) | ||
}) | ||
}) |
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
91 changes: 91 additions & 0 deletions
91
app/src/pages/OnDeviceDisplay/RobotDashboard/AnalyticsOptInModal.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,91 @@ | ||
import * as React from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
import { useDispatch, useSelector } from 'react-redux' | ||
|
||
import { | ||
Flex, | ||
COLORS, | ||
DIRECTION_COLUMN, | ||
DIRECTION_ROW, | ||
SPACING, | ||
} from '@opentrons/components' | ||
|
||
import { SmallButton } from '../../../atoms/buttons' | ||
import { StyledText } from '../../../atoms/text' | ||
import { Modal } from '../../../molecules/Modal' | ||
import { updateConfigValue } from '../../../redux/config' | ||
import { getLocalRobot } from '../../../redux/discovery' | ||
import { updateSetting } from '../../../redux/robot-settings' | ||
|
||
import type { Dispatch } from '../../../redux/types' | ||
|
||
export const ROBOT_ANALYTICS_SETTING_ID = 'disableLogAggregation' | ||
|
||
interface AnalyticsOptInModalProps { | ||
setShowAnalyticsOptInModal: (showAnalyticsOptInModal: boolean) => void | ||
} | ||
|
||
export function AnalyticsOptInModal({ | ||
setShowAnalyticsOptInModal, | ||
}: AnalyticsOptInModalProps): JSX.Element { | ||
const { t } = useTranslation(['app_settings', 'shared']) | ||
const dispatch = useDispatch<Dispatch>() | ||
|
||
const localRobot = useSelector(getLocalRobot) | ||
const robotName = localRobot?.name != null ? localRobot.name : 'no name' | ||
|
||
const handleCloseModal = (): void => { | ||
dispatch( | ||
updateConfigValue( | ||
'onDeviceDisplaySettings.unfinishedUnboxingFlowRoute', | ||
null | ||
) | ||
) | ||
setShowAnalyticsOptInModal(false) | ||
} | ||
|
||
const handleOptIn = (): void => { | ||
dispatch(updateSetting(robotName, ROBOT_ANALYTICS_SETTING_ID, false)) | ||
dispatch(updateConfigValue('analytics.optedIn', true)) | ||
handleCloseModal() | ||
} | ||
|
||
const handleOptOut = (): void => { | ||
dispatch(updateSetting(robotName, ROBOT_ANALYTICS_SETTING_ID, true)) | ||
dispatch(updateConfigValue('analytics.optedIn', false)) | ||
handleCloseModal() | ||
} | ||
|
||
return ( | ||
<Modal modalSize="medium" header={{ title: t('want_to_help_out') }}> | ||
<Flex flexDirection={DIRECTION_COLUMN}> | ||
<Flex | ||
flexDirection={DIRECTION_COLUMN} | ||
gridGap={SPACING.spacing12} | ||
paddingBottom={SPACING.spacing32} | ||
> | ||
<StyledText as="p" color={COLORS.darkBlack90}> | ||
{t('opt_in_description')} | ||
</StyledText> | ||
</Flex> | ||
<Flex | ||
flexDirection={DIRECTION_ROW} | ||
gridGap={SPACING.spacing8} | ||
width="100%" | ||
> | ||
<SmallButton | ||
flex="1" | ||
buttonText={t('opt_out')} | ||
buttonType="secondary" | ||
onClick={handleOptOut} | ||
/> | ||
<SmallButton | ||
flex="1" | ||
buttonText={t('opt_in')} | ||
onClick={handleOptIn} | ||
/> | ||
</Flex> | ||
</Flex> | ||
</Modal> | ||
) | ||
} |
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.