-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a "my sequences page" displaying released sequences (#1037)
* wip * still types to fix * add link * fix types and more * remove download dialog * remove redundancies * Update my_sequences.astro * Update website/src/routes.ts Co-authored-by: Fabian Engelniederhammer <[email protected]> * Update website/src/pages/[organism]/my_sequences/[group].astro Co-authored-by: Fabian Engelniederhammer <[email protected]> * Update website/src/pages/[organism]/my_sequences/[group].astro Co-authored-by: Fabian Engelniederhammer <[email protected]> * refactor(website): use GroupManagementClient * refactor to reduce code duplication * improve error message * add back group functionality with better exclude option * lots of fixes * add underline to link * get user groups not all groups --------- Co-authored-by: Fabian Engelniederhammer <[email protected]> Co-authored-by: Fabian Engelniederhammer <[email protected]>
- Loading branch information
1 parent
88dc4fe
commit 6163414
Showing
14 changed files
with
380 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { type FC } from 'react'; | ||
|
||
import { routes } from '../../routes'; | ||
|
||
type GroupSelectorProps = { | ||
groupNames: string[]; | ||
selectedGroupName: string; | ||
organism: string; | ||
}; | ||
export const GroupSelector: FC<GroupSelectorProps> = ({ groupNames, selectedGroupName, organism }) => { | ||
return ( | ||
<select | ||
className='mt-4 select select-bordered' | ||
onChange={(event) => { | ||
const newGroup = event.target.value; | ||
const page = routes.mySequencesPage(organism, newGroup); | ||
location.href = page; | ||
}} | ||
> | ||
{groupNames.map((groupName: string) => ( | ||
<option selected={groupName === selectedGroupName} value={groupName} key={groupName}> | ||
{groupName} | ||
</option> | ||
))} | ||
</select> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
--- | ||
import BaseLayout from '../../layouts/BaseLayout.astro'; | ||
import { routes } from '../../routes'; | ||
import { GroupManagementClient } from '../../services/groupManagementClient'; | ||
import { getAccessToken } from '../../utils/getAccessToken'; | ||
const accessToken = getAccessToken(Astro.locals.session)!; | ||
const groupsResult = await GroupManagementClient.create().getGroupsOfUser(accessToken); | ||
const organism = Astro.params.organism; | ||
let noGroups = false; | ||
let errorMessage = ''; | ||
if (groupsResult.isOk()) { | ||
if (groupsResult.value.length > 0) { | ||
return Astro.redirect(routes.mySequencesPage(organism, groupsResult.value[0].groupName)); | ||
} | ||
noGroups = true; | ||
} else { | ||
errorMessage = groupsResult.error.detail; | ||
} | ||
--- | ||
|
||
<BaseLayout title='My Sequences'> | ||
<div> | ||
<p> | ||
{ | ||
noGroups && ( | ||
<div> | ||
To access sequence-management pages your account needs to be part of a group. Please{' '} | ||
<a href={routes.whereYouCreateAGroup()}>create a group</a>, or ask an existing group admin to | ||
add you to their group. | ||
</div> | ||
) | ||
} | ||
{errorMessage && <div class='bg-red-500'>{errorMessage}</div>} | ||
</p> | ||
</div> | ||
</BaseLayout> |
111 changes: 111 additions & 0 deletions
111
website/src/pages/[organism]/my_sequences/[group].astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
--- | ||
import { GroupSelector } from '../../../components/MySequencesPage/GroupSelector'; | ||
import { SearchForm } from '../../../components/SearchPage/SearchForm'; | ||
import { SearchPagination } from '../../../components/SearchPage/SearchPagination'; | ||
import { Table } from '../../../components/SearchPage/Table'; | ||
import ErrorBox from '../../../components/common/ErrorBox.astro'; | ||
import BaseLayout from '../../../layouts/BaseLayout.astro'; | ||
import { MY_SEQUENCES } from '../../../routes'; | ||
import { GroupManagementClient } from '../../../services/groupManagementClient'; | ||
import { pageSize } from '../../../settings'; | ||
import { getAccessToken } from '../../../utils/getAccessToken'; | ||
import { processParametersAndFetchSearch } from '../../../utils/processParametersAndFetchSearch'; | ||
const group = Astro.params.group!; | ||
const accessToken = getAccessToken(Astro.locals.session)!; | ||
const groupsResult = await GroupManagementClient.create().getGroupsOfUser(accessToken); | ||
if (groupsResult.isOk() === false) { | ||
return new Response(undefined, { | ||
status: 500, | ||
message: 'Failed to get groups', | ||
}); | ||
} | ||
const groups = groupsResult.value; | ||
const groupNames = groups.map((group: { groupName: string }) => group.groupName); | ||
const groupExists = groupNames.includes(group); | ||
if (groupExists === false) { | ||
return new Response(undefined, { | ||
status: 404, | ||
}); | ||
} | ||
const { | ||
cleanedOrganism, | ||
organism, | ||
data, | ||
page, | ||
metadataFilter, | ||
mutationFilter, | ||
referenceGenomesSequenceNames, | ||
schema, | ||
clientConfig, | ||
orderBy, | ||
} = await processParametersAndFetchSearch(Astro, group); | ||
--- | ||
|
||
<BaseLayout title={`${cleanedOrganism.displayName} - My sequences`}> | ||
<h1 class='title'>Viewing sequences for group {group}</h1> | ||
{ | ||
groupNames.length > 1 && ( | ||
<> | ||
Choose group: | ||
<GroupSelector groupNames={groupNames} selectedGroupName={group} organism={organism} client:load /> | ||
</> | ||
) | ||
} | ||
|
||
<div class='flex flex-col md:flex-row gap-8 md:gap-4'> | ||
<div class='md:w-72'> | ||
<SearchForm | ||
organism={organism} | ||
filters={metadataFilter} | ||
initialMutationFilter={mutationFilter} | ||
clientConfig={clientConfig} | ||
referenceGenomesSequenceNames={referenceGenomesSequenceNames} | ||
classOfSearchPage={MY_SEQUENCES} | ||
group={group} | ||
client:only='react' | ||
/> | ||
</div> | ||
{ | ||
data.match( | ||
(data) => ( | ||
<div class='flex-1'> | ||
<div class='mt-4 mb-1'> | ||
Search returned {data.totalCount.toLocaleString()} | ||
sequence{data.totalCount === 1 ? '' : 's'} | ||
</div> | ||
<Table | ||
organism={organism} | ||
data={data.data} | ||
schema={schema} | ||
metadataFilter={metadataFilter} | ||
mutationFilter={mutationFilter} | ||
page={page} | ||
orderBy={orderBy} | ||
classOfSearchPage={MY_SEQUENCES} | ||
group={group} | ||
client:load | ||
/> | ||
|
||
<div class='mt-4 flex justify-center'> | ||
<SearchPagination | ||
client:only='react' | ||
count={Math.ceil(data.totalCount / pageSize)} | ||
page={page} | ||
metadataFilter={metadataFilter} | ||
mutationFilter={mutationFilter} | ||
orderBy={orderBy} | ||
organism={organism} | ||
classOfSearchPage={MY_SEQUENCES} | ||
group={group} | ||
/> | ||
</div> | ||
</div> | ||
), | ||
(error) => <ErrorBox title='Failed searching sequences' message={error.detail} />, | ||
) | ||
} | ||
</div> | ||
</BaseLayout> |
Oops, something went wrong.