Skip to content

Commit

Permalink
Merge pull request #7910 from nixocio/ui_issue_5684
Browse files Browse the repository at this point in the history
Add type column to users list

Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
  • Loading branch information
softwarefactory-project-zuul[bot] authored Aug 20, 2020
2 parents 5458411 + 8402cf9 commit 51029a8
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 66 deletions.
147 changes: 82 additions & 65 deletions awx/ui_next/src/screens/User/UserList/UserListItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,72 +19,89 @@ import DataListCell from '../../../components/DataListCell';

import { User } from '../../../types';

class UserListItem extends React.Component {
static propTypes = {
user: User.isRequired,
detailUrl: string.isRequired,
isSelected: bool.isRequired,
onSelect: func.isRequired,
};
function UserListItem({ user, isSelected, onSelect, detailUrl, i18n }) {
const labelId = `check-action-${user.id}`;

render() {
const { user, isSelected, onSelect, detailUrl, i18n } = this.props;
const labelId = `check-action-${user.id}`;
return (
<DataListItem key={user.id} aria-labelledby={labelId} id={`${user.id}`}>
<DataListItemRow>
<DataListCheck
id={`select-user-${user.id}`}
checked={isSelected}
onChange={onSelect}
aria-labelledby={labelId}
/>
<DataListItemCells
dataListCells={[
<DataListCell key="username">
<Link to={`${detailUrl}`} id={labelId}>
<b>{user.username}</b>
</Link>
</DataListCell>,
<DataListCell key="first-name">
{user.first_name && (
<Fragment>
<b css="margin-right: 24px">{i18n._(t`First Name`)}</b>
{user.first_name}
</Fragment>
)}
</DataListCell>,
<DataListCell key="last-name">
{user.last_name && (
<Fragment>
<b css="margin-right: 24px">{i18n._(t`Last Name`)}</b>
{user.last_name}
</Fragment>
)}
</DataListCell>,
]}
/>
<DataListAction
aria-label="actions"
aria-labelledby={labelId}
id={labelId}
>
{user.summary_fields.user_capabilities.edit && (
<Tooltip content={i18n._(t`Edit User`)} position="top">
<Button
aria-label={i18n._(t`Edit User`)}
variant="plain"
component={Link}
to={`/users/${user.id}/edit`}
>
<PencilAltIcon />
</Button>
</Tooltip>
)}
</DataListAction>
</DataListItemRow>
</DataListItem>
);
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 (
<DataListItem key={user.id} aria-labelledby={labelId} id={`${user.id}`}>
<DataListItemRow>
<DataListCheck
id={`select-user-${user.id}`}
checked={isSelected}
onChange={onSelect}
aria-labelledby={labelId}
/>
<DataListItemCells
dataListCells={[
<DataListCell key="username" aria-label={i18n._(t`username`)}>
<Link to={`${detailUrl}`} id={labelId}>
<b>{user.username}</b>
</Link>
</DataListCell>,
<DataListCell
key="first-name"
aria-label={i18n._(t`user first name`)}
>
{user.first_name && (
<Fragment>
<b css="margin-right: 24px">{i18n._(t`First Name`)}</b>
{user.first_name}
</Fragment>
)}
</DataListCell>,
<DataListCell
key="last-name"
aria-label={i18n._(t`user last name`)}
>
{user.last_name && (
<Fragment>
<b css="margin-right: 24px">{i18n._(t`Last Name`)}</b>
{user.last_name}
</Fragment>
)}
</DataListCell>,
<DataListCell key="user-type" aria-label={i18n._(t`user type`)}>
{user_type}
</DataListCell>,
]}
/>
<DataListAction
aria-label="actions"
aria-labelledby={labelId}
id={labelId}
>
{user.summary_fields.user_capabilities.edit && (
<Tooltip content={i18n._(t`Edit User`)} position="top">
<Button
aria-label={i18n._(t`Edit User`)}
variant="plain"
component={Link}
to={`/users/${user.id}/edit`}
>
<PencilAltIcon />
</Button>
</Tooltip>
)}
</DataListAction>
</DataListItemRow>
</DataListItem>
);
}

UserListItem.prototype = {
user: User.isRequired,
detailUrl: string.isRequired,
isSelected: bool.isRequired,
onSelect: func.isRequired,
};

export default withI18n()(UserListItem);
8 changes: 7 additions & 1 deletion awx/ui_next/src/screens/User/UserList/UserListItem.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,18 @@ describe('UserListItem with full permissions', () => {
</I18nProvider>
);
});
test('initially renders succesfully', () => {
test('initially renders successfully', () => {
expect(wrapper.length).toBe(1);
});
test('edit button shown to users with edit capabilities', () => {
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', () => {
Expand Down

0 comments on commit 51029a8

Please sign in to comment.