This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 828
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Device manager - device security recommendation card (PSG-637) (#9158)
* add security card and style * deprecate warning and verified svgs that use hard coded color * style icons, test * i18n * stylelint * redo lost lint fixes * fix svg ref * actually fix svg * fix stupid copy pasting * use rgba for e2e light variations * add security card and style * deprecate warning and verified svgs that use hard coded color * style icons, test * i18n * stylelint * fix svg ref * actually fix svg * fix stupid copy pasting * use rgba for e2e light variations * use device security card in current session section * lint * update snapshot test after dev merge
- Loading branch information
Kerry
authored
Aug 11, 2022
1 parent
0be622e
commit 7b52145
Showing
18 changed files
with
401 additions
and
11 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
69 changes: 69 additions & 0 deletions
69
res/css/components/views/settings/devices/_DeviceSecurityCard.pcss
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,69 @@ | ||
/* | ||
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_DeviceSecurityCard { | ||
width: 100%; | ||
display: flex; | ||
flex-direction: row; | ||
align-items: flex-start; | ||
|
||
padding: $spacing-16; | ||
|
||
border: 1px solid $quinary-content; | ||
border-radius: 8px; | ||
} | ||
|
||
.mx_DeviceSecurityCard_icon { | ||
flex: 0 0 40px; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
margin-right: $spacing-16; | ||
border-radius: 8px; | ||
|
||
height: 40px; | ||
width: 40px; | ||
|
||
color: var(--icon-color); | ||
background-color: var(--background-color); | ||
|
||
&.Verified { | ||
--icon-color: $e2e-verified-color; | ||
--background-color: $e2e-verified-color-light; | ||
} | ||
|
||
&.Unverified { | ||
--icon-color: $e2e-warning-color; | ||
--background-color: $e2e-warning-color-light; | ||
} | ||
|
||
&.Inactive { | ||
--icon-color: $secondary-content; | ||
--background-color: $system; | ||
} | ||
} | ||
|
||
.mx_DeviceSecurityCard_content { | ||
flex: 1 1; | ||
} | ||
.mx_DeviceSecurityCard_heading { | ||
margin: 0 0 $spacing-4 0; | ||
} | ||
.mx_DeviceSecurityCard_description { | ||
margin: 0 0 $spacing-8 0; | ||
font-size: $font-12px; | ||
color: $secondary-content; | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
60 changes: 60 additions & 0 deletions
60
src/components/views/settings/devices/DeviceSecurityCard.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 @@ | ||
/* | ||
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 VerifiedIcon } from '../../../../../res/img/e2e/verified.svg'; | ||
import { Icon as UnverifiedIcon } from '../../../../../res/img/e2e/warning.svg'; | ||
import { Icon as InactiveIcon } from '../../../../../res/img/element-icons/settings/inactive.svg'; | ||
|
||
export enum DeviceSecurityVariation { | ||
Verified = 'Verified', | ||
Unverified = 'Unverified', | ||
Inactive = 'Inactive', | ||
} | ||
interface Props { | ||
variation: DeviceSecurityVariation; | ||
heading: string; | ||
description: string | React.ReactNode; | ||
children?: React.ReactNode; | ||
} | ||
|
||
const VariationIcon: Record<DeviceSecurityVariation, React.FC<React.SVGProps<SVGSVGElement>>> = { | ||
[DeviceSecurityVariation.Inactive]: InactiveIcon, | ||
[DeviceSecurityVariation.Verified]: VerifiedIcon, | ||
[DeviceSecurityVariation.Unverified]: UnverifiedIcon, | ||
}; | ||
|
||
const DeviceSecurityIcon: React.FC<{ variation: DeviceSecurityVariation }> = ({ variation }) => { | ||
const Icon = VariationIcon[variation]; | ||
return <div className={classNames('mx_DeviceSecurityCard_icon', variation)}> | ||
<Icon height={16} width={16} /> | ||
</div>; | ||
}; | ||
|
||
const DeviceSecurityCard: React.FC<Props> = ({ variation, heading, description, children }) => { | ||
return <div className='mx_DeviceSecurityCard'> | ||
<DeviceSecurityIcon variation={variation} /> | ||
<div className='mx_DeviceSecurityCard_content'> | ||
<p className='mx_DeviceSecurityCard_heading'>{ heading }</p> | ||
<p className='mx_DeviceSecurityCard_description'>{ description }</p> | ||
{ children } | ||
</div> | ||
</div>; | ||
}; | ||
|
||
export default DeviceSecurityCard; |
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
45 changes: 45 additions & 0 deletions
45
test/components/views/settings/devices/DeviceSecurityCard-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,45 @@ | ||
/* | ||
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 { render } from '@testing-library/react'; | ||
import React from 'react'; | ||
|
||
import DeviceSecurityCard, { | ||
DeviceSecurityVariation, | ||
} from '../../../../../src/components/views/settings/devices/DeviceSecurityCard'; | ||
|
||
describe('<DeviceSecurityCard />', () => { | ||
const defaultProps = { | ||
variation: DeviceSecurityVariation.Verified, | ||
heading: 'Verified session', | ||
description: 'nice', | ||
}; | ||
const getComponent = (props = {}): React.ReactElement => | ||
<DeviceSecurityCard {...defaultProps} {...props} />; | ||
|
||
it('renders basic card', () => { | ||
const { container } = render(getComponent()); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
|
||
it('renders with children', () => { | ||
const { container } = render(getComponent({ | ||
children: <div>hey</div>, | ||
variation: DeviceSecurityVariation.Unverified, | ||
})); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
}); |
66 changes: 66 additions & 0 deletions
66
test/components/views/settings/devices/__snapshots__/DeviceSecurityCard-test.tsx.snap
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,66 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`<DeviceSecurityCard /> renders basic card 1`] = ` | ||
<div> | ||
<div | ||
class="mx_DeviceSecurityCard" | ||
> | ||
<div | ||
class="mx_DeviceSecurityCard_icon Verified" | ||
> | ||
<div | ||
height="16" | ||
width="16" | ||
/> | ||
</div> | ||
<div | ||
class="mx_DeviceSecurityCard_content" | ||
> | ||
<p | ||
class="mx_DeviceSecurityCard_heading" | ||
> | ||
Verified session | ||
</p> | ||
<p | ||
class="mx_DeviceSecurityCard_description" | ||
> | ||
nice | ||
</p> | ||
</div> | ||
</div> | ||
</div> | ||
`; | ||
|
||
exports[`<DeviceSecurityCard /> renders with children 1`] = ` | ||
<div> | ||
<div | ||
class="mx_DeviceSecurityCard" | ||
> | ||
<div | ||
class="mx_DeviceSecurityCard_icon Unverified" | ||
> | ||
<div | ||
height="16" | ||
width="16" | ||
/> | ||
</div> | ||
<div | ||
class="mx_DeviceSecurityCard_content" | ||
> | ||
<p | ||
class="mx_DeviceSecurityCard_heading" | ||
> | ||
Verified session | ||
</p> | ||
<p | ||
class="mx_DeviceSecurityCard_description" | ||
> | ||
nice | ||
</p> | ||
<div> | ||
hey | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
`; |
Oops, something went wrong.