-
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.
Revert "feat(app): remove privacy setting tabs (#14423)"
This reverts commit c4660ae.
- Loading branch information
Showing
17 changed files
with
398 additions
and
2 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
71 changes: 71 additions & 0 deletions
71
app/src/organisms/Devices/RobotSettings/RobotSettingsPrivacy.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,71 @@ | ||
import * as React from 'react' | ||
import { useSelector, useDispatch } from 'react-redux' | ||
import { useTranslation } from 'react-i18next' | ||
|
||
import { getRobotSettings, fetchSettings } from '../../../redux/robot-settings' | ||
|
||
import type { State, Dispatch } from '../../../redux/types' | ||
import type { | ||
RobotSettings, | ||
RobotSettingsField, | ||
} from '../../../redux/robot-settings/types' | ||
import { SettingToggle } from './SettingToggle' | ||
|
||
interface RobotSettingsPrivacyProps { | ||
robotName: string | ||
} | ||
|
||
const PRIVACY_SETTINGS = ['disableLogAggregation'] | ||
|
||
const INFO_BY_SETTING_ID: { | ||
[id: string]: { | ||
titleKey: string | ||
descriptionKey: string | ||
invert: boolean | ||
} | ||
} = { | ||
disableLogAggregation: { | ||
titleKey: 'share_logs_with_opentrons', | ||
descriptionKey: 'share_logs_with_opentrons_description', | ||
invert: true, | ||
}, | ||
} | ||
|
||
export function RobotSettingsPrivacy({ | ||
robotName, | ||
}: RobotSettingsPrivacyProps): JSX.Element { | ||
const { t } = useTranslation('device_settings') | ||
const settings = useSelector<State, RobotSettings>((state: State) => | ||
getRobotSettings(state, robotName) | ||
) | ||
const privacySettings = settings.filter(({ id }) => | ||
PRIVACY_SETTINGS.includes(id) | ||
) | ||
const translatedPrivacySettings: Array< | ||
RobotSettingsField & { invert: boolean } | ||
> = privacySettings.map(s => { | ||
const { titleKey, descriptionKey, invert } = INFO_BY_SETTING_ID[s.id] | ||
return s.id in INFO_BY_SETTING_ID | ||
? { | ||
...s, | ||
title: t(titleKey), | ||
description: t(descriptionKey), | ||
invert, | ||
} | ||
: { ...s, invert: false } | ||
}) | ||
|
||
const dispatch = useDispatch<Dispatch>() | ||
|
||
React.useEffect(() => { | ||
dispatch(fetchSettings(robotName)) | ||
}, [dispatch, robotName]) | ||
|
||
return ( | ||
<> | ||
{translatedPrivacySettings.map(field => ( | ||
<SettingToggle key={field.id} {...field} robotName={robotName} /> | ||
))} | ||
</> | ||
) | ||
} |
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/RobotDashboard/AnalyticsOptInModal' | ||
import { RobotSettingButton } from '../../pages/RobotSettingsDashboard/RobotSettingButton' | ||
import { OnOffToggle } from '../../pages/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/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> | ||
) | ||
} |
71 changes: 71 additions & 0 deletions
71
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,71 @@ | ||
import * as React from 'react' | ||
import { fireEvent, screen } from '@testing-library/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', () => { | ||
render(props) | ||
screen.getByText('Privacy') | ||
screen.getByText( | ||
'Opentrons cares about your privacy. We anonymize all data and only use it to improve our products.' | ||
) | ||
screen.getByText('Share robot logs') | ||
screen.getByText('Data on actions the robot does, like running protocols.') | ||
screen.getByText('Share display usage') | ||
screen.getByText('Data on how you interact with the touchscreen on Flex.') | ||
}) | ||
|
||
it('should toggle display usage sharing on click', () => { | ||
render(props) | ||
fireEvent.click(screen.getByText('Share display usage')) | ||
expect(mockToggleAnalyticsOptedIn).toBeCalled() | ||
}) | ||
|
||
it('should toggle robot logs sharing on click', () => { | ||
render(props) | ||
fireEvent.click(screen.getByText('Share robot logs')) | ||
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
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,56 @@ | ||
import * as React from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
import { useSelector, useDispatch } from 'react-redux' | ||
|
||
import { | ||
Flex, | ||
Box, | ||
SIZE_2, | ||
TYPOGRAPHY, | ||
JUSTIFY_SPACE_BETWEEN, | ||
SPACING, | ||
} from '@opentrons/components' | ||
|
||
import { | ||
toggleAnalyticsOptedIn, | ||
getAnalyticsOptedIn, | ||
} from '../../redux/analytics' | ||
import { ToggleButton } from '../../atoms/buttons' | ||
import { StyledText } from '../../atoms/text' | ||
|
||
import type { Dispatch, State } from '../../redux/types' | ||
|
||
export function PrivacySettings(): JSX.Element { | ||
const { t } = useTranslation('app_settings') | ||
const dispatch = useDispatch<Dispatch>() | ||
const analyticsOptedIn = useSelector((s: State) => getAnalyticsOptedIn(s)) | ||
|
||
return ( | ||
<Flex | ||
height="calc(100vh - 8.5rem)" | ||
justifyContent={JUSTIFY_SPACE_BETWEEN} | ||
paddingX={SPACING.spacing16} | ||
paddingY={SPACING.spacing24} | ||
gridGap={SPACING.spacing16} | ||
> | ||
<Box width="70%"> | ||
<StyledText | ||
css={TYPOGRAPHY.h3SemiBold} | ||
paddingBottom={SPACING.spacing8} | ||
> | ||
{t('share_app_analytics')} | ||
</StyledText> | ||
<StyledText css={TYPOGRAPHY.pRegular} paddingBottom={SPACING.spacing8}> | ||
{t('share_app_analytics_description')} | ||
</StyledText> | ||
</Box> | ||
<ToggleButton | ||
label="analytics_opt_in" | ||
size={SIZE_2} | ||
toggledOn={analyticsOptedIn} | ||
onClick={() => dispatch(toggleAnalyticsOptedIn())} | ||
id="PrivacySettings_analytics" | ||
/> | ||
</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
Oops, something went wrong.