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

4203 - Admin Collaborators: Multiple countries truncated with ... #4212

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 3 additions & 5 deletions src/client/pages/AdminCollaborators/RoleField/RoleField.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
.admin-user-management__role-field {
text-align: left;
word-break: break-word;

.invitation {
color: $text-disabled;
font-style: italic;
}
max-width: 250px;
overflow: hidden;
text-overflow: ellipsis;

span:not(:last-child)::after {
content: ', ';
Expand Down
43 changes: 14 additions & 29 deletions src/client/pages/AdminCollaborators/RoleField/RoleField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,64 +2,49 @@ import './RoleField.scss'
import React from 'react'
import { useTranslation } from 'react-i18next'

import classNames from 'classnames'
import { TFunction } from 'i18next'

import { Areas, CountryIso } from 'meta/area'
import { TooltipId } from 'meta/tooltip'
import { CountryUserSummary, RoleName, Users } from 'meta/user'

const MAX_ITEMS = 3

type Props = {
roleName: RoleName
userSummary: CountryUserSummary
}

const _getAllRolesAndInvitations = (props: Props): Array<{ countryIso: CountryIso; invitation?: boolean }> => {
const _getAllRoles = (props: Props): Array<{ countryIso: CountryIso }> => {
const { userSummary, roleName } = props

const invitations = userSummary.invitations
?.filter((role) => role.role === roleName)
.map(({ countryIso }) => ({ countryIso, invitation: true }))

const roles = userSummary.roles?.filter((role) => role.role === roleName).map(({ countryIso }) => ({ countryIso }))

return [...(roles ?? []), ...(invitations ?? [])]
return userSummary.roles?.filter((role) => role.role === roleName).map(({ countryIso }) => ({ countryIso })) ?? []
}

const _getRoleLabel = (countryIso: CountryIso, roleName: RoleName, invitation: boolean, t: TFunction): string => {
const baseLabel =
roleName === RoleName.ADMINISTRATOR
? t(Users.getI18nRoleLabelKey(RoleName.ADMINISTRATOR))
: t(Areas.getTranslationKey(countryIso))

return invitation ? `${baseLabel} (${t('admin.invitationPending')})` : baseLabel
const _getRoleLabel = (countryIso: CountryIso, roleName: RoleName, t: TFunction): string => {
return roleName === RoleName.ADMINISTRATOR
? t(Users.getI18nRoleLabelKey(RoleName.ADMINISTRATOR))
: t(Areas.getTranslationKey(countryIso))
}

const RoleField: React.FC<Props> = (props: Props) => {
const { roleName, userSummary } = props
const { t } = useTranslation()

const allItems = _getAllRolesAndInvitations({ roleName, userSummary })
const allItems = _getAllRoles({ roleName, userSummary })

const shouldCut = allItems.length > 3
const firstThreeItems = shouldCut ? allItems.slice(0, 3) : allItems
const shouldCut = allItems.length > MAX_ITEMS
const firstThreeItems = shouldCut ? allItems.slice(0, MAX_ITEMS) : allItems

const tooltipContent = shouldCut
? allItems
.map(({ countryIso, invitation }) => _getRoleLabel(countryIso, roleName, invitation ?? false, t))
.join(', ')
: ''
const tooltipContent = allItems.map(({ countryIso }) => _getRoleLabel(countryIso, roleName, t)).join(', ')

return (
<div
className="admin-user-management__role-field"
data-tooltip-content={tooltipContent}
data-tooltip-id={TooltipId.info}
>
{firstThreeItems.map(({ countryIso, invitation }) => (
<span key={`${userSummary.uuid}-${countryIso}`} className={classNames({ invitation })}>
{_getRoleLabel(countryIso, roleName, false, t)}
</span>
{firstThreeItems.map(({ countryIso }) => (
<span key={`${userSummary.uuid}-${countryIso}`}>{_getRoleLabel(countryIso, roleName, t)}</span>
))}
</div>
)
Expand Down
Loading