Skip to content

Commit 65463fb

Browse files
melissawmczi-github-helper[bot]
andauthored
feat: Add a citation button to pages (#1856)
* feat: Add citation button to single pages * chore: Update wording * feat: Add cite button to single dataset and single deposition pages * chore: Lint * chore: Updated [rdev] values.yaml image tags to sha-d2c0b69 * feat: Add plausible tracking and fix key press behaviour * chore: Updated [rdev] values.yaml image tags to sha-f2fcc15 * fix: Plausible tracking * chore: Updated [rdev] values.yaml image tags to sha-e768c4c * fix: Fix citation button in dataset, deposition, and run headers * chore: Updated [rdev] values.yaml image tags to sha-cedf449 * fix: Lint * chore: Updated [rdev] values.yaml image tags to sha-999061d * chore: Change gap between buttons to sds element * chore: Updated [rdev] values.yaml image tags to sha-01d81cb --------- Co-authored-by: czi-github-helper[bot] <+czi-github-helper[bot]@users.noreply.github.com>
1 parent b393913 commit 65463fb

File tree

7 files changed

+124
-3
lines changed

7 files changed

+124
-3
lines changed

.infra/rdev/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ stack:
22
services:
33
frontend:
44
image:
5-
tag: sha-9b33749
5+
tag: sha-01d81cb
66
replicaCount: 1
77
env:
88
- name: API_URL_V2
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { Button, ButtonProps, TooltipProps } from '@czi-sds/components'
2+
3+
import { useI18n } from 'app/hooks/useI18n'
4+
import { EventPayloads, Events, usePlausible } from 'app/hooks/usePlausible'
5+
6+
import { Link } from './Link'
7+
import { Tooltip } from './Tooltip'
8+
9+
export interface CitationButtonProps {
10+
buttonProps: Partial<ButtonProps>
11+
event: EventPayloads[Events.CitePortal]
12+
tooltipPlacement: TooltipProps['placement']
13+
setIsHoveringOver?: (isHoveringOver: boolean) => void
14+
}
15+
16+
export function CitationButton({
17+
buttonProps,
18+
event,
19+
tooltipPlacement,
20+
setIsHoveringOver,
21+
}: CitationButtonProps) {
22+
const plausible = usePlausible()
23+
const { t } = useI18n()
24+
25+
function trackCitation() {
26+
plausible(Events.CitePortal, event)
27+
}
28+
29+
return (
30+
<Tooltip
31+
tooltip={
32+
<>
33+
<h4 className="font-semibold">{t('citePortalText')}</h4>
34+
</>
35+
}
36+
sdsStyle="dark"
37+
center
38+
placement={tooltipPlacement}
39+
size="m"
40+
>
41+
{/* We need to disable this rule because we need the div to capture bubbled click events from
42+
the link button below. This is because Plausible automatically adds event listeners to every
43+
link on the page to track outbound links, so we can't attach a click listener to the link
44+
directly because Plausible will overwrite it. */}
45+
{/* eslint-disable-next-line jsx-a11y/no-static-element-interactions */}
46+
<div
47+
onClick={(e) => {
48+
e.stopPropagation()
49+
trackCitation()
50+
}}
51+
onKeyDown={({ key }) => {
52+
if (key === 'Enter') {
53+
trackCitation()
54+
}
55+
}}
56+
onMouseEnter={() => setIsHoveringOver?.(false)} // could be changed back to true if we needed this fine-grained control
57+
onMouseLeave={() => setIsHoveringOver?.(false)}
58+
>
59+
<Button
60+
href={t('citePortalLink')}
61+
disabled={false}
62+
LinkComponent={Link}
63+
{...(buttonProps as ButtonProps)}
64+
>
65+
<span>{t('citePortal')}</span>
66+
</Button>
67+
</div>
68+
</Tooltip>
69+
)
70+
}

frontend/packages/data-portal/app/components/Dataset/DatasetHeader.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Button, Icon } from '@czi-sds/components'
22

33
import { Breadcrumbs } from 'app/components/Breadcrumbs'
4+
import { CitationButton } from 'app/components/CitationButton'
45
import { DatasetOverview } from 'app/components/Dataset/DatasetOverview'
56
import { PageHeader } from 'app/components/PageHeader'
67
import { DATA_TYPES } from 'app/constants/dataTypes'
@@ -25,7 +26,7 @@ export function DatasetHeader() {
2526
return (
2627
<PageHeader
2728
actions={
28-
<div>
29+
<div className="flex items-center gap-sds-s">
2930
<Button
3031
startIcon={<Icon sdsIcon="Download" sdsSize="l" />}
3132
sdsType="primary"
@@ -34,6 +35,18 @@ export function DatasetHeader() {
3435
>
3536
{t('downloadDataset')}
3637
</Button>
38+
39+
<CitationButton
40+
buttonProps={{
41+
sdsStyle: 'rounded',
42+
sdsType: 'secondary',
43+
startIcon: <Icon sdsIcon="Book" sdsSize="s" />,
44+
}}
45+
tooltipPlacement="bottom"
46+
event={{
47+
cite: true,
48+
}}
49+
/>
3750
</div>
3851
}
3952
breadcrumbs={<Breadcrumbs variant="dataset" data={dataset} />}

frontend/packages/data-portal/app/components/Deposition/DepositionHeader.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
import { Icon } from '@czi-sds/components'
2+
13
import { Breadcrumbs } from 'app/components/Breadcrumbs'
4+
import { CitationButton } from 'app/components/CitationButton'
25
import { HeaderKeyPhoto } from 'app/components/HeaderKeyPhoto'
36
import { PageHeader } from 'app/components/PageHeader'
47
import { DATA_TYPES } from 'app/constants/dataTypes'
@@ -20,6 +23,21 @@ export function DepositionHeader() {
2023

2124
return (
2225
<PageHeader
26+
actions={
27+
<div>
28+
<CitationButton
29+
buttonProps={{
30+
sdsStyle: 'rounded',
31+
sdsType: 'secondary',
32+
startIcon: <Icon sdsIcon="Book" sdsSize="s" />,
33+
}}
34+
tooltipPlacement="bottom"
35+
event={{
36+
cite: true,
37+
}}
38+
/>
39+
</div>
40+
}
2341
breadcrumbs={<Breadcrumbs variant="deposition" data={deposition} />}
2442
lastModifiedDate={deposition.lastModifiedDate.split('T')[0]}
2543
metadata={[

frontend/packages/data-portal/app/components/Run/RunHeader.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Button, Icon } from '@czi-sds/components'
22

33
import { Breadcrumbs } from 'app/components/Breadcrumbs'
4+
import { CitationButton } from 'app/components/CitationButton'
45
import { CollapsibleList } from 'app/components/CollapsibleList'
56
import { HeaderKeyPhoto } from 'app/components/HeaderKeyPhoto'
67
import { I18n } from 'app/components/I18n'
@@ -61,7 +62,7 @@ export function RunHeader() {
6162
return (
6263
<PageHeader
6364
actions={
64-
<div className="flex items-center gap-2.5">
65+
<div className="flex items-center gap-sds-s">
6566
<ViewTomogramButton
6667
tomogramId={tomogramId}
6768
neuroglancerConfig={neuroglancerConfig}
@@ -93,6 +94,18 @@ export function RunHeader() {
9394
>
9495
{t('downloadWithAdditionalOptions')}
9596
</Button>
97+
98+
<CitationButton
99+
buttonProps={{
100+
sdsStyle: 'rounded',
101+
sdsType: 'secondary',
102+
startIcon: <Icon sdsIcon="Book" sdsSize="s" />,
103+
}}
104+
tooltipPlacement="bottom"
105+
event={{
106+
cite: true,
107+
}}
108+
/>
96109
</div>
97110
}
98111
releaseDate={run.dataset?.releaseDate.split('T')[0]}

frontend/packages/data-portal/app/hooks/usePlausible.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const PLAUSIBLE_ENV_URL_MAP: Record<NodeJS.ProcessEnv['ENV'], string> = {
1616
}
1717

1818
export enum Events {
19+
CitePortal = 'Cite Portal',
1920
ClickBackToConfigureDownload = 'Click back to configure download',
2021
ClickBreadcrumb = 'Click breadcrumb',
2122
ClickBrowseDataTab = 'Click browse data tab',
@@ -52,6 +53,9 @@ export type PlausibleDownloadModalPayload<T = object> = T & {
5253
export type DownloadModalPropKeys = keyof PlausibleDownloadModalPayload
5354

5455
export type EventPayloads = {
56+
[Events.CitePortal]: {
57+
cite: boolean
58+
}
5559
[Events.ClickBackToConfigureDownload]: PlausibleDownloadModalPayload
5660
[Events.ClickDownloadTab]: PlausibleDownloadModalPayload
5761
[Events.ClickDownloadTomogram]: PlausibleDownloadModalPayload<{

frontend/packages/data-portal/public/locales/en/translation.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@
8181
"cellLineOrStrainName": "Cell Line or Strain Name",
8282
"cellName": "Cell Name",
8383
"cellularComponent": "Cellular Component",
84+
"citePortal": "Cite",
85+
"citePortalLink": "https://chanzuckerberg.github.io/cryoet-data-portal/stable/#citing-the-cryoet-data-portal",
86+
"citePortalText": "Learn how to cite this data and the Portal",
8487
"clickToDownloadViaBrowser": "Click to download via your browser",
8588
"close": "Close",
8689
"comingFall2024": "Coming in Fall 2024",

0 commit comments

Comments
 (0)