Skip to content

Commit

Permalink
wip, revise page not working
Browse files Browse the repository at this point in the history
  • Loading branch information
theosanderson authored Feb 20, 2024
1 parent 6163414 commit 8439374
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 30 deletions.
45 changes: 19 additions & 26 deletions website/src/components/DataUploadForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type DataUploadFormProps = {
organism: string;
clientConfig: ClientConfig;
action: Action;
groupsOfUser: any[]; // figure out what to do here
onSuccess: () => void;
onError: (message: string) => void;
};
Expand All @@ -42,25 +43,18 @@ const InnerDataUploadForm = ({
action,
onSuccess,
onError,
groupsOfUser,
}: DataUploadFormProps) => {
const [metadataFile, setMetadataFile] = useState<File | null>(null);
const [sequenceFile, setSequenceFile] = useState<File | null>(null);
const [exampleEntries, setExampleEntries] = useState<number | undefined>(undefined);
const metadataFileInputRef = useRef<HTMLInputElement>(null);
const sequenceFileInputRef = useRef<HTMLInputElement>(null);

const { zodiosHooks } = useGroupManagementClient(clientConfig);
const groupsOfUser = zodiosHooks.useGetGroupsOfUser({
headers: createAuthorizationHeader(accessToken),
});

if (groupsOfUser.error) {
onError(`Failed to query Groups: ${stringifyMaybeAxiosError(groupsOfUser.error)}`);
}

const noGroup = useMemo(
() => groupsOfUser.data === undefined || groupsOfUser.data.length === 0,
[groupsOfUser.data],
() => groupsOfUser === undefined || groupsOfUser.length === 0,

Check failure on line 56 in website/src/components/DataUploadForm.tsx

View workflow job for this annotation

GitHub Actions / Check format

Unnecessary conditional, the types have no overlap
[groupsOfUser],
);

const { submit, revise, isLoading } = useSubmitFiles(accessToken, organism, clientConfig, onSuccess, onError);
Expand Down Expand Up @@ -94,7 +88,7 @@ const InnerDataUploadForm = ({

switch (action) {
case 'submit':
const groupName = selectedGroup ?? groupsOfUser.data?.[0].groupName;
const groupName = selectedGroup ?? groupsOfUser?.[0].groupName;

Check failure on line 91 in website/src/components/DataUploadForm.tsx

View workflow job for this annotation

GitHub Actions / Check format

Unnecessary optional chain on a non-nullish value
if (groupName === undefined) {
onError('Please select a group');
return;
Expand Down Expand Up @@ -142,22 +136,21 @@ const InnerDataUploadForm = ({
return () => clearInterval(interval);
}, [metadataFile, sequenceFile]);

if (noGroup){
return (<p className='text-red-500'>
Sequences are submitted on behalf of a group. To submit, please either
<a href={routes.userOverviewPage()} className='underline'>
create a group
</a> or ask a group administrator to add you to an existing group.

</p>)
}


return (
<form onSubmit={handleSubmit} className='p-6 space-y-6 max-w-md w-full'>
{action === 'submit' &&
(noGroup ? (
groupsOfUser.isLoading ? (
<p className='text-gray-500'>Loading groups...</p>
) : (
<p className='text-red-500'>
No group found. Please join or{' '}
<a href={routes.userOverviewPage()} className='underline'>
create a group
</a>
.
</p>
)
) : (
(
<div className='flex flex-col gap-3 w-fit'>
<span className='text-gray-700'>Submitting for:</span>
<select
Expand All @@ -168,14 +161,14 @@ const InnerDataUploadForm = ({
disabled={false}
className='p-2 border rounded-md'
>
{groupsOfUser.data!.map((group) => (
{groupsOfUser!.map((group) => (

Check failure on line 164 in website/src/components/DataUploadForm.tsx

View workflow job for this annotation

GitHub Actions / Check format

This assertion is unnecessary since it does not change the type of the expression
<option key={group.groupName} value={group.groupName}>
{group.groupName}
</option>
))}
</select>
</div>
))}
)}

<TextField
variant='outlined'
Expand Down
3 changes: 2 additions & 1 deletion website/src/components/Submission/SubmissionForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type SubmissionFormProps = {
clientConfig: ClientConfig;
};

export const SubmissionForm: FC<SubmissionFormProps> = ({ accessToken, organism, clientConfig }) => {
export const SubmissionForm: FC<SubmissionFormProps> = ({ accessToken, organism, clientConfig, groupsOfUser }) => {
const { errorMessage, isErrorOpen, openErrorFeedback, closeErrorFeedback } = useErrorFeedbackState();

return (
Expand All @@ -23,6 +23,7 @@ export const SubmissionForm: FC<SubmissionFormProps> = ({ accessToken, organism,
clientConfig={clientConfig}
action='submit'
onError={openErrorFeedback}
groupsOfUser={groupsOfUser}
onSuccess={() => {
window.location.href = routes.userSequenceReviewPage(organism);
}}
Expand Down
11 changes: 9 additions & 2 deletions website/src/pages/[organism]/submit/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@ import { getRuntimeConfig } from '../../../config';
import BaseLayout from '../../../layouts/BaseLayout.astro';
import { getAccessToken } from '../../../utils/getAccessToken';

Check failure on line 5 in website/src/pages/[organism]/submit/index.astro

View workflow job for this annotation

GitHub Actions / Check format

There should be no empty line within import group
import { GroupManagementClient } from '../../../services/groupManagementClient';

Check failure on line 8 in website/src/pages/[organism]/submit/index.astro

View workflow job for this annotation

GitHub Actions / Check format

`../../../services/groupManagementClient` import should occur before import of `../../../utils/getAccessToken`
const organism = Astro.params.organism!;
const accessToken = getAccessToken(Astro.locals.session)!;
const groupsResult = await GroupManagementClient.create().getGroupsOfUser(accessToken);
const clientConfig = getRuntimeConfig().public;
---

<BaseLayout title='Submit'>
<h1 class='title'>Submission Page</h1>
<SubmissionForm accessToken={accessToken} organism={organism} clientConfig={clientConfig} client:only='react' />
<h1 class='title'>Submission</h1>
<SubmissionForm accessToken={accessToken} organism={organism} clientConfig={clientConfig}
groupsOfUser={groupsResult.value}
client:load />
</BaseLayout>
1 change: 0 additions & 1 deletion website/tests/pages/navigation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const organismIndependentNavigationItems = [
const organismNavigationItems = [
{ link: 'Search', title: '[Organism] - Browse' },
{ link: 'Submit', title: 'Submit' },
{ link: 'Revise', title: 'Revise' },
{ link: 'User', title: 'Login' },
{ link: 'Sequence Overview', title: 'Sequences' },
];
Expand Down

0 comments on commit 8439374

Please sign in to comment.