Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Device manager - current session expandable details (PSG-644) #9185

Merged
merged 6 commits into from
Aug 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion res/css/_components.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
@import "./components/views/messages/_MBeaconBody.pcss";
@import "./components/views/messages/shared/_MediaProcessingError.pcss";
@import "./components/views/settings/devices/_DeviceDetails.pcss";
@import "./components/views/settings/devices/_DeviceExpandDetailsButton.pcss";
@import "./components/views/settings/devices/_DeviceSecurityCard.pcss";
@import "./components/views/settings/devices/_DeviceTile.pcss";
@import "./components/views/settings/devices/_FilteredDeviceList.pcss";
Expand Down Expand Up @@ -333,12 +334,12 @@
@import "./views/toasts/_IncomingCallToast.pcss";
@import "./views/toasts/_NonUrgentEchoFailureToast.pcss";
@import "./views/typography/_Heading.pcss";
@import "./views/user-onboarding/_UserOnboardingButton.pcss";
@import "./views/user-onboarding/_UserOnboardingFeedback.pcss";
@import "./views/user-onboarding/_UserOnboardingHeader.pcss";
@import "./views/user-onboarding/_UserOnboardingList.pcss";
@import "./views/user-onboarding/_UserOnboardingPage.pcss";
@import "./views/user-onboarding/_UserOnboardingTask.pcss";
@import "./views/user-onboarding/_UserOnboardingButton.pcss";
@import "./views/verification/_VerificationShowSas.pcss";
@import "./views/voip/CallView/_CallViewButtons.pcss";
@import "./views/voip/_CallPreview.pcss";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,20 @@ limitations under the License.
.mx_DeviceDetails {
display: flex;
flex-direction: column;
box-sizing: border-box;

width: 100%;

margin-top: $spacing-16;
padding: $spacing-16;
border-radius: 8px;
border: 1px solid $system;
border: 1px solid $quinary-content;
}

.mx_DeviceDetails_section {
padding-bottom: $spacing-16;
margin-bottom: $spacing-16;
border-bottom: 1px solid $system;
border-bottom: 1px solid $quinary-content;

&:last-child {
padding-bottom: 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
Copyright 2022 The Matrix.org Foundation C.I.C.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

.mx_DeviceExpandDetailsButton {
height: 32px;
width: 32px;
background: transparent;

border-radius: 4px;
color: $secondary-content;

--icon-transform: rotate(-90deg);
}

.mx_DeviceExpandDetailsButton.mx_DeviceExpandDetailsButton_expanded {
--icon-transform: rotate(0deg);

background: $system;
}

.mx_DeviceExpandDetailsButton_icon {
height: 12px;
width: 12px;

transition: all 0.3s;
transform: var(--icon-transform);
transform-origin: center;
}
6 changes: 6 additions & 0 deletions res/css/views/elements/_AccessibleButton.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ limitations under the License.
mask-image: url('$(res)/img/feather-customised/x.svg');
}
}

&.mx_AccessibleButton_kind_icon {
padding: 0;
height: 32px;
width: 32px;
}
}

&.mx_AccessibleButton_kind_primary,
Expand Down
2 changes: 1 addition & 1 deletion res/img/feather-customised/dropdown-arrow.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion src/components/views/elements/AccessibleButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ type AccessibleButtonKind = | 'primary'
| 'link_inline'
| 'link_sm'
| 'confirm_sm'
| 'cancel_sm';
| 'cancel_sm'
| 'icon';

/**
* This type construct allows us to specifically pass those props down to the element we’re creating that the element
Expand Down
74 changes: 74 additions & 0 deletions src/components/views/settings/devices/CurrentDeviceSection.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
Copyright 2022 The Matrix.org Foundation C.I.C.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import React, { useState } from 'react';

import { _t } from '../../../../languageHandler';
import Spinner from '../../elements/Spinner';
import SettingsSubsection from '../shared/SettingsSubsection';
import DeviceDetails from './DeviceDetails';
import DeviceExpandDetailsButton from './DeviceExpandDetailsButton';
import DeviceSecurityCard from './DeviceSecurityCard';
import DeviceTile from './DeviceTile';
import {
DeviceSecurityVariation,
DeviceWithVerification,
} from './types';

interface Props {
device?: DeviceWithVerification;
isLoading: boolean;
}

const CurrentDeviceSection: React.FC<Props> = ({
device, isLoading,
}) => {
const [isExpanded, setIsExpanded] = useState(false);
const securityCardProps = device?.isVerified ? {
variation: DeviceSecurityVariation.Verified,
heading: _t('Verified session'),
description: _t('This session is ready for secure messaging.'),
} : {
variation: DeviceSecurityVariation.Unverified,
heading: _t('Unverified session'),
description: _t('Verify or sign out from this session for best security and reliability.'),
};
return <SettingsSubsection
heading={_t('Current session')}
data-testid='current-session-section'
>
{ isLoading && <Spinner /> }
{ !!device && <>
<DeviceTile
device={device}
>
<DeviceExpandDetailsButton
data-testid='current-session-toggle-details'
isExpanded={isExpanded}
onClick={() => setIsExpanded(!isExpanded)}
/>
</DeviceTile>
{ isExpanded && <DeviceDetails device={device} /> }
<br />
<DeviceSecurityCard
{...securityCardProps}
/>
</>
}
</SettingsSubsection>;
};

export default CurrentDeviceSection;
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
Copyright 2022 The Matrix.org Foundation C.I.C.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import classNames from 'classnames';
import React from 'react';

import { Icon as CaretIcon } from '../../../../../res/img/feather-customised/dropdown-arrow.svg';
import AccessibleButton from '../../elements/AccessibleButton';

interface Props {
isExpanded: boolean;
onClick: () => void;
}

const DeviceExpandDetailsButton: React.FC<Props> = ({ isExpanded, onClick, ...rest }) => {
return <AccessibleButton
{...rest}
kind='icon'
className={classNames('mx_DeviceExpandDetailsButton', {
mx_DeviceExpandDetailsButton_expanded: isExpanded,
})}
onClick={onClick}
>
<CaretIcon className='mx_DeviceExpandDetailsButton_icon' />
</AccessibleButton>;
};

export default DeviceExpandDetailsButton;
35 changes: 5 additions & 30 deletions src/components/views/settings/tabs/user/SessionManagerTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@ limitations under the License.
import React from 'react';

import { _t } from "../../../../../languageHandler";
import Spinner from '../../../elements/Spinner';
import { useOwnDevices } from '../../devices/useOwnDevices';
import DeviceTile from '../../devices/DeviceTile';
import DeviceSecurityCard from '../../devices/DeviceSecurityCard';
import SettingsSubsection from '../../shared/SettingsSubsection';
import FilteredDeviceList from '../../devices/FilteredDeviceList';
import { DeviceSecurityVariation } from '../../devices/types';
import CurrentDeviceSection from '../../devices/CurrentDeviceSection';
import SecurityRecommendations from '../../devices/SecurityRecommendations';
import SettingsTab from '../SettingsTab';

Expand All @@ -33,34 +30,12 @@ const SessionManagerTab: React.FC = () => {
const { [currentDeviceId]: currentDevice, ...otherDevices } = devices;
const shouldShowOtherSessions = Object.keys(otherDevices).length > 0;

const securityCardProps = currentDevice?.isVerified ? {
variation: DeviceSecurityVariation.Verified,
heading: _t('Verified session'),
description: _t('This session is ready for secure messaging.'),
} : {
variation: DeviceSecurityVariation.Unverified,
heading: _t('Unverified session'),
description: _t('Verify or sign out from this session for best security and reliability.'),
};

return <SettingsTab heading={_t('Sessions')}>
<SecurityRecommendations devices={devices} />
<SettingsSubsection
heading={_t('Current session')}
data-testid='current-session-section'
>
{ isLoading && <Spinner /> }
{ !!currentDevice && <>
<DeviceTile
device={currentDevice}
/>
<br />
<DeviceSecurityCard
{...securityCardProps}
/>
</>
}
</SettingsSubsection>
<CurrentDeviceSection
device={currentDevice}
isLoading={isLoading}
/>
{
shouldShowOtherSessions &&
<SettingsSubsection
Expand Down
10 changes: 5 additions & 5 deletions src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -1555,12 +1555,7 @@
"Share anonymous data to help us identify issues. Nothing personal. No third parties.": "Share anonymous data to help us identify issues. Nothing personal. No third parties.",
"Where you're signed in": "Where you're signed in",
"Manage your signed-in devices below. A device's name is visible to people you communicate with.": "Manage your signed-in devices below. A device's name is visible to people you communicate with.",
"Verified session": "Verified session",
"This session is ready for secure messaging.": "This session is ready for secure messaging.",
"Unverified session": "Unverified session",
"Verify or sign out from this session for best security and reliability.": "Verify or sign out from this session for best security and reliability.",
"Sessions": "Sessions",
"Current session": "Current session",
"Other sessions": "Other sessions",
"For best security, verify your sessions and sign out from any session that you don't recognize or use anymore.": "For best security, verify your sessions and sign out from any session that you don't recognize or use anymore.",
"Sidebar": "Sidebar",
Expand Down Expand Up @@ -1691,6 +1686,11 @@
"Please enter verification code sent via text.": "Please enter verification code sent via text.",
"Verification code": "Verification code",
"Discovery options will appear once you have added a phone number above.": "Discovery options will appear once you have added a phone number above.",
"Verified session": "Verified session",
"This session is ready for secure messaging.": "This session is ready for secure messaging.",
"Unverified session": "Unverified session",
"Verify or sign out from this session for best security and reliability.": "Verify or sign out from this session for best security and reliability.",
"Current session": "Current session",
"Confirm logging out these devices by using Single Sign On to prove your identity.|other": "Confirm logging out these devices by using Single Sign On to prove your identity.",
"Confirm logging out these devices by using Single Sign On to prove your identity.|one": "Confirm logging out this device by using Single Sign On to prove your identity.",
"Confirm signing out these devices|other": "Confirm signing out these devices",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
Copyright 2022 The Matrix.org Foundation C.I.C.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import React from 'react';
import { fireEvent, render } from '@testing-library/react';
import { act } from 'react-dom/test-utils';

import CurrentDeviceSection from '../../../../../src/components/views/settings/devices/CurrentDeviceSection';

describe('<CurrentDeviceSection />', () => {
const deviceId = 'alices_device';

const alicesVerifiedDevice = {
device_id: deviceId,
isVerified: false,
};
const alicesUnverifiedDevice = {
device_id: deviceId,
isVerified: false,
};

const defaultProps = {
device: alicesVerifiedDevice,
isLoading: false,
};
const getComponent = (props = {}): React.ReactElement =>
(<CurrentDeviceSection {...defaultProps} {...props} />);

it('renders spinner while device is loading', () => {
const { container } = render(getComponent({ device: undefined, isLoading: true }));
expect(container.getElementsByClassName('mx_Spinner').length).toBeTruthy();
});

it('handles when device is falsy', async () => {
const { container } = render(getComponent({ device: undefined }));
expect(container).toMatchSnapshot();
});

it('renders device and correct security card when device is verified', () => {
const { container } = render(getComponent());
expect(container).toMatchSnapshot();
});

it('renders device and correct security card when device is unverified', () => {
const { container } = render(getComponent({ device: alicesUnverifiedDevice }));
expect(container).toMatchSnapshot();
});

it('displays device details on toggle click', () => {
const { container, getByTestId } = render(getComponent({ device: alicesUnverifiedDevice }));

act(() => {
fireEvent.click(getByTestId('current-session-toggle-details'));
});

expect(container.getElementsByClassName('mx_DeviceDetails')).toMatchSnapshot();

act(() => {
fireEvent.click(getByTestId('current-session-toggle-details'));
});

// device details are hidden
expect(container.getElementsByClassName('mx_DeviceDetails').length).toBeFalsy();
});
});
Loading