-
Notifications
You must be signed in to change notification settings - Fork 13
feat: Add a citation button to pages #1856
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 13 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
2d4ddba
feat: Add citation button to single pages
melissawm 7429b69
chore: Update wording
melissawm 8270623
feat: Add cite button to single dataset and single deposition pages
melissawm d2c0b69
chore: Lint
melissawm 4f1a32c
chore: Updated [rdev] values.yaml image tags to sha-d2c0b69
f2fcc15
feat: Add plausible tracking and fix key press behaviour
melissawm 35ca023
chore: Updated [rdev] values.yaml image tags to sha-f2fcc15
e768c4c
fix: Plausible tracking
melissawm b189ac3
chore: Updated [rdev] values.yaml image tags to sha-e768c4c
cedf449
fix: Fix citation button in dataset, deposition, and run headers
melissawm db519aa
chore: Updated [rdev] values.yaml image tags to sha-cedf449
999061d
fix: Lint
melissawm c7eb337
chore: Updated [rdev] values.yaml image tags to sha-999061d
01d81cb
chore: Change gap between buttons to sds element
melissawm fd2aee4
chore: Updated [rdev] values.yaml image tags to sha-01d81cb
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
70 changes: 70 additions & 0 deletions
70
frontend/packages/data-portal/app/components/CitationButton.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,70 @@ | ||
import { Button, ButtonProps, TooltipProps } from '@czi-sds/components' | ||
|
||
import { useI18n } from 'app/hooks/useI18n' | ||
import { EventPayloads, Events, usePlausible } from 'app/hooks/usePlausible' | ||
|
||
import { Link } from './Link' | ||
import { Tooltip } from './Tooltip' | ||
|
||
export interface CitationButtonProps { | ||
buttonProps: Partial<ButtonProps> | ||
event: EventPayloads[Events.CitePortal] | ||
tooltipPlacement: TooltipProps['placement'] | ||
setIsHoveringOver?: (isHoveringOver: boolean) => void | ||
} | ||
|
||
export function CitationButton({ | ||
buttonProps, | ||
event, | ||
tooltipPlacement, | ||
setIsHoveringOver, | ||
}: CitationButtonProps) { | ||
const plausible = usePlausible() | ||
const { t } = useI18n() | ||
|
||
function trackCitation() { | ||
plausible(Events.CitePortal, event) | ||
} | ||
|
||
return ( | ||
<Tooltip | ||
tooltip={ | ||
<> | ||
<h4 className="font-semibold">{t('citePortalText')}</h4> | ||
</> | ||
} | ||
sdsStyle="dark" | ||
center | ||
placement={tooltipPlacement} | ||
size="m" | ||
> | ||
{/* We need to disable this rule because we need the div to capture bubbled click events from | ||
the link button below. This is because Plausible automatically adds event listeners to every | ||
link on the page to track outbound links, so we can't attach a click listener to the link | ||
directly because Plausible will overwrite it. */} | ||
{/* eslint-disable-next-line jsx-a11y/no-static-element-interactions */} | ||
<div | ||
onClick={(e) => { | ||
e.stopPropagation() | ||
trackCitation() | ||
}} | ||
onKeyDown={({ key }) => { | ||
if (key === 'Enter') { | ||
trackCitation() | ||
} | ||
}} | ||
onMouseEnter={() => setIsHoveringOver?.(false)} // could be changed back to true if we needed this fine-grained control | ||
onMouseLeave={() => setIsHoveringOver?.(false)} | ||
> | ||
<Button | ||
href={t('citePortalLink')} | ||
disabled={false} | ||
LinkComponent={Link} | ||
{...(buttonProps as ButtonProps)} | ||
> | ||
<span>{t('citePortal')}</span> | ||
</Button> | ||
</div> | ||
</Tooltip> | ||
) | ||
} |
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: let's use
gap-sds-s
to keep our spacing scale explicitly in line with sds recommendations!Though I can see you got it from RunHeader, nice detective work, we would have to swap it there too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see! Thanks, fixed it in both places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rainandbare hopefully this is what you meant!