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

task/DES-2685: Add API endpoint and frontend view for project listing #1167

Merged
merged 13 commits into from
Feb 26, 2024
Merged
Prev Previous commit
Next Next commit
proof of concept populating form with data
  • Loading branch information
jarosenb committed Feb 7, 2024
commit 4fd0220cab457b6a8251b1e27edbfd1d5e2eaffd
69 changes: 68 additions & 1 deletion client/modules/datafiles/src/projects/forms/BaseProjectForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
RelatedWorkInput,
ReferencedDataInput,
} from './_fields';
import { TProjectUser } from './_fields/UserSelect';

const customizeRequiredMark = (
label: React.ReactNode,
Expand Down Expand Up @@ -41,11 +42,77 @@ const customizeRequiredMark = (
export const BaseProjectForm: React.FC = () => {
const [form] = Form.useForm();

function processFormData(formData: Record<string, TProjectUser[]>) {
const { pi, coPis, teamMembers, guestMembers, ...rest } = formData;
return {
...rest,
users: [...pi, ...coPis, ...teamMembers, ...guestMembers],
};
}

function cleanInitialvalues(projectData: Record<string, TProjectUser[]>) {
const { users, ...rest } = projectData;
return {
...rest,
pi: users.filter((u) => u.role === 'pi'),
coPis: users.filter((u) => u.role === 'co_pi'),
teamMembers: users.filter((u) => u.role === 'team_member'),
guestMembers: users.filter((u) => u.role === 'guest'),
};
}

const initialdata = {
users: [
{
fname: 'Jake',
lname: 'Rosenberg',
inst: 'University of Texas at Austin (utexas.edu)',
email: '...',
username: 'jarosenb',
role: 'pi',
},
{
fname: 'Sarah',
lname: 'Gray',
inst: 'University of Texas at Austin (utexas.edu)',
email: '...',
username: 'sgray',
role: 'co_pi',
},
{
fname: 'Ellen',
lname: 'Rathje',
inst: 'University of Texas at Austin (utexas.edu)',
email: '...',
username: 'erathje',
role: 'team_member',
},
{
fname: 'Tracy',
lname: 'Brown',
inst: 'University of Texas at Austin (utexas.edu)',
email: '...',
username: 'thbrown',
role: 'team_member',
},
{
fname: 'Tracy2',
lname: 'Brown2',
inst: 'University of Texas at Austin (utexas.edu)',
email: '...',
username: 'thbrown',
role: 'guest',
},
],
};

return (
<Form
form={form}
layout="vertical"
onFinish={(v) => console.log(v)}
onFinish={(v) => console.log(processFormData(v))}
onFinishFailed={(v) => console.log(processFormData(v.values))}
initialValues={cleanInitialvalues(initialdata)}
requiredMark={customizeRequiredMark}
>
<Form.Item label="Project Title" required>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ export const GuestMembersInput: React.FC<{ name: string }> = ({ name }) => {
>
<Input disabled={disabled} />
</Form.Item>
<Form.Item
hidden
name={disabled ? undefined : [name, 'role']}
initialValue="guest"
>
<Input hidden />
</Form.Item>
<Form.Item label="&nbsp;" hidden={disabled}>
<Button
type="primary"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@ export const UserSelect: React.FC<{
userRole?: string;
maxCount?: number;
}> = ({ value, onChange, userRole, maxCount }) => {
const [data, setData] = useState<SelectProps['options']>([]);
const initialOptions = value?.map((u) => ({
label: `${u.fname} ${u.lname} (${u.email})`,
value: JSON.stringify(u),
}));
const [data, setData] = useState<SelectProps['options']>(initialOptions);

const [searchTerm, setSearchTerm] = useState<string>('');
const debouncedSearchTerm = useDebounceValue(searchTerm, 100);

useEffect(() => {
if (!debouncedSearchTerm || debouncedSearchTerm.length < 3) {
setData([]);
if (!debouncedSearchTerm) return;
if (debouncedSearchTerm && debouncedSearchTerm.length < 3) {
return;
}
apiClient
Expand Down