From 0d25d297a33841b8e8e0c24c0d48c60a37fa784a Mon Sep 17 00:00:00 2001 From: Vladimir Masarik Date: Mon, 5 Sep 2022 16:46:08 +0200 Subject: [PATCH] add more info into providers Signed-off-by: Vladimir Masarik --- .../AuthProviders/ProviderSettingsAvatar.tsx | 38 +++++++++++++++++++ .../AuthProviders/ProviderSettingsItem.tsx | 37 +++++++++++++++--- 2 files changed, 70 insertions(+), 5 deletions(-) create mode 100644 plugins/user-settings/src/components/AuthProviders/ProviderSettingsAvatar.tsx diff --git a/plugins/user-settings/src/components/AuthProviders/ProviderSettingsAvatar.tsx b/plugins/user-settings/src/components/AuthProviders/ProviderSettingsAvatar.tsx new file mode 100644 index 0000000000..e92b0efe15 --- /dev/null +++ b/plugins/user-settings/src/components/AuthProviders/ProviderSettingsAvatar.tsx @@ -0,0 +1,38 @@ +/* + * Copyright 2020 The Backstage Authors + * + * 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 { BackstageTheme } from '@backstage/theme'; +import { makeStyles, Avatar } from '@material-ui/core'; +import { sidebarConfig } from '@backstage/core-components'; + +const useStyles = makeStyles(theme => ({ + avatar: { + width: ({ size }) => size, + height: ({ size }) => size, + fontSize: ({ size }) => size * 0.7, + border: `1px solid ${theme.palette.textSubtle}`, + }, +})); + +type Props = { size?: number; picture: string | undefined }; + +export const ProviderSettingsAvatar = ({ size, picture }: Props) => { + const { iconSize } = sidebarConfig; + const classes = useStyles(size ? { size } : { size: iconSize }); + + return ; +}; diff --git a/plugins/user-settings/src/components/AuthProviders/ProviderSettingsItem.tsx b/plugins/user-settings/src/components/AuthProviders/ProviderSettingsItem.tsx index 4a3b28b335..ef31e70d81 100644 --- a/plugins/user-settings/src/components/AuthProviders/ProviderSettingsItem.tsx +++ b/plugins/user-settings/src/components/AuthProviders/ProviderSettingsItem.tsx @@ -17,11 +17,13 @@ import React, { useEffect, useState } from 'react'; import { Button, + Grid, ListItem, ListItemIcon, ListItemSecondaryAction, ListItemText, Tooltip, + Typography, } from '@material-ui/core'; import { ApiRef, @@ -32,6 +34,7 @@ import { useApi, IconComponent, } from '@backstage/core-plugin-api'; +import { ProviderSettingsAvatar } from './ProviderSettingsAvatar'; /** @public */ export const ProviderSettingsItem = (props: { @@ -44,7 +47,8 @@ export const ProviderSettingsItem = (props: { const api = useApi(apiRef); const [signedIn, setSignedIn] = useState(false); - const [profileEmail, setProfileEmail] = useState(''); + const emptyProfile: ProfileInfo = {}; + const [profile, setProfile] = useState(emptyProfile); useEffect(() => { let didCancel = false; @@ -55,13 +59,13 @@ export const ProviderSettingsItem = (props: { if (!didCancel) { api .getProfile({ optional: true }) - .then((profile: ProfileInfo | undefined) => { + .then((profileResponse: ProfileInfo | undefined) => { if (sessionState === SessionState.SignedIn) { setSignedIn(true); } else { - setSignedIn(profile !== undefined); + setSignedIn(profileResponse !== undefined); } - setProfileEmail(profile?.email ?? ''); + setProfile(profileResponse ?? {}); }); } }); @@ -82,7 +86,30 @@ export const ProviderSettingsItem = (props: { secondary={ - {description}. Signed in as {profileEmail} + + + + + + + + + {profile.displayName} + + + {profile.email} + + + {description} + + + + + }