Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task: tenant name ellipsis #1799

Merged
merged 8 commits into from
Jun 6, 2022
Merged
Show file tree
Hide file tree
Changes from 6 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
1 change: 1 addition & 0 deletions src/app/custom-hooks/ellipsis-detector/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { useEllipsisDetector } from './useEllipsisDetector';
20 changes: 20 additions & 0 deletions src/app/custom-hooks/ellipsis-detector/useEllipsisDetector.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { useEffect, useState } from 'react';

export const useEllipsisDetector = (className: string): boolean => {
const [isEllipsisActive, setIsEllipsisActive] = useState<boolean>(false);
useEffect(() => {

const ellipsisCheck = (collection: any) => {
if (collection?.length === 0) {
return;
}
if (collection[0].offsetWidth < collection[0].scrollWidth) {
setIsEllipsisActive(true);
}
}

ellipsisCheck(document.getElementsByClassName(className));
});

return isEllipsisActive;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ export const profileButtonStyles = (theme: ITheme) => {
':hover': {
background: `${theme.palette.neutralLight} !important`
}
},
icon: {
flex: 1
}
}
}
Expand Down
13 changes: 11 additions & 2 deletions src/app/views/authentication/profile/Profile.styles.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ITheme } from '@fluentui/react'
import { FontSizes, ITheme } from '@fluentui/react'

export const profileStyles = (theme: ITheme) => {
return {
Expand All @@ -17,7 +17,12 @@ export const profileStyles = (theme: ITheme) => {
secondaryText:
{
paddingBottom: 10,
textTransform: 'lowercase'
textTransform: 'lowercase',
textOverflow: 'ellipsis',
overflow: 'hidden',
whiteSpace: 'nowrap' as 'nowrap',
fontSize: FontSizes.small,
maxWidth: '165px'
},
root: {
height: '100%',
Expand Down Expand Up @@ -71,6 +76,10 @@ export const profileStyles = (theme: ITheme) => {
activeConsentStyles: {
marginRight: 10,
backgroundColor: theme.palette.themeDarker
},
tooltipContentStyle: {
dusplay: 'inline-block',
height: '15px'
}
}
}
33 changes: 26 additions & 7 deletions src/app/views/authentication/profile/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import {
Callout,
DefaultButton,
FontSizes,
getId,
getTheme,
IOverlayProps,
IPersonaProps,
IPersonaSharedProps,
ITooltipHostStyles,
Label,
mergeStyleSets,
Panel,
Expand All @@ -17,7 +19,8 @@ import {
Spinner,
SpinnerSize,
Stack,
styled
styled,
TooltipHost
} from '@fluentui/react';
import React, { useEffect, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
Expand All @@ -34,6 +37,7 @@ import { classNames } from '../../classnames';
import { Permission } from '../../query-runner/request/permissions';
import { authenticationStyles } from '../Authentication.styles';
import { profileStyles } from './Profile.styles';
import { useEllipsisDetector } from '../../../custom-hooks/ellipsis-detector';

const getInitials = (name: string) => {
let initials = '';
Expand Down Expand Up @@ -66,15 +70,15 @@ const Profile = (props: any) => {
const labelId = useId('callout-label');
const descriptionId = useId('callout-description');
const theme = getTheme();
const { personaStyleToken , profileSpinnerStyles, permissionsLabelStyles, inactiveConsentStyles,
const { personaStyleToken , profileSpinnerStyles, permissionsLabelStyles, inactiveConsentStyles, tooltipContentStyle,
personaButtonStyles, profileContainerStyles, permissionPanelStyles, activeConsentStyles } = profileStyles(theme);
const showTooltipContent : boolean = useEllipsisDetector('ms-Persona-secondaryText');

useEffect(() => {
if (authenticated) {
dispatch(getProfileInfo());
}
}, [authenticated]);

}, [authenticated, isCalloutVisible]);

if (!profile) {
return (<Spinner size={SpinnerSize.medium} styles={profileSpinnerStyles} />);
Expand Down Expand Up @@ -154,14 +158,28 @@ const Profile = (props: any) => {
const panelOverlayProps: IOverlayProps = {
isDarkThemed: true
}

const onRenderSecondaryText = (prop: IPersonaProps): JSX.Element => {
return (
<span style={{fontSize: FontSizes.small}}>
<TooltipHost
content={showTooltipContent ? prop.secondaryText : ''}
id= {getId()}
calloutProps={{ gapSpace: 0}}
tooltipProps={{onRenderContent: () => renderTooltipContent(prop.secondaryText!)}}
>
{prop.secondaryText}
</span>
</TooltipHost>
);
}

const renderTooltipContent = (tooltipText: string) : JSX.Element => {
return (
<div style={tooltipContentStyle}>
{tooltipText}
</div>
)
}

const showProfileComponent = (userPersona: any): React.ReactNode => {

const smallPersona = <Persona
Expand All @@ -175,7 +193,8 @@ const Profile = (props: any) => {
size={PersonaSize.size72}
hidePersonaDetails={false}
onRenderSecondaryText={onRenderSecondaryText}
styles={personaStyleToken} />
styles={personaStyleToken}
className='personaEmailLabel' />

return (<>
<ActionButton ariaLabel='profile'
Expand Down
9 changes: 7 additions & 2 deletions src/app/views/main-header/MainHeader.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ export const mainHeaderStyles = (theme: ITheme, mobileScreen?: boolean) => {
},
rightItemsStyles: {
root: {
alignItems: 'center',
flexBasis: mobileScreen ? '137px' : ''
alignItems: 'center'
}
},
feedbackIconAdjustmentStyles: {
Expand All @@ -29,6 +28,12 @@ export const mainHeaderStyles = (theme: ITheme, mobileScreen?: boolean) => {
tenantContainerStyle: {
margin: '0px 10px'
},
tenantNameStyle: {
textOverflow: 'ellipsis',
overflow: 'hidden',
maxWidth: '100px',
whiteSpace: 'nowrap' as 'nowrap'
},
iconButton: {
menuIcon: { fontSize: 15 },
root: {
Expand Down
16 changes: 13 additions & 3 deletions src/app/views/main-header/MainHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { useSelector } from 'react-redux';
import { IRootState } from '../../../types/root';
import { mainHeaderStyles } from './MainHeader.styles';
import TenantIcon from './tenantIcon';
import { useEllipsisDetector } from '../../custom-hooks/ellipsis-detector';

interface MainHeaderProps {
minimised: boolean;
Expand All @@ -44,8 +45,11 @@ export const MainHeader: React.FunctionComponent <MainHeaderProps> = (props: Mai
const minimised = props.minimised;
const mobileScreen = props.mobileScreen;
const currentTheme = getTheme();
const showTooltipContent : boolean = useEllipsisDetector('tenantLabel');


const { rootStyles : itemAlignmentStackStyles, rightItemsStyles, graphExplorerLabelStyles,
feedbackIconAdjustmentStyles, tenantIconStyles, moreInformationStyles,
feedbackIconAdjustmentStyles, tenantIconStyles, moreInformationStyles, tenantNameStyle,
tenantLabelStyle, tenantContainerStyle } = mainHeaderStyles(currentTheme, mobileScreen);

return (
Expand Down Expand Up @@ -80,7 +84,7 @@ export const MainHeader: React.FunctionComponent <MainHeaderProps> = (props: Mai
</Stack>

<Stack horizontal styles={rightItemsStyles}
tokens={{childrenGap:mobileScreen? 0: 10}}
tokens={{childrenGap: mobileScreen ? 0: 10}}
>
{!mobileScreen && <FontIcon aria-label='tenant icon' iconName='tenantIcon' style={tenantIconStyles} />}
{!profile && !mobileScreen &&
Expand All @@ -102,7 +106,13 @@ export const MainHeader: React.FunctionComponent <MainHeaderProps> = (props: Mai
{profile && !mobileScreen &&
<div style={tenantContainerStyle}>
<Label style={tenantLabelStyle}>Tenant</Label>
<Label>{profile.tenant}</Label>
<TooltipHost
content={showTooltipContent ? profile.tenant : ''}
id= { getId() }
calloutProps={{ gapSpace: 0 }}
>
<Label className='tenantLabel' style={tenantNameStyle}> {profile.tenant} </Label>
</TooltipHost>
</div>
}
<span style={ moreInformationStyles }> <Settings /> </span>
Expand Down