Merge pull request #9182 from keithjgrant/6189-hosts-users-teams-tables

Convert Hosts/Users/Teams list to tables

Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
softwarefactory-project-zuul[bot]
2021-02-09 13:16:59 +00:00
committed by GitHub
11 changed files with 375 additions and 378 deletions

View File

@@ -8,10 +8,14 @@ import { HostsAPI } from '../../../api';
import AlertModal from '../../../components/AlertModal'; import AlertModal from '../../../components/AlertModal';
import DataListToolbar from '../../../components/DataListToolbar'; import DataListToolbar from '../../../components/DataListToolbar';
import ErrorDetail from '../../../components/ErrorDetail'; import ErrorDetail from '../../../components/ErrorDetail';
import PaginatedDataList, { import {
ToolbarAddButton, ToolbarAddButton,
ToolbarDeleteButton, ToolbarDeleteButton,
} from '../../../components/PaginatedDataList'; } from '../../../components/PaginatedDataList';
import PaginatedTable, {
HeaderRow,
HeaderCell,
} from '../../../components/PaginatedTable';
import useRequest, { useDeleteItems } from '../../../util/useRequest'; import useRequest, { useDeleteItems } from '../../../util/useRequest';
import { import {
encodeQueryString, encodeQueryString,
@@ -130,7 +134,7 @@ function HostList({ i18n }) {
return ( return (
<PageSection> <PageSection>
<Card> <Card>
<PaginatedDataList <PaginatedTable
contentError={contentError} contentError={contentError}
hasContentLoading={isLoading || isDeleteLoading} hasContentLoading={isLoading || isDeleteLoading}
items={hosts} items={hosts}
@@ -157,14 +161,15 @@ function HostList({ i18n }) {
key: 'modified_by__username__icontains', key: 'modified_by__username__icontains',
}, },
]} ]}
toolbarSortColumns={[
{
name: i18n._(t`Name`),
key: 'name',
},
]}
toolbarSearchableKeys={searchableKeys} toolbarSearchableKeys={searchableKeys}
toolbarRelatedSearchableKeys={relatedSearchableKeys} toolbarRelatedSearchableKeys={relatedSearchableKeys}
headerRow={
<HeaderRow qsConfig={QS_CONFIG}>
<HeaderCell sortKey="name">{i18n._(t`Name`)}</HeaderCell>
<HeaderCell>{i18n._(t`Inventory`)}</HeaderCell>
<HeaderCell>{i18n._(t`Actions`)}</HeaderCell>
</HeaderRow>
}
renderToolbar={props => ( renderToolbar={props => (
<DataListToolbar <DataListToolbar
{...props} {...props}
@@ -193,13 +198,14 @@ function HostList({ i18n }) {
]} ]}
/> />
)} )}
renderItem={host => ( renderRow={(host, index) => (
<HostListItem <HostListItem
key={host.id} key={host.id}
host={host} host={host}
detailUrl={`${match.url}/${host.id}/details`} detailUrl={`${match.url}/${host.id}/details`}
isSelected={selected.some(row => row.id === host.id)} isSelected={selected.some(row => row.id === host.id)}
onSelect={() => handleSelect(host)} onSelect={() => handleSelect(host)}
rowIndex={index}
/> />
)} )}
emptyStateControls={ emptyStateControls={

View File

@@ -134,8 +134,9 @@ describe('<HostList />', () => {
act(() => { act(() => {
wrapper wrapper
.find('input#select-host-1') .find('.pf-c-table__check')
.closest('DataListCheck') .first()
.find('input')
.invoke('onChange')(); .invoke('onChange')();
}); });
wrapper.update(); wrapper.update();
@@ -147,8 +148,9 @@ describe('<HostList />', () => {
).toEqual(true); ).toEqual(true);
act(() => { act(() => {
wrapper wrapper
.find('input#select-host-1') .find('.pf-c-table__check')
.closest('DataListCheck') .first()
.find('input')
.invoke('onChange')(); .invoke('onChange')();
}); });
wrapper.update(); wrapper.update();

View File

@@ -1,91 +1,67 @@
import 'styled-components/macro'; import 'styled-components/macro';
import React, { Fragment } from 'react'; import React from 'react';
import { string, bool, func } from 'prop-types'; import { string, bool, func } from 'prop-types';
import { withI18n } from '@lingui/react'; import { withI18n } from '@lingui/react';
import { t } from '@lingui/macro'; import { t } from '@lingui/macro';
import { import { Button } from '@patternfly/react-core';
Button, import { Tr, Td } from '@patternfly/react-table';
DataListAction as _DataListAction,
DataListCheck,
DataListItem,
DataListItemRow,
DataListItemCells,
Tooltip,
} from '@patternfly/react-core';
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
import { PencilAltIcon } from '@patternfly/react-icons'; import { PencilAltIcon } from '@patternfly/react-icons';
import styled from 'styled-components'; import { ActionsTd, ActionItem } from '../../../components/PaginatedTable';
import DataListCell from '../../../components/DataListCell';
import Sparkline from '../../../components/Sparkline';
import { Host } from '../../../types'; import { Host } from '../../../types';
import HostToggle from '../../../components/HostToggle'; import HostToggle from '../../../components/HostToggle';
const DataListAction = styled(_DataListAction)` function HostListItem({
align-items: center; i18n,
display: grid; host,
grid-gap: 24px; isSelected,
grid-template-columns: 92px 40px; onSelect,
`; detailUrl,
rowIndex,
function HostListItem({ i18n, host, isSelected, onSelect, detailUrl }) { }) {
const labelId = `check-action-${host.id}`; const labelId = `check-action-${host.id}`;
return ( return (
<DataListItem key={host.id} aria-labelledby={labelId} id={`${host.id}`}> <Tr id={`host-row-${host.id}`}>
<DataListItemRow> <Td
<DataListCheck select={{
id={`select-host-${host.id}`} rowIndex,
checked={isSelected} isSelected,
onChange={onSelect} onSelect,
aria-labelledby={labelId} }}
/> dataLabel={i18n._(t`Selected`)}
<DataListItemCells />
dataListCells={[ <Td id={labelId} dataLabel={i18n._(t`Name`)}>
<DataListCell key="name"> <Link to={`${detailUrl}`}>
<Link to={`${detailUrl}`}> <b>{host.name}</b>
<b>{host.name}</b> </Link>
</Link> </Td>
</DataListCell>, <Td dataLabel={i18n._(t`Inventory`)}>
<DataListCell key="recentJobs"> {host.summary_fields.inventory && (
<Sparkline jobs={host.summary_fields.recent_jobs} /> <Link
</DataListCell>, to={`/inventories/inventory/${host.summary_fields.inventory.id}/details`}
<DataListCell key="inventory"> >
{host.summary_fields.inventory && ( {host.summary_fields.inventory.name}
<Fragment> </Link>
<b css="margin-right: 24px">{i18n._(t`Inventory`)}</b> )}
<Link </Td>
to={`/inventories/inventory/${host.summary_fields.inventory.id}/details`} <ActionsTd dataLabel={i18n._(t`Actions`)} gridColumns="auto 40px">
> <HostToggle host={host} />
{host.summary_fields.inventory.name} <ActionItem
</Link> visible={host.summary_fields.user_capabilities.edit}
</Fragment> tooltip={i18n._(t`Edit Host`)}
)}
</DataListCell>,
]}
/>
<DataListAction
aria-label={i18n._(t`actions`)}
aria-labelledby={labelId}
id={labelId}
> >
<HostToggle host={host} /> <Button
{host.summary_fields.user_capabilities.edit ? ( aria-label={i18n._(t`Edit Host`)}
<Tooltip content={i18n._(t`Edit Host`)} position="top"> variant="plain"
<Button component={Link}
aria-label={i18n._(t`Edit Host`)} to={`/hosts/${host.id}/edit`}
variant="plain" >
component={Link} <PencilAltIcon />
to={`/hosts/${host.id}/edit`} </Button>
> </ActionItem>
<PencilAltIcon /> </ActionsTd>
</Button> </Tr>
</Tooltip>
) : (
''
)}
</DataListAction>
</DataListItemRow>
</DataListItem>
); );
} }

View File

@@ -25,12 +25,16 @@ describe('<HostsListItem />', () => {
beforeEach(() => { beforeEach(() => {
wrapper = mountWithContexts( wrapper = mountWithContexts(
<HostsListItem <table>
isSelected={false} <tbody>
detailUrl="/host/1" <HostsListItem
onSelect={() => {}} isSelected={false}
host={mockHost} detailUrl="/host/1"
/> onSelect={() => {}}
host={mockHost}
/>
</tbody>
</table>
); );
}); });
@@ -46,12 +50,16 @@ describe('<HostsListItem />', () => {
const copyMockHost = Object.assign({}, mockHost); const copyMockHost = Object.assign({}, mockHost);
copyMockHost.summary_fields.user_capabilities.edit = false; copyMockHost.summary_fields.user_capabilities.edit = false;
wrapper = mountWithContexts( wrapper = mountWithContexts(
<HostsListItem <table>
isSelected={false} <tbody>
detailUrl="/host/1" <HostsListItem
onSelect={() => {}} isSelected={false}
host={copyMockHost} detailUrl="/host/1"
/> onSelect={() => {}}
host={copyMockHost}
/>
</tbody>
</table>
); );
expect(wrapper.find('PencilAltIcon').exists()).toBeFalsy(); expect(wrapper.find('PencilAltIcon').exists()).toBeFalsy();
}); });

View File

@@ -9,7 +9,11 @@ import useRequest, { useDeleteItems } from '../../../util/useRequest';
import AlertModal from '../../../components/AlertModal'; import AlertModal from '../../../components/AlertModal';
import DataListToolbar from '../../../components/DataListToolbar'; import DataListToolbar from '../../../components/DataListToolbar';
import ErrorDetail from '../../../components/ErrorDetail'; import ErrorDetail from '../../../components/ErrorDetail';
import PaginatedDataList, { import PaginatedTable, {
HeaderRow,
HeaderCell,
} from '../../../components/PaginatedTable';
import {
ToolbarAddButton, ToolbarAddButton,
ToolbarDeleteButton, ToolbarDeleteButton,
} from '../../../components/PaginatedDataList'; } from '../../../components/PaginatedDataList';
@@ -112,7 +116,7 @@ function TeamList({ i18n }) {
<Fragment> <Fragment>
<PageSection> <PageSection>
<Card> <Card>
<PaginatedDataList <PaginatedTable
contentError={contentError} contentError={contentError}
hasContentLoading={hasContentLoading} hasContentLoading={hasContentLoading}
items={teams} items={teams}
@@ -143,14 +147,15 @@ function TeamList({ i18n }) {
key: 'modified_by__username__icontains', key: 'modified_by__username__icontains',
}, },
]} ]}
toolbarSortColumns={[
{
name: i18n._(t`Name`),
key: 'name',
},
]}
toolbarSearchableKeys={searchableKeys} toolbarSearchableKeys={searchableKeys}
toolbarRelatedSearchableKeys={relatedSearchableKeys} toolbarRelatedSearchableKeys={relatedSearchableKeys}
headerRow={
<HeaderRow qsConfig={QS_CONFIG}>
<HeaderCell sortKey="name">{i18n._(t`Name`)}</HeaderCell>
<HeaderCell>{i18n._(t`Organization`)}</HeaderCell>
<HeaderCell>{i18n._(t`Actions`)}</HeaderCell>
</HeaderRow>
}
renderToolbar={props => ( renderToolbar={props => (
<DataListToolbar <DataListToolbar
{...props} {...props}
@@ -176,13 +181,14 @@ function TeamList({ i18n }) {
]} ]}
/> />
)} )}
renderItem={o => ( renderRow={(team, index) => (
<TeamListItem <TeamListItem
key={o.id} key={team.id}
team={o} team={team}
detailUrl={`${match.url}/${o.id}`} detailUrl={`${match.url}/${team.id}`}
isSelected={selected.some(row => row.id === o.id)} isSelected={selected.some(row => row.id === team.id)}
onSelect={() => handleSelect(o)} onSelect={() => handleSelect(team)}
rowIndex={index}
/> />
)} )}
emptyStateControls={ emptyStateControls={

View File

@@ -1,33 +1,23 @@
import 'styled-components/macro'; import 'styled-components/macro';
import React, { Fragment } from 'react'; import React from 'react';
import { string, bool, func } from 'prop-types'; import { string, bool, func } from 'prop-types';
import { withI18n } from '@lingui/react'; import { withI18n } from '@lingui/react';
import { t } from '@lingui/macro'; import { t } from '@lingui/macro';
import { import { Button } from '@patternfly/react-core';
Button, import { Tr, Td } from '@patternfly/react-table';
DataListAction as _DataListAction,
DataListCheck,
DataListItem,
DataListItemCells,
DataListItemRow,
Tooltip,
} from '@patternfly/react-core';
import styled from 'styled-components';
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
import { PencilAltIcon } from '@patternfly/react-icons'; import { PencilAltIcon } from '@patternfly/react-icons';
import DataListCell from '../../../components/DataListCell'; import { ActionsTd, ActionItem } from '../../../components/PaginatedTable';
import { Team } from '../../../types'; import { Team } from '../../../types';
const DataListAction = styled(_DataListAction)` function TeamListItem({
align-items: center; team,
display: grid; isSelected,
grid-gap: 16px; onSelect,
grid-template-columns: 40px; detailUrl,
`; rowIndex,
i18n,
function TeamListItem({ team, isSelected, onSelect, detailUrl, i18n }) { }) {
TeamListItem.propTypes = { TeamListItem.propTypes = {
team: Team.isRequired, team: Team.isRequired,
detailUrl: string.isRequired, detailUrl: string.isRequired,
@@ -38,57 +28,45 @@ function TeamListItem({ team, isSelected, onSelect, detailUrl, i18n }) {
const labelId = `check-action-${team.id}`; const labelId = `check-action-${team.id}`;
return ( return (
<DataListItem key={team.id} aria-labelledby={labelId} id={`${team.id}`}> <Tr id={`team-row-${team.id}`}>
<DataListItemRow> <Td
<DataListCheck select={{
id={`select-team-${team.id}`} rowIndex,
checked={isSelected} isSelected,
onChange={onSelect} onSelect,
aria-labelledby={labelId} }}
/> dataLabel={i18n._(t`Selected`)}
<DataListItemCells />
dataListCells={[ <Td id={labelId} dataLabel={i18n._(t`Name`)}>
<DataListCell key="name"> <Link id={labelId} to={`${detailUrl}`}>
<Link id={labelId} to={`${detailUrl}`}> <b>{team.name}</b>
<b>{team.name}</b> </Link>
</Link> </Td>
</DataListCell>, <Td dataLabel={i18n._(t`Organization`)}>
<DataListCell key="organization"> {team.summary_fields.organization && (
{team.summary_fields.organization && ( <Link
<Fragment> to={`/organizations/${team.summary_fields.organization.id}/details`}
<b>{i18n._(t`Organization`)}</b>{' '} >
<Link <b>{team.summary_fields.organization.name}</b>
to={`/organizations/${team.summary_fields.organization.id}/details`} </Link>
> )}
<b>{team.summary_fields.organization.name}</b> </Td>
</Link> <ActionsTd dataLabel={i18n._(t`Actions`)}>
</Fragment> <ActionItem
)} visible={team.summary_fields.user_capabilities.edit}
</DataListCell>, tooltip={i18n._(t`Edit Team`)}
]}
/>
<DataListAction
aria-label={i18n._(t`Actions`)}
aria-labelledby={labelId}
id={labelId}
> >
{team.summary_fields.user_capabilities.edit ? ( <Button
<Tooltip content={i18n._(t`Edit Team`)} position="top"> aria-label={i18n._(t`Edit Team`)}
<Button variant="plain"
aria-label={i18n._(t`Edit Team`)} component={Link}
variant="plain" to={`/teams/${team.id}/edit`}
component={Link} >
to={`/teams/${team.id}/edit`} <PencilAltIcon />
> </Button>
<PencilAltIcon /> </ActionItem>
</Button> </ActionsTd>
</Tooltip> </Tr>
) : (
''
)}
</DataListAction>
</DataListItemRow>
</DataListItem>
); );
} }
export default withI18n()(TeamListItem); export default withI18n()(TeamListItem);

View File

@@ -11,20 +11,24 @@ describe('<TeamListItem />', () => {
mountWithContexts( mountWithContexts(
<I18nProvider> <I18nProvider>
<MemoryRouter initialEntries={['/teams']} initialIndex={0}> <MemoryRouter initialEntries={['/teams']} initialIndex={0}>
<TeamListItem <table>
team={{ <tbody>
id: 1, <TeamListItem
name: 'Team 1', team={{
summary_fields: { id: 1,
user_capabilities: { name: 'Team 1',
edit: true, summary_fields: {
}, user_capabilities: {
}, edit: true,
}} },
detailUrl="/team/1" },
isSelected }}
onSelect={() => {}} detailUrl="/team/1"
/> isSelected
onSelect={() => {}}
/>
</tbody>
</table>
</MemoryRouter> </MemoryRouter>
</I18nProvider> </I18nProvider>
); );
@@ -33,20 +37,24 @@ describe('<TeamListItem />', () => {
const wrapper = mountWithContexts( const wrapper = mountWithContexts(
<I18nProvider> <I18nProvider>
<MemoryRouter initialEntries={['/teams']} initialIndex={0}> <MemoryRouter initialEntries={['/teams']} initialIndex={0}>
<TeamListItem <table>
team={{ <tbody>
id: 1, <TeamListItem
name: 'Team', team={{
summary_fields: { id: 1,
user_capabilities: { name: 'Team',
edit: true, summary_fields: {
}, user_capabilities: {
}, edit: true,
}} },
detailUrl="/team/1" },
isSelected }}
onSelect={() => {}} detailUrl="/team/1"
/> isSelected
onSelect={() => {}}
/>
</tbody>
</table>
</MemoryRouter> </MemoryRouter>
</I18nProvider> </I18nProvider>
); );
@@ -56,20 +64,24 @@ describe('<TeamListItem />', () => {
const wrapper = mountWithContexts( const wrapper = mountWithContexts(
<I18nProvider> <I18nProvider>
<MemoryRouter initialEntries={['/teams']} initialIndex={0}> <MemoryRouter initialEntries={['/teams']} initialIndex={0}>
<TeamListItem <table>
team={{ <tbody>
id: 1, <TeamListItem
name: 'Team', team={{
summary_fields: { id: 1,
user_capabilities: { name: 'Team',
edit: false, summary_fields: {
}, user_capabilities: {
}, edit: false,
}} },
detailUrl="/team/1" },
isSelected }}
onSelect={() => {}} detailUrl="/team/1"
/> isSelected
onSelect={() => {}}
/>
</tbody>
</table>
</MemoryRouter> </MemoryRouter>
</I18nProvider> </I18nProvider>
); );

View File

@@ -7,7 +7,11 @@ import { UsersAPI } from '../../../api';
import AlertModal from '../../../components/AlertModal'; import AlertModal from '../../../components/AlertModal';
import DataListToolbar from '../../../components/DataListToolbar'; import DataListToolbar from '../../../components/DataListToolbar';
import ErrorDetail from '../../../components/ErrorDetail'; import ErrorDetail from '../../../components/ErrorDetail';
import PaginatedDataList, { import PaginatedTable, {
HeaderRow,
HeaderCell,
} from '../../../components/PaginatedTable';
import {
ToolbarAddButton, ToolbarAddButton,
ToolbarDeleteButton, ToolbarDeleteButton,
} from '../../../components/PaginatedDataList'; } from '../../../components/PaginatedDataList';
@@ -101,7 +105,7 @@ function UserList({ i18n }) {
<> <>
<PageSection> <PageSection>
<Card> <Card>
<PaginatedDataList <PaginatedTable
contentError={contentError} contentError={contentError}
hasContentLoading={hasContentLoading} hasContentLoading={hasContentLoading}
items={users} items={users}
@@ -124,20 +128,6 @@ function UserList({ i18n }) {
key: 'last_name__icontains', key: 'last_name__icontains',
}, },
]} ]}
toolbarSortColumns={[
{
name: i18n._(t`Username`),
key: 'username',
},
{
name: i18n._(t`First Name`),
key: 'first_name',
},
{
name: i18n._(t`Last Name`),
key: 'last_name',
},
]}
toolbarSearchableKeys={searchableKeys} toolbarSearchableKeys={searchableKeys}
toolbarRelatedSearchableKeys={relatedSearchableKeys} toolbarRelatedSearchableKeys={relatedSearchableKeys}
renderToolbar={props => ( renderToolbar={props => (
@@ -167,13 +157,29 @@ function UserList({ i18n }) {
]} ]}
/> />
)} )}
renderItem={o => ( headerRow={
<HeaderRow qsConfig={QS_CONFIG}>
<HeaderCell sortKey="username">
{i18n._(t`Username`)}
</HeaderCell>
<HeaderCell sortKey="first_name">
{i18n._(t`First Name`)}
</HeaderCell>
<HeaderCell sortKey="last_name">
{i18n._(t`Last Name`)}
</HeaderCell>
<HeaderCell>{i18n._(t`Role`)}</HeaderCell>
<HeaderCell>{i18n._(t`Actions`)}</HeaderCell>
</HeaderRow>
}
renderRow={(user, index) => (
<UserListItem <UserListItem
key={o.id} key={user.id}
user={o} user={user}
detailUrl={`${match.url}/${o.id}/details`} detailUrl={`${match.url}/${user.id}/details`}
isSelected={selected.some(row => row.id === o.id)} isSelected={selected.some(row => row.id === user.id)}
onSelect={() => handleSelect(o)} onSelect={() => handleSelect(user)}
rowIndex={index}
/> />
)} )}
emptyStateControls={ emptyStateControls={

View File

@@ -129,51 +129,66 @@ describe('UsersList with full permissions', () => {
test('should check and uncheck the row item', async () => { test('should check and uncheck the row item', async () => {
expect( expect(
wrapper.find('DataListCheck[id="select-user-1"]').props().checked wrapper
.find('.pf-c-table__check input')
.first()
.props().checked
).toBe(false); ).toBe(false);
await act(async () => { await act(async () => {
wrapper.find('DataListCheck[id="select-user-1"]').invoke('onChange')( wrapper
true .find('.pf-c-table__check input')
); .first()
.invoke('onChange')(true);
}); });
wrapper.update(); wrapper.update();
expect( expect(
wrapper.find('DataListCheck[id="select-user-1"]').props().checked wrapper
.find('.pf-c-table__check input')
.first()
.props().checked
).toBe(true); ).toBe(true);
await act(async () => { await act(async () => {
wrapper.find('DataListCheck[id="select-user-1"]').invoke('onChange')( wrapper
false .find('.pf-c-table__check input')
); .first()
.invoke('onChange')(false);
}); });
wrapper.update(); wrapper.update();
expect( expect(
wrapper.find('DataListCheck[id="select-user-1"]').props().checked wrapper
.find('.pf-c-table__check input')
.first()
.props().checked
).toBe(false); ).toBe(false);
}); });
test('should check all row items when select all is checked', async () => { test('should check all row items when select all is checked', async () => {
wrapper.find('DataListCheck').forEach(el => { expect(wrapper.find('.pf-c-table__check input')).toHaveLength(2);
wrapper.find('.pf-c-table__check input').forEach(el => {
expect(el.props().checked).toBe(false); expect(el.props().checked).toBe(false);
}); });
await act(async () => { await act(async () => {
wrapper.find('Checkbox#select-all').invoke('onChange')(true); wrapper.find('Checkbox#select-all').invoke('onChange')(true);
}); });
wrapper.update(); wrapper.update();
wrapper.find('DataListCheck').forEach(el => { wrapper.find('.pf-c-table__check input').forEach(el => {
expect(el.props().checked).toBe(true); expect(el.props().checked).toBe(true);
}); });
await act(async () => { await act(async () => {
wrapper.find('Checkbox#select-all').invoke('onChange')(false); wrapper.find('Checkbox#select-all').invoke('onChange')(false);
}); });
wrapper.update(); wrapper.update();
wrapper.find('DataListCheck').forEach(el => { wrapper.find('.pf-c-table__check input').forEach(el => {
expect(el.props().checked).toBe(false); expect(el.props().checked).toBe(false);
}); });
}); });
test('should call api delete users for each selected user', async () => { test('should call api delete users for each selected user', async () => {
await act(async () => { await act(async () => {
wrapper.find('DataListCheck[id="select-user-1"]').invoke('onChange')(); wrapper
.find('.pf-c-table__check input')
.first()
.invoke('onChange')();
}); });
wrapper.update(); wrapper.update();
await act(async () => { await act(async () => {
@@ -185,10 +200,12 @@ describe('UsersList with full permissions', () => {
test('should show error modal when user is not successfully deleted from api', async () => { test('should show error modal when user is not successfully deleted from api', async () => {
UsersAPI.destroy.mockImplementationOnce(() => Promise.reject(new Error())); UsersAPI.destroy.mockImplementationOnce(() => Promise.reject(new Error()));
// expect(wrapper.debug()).toBe(false);
expect(wrapper.find('Modal').length).toBe(0); expect(wrapper.find('Modal').length).toBe(0);
await act(async () => { await act(async () => {
wrapper.find('DataListCheck[id="select-user-1"]').invoke('onChange')(); wrapper
.find('.pf-c-table__check input')
.first()
.invoke('onChange')();
}); });
wrapper.update(); wrapper.update();
await act(async () => { await act(async () => {

View File

@@ -3,24 +3,22 @@ import React, { Fragment } from 'react';
import { string, bool, func } from 'prop-types'; import { string, bool, func } from 'prop-types';
import { withI18n } from '@lingui/react'; import { withI18n } from '@lingui/react';
import { t } from '@lingui/macro'; import { t } from '@lingui/macro';
import { import { Button, Label } from '@patternfly/react-core';
Button, import { Tr, Td } from '@patternfly/react-table';
DataListAction,
DataListCheck,
DataListItem,
DataListItemCells,
DataListItemRow,
Label,
Tooltip,
} from '@patternfly/react-core';
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
import { PencilAltIcon } from '@patternfly/react-icons'; import { PencilAltIcon } from '@patternfly/react-icons';
import DataListCell from '../../../components/DataListCell'; import { ActionsTd, ActionItem } from '../../../components/PaginatedTable';
import { User } from '../../../types'; import { User } from '../../../types';
function UserListItem({ user, isSelected, onSelect, detailUrl, i18n }) { function UserListItem({
user,
isSelected,
onSelect,
detailUrl,
rowIndex,
i18n,
}) {
const labelId = `check-action-${user.id}`; const labelId = `check-action-${user.id}`;
let user_type; let user_type;
@@ -36,84 +34,64 @@ function UserListItem({ user, isSelected, onSelect, detailUrl, i18n }) {
const socialAuthUser = user.auth.length > 0; const socialAuthUser = user.auth.length > 0;
return ( return (
<DataListItem key={user.id} aria-labelledby={labelId} id={`${user.id}`}> <Tr id={`user-row-${user.id}`}>
<DataListItemRow> <Td
<DataListCheck select={{
id={`select-user-${user.id}`} rowIndex,
checked={isSelected} isSelected,
onChange={onSelect} onSelect,
aria-labelledby={labelId} }}
/> />
<DataListItemCells <Td id={labelId} dataLabel={i18n._(t`Username`)}>
dataListCells={[ <Link to={`${detailUrl}`} id={labelId}>
<DataListCell key="username" aria-label={i18n._(t`username`)}> <b>{user.username}</b>
<span id={labelId}> </Link>
<Link to={`${detailUrl}`} id={labelId}> {ldapUser && (
<b>{user.username}</b> <span css="margin-left: 12px">
</Link> <Label aria-label={i18n._(t`ldap user`)}>{i18n._(t`LDAP`)}</Label>
</span> </span>
{ldapUser && ( )}
<span css="margin-left: 12px"> {socialAuthUser && (
<Label aria-label={i18n._(t`ldap user`)}> <span css="margin-left: 12px">
{i18n._(t`LDAP`)} <Label aria-label={i18n._(t`social login`)}>
</Label> {i18n._(t`SOCIAL`)}
</span> </Label>
)} </span>
{socialAuthUser && ( )}
<span css="margin-left: 12px"> </Td>
<Label aria-label={i18n._(t`social login`)}> <Td dataLabel={i18n._(t`First Name`)}>
{i18n._(t`SOCIAL`)} {user.first_name && (
</Label> <Fragment>
</span> <b css="margin-right: 24px">{i18n._(t`First Name`)}</b>
)} {user.first_name}
</DataListCell>, </Fragment>
<DataListCell )}
key="first-name" </Td>
aria-label={i18n._(t`user first name`)} <Td dataLabel={i18n._(t`Last Name`)}>
> {user.last_name && (
{user.first_name && ( <Fragment>
<Fragment> <b css="margin-right: 24px">{i18n._(t`Last Name`)}</b>
<b css="margin-right: 24px">{i18n._(t`First Name`)}</b> {user.last_name}
{user.first_name} </Fragment>
</Fragment> )}
)} </Td>
</DataListCell>, <Td dataLabel={i18n._(t`Role`)}>{user_type}</Td>
<DataListCell <ActionsTd dataLabel={i18n._(t`Actions`)}>
key="last-name" <ActionItem
aria-label={i18n._(t`user last name`)} visible={user.summary_fields.user_capabilities.edit}
> tooltip={i18n._(t`Edit User`)}
{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={i18n._(t`actions`)}
aria-labelledby={labelId}
id={labelId}
> >
{user.summary_fields.user_capabilities.edit && ( <Button
<Tooltip content={i18n._(t`Edit User`)} position="top"> aria-label={i18n._(t`Edit User`)}
<Button variant="plain"
aria-label={i18n._(t`Edit User`)} component={Link}
variant="plain" to={`/users/${user.id}/edit`}
component={Link} >
to={`/users/${user.id}/edit`} <PencilAltIcon />
> </Button>
<PencilAltIcon /> </ActionItem>
</Button> </ActionsTd>
</Tooltip> </Tr>
)}
</DataListAction>
</DataListItemRow>
</DataListItem>
); );
} }

View File

@@ -18,12 +18,16 @@ describe('UserListItem with full permissions', () => {
wrapper = mountWithContexts( wrapper = mountWithContexts(
<I18nProvider> <I18nProvider>
<MemoryRouter initialEntries={['/users']} initialIndex={0}> <MemoryRouter initialEntries={['/users']} initialIndex={0}>
<UserListItem <table>
user={mockDetails} <tbody>
detailUrl="/user/1" <UserListItem
isSelected user={mockDetails}
onSelect={() => {}} detailUrl="/user/1"
/> isSelected
onSelect={() => {}}
/>
</tbody>
</table>
</MemoryRouter> </MemoryRouter>
</I18nProvider> </I18nProvider>
); );
@@ -36,9 +40,9 @@ describe('UserListItem with full permissions', () => {
}); });
test('should display user data', () => { test('should display user data', () => {
expect( expect(wrapper.find('td[data-label="Role"]').prop('children')).toEqual(
wrapper.find('DataListCell[aria-label="user type"]').prop('children') 'System Administrator'
).toEqual('System Administrator'); );
expect( expect(
wrapper.find('Label[aria-label="social login"]').prop('children') wrapper.find('Label[aria-label="social login"]').prop('children')
).toEqual('SOCIAL'); ).toEqual('SOCIAL');
@@ -50,19 +54,23 @@ describe('UserListItem without full permissions', () => {
wrapper = mountWithContexts( wrapper = mountWithContexts(
<I18nProvider> <I18nProvider>
<MemoryRouter initialEntries={['/users']} initialIndex={0}> <MemoryRouter initialEntries={['/users']} initialIndex={0}>
<UserListItem <table>
user={{ <tbody>
...mockDetails, <UserListItem
summary_fields: { user={{
user_capabilities: { ...mockDetails,
edit: false, summary_fields: {
}, user_capabilities: {
}, edit: false,
}} },
detailUrl="/user/1" },
isSelected }}
onSelect={() => {}} detailUrl="/user/1"
/> isSelected
onSelect={() => {}}
/>
</tbody>
</table>
</MemoryRouter> </MemoryRouter>
</I18nProvider> </I18nProvider>
); );