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

Commit 0d726cd

Browse files
Kerry Archibaldsandhose
authored andcommitted
add client logo to session tile and detail
1 parent 0bee128 commit 0d726cd

File tree

13 files changed

+121
-14
lines changed

13 files changed

+121
-14
lines changed

frontend/src/components/OAuth2Session.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export const OAUTH2_SESSION_FRAGMENT = graphql(/* GraphQL */ `
3434
clientId
3535
clientName
3636
clientUri
37+
logoUri
3738
}
3839
}
3940
`);
@@ -48,6 +49,7 @@ export type Oauth2SessionType = {
4849
clientId: string;
4950
clientName: string;
5051
clientUri: string;
52+
logoUri: string | null;
5153
};
5254
};
5355

@@ -103,6 +105,7 @@ const OAuth2Session: React.FC<Props> = ({ session }) => {
103105
createdAt={data.createdAt}
104106
finishedAt={data.finishedAt || undefined}
105107
clientName={data.client.clientName}
108+
clientLogoUri={data.client.logoUri || undefined}
106109
>
107110
{!data.finishedAt && <EndSessionButton endSession={onSessionEnd} />}
108111
</Session>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* Copyright 2023 The Matrix.org Foundation C.I.C.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
.avatar {
17+
object-fit: cover;
18+
overflow: hidden;
19+
aspect-ratio: 1 / 1;
20+
width: var(--mas-avatar-size);
21+
border-radius: 50%;
22+
display: inline-block;
23+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright 2023 The Matrix.org Foundation C.I.C.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import { Avatar } from "@vector-im/compound-web";
16+
import { CSSProperties } from "react";
17+
18+
import styles from "./ClientAvatar.module.css";
19+
20+
const ClientAvatar: React.FC<{
21+
name: string;
22+
logoUri?: string;
23+
/**
24+
* Render a fallback avatar using client name when truthy
25+
* Otherwise return null when no logoUri
26+
*/
27+
withFallback?: boolean;
28+
size: string;
29+
}> = ({ name, logoUri, withFallback, size }) => {
30+
// compound's lazy loading for avatars does not allow CORS requests
31+
if (logoUri) {
32+
return (
33+
<img
34+
className={styles.avatar}
35+
src={logoUri}
36+
alt={name}
37+
style={
38+
{
39+
"--mas-avatar-size": size,
40+
} as CSSProperties
41+
}
42+
/>
43+
);
44+
}
45+
if (withFallback) {
46+
return <Avatar size={size} id={name} name={name} src={logoUri} />;
47+
}
48+
return null;
49+
};
50+
51+
export default ClientAvatar;

frontend/src/components/Session/Session.module.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
}
2222

2323
.session-metadata {
24+
display: flex;
25+
flex-direction: row;
26+
align-items: center;
27+
gap: var(--cpd-space-1x);
2428
color: var(--cpd-color-text-secondary);
2529

2630
&[data-finished] {

frontend/src/components/Session/Session.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { ReactNode } from "react";
1818
import Block from "../Block";
1919
import DateTime from "../DateTime";
2020

21+
import ClientAvatar from "./ClientAvatar";
2122
import styles from "./Session.module.css";
2223

2324
const SessionMetadata: React.FC<React.ComponentProps<typeof Body>> = (
@@ -30,6 +31,7 @@ export type SessionProps = {
3031
createdAt: string;
3132
finishedAt?: string;
3233
clientName?: string;
34+
clientLogoUri?: string;
3335
isCurrent?: boolean;
3436
};
3537
const Session: React.FC<React.PropsWithChildren<SessionProps>> = ({
@@ -38,6 +40,7 @@ const Session: React.FC<React.PropsWithChildren<SessionProps>> = ({
3840
createdAt,
3941
finishedAt,
4042
clientName,
43+
clientLogoUri,
4144
isCurrent,
4245
children,
4346
}) => {
@@ -56,7 +59,6 @@ const Session: React.FC<React.PropsWithChildren<SessionProps>> = ({
5659
<H6 className={styles.sessionName} title={id}>
5760
{name || id}
5861
</H6>
59-
6062
<SessionMetadata weight="semibold">
6163
Signed in <DateTime datetime={createdAt} />
6264
</SessionMetadata>
@@ -67,7 +69,11 @@ const Session: React.FC<React.PropsWithChildren<SessionProps>> = ({
6769
)}
6870
{!!clientName && (
6971
<SessionMetadata>
70-
Client:{" "}
72+
<ClientAvatar
73+
size="var(--cpd-space-4x)"
74+
name={clientName}
75+
logoUri={clientLogoUri}
76+
/>{" "}
7177
<SessionMetadata weight="semibold" as="span">
7278
{clientName}
7379
</SessionMetadata>

frontend/src/components/Session/__snapshots__/Session.test.tsx.snap

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ exports[`<Session /> > uses client name when truthy 1`] = `
8181
<p
8282
className="_font-body-sm-regular_1g2sj_45 _sessionMetadata_634806"
8383
>
84-
Client:
8584
8685
<span
8786
className="_font-body-sm-semibold_1g2sj_49 _sessionMetadata_634806"

frontend/src/components/SessionDetail/OAuth2SessionDetail.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
Oauth2SessionType,
2525
endSessionFamily,
2626
} from "../OAuth2Session";
27+
import ClientAvatar from "../Session/ClientAvatar";
2728
import EndSessionButton from "../Session/EndSessionButton";
2829

2930
import SessionDetails from "./SessionDetails";
@@ -70,7 +71,19 @@ const OAuth2SessionDetail: React.FC<Props> = ({ session }) => {
7071
];
7172

7273
const clientDetails = [
73-
{ label: "Name", value: data.client.clientName },
74+
{
75+
label: "Name",
76+
value: (
77+
<>
78+
<ClientAvatar
79+
name={data.client.clientName}
80+
logoUri={data.client.logoUri || undefined}
81+
size="var(--cpd-space-4x)"
82+
/>
83+
{data.client.clientName}
84+
</>
85+
),
86+
},
7487
{ label: "ID", value: <code>{data.client.clientId}</code> },
7588
{
7689
label: "Uri",

frontend/src/components/SessionDetail/SessionDetails.module.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,8 @@
3333

3434
.detail-value {
3535
overflow-wrap: anywhere;
36+
display: flex;
37+
flex-direction: row;
38+
align-items: center;
39+
gap: var(--cpd-space-1x);
3640
}

frontend/src/components/__snapshots__/CompatSession.test.tsx.snap

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ exports[`<CompatSession /> > renders a finished session 1`] = `
3636
<p
3737
className="_font-body-sm-regular_1g2sj_45 _sessionMetadata_634806"
3838
>
39-
Client:
4039
4140
<span
4241
className="_font-body-sm-semibold_1g2sj_49 _sessionMetadata_634806"
@@ -74,7 +73,6 @@ exports[`<CompatSession /> > renders an active session 1`] = `
7473
<p
7574
className="_font-body-sm-regular_1g2sj_45 _sessionMetadata_634806"
7675
>
77-
Client:
7876
7977
<span
8078
className="_font-body-sm-semibold_1g2sj_49 _sessionMetadata_634806"

frontend/src/components/__snapshots__/OAuth2Session.test.tsx.snap

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ exports[`<OAuth2Session /> > renders a finished session 1`] = `
3636
<p
3737
className="_font-body-sm-regular_1g2sj_45 _sessionMetadata_634806"
3838
>
39-
Client:
4039
4140
<span
4241
className="_font-body-sm-semibold_1g2sj_49 _sessionMetadata_634806"
@@ -74,7 +73,6 @@ exports[`<OAuth2Session /> > renders an active session 1`] = `
7473
<p
7574
className="_font-body-sm-regular_1g2sj_45 _sessionMetadata_634806"
7675
>
77-
Client:
7876
7977
<span
8078
className="_font-body-sm-semibold_1g2sj_49 _sessionMetadata_634806"

0 commit comments

Comments
 (0)