Skip to content

Commit

Permalink
modularize users page
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronshiel committed Oct 3, 2024
1 parent 2c9086a commit 432375f
Show file tree
Hide file tree
Showing 5 changed files with 754 additions and 712 deletions.
2 changes: 1 addition & 1 deletion client/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ clean:

.PHONY: develop
develop: node_modules/gatsby
npx gatsby develop -p 8000
npx gatsby develop -p 80

.PHONY: pretty
pretty:
Expand Down
253 changes: 253 additions & 0 deletions client/src/components/users/table-footer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,253 @@
/*
This software is Copyright ©️ 2020 The University of Southern California. All Rights Reserved.
Permission to use, copy, modify, and distribute this software and its documentation for educational, research and non-profit purposes, without fee, and without a written agreement is hereby granted, provided that the above copyright notice and subject to the full license file found in the root of this software deliverable. Permission to make commercial use of this software may be obtained by contacting: USC Stevens Center for Innovation University of Southern California 1150 S. Olive Street, Suite 2300, Los Angeles, CA 90115, USA Email: [email protected]
The full terms of this copyright and license should always be found in the root directory of this software deliverable as "license.txt" and if these terms are not found with this software, please contact the USC Stevens Center for the full license.
*/
import React from "react";
import {
AppBar,
Toolbar,
Select,
SelectChangeEvent,
MenuItem,
IconButton,
Autocomplete,
TextField,
Switch,
} from "@mui/material";
import { ColumnDef } from "components/column-header";
import { UseUserData } from "hooks/graphql/use-with-users";
import { makeStyles } from "tss-react/mui";
import { User, Organization } from "types";
import {
KeyboardArrowLeft as KeyboardArrowLeftIcon,
KeyboardArrowRight as KeyboardArrowRightIcon,
} from "@mui/icons-material";
import { v4 as uuid4 } from "uuid";
const useStyles = makeStyles({ name: { TableFooter } })(() => ({
appBar: {
height: "10%",
top: "auto",
bottom: 0,
},
paging: {
display: "flex",
flexDirection: "row",
marginLeft: "auto",
marginRight: "auto",
},
}));

export function getTableColumns(
viewArchivedMentors: boolean,
isAdmin: boolean
): ColumnDef[] {
let columns: ColumnDef[] = [
{
id: "defaultMentor",
subField: ["isPublicApproved"],
label: "Approval",
minWidth: 0,
align: "left",
sortable: true,
},
{
id: "name",
label: "Name",
minWidth: 0,
align: "left",
sortable: true,
},
{
id: "defaultMentor",
subField: ["name"],
label: "Mentor",
minWidth: 0,
align: "left",
sortable: true,
},
{
id: "email",
label: "Email",
minWidth: 0,
align: "left",
sortable: true,
},
{
id: "userRole",
label: "Role",
minWidth: 0,
align: "left",
sortable: true,
},
{
id: "defaultMentor",
subField: ["isPrivate"],
label: "Privacy",
minWidth: 0,
align: "left",
sortable: true,
},
{
id: "isDisabled",
label: "Disabled",
minWidth: 0,
align: "left",
sortable: true,
},
{
id: "defaultMentor",
subField: ["isAdvanced"],
label: "Advanced",
minWidth: 0,
align: "left",
sortable: true,
},
{
id: "defaultMentor",
subField: ["isArchived"],
label: "Archived",
minWidth: 0,
align: "left",
sortable: true,
},
{
id: "defaultMentor",
subField: ["lockedToConfig"],
label: "Locked",
minWidth: 0,
align: "left",
sortable: true,
},
{
id: "defaultMentor",
subField: ["updatedAt"],
label: "Last Updated",
minWidth: 0,
align: "left",
sortable: true,
},
{
id: "actions",
label: "",
minWidth: 0,
align: "left",
sortable: false,
},
];
if (!viewArchivedMentors) {
columns = columns.filter((c) => c.label !== "Archived");
}
if (!isAdmin) {
columns = columns.filter(
(c) => c.label !== "Disabled" && c.label !== "Disabled"
);
}
return columns;
}

export function TableFooter(props: {
userPagin: UseUserData;
user: User;
orgs: Organization[];
viewArchivedMentors: boolean;
viewUnapprovedMentors: boolean;
onToggleArchivedMentors: (v: boolean) => void;
onToggleViewUnapprovedMentors: (v: boolean) => void;
}): JSX.Element {
const { userPagin, viewUnapprovedMentors } = props;
const { classes: styles } = useStyles();
const edges = userPagin.searchData?.edges || [];
const hasNext = userPagin.pageData?.pageInfo.hasNextPage || false;
const hasPrev = userPagin.pageData?.pageInfo.hasPreviousPage || false;
const pageSizes = [10, 20, 50, 100];

return (
<AppBar position="sticky" color="default" className={styles.appBar}>
<Toolbar>
<div className={styles.paging}>
<Select
value={userPagin.pageSize || 0}
onChange={(e: SelectChangeEvent<number>) =>
userPagin.setPageSize(e.target.value as number)
}
>
{pageSizes.map((p) => (
<MenuItem key={p} value={p}>
{p}
</MenuItem>
))}
</Select>
<IconButton
data-cy="prev-page"
disabled={!hasPrev}
onClick={userPagin.prevPage}
size="large"
>
<KeyboardArrowLeftIcon />
</IconButton>
<IconButton
data-cy="next-page"
disabled={!hasNext}
onClick={userPagin.nextPage}
size="large"
>
<KeyboardArrowRightIcon />
</IconButton>
<Autocomplete
data-cy="user-filter"
freeSolo
options={edges.map((e) => e.node.name)}
onChange={(e, v) => {
const value = v || "";
userPagin.filter(
value
? {
$or: [
{ name: value },
{ defaultMentor: { name: value } },
],
}
: {}
);
}}
style={{ width: 300 }}
renderInput={(params) => (
<TextField
{...params}
variant="outlined"
placeholder="Search users"
/>
)}
renderOption={(props, option) => (
<li {...props} key={`${option}${uuid4()}`}>
{option}
</li>
)}
/>
<span style={{ margin: "15px" }}>
View Archived Mentors
<Switch
data-cy="archive-mentor-switch"
data-test={props.viewArchivedMentors}
checked={props.viewArchivedMentors}
onChange={(e) => props.onToggleArchivedMentors(e.target.checked)}
/>
</span>
<span style={{ margin: "15px" }}>
View Unapproved Mentors Only
<Switch
data-cy="mentors-approval-switch"
data-test={viewUnapprovedMentors}
checked={viewUnapprovedMentors}
onChange={(e) =>
props.onToggleViewUnapprovedMentors(e.target.checked)
}
/>
</span>
</div>
</Toolbar>
</AppBar>
);
}
Loading

0 comments on commit 432375f

Please sign in to comment.