Skip to content

Commit 1b1b7fd

Browse files
Merge pull request #532 from kartverket/flicker-fix-secchamp
Pass selectedUser to secchampitem
2 parents ff5b239 + 2773a32 commit 1b1b7fd

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

plugins/security-champion/src/components/SecurityChampion.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ export const SecurityChampion = ({
123123
onSuccess: () => {
124124
refetch();
125125
setEdit(false);
126-
setSelectedUser(null);
127126
},
128127
onError: () => {
129128
setIsMutationError(true);
@@ -138,7 +137,6 @@ export const SecurityChampion = ({
138137
onSuccess: () => {
139138
refetch();
140139
setEdit(false);
141-
setSelectedUser(null);
142140
},
143141
onError: () => {
144142
setIsMutationError(true);
@@ -149,6 +147,7 @@ export const SecurityChampion = ({
149147
};
150148

151149
const onEdit = () => {
150+
setSelectedUser(null);
152151
setEdit(!edit);
153152
};
154153

@@ -229,6 +228,7 @@ export const SecurityChampion = ({
229228
key={0}
230229
champion={data[0]}
231230
repositories={[data[0].repositoryName]}
231+
selectedUser={selectedUser}
232232
/>
233233
<MissingReposItem
234234
reposWithSecChamps={[data[0].repositoryName]}

plugins/security-champion/src/components/SecurityChampionItem.tsx

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,20 @@ import Stack from '@mui/material/Stack';
1212
import List from '@mui/material/List';
1313
import Link from '@mui/material/Link';
1414
import IconButton from '@mui/material/IconButton';
15+
import { UserEntity } from '@backstage/catalog-model';
1516

16-
import style from './securityCard.module.css';
17-
18-
const KVSecurityChampionItem = ({ champion }: { champion: SecurityChamp }) => {
17+
const KVSecurityChampionItem = ({
18+
champion,
19+
selectedUser,
20+
}: {
21+
champion: SecurityChamp;
22+
selectedUser?: UserEntity | null;
23+
}) => {
1924
const { user, loading, error } = useUserProfile(
2025
champion.securityChampionEmail!,
2126
);
2227

23-
if (loading && !user)
28+
if (loading && !selectedUser)
2429
return (
2530
<Box sx={{ display: 'flex' }}>
2631
<CircularProgress />
@@ -32,13 +37,23 @@ const KVSecurityChampionItem = ({ champion }: { champion: SecurityChamp }) => {
3237
return (
3338
<ListItem>
3439
<ListItemAvatar>
35-
<Avatar src={user?.spec.profile?.picture} />
40+
<Avatar
41+
src={
42+
user?.spec.profile?.picture || selectedUser?.spec.profile?.picture
43+
}
44+
/>
3645
</ListItemAvatar>
3746
<ListItemText
3847
primary={
39-
user?.spec?.profile?.displayName || champion.securityChampionEmail
48+
user?.spec?.profile?.displayName ||
49+
selectedUser?.spec?.profile?.displayName ||
50+
champion.securityChampionEmail
51+
}
52+
secondary={
53+
user?.spec.profile?.email ||
54+
selectedUser?.spec.profile?.email ||
55+
'User not in catalog'
4056
}
41-
secondary={user?.spec.profile?.email || 'User not in catalog'}
4257
/>
4358
</ListItem>
4459
);
@@ -61,15 +76,20 @@ const UnknownSecurityChampionItem = ({
6176
export const SecurityChampionItem = ({
6277
champion,
6378
repositories,
79+
selectedUser,
6480
}: {
6581
champion: SecurityChamp;
6682
repositories?: string[];
83+
selectedUser?: UserEntity | null;
6784
}) => {
6885
return (
6986
<ListItem>
7087
<Stack className={style.item}>
7188
{champion.securityChampionEmail && (
72-
<KVSecurityChampionItem champion={champion} />
89+
<KVSecurityChampionItem
90+
champion={champion}
91+
selectedUser={selectedUser}
92+
/>
7393
)}
7494
{!champion.securityChampionEmail && (
7595
<UnknownSecurityChampionItem champion={champion} />

0 commit comments

Comments
 (0)