Skip to content

Commit

Permalink
Fixup users
Browse files Browse the repository at this point in the history
  • Loading branch information
dmichaels-harvard committed Sep 4, 2023
1 parent d035521 commit 34a55e5
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 26 deletions.
82 changes: 61 additions & 21 deletions react/src/pages/UserDefs.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useState } from 'react';
import Char from '../utils/Char';
import Client from '../utils/Client';
import DateTime from '../utils/DateTime';
import Env from '../utils/Env';
import useFetch from '../hooks/Fetch';
import { ExternalLink } from '../Components';
Expand All @@ -16,99 +17,130 @@ const _UserInputs = [
label: "Email Address",
type: "email",
focus: true,
required: true
required: true,
flavors: "all",
pages: [ "list", "view", "edit" ]
},
{
name: "first_name",
label: "First Name",
required: true
required: true,
flavors: "all",
pages: [ "list", "view", "edit" ]
},
{
name: "last_name",
label: "Last Name",
required: true
required: true,
flavors: "all",
pages: [ "list", "view", "edit" ]
},
{
name: "group_titles",
label: "Groups",
flavors: "all",
pages: [ "view" ]
},
{
name: "admin",
label: "Administrator",
type: "boolean"
type: "boolean",
flavors: "all",
pages: [ "edit" ]
},
{
name: "role",
label: "Role",
type: "select",
url: "/users/roles",
dependsOn: "project",
onlyFor: [Env.FoursightTitleCgap]
flavors: [Env.FoursightTitleCgap],
pages: [ "list", "view", "edit" ]
},
{
name: "institution",
label: "Institution",
type: "select",
url: "/users/institutions",
dependsOn: "institution",
onlyFor: [Env.FoursightTitleCgap],
subComponent: (institution) => <PrincipalInvestigatorLine institution={institution} />
subComponent: (institution) => <PrincipalInvestigatorLine institution={institution} />,
flavors: [Env.FoursightTitleCgap],
pages: [ "list", "view", "edit" ]
},
{
name: "project",
label: "Project",
type: "select",
url: "/users/projects",
onlyFor: [Env.FoursightTitleCgap]
flavors: [Env.FoursightTitleCgap],
pages: [ "list", "view", "edit" ]
},
{
name: "award",
label: "Award",
type: "select",
url: "/users/awards",
dependsOn: "award",
onlyFor: [Env.FoursightTitleFourfront]
flavors: [Env.FoursightTitleFourfront],
pages: [ "list", "view", "edit" ]
},
{
name: "lab",
label: "Lab",
type: "select",
url: "/users/labs",
onlyFor: [Env.FoursightTitleFourfront]
flavors: [Env.FoursightTitleFourfront],
pages: [ "list", "view", "edit" ]
},
{
name: "consortium",
label: "Consortium",
type: "select",
url: "/users/consortia",
dependsOn: "consortia",
onlyFor: [Env.FoursightTitleSmaht]
flavors: [Env.FoursightTitleSmaht],
pages: [ "list", "view", "edit" ]
},
{
name: "submission_center",
label: "Submission Center",
type: "select",
url: "/users/submission_centers",
onlyFor: [Env.FoursightTitleSmaht]
flavors: [Env.FoursightTitleSmaht],
pages: [ "list", "view", "edit" ]
},
{
name: "status",
label: "Status",
type: "select",
url: "/users/statuses",
flavors: "all",
pages: [ "list", "view", "edit" ]
},
{
name: "created",
label: "Created",
readonly: true
readonly: true,
map: value => DateTime.Format(value),
flavors: "all",
pages: [ "list", "view", "edit" ]
},
{
name: "updated",
label: "Updated",
readonly: true
readonly: true,
map: value => DateTime.Format(value),
flavors: "all",
pages: [ "list", "view", "edit" ]
},
{
name: "uuid",
label: "UUID",
readonly: true,
readonlyOverridableOnCreate: true,
readonlyOverridableOnCreateMessage: "Warning: Only set UUID if you know what you are doing."
readonlyOverridableOnCreateMessage: "Warning: Only set UUID if you know what you are doing.",
flavors: "all",
pages: [ "list", "view", "edit" ]
}
];

Expand Down Expand Up @@ -161,7 +193,9 @@ const _userInfo = {
map: value => affiliationInfo.institutionTitle(value),
subComponent: (institution) => <PrincipalInvestigatorLine institution={institution} /> },
{ label: "Roles", xkey: "roles", name: "roles",
ui: (user) => <RolesBox affiliationInfo={affiliationInfo} user={user} />, toggle: true }
ui: (user) => <RolesBox affiliationInfo={affiliationInfo} user={user} />, toggle: true,
flavors: [Env.FoursightTitleCgap],
pages: [ "view", "edit" ] }
];
},
useAffiliationInfo: function () {
Expand Down Expand Up @@ -301,14 +335,20 @@ const useUserInfo = () => {
return userInfo;
}

const useUserInputs = () => {
const useUserInputs = (page) => {
const header = useHeader();
const flavor = Env.FoursightFlavorTitle(header);
const inputs = Json.Clone(_UserInputs).filter(input => !input.onlyFor || input.onlyFor.includes(flavor));

const inputs = Json.Clone(_UserInputs).filter(input => !input.flavors || input.flavors === "all" || input.flavors == flavor || input.flavors.includes(flavor))
.filter(input => !input.pages || input.pages === "all" || input.pages == page || input.pages.includes(page))
let xyzzy = Json.Clone(inputs);
const institutionInput = xyzzy.find(input => input.name === "institution");
institutionInput.subComponent = (institution) => <PrincipalInvestigatorLine institution={institution} />
//const xyzzy = inputs.map((item) => ({ ...item }));
let foo = xyzzy.find(input => input.name === "institution");
foo.subComponent = (institution) => <PrincipalInvestigatorLine institution={institution} />
foo = xyzzy.find(input => input.name === "created");
foo.map = (value) => DateTime.Format(value)
foo = xyzzy.find(input => input.name === "updated");
foo.map = (value) => DateTime.Format(value)
return xyzzy;
return useState(xyzzy)
//return useState(Json.Clone(inputs));
}
Expand Down
2 changes: 1 addition & 1 deletion react/src/pages/UserEditPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import useReadOnlyMode from '../hooks/ReadOnlyMode';
const UserEditPage = () => {

const { uuid } = useParams();
const [ inputs, setInputs ] = UserDefs.useUserInputs();
const [ inputs, setInputs ] = UserDefs.useUserInputs("edit");
const [ notFound, setNotFound ] = useState(false);
const [ readOnlyMode ] = useReadOnlyMode();
const user = useFetch({
Expand Down
7 changes: 4 additions & 3 deletions react/src/pages/UserPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const KeyValueBox = (props) => {
const [ toggle, setToggle ] = useState({});
return <div className="box" style={{marginBottom:"8pt"}}>
<table><tbody>
{props.keys.map((key, i) => <React.Fragment key={key.name}>
{props.inputs.map((key, i) => <React.Fragment key={key.name}>
{ props.separators && i > 0 && <>
<tr><td colSpan="2" style={{height:"1pt"}}></td></tr>
<tr><td colSpan="2" style={{height:"1px",marginTop:"2pt",marginBottom:"2pt",background:"gray"}}></td></tr>
Expand Down Expand Up @@ -92,8 +92,9 @@ const UserBox = (props) => {
const header = useHeader();
const user = props.user;
const userInfo = UserDefs.useUserInfo();
const inputs = UserDefs.useUserInputs("view");

let items = [
let xinputs = [
{ label: "Email", name: "email" },
{ label: "First Name", name: "first_name" },
{ label: "Last Name", name: "last_name" },
Expand All @@ -113,7 +114,7 @@ const UserBox = (props) => {

return <>
[[{JSON.stringify(props.user)}]]
<KeyValueBox keys={items} value={props.user} separators={true} />
<KeyValueBox inputs={inputs} value={props.user} separators={true} />
</>
}

Expand Down
2 changes: 1 addition & 1 deletion react/src/pages/UsersPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const UsersPage = () => {
const { environ } = useParams();
const [ args, setArgs ] = useSearchParams();
const users = useFetch();
const inputs = UserDefs.useUserInputs();
const inputs = UserDefs.useUserInputs("list");

const [ search, setSearch ] = useState(args.get("search") || "");
const [ showSearch, setShowSearch ] = useState(Str.HasValue(search));
Expand Down

0 comments on commit 34a55e5

Please sign in to comment.