-
Notifications
You must be signed in to change notification settings - Fork 12
feat: links to user, proposal, FAP from Experiments and Proposals table #1593
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
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
6254d9b
feat: add RoleBasedLink and role-aware proposal links from experiments
shivoomiess 6bb41a8
feat: add role-aware links to User, Instrument, Calls, FAP in ProposalsT
shivoomiess c3cfd0a
feat: link redirects to call / instrument page with search
shivoomiess e70b01c
fix: link to Principal Investigator (add id to graphql query)
shivoomiess 4729dfb
feat: add RoleBasedLink and role-aware proposal links from experiments
shivoomiess 549b406
feat: add role-aware links to User, Instrument, Calls, FAP in ProposalsT
shivoomiess 5692684
feat: link redirects to call / instrument page with search
shivoomiess c8d3b9a
fix: link to Principal Investigator (add id to graphql query)
shivoomiess d0acc19
Merge branch 'SWAP-5403-links' of github.com:UserOfficeProject/user-o…
shivoomiess bd65ffc
fix: use MUI Link styles with Router Link
shivoomiess c7fdfa3
Merge branch 'develop' into SWAP-5403-links
shivoomiess d2cd1de
Merge branch 'develop' into SWAP-5403-links
yoganandaness b796686
Merge branch 'develop' into SWAP-5403-links
shivoomiess bf7965f
Merge branch 'develop' into SWAP-5403-links
jekabs-karklins 1458304
Merge branch 'develop' into SWAP-5403-links
yoganandaness f971176
Merge branch 'develop' into SWAP-5403-links
jekabs-karklins 1a74d92
Merge branch 'develop' into SWAP-5403-links
jekabs-karklins 1133837
Merge branch 'develop' into SWAP-5403-links
jekabs-karklins File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,34 @@ | ||
| import { Link as MuiLink, LinkProps as MuiLinkProps } from '@mui/material'; | ||
| import React, { useContext } from 'react'; | ||
| import { Link as RouterLink, To } from 'react-router-dom'; | ||
|
|
||
| import { UserContext } from 'context/UserContextProvider'; | ||
| import { UserRole } from 'generated/sdk'; | ||
|
|
||
| export type RoleBasedLinkProps = Omit<MuiLinkProps, 'href' | 'component'> & { | ||
| /** Map of role -> destination. Roles omitted here render children as-is without a link. */ | ||
| roleRoutes: Partial<Record<UserRole, To>>; | ||
| }; | ||
|
|
||
| const RoleBasedLink = ({ | ||
| roleRoutes, | ||
| children, | ||
| ...linkProps | ||
| }: RoleBasedLinkProps) => { | ||
| const { currentRole } = useContext(UserContext); | ||
|
|
||
| const to: To | undefined = currentRole ? roleRoutes[currentRole] : undefined; | ||
|
|
||
| // With a destination for this role, render an MUI-styled link that navigates | ||
| // via react-router (client-side); otherwise render children as plain content | ||
| // with no link behavior. | ||
| return to !== undefined ? ( | ||
| <MuiLink component={RouterLink} to={to} {...linkProps}> | ||
| {children} | ||
| </MuiLink> | ||
| ) : ( | ||
| <>{children}</> | ||
| ); | ||
| }; | ||
|
|
||
| export default RoleBasedLink; |
This file contains hidden or 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 hidden or 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 hidden or 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
28 changes: 28 additions & 0 deletions
28
apps/frontend/src/utils/fromArrayToCommaSeparatedLinks.tsx
This file contains hidden or 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,28 @@ | ||
| import React from 'react'; | ||
|
|
||
| import RoleBasedLink, { | ||
| RoleBasedLinkProps, | ||
| } from 'components/common/RoleBasedLink'; | ||
|
|
||
| type CommaSeparatedLink = { | ||
| key: React.Key; | ||
| label: React.ReactNode; | ||
| roleRoutes: RoleBasedLinkProps['roleRoutes']; | ||
| }; | ||
|
|
||
| export function fromArrayToCommaSeparatedLinks( | ||
| links: CommaSeparatedLink[] | null | undefined | ||
| ) { | ||
| return ( | ||
| <> | ||
| {links?.map((link, index) => ( | ||
| <React.Fragment key={link.key}> | ||
| {index > 0 && ', '} | ||
| <RoleBasedLink roleRoutes={link.roleRoutes}> | ||
| {link.label} | ||
| </RoleBasedLink> | ||
| </React.Fragment> | ||
| ))} | ||
| </> | ||
| ); | ||
| } | ||
|
shivoomiess marked this conversation as resolved.
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.