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

[BHBC-950] UI Cleanup #648

Merged
merged 8 commits into from
Nov 22, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion app/src/components/toolbar/ActionToolbars.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export const CustomMenuIconButton: React.FC<ICustomMenuIconButtonProps> = (props
anchorEl={anchorEl}
getContentAnchorEl={null}
anchorOrigin={{
vertical: 'bottom',
vertical: 'top',
horizontal: 'right'
}}
transformOrigin={{
Expand Down
25 changes: 9 additions & 16 deletions app/src/features/admin/users/AccessRequestList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,9 @@ describe('AccessRequestList', () => {
);

await waitFor(() => {
expect(getByText('test user')).toBeVisible();
expect(getByText('testusername')).toBeVisible();
expect(getByText('test company')).toBeVisible();
expect(getByText('April-20-2020')).toBeVisible();
expect(getByText('PENDING')).toBeVisible();
expect(getByText('Apr 20, 2020')).toBeVisible();
expect(getByText('Pending')).toBeVisible();
expect(getByRole('button')).toHaveTextContent('Review');
});
});
Expand Down Expand Up @@ -110,11 +108,9 @@ describe('AccessRequestList', () => {
);

await waitFor(() => {
expect(getByText('test user')).toBeVisible();
expect(getByText('testusername')).toBeVisible();
expect(getByText('test company')).toBeVisible();
expect(getByText('April-20-2020')).toBeVisible();
expect(getByText('DENIED')).toBeVisible();
expect(getByText('Apr 20, 2020')).toBeVisible();
expect(getByText('Denied')).toBeVisible();
expect(queryByRole('button')).not.toBeInTheDocument();
});
});
Expand Down Expand Up @@ -148,17 +144,15 @@ describe('AccessRequestList', () => {
);

await waitFor(() => {
expect(getByText('test user')).toBeVisible();
expect(getByText('testusername')).toBeVisible();
expect(getByText('test company')).toBeVisible();
expect(getByText('April-20-2020')).toBeVisible();
expect(getByText('APPROVED')).toBeVisible();
expect(getByText('Apr 20, 2020')).toBeVisible();
expect(getByText('Approved')).toBeVisible();
expect(queryByRole('button')).not.toBeInTheDocument();
});
});

it('shows a table row when the data object is null', async () => {
const { getByText, getAllByText } = renderContainer(
const { getByText } = renderContainer(
[
{
id: 1,
Expand All @@ -177,9 +171,8 @@ describe('AccessRequestList', () => {
);

await waitFor(() => {
expect(getAllByText('Not Applicable').length).toEqual(2);
expect(getByText('April-20-2020')).toBeVisible();
expect(getByText('PENDING')).toBeVisible();
expect(getByText('Apr 20, 2020')).toBeVisible();
expect(getByText('Pending')).toBeVisible();
});
});

Expand Down
55 changes: 22 additions & 33 deletions app/src/features/admin/users/AccessRequestList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ import ReviewAccessRequestForm, {
} from './ReviewAccessRequestForm';

const useStyles = makeStyles((theme: Theme) => ({
table: {
tableLayout: 'fixed',
'& td': {
verticalAlign: 'middle'
}
},
chip: {
padding: '0px 8px',
borderRadius: '4px',
color: 'white'
},
chipPending: {
Expand All @@ -42,12 +46,6 @@ const useStyles = makeStyles((theme: Theme) => ({
},
chipRejected: {
backgroundColor: theme.palette.error.main
},
actionButton: {
minWidth: '6rem',
'& + button': {
marginLeft: '0.5rem'
}
}
}));

Expand Down Expand Up @@ -143,13 +141,13 @@ const AccessRequestList: React.FC<IAccessRequestListProps> = (props) => {
let chipStatusClass;

if (AdministrativeActivityStatusType.REJECTED === status_name) {
chipLabel = 'DENIED';
chipLabel = 'Denied';
chipStatusClass = classes.chipRejected;
} else if (AdministrativeActivityStatusType.ACTIONED === status_name) {
chipLabel = 'APPROVED';
chipLabel = 'Approved';
chipStatusClass = classes.chipActioned;
} else {
chipLabel = 'PENDING';
chipLabel = 'Pending';
chipStatusClass = classes.chipPending;
}

Expand Down Expand Up @@ -183,53 +181,44 @@ const AccessRequestList: React.FC<IAccessRequestListProps> = (props) => {
)
}}
/>
<Paper>
<Box p={2}>
<Box component={Paper} p={3}>
<Box pb={3}>
<Typography variant="h2">Access Requests ({accessRequests?.length || 0})</Typography>
</Box>
<TableContainer>
<Table>
<Table className={classes.table}>
<TableHead>
<TableRow>
<TableCell>Name</TableCell>
<TableCell>Username</TableCell>
<TableCell>Company</TableCell>
<TableCell>Regional Offices</TableCell>
<TableCell>Request Date</TableCell>
<TableCell>Status</TableCell>
<TableCell></TableCell>
<TableCell>Date of Request</TableCell>
<TableCell>Access Status</TableCell>
<TableCell width="130px" align="center">
Actions
</TableCell>
</TableRow>
</TableHead>
<TableBody data-testid="access-request-table">
{!accessRequests?.length && (
<TableRow data-testid={'access-request-row-0'}>
<TableCell colSpan={6} style={{ textAlign: 'center' }}>
<TableCell colSpan={7} align="center">
No Access Requests
</TableCell>
</TableRow>
)}
{accessRequests?.map((row, index) => {
const regional_offices = row.data?.regional_offices
?.map((regionId) => codes.regional_offices.find((code) => code.id === regionId)?.name)
.join(', ');

return (
<TableRow data-testid={`access-request-row-${index}`} key={index}>
<TableCell>{row.data?.name || ''}</TableCell>
<TableCell>{row.data?.username || ''}</TableCell>
<TableCell>{row.data?.company || 'Not Applicable'}</TableCell>
<TableCell>{regional_offices || 'Not Applicable'}</TableCell>
<TableCell>{getFormattedDate(DATE_FORMAT.MediumDateFormat2, row.create_date)}</TableCell>
<TableCell>{getFormattedDate(DATE_FORMAT.ShortMediumDateFormat, row.create_date)}</TableCell>
<TableCell>{getChipIcon(row.status_name)}</TableCell>

<TableCell>
<TableCell align="center">
{row.status_name === AdministrativeActivityStatusType.PENDING && (
<Button
className={classes.actionButton}
color="primary"
variant="outlined"
onClick={() => setActiveReviewDialog({ open: true, request: row })}>
Review
<strong>Review</strong>
</Button>
)}
</TableCell>
Expand All @@ -239,7 +228,7 @@ const AccessRequestList: React.FC<IAccessRequestListProps> = (props) => {
</TableBody>
</Table>
</TableContainer>
</Paper>
</Box>
</>
);
};
Expand Down
68 changes: 37 additions & 31 deletions app/src/features/admin/users/ActiveUsersList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import Box from '@material-ui/core/Box';
import Paper from '@material-ui/core/Paper';
import Table from '@material-ui/core/Table';
import TableBody from '@material-ui/core/TableBody';
import { Theme } from '@material-ui/core/styles/createMuiTheme';
import makeStyles from '@material-ui/core/styles/makeStyles';
import TableCell from '@material-ui/core/TableCell';
import TableContainer from '@material-ui/core/TableContainer';
import TableHead from '@material-ui/core/TableHead';
Expand All @@ -20,6 +22,15 @@ import { IGetUserResponse } from 'interfaces/useUserApi.interface';
import React, { useContext, useState } from 'react';
import { handleChangePage, handleChangeRowsPerPage } from 'utils/tablePaginationUtils';

const useStyles = makeStyles((theme: Theme) => ({
table: {
tableLayout: 'fixed',
'& td': {
verticalAlign: 'middle'
}
}
}));

export interface IActiveUsersListProps {
activeUsers: IGetUserResponse[];
getUsers: (forceFetch: boolean) => void;
Expand All @@ -32,6 +43,7 @@ export interface IActiveUsersListProps {
* @return {*}
*/
const ActiveUsersList: React.FC<IActiveUsersListProps> = (props) => {
const classes = useStyles();
const biohubApi = useBiohubApi();
const { activeUsers } = props;

Expand Down Expand Up @@ -64,13 +76,11 @@ const ActiveUsersList: React.FC<IActiveUsersListProps> = (props) => {
dialogTitle: 'Remove user?',
dialogContent: (
<>
<Typography variant="body2" component="div">
Removing <strong>{row.user_identifier}</strong> will revoke their access to this application and all related
projects.
</Typography>
<Typography variant="body2" component="div">
Are you sure you want to proceed?
<Typography variant="body1">
Removing user <strong>{row.user_identifier}</strong> will revoke their access to this application and all
related projects.
</Typography>
<Typography variant="body1">Are you sure you want to proceed?</Typography>
</>
),
yesButtonLabel: 'Remove User',
Expand Down Expand Up @@ -108,21 +118,19 @@ const ActiveUsersList: React.FC<IActiveUsersListProps> = (props) => {

return (
<>
<Paper>
<Box p={2}>
<Box component={Paper} p={3}>
<Box pb={3}>
<Typography variant="h2">Active Users ({activeUsers?.length || 0})</Typography>
</Box>
<TableContainer>
<Table>
<Table className={classes.table}>
<TableHead>
<TableRow>
<TableCell>Name</TableCell>
<TableCell>Username</TableCell>
<TableCell>Company</TableCell>
<TableCell>Regional Offices</TableCell>
<TableCell>Roles</TableCell>
<TableCell>Last Active</TableCell>
<TableCell width="50px">Actions</TableCell>
<TableCell width="100px" align="center">
Actions
</TableCell>
</TableRow>
</TableHead>
<TableBody data-testid="active-users-table">
Expand All @@ -136,24 +144,22 @@ const ActiveUsersList: React.FC<IActiveUsersListProps> = (props) => {
{activeUsers.length > 0 &&
activeUsers.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage).map((row, index) => (
<TableRow data-testid={`active-user-row-${index}`} key={row.id}>
<TableCell></TableCell>
<TableCell>{row.user_identifier || 'Not Applicable'}</TableCell>
<TableCell></TableCell>
<TableCell></TableCell>
<TableCell>{row.role_names.join(', ') || 'Not Applicable'}</TableCell>
<TableCell></TableCell>
<TableCell>
<CustomMenuIconButton
buttonTitle="Actions"
buttonIcon={<Icon path={mdiDotsVertical} size={0.875} />}
menuItems={[
{
menuIcon: <Icon path={mdiTrashCanOutline} size={0.875} />,
menuLabel: 'Remove User',
menuOnClick: () => handleRemoveUserClick(row)
}
]}
/>
<TableCell align="center">
<Box my={-1}>
<CustomMenuIconButton
buttonTitle="Actions"
buttonIcon={<Icon path={mdiDotsVertical} size={0.875} />}
menuItems={[
{
menuIcon: <Icon path={mdiTrashCanOutline} size={0.875} />,
menuLabel: 'Remove User',
menuOnClick: () => handleRemoveUserClick(row)
}
]}
/>
</Box>
</TableCell>
</TableRow>
))}
Expand All @@ -173,7 +179,7 @@ const ActiveUsersList: React.FC<IActiveUsersListProps> = (props) => {
}
/>
)}
</Paper>
</Box>
</>
);
};
Expand Down
Loading