Merge pull request #7910 from nixocio/ui_issue_5684

Add type column to users list

Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
softwarefactory-project-zuul[bot]
2020-08-20 21:13:00 +00:00
committed by GitHub
2 changed files with 89 additions and 66 deletions

View File

@@ -19,17 +19,18 @@ import DataListCell from '../../../components/DataListCell';
import { User } from '../../../types'; import { User } from '../../../types';
class UserListItem extends React.Component { function UserListItem({ user, isSelected, onSelect, detailUrl, i18n }) {
static propTypes = {
user: User.isRequired,
detailUrl: string.isRequired,
isSelected: bool.isRequired,
onSelect: func.isRequired,
};
render() {
const { user, isSelected, onSelect, detailUrl, i18n } = this.props;
const labelId = `check-action-${user.id}`; const labelId = `check-action-${user.id}`;
let user_type;
if (user.is_superuser) {
user_type = i18n._(t`System Administrator`);
} else if (user.is_system_auditor) {
user_type = i18n._(t`System Auditor`);
} else {
user_type = i18n._(t`Normal User`);
}
return ( return (
<DataListItem key={user.id} aria-labelledby={labelId} id={`${user.id}`}> <DataListItem key={user.id} aria-labelledby={labelId} id={`${user.id}`}>
<DataListItemRow> <DataListItemRow>
@@ -41,12 +42,15 @@ class UserListItem extends React.Component {
/> />
<DataListItemCells <DataListItemCells
dataListCells={[ dataListCells={[
<DataListCell key="username"> <DataListCell key="username" aria-label={i18n._(t`username`)}>
<Link to={`${detailUrl}`} id={labelId}> <Link to={`${detailUrl}`} id={labelId}>
<b>{user.username}</b> <b>{user.username}</b>
</Link> </Link>
</DataListCell>, </DataListCell>,
<DataListCell key="first-name"> <DataListCell
key="first-name"
aria-label={i18n._(t`user first name`)}
>
{user.first_name && ( {user.first_name && (
<Fragment> <Fragment>
<b css="margin-right: 24px">{i18n._(t`First Name`)}</b> <b css="margin-right: 24px">{i18n._(t`First Name`)}</b>
@@ -54,7 +58,10 @@ class UserListItem extends React.Component {
</Fragment> </Fragment>
)} )}
</DataListCell>, </DataListCell>,
<DataListCell key="last-name"> <DataListCell
key="last-name"
aria-label={i18n._(t`user last name`)}
>
{user.last_name && ( {user.last_name && (
<Fragment> <Fragment>
<b css="margin-right: 24px">{i18n._(t`Last Name`)}</b> <b css="margin-right: 24px">{i18n._(t`Last Name`)}</b>
@@ -62,6 +69,9 @@ class UserListItem extends React.Component {
</Fragment> </Fragment>
)} )}
</DataListCell>, </DataListCell>,
<DataListCell key="user-type" aria-label={i18n._(t`user type`)}>
{user_type}
</DataListCell>,
]} ]}
/> />
<DataListAction <DataListAction
@@ -85,6 +95,13 @@ class UserListItem extends React.Component {
</DataListItemRow> </DataListItemRow>
</DataListItem> </DataListItem>
); );
}
} }
UserListItem.prototype = {
user: User.isRequired,
detailUrl: string.isRequired,
isSelected: bool.isRequired,
onSelect: func.isRequired,
};
export default withI18n()(UserListItem); export default withI18n()(UserListItem);

View File

@@ -28,12 +28,18 @@ describe('UserListItem with full permissions', () => {
</I18nProvider> </I18nProvider>
); );
}); });
test('initially renders succesfully', () => { test('initially renders successfully', () => {
expect(wrapper.length).toBe(1); expect(wrapper.length).toBe(1);
}); });
test('edit button shown to users with edit capabilities', () => { test('edit button shown to users with edit capabilities', () => {
expect(wrapper.find('PencilAltIcon').exists()).toBeTruthy(); expect(wrapper.find('PencilAltIcon').exists()).toBeTruthy();
}); });
test('should display user type', () => {
expect(
wrapper.find('DataListCell[aria-label="user type"]').prop('children')
).toEqual('System Administrator');
});
}); });
describe('UserListItem without full permissions', () => { describe('UserListItem without full permissions', () => {