Skip to content

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 15 commits into from
Jun 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .infra/rdev/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ stack:
services:
frontend:
image:
tag: sha-9b33749
tag: sha-01d81cb
replicaCount: 1
env:
- name: API_URL_V2
Expand Down
70 changes: 70 additions & 0 deletions frontend/packages/data-portal/app/components/CitationButton.tsx
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>
)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Button, Icon } from '@czi-sds/components'

import { Breadcrumbs } from 'app/components/Breadcrumbs'
import { CitationButton } from 'app/components/CitationButton'
import { DatasetOverview } from 'app/components/Dataset/DatasetOverview'
import { PageHeader } from 'app/components/PageHeader'
import { DATA_TYPES } from 'app/constants/dataTypes'
Expand All @@ -25,7 +26,7 @@ export function DatasetHeader() {
return (
<PageHeader
actions={
<div>
<div className="flex items-center gap-sds-s">
<Button
startIcon={<Icon sdsIcon="Download" sdsSize="l" />}
sdsType="primary"
Expand All @@ -34,6 +35,18 @@ export function DatasetHeader() {
>
{t('downloadDataset')}
</Button>

<CitationButton
buttonProps={{
sdsStyle: 'rounded',
sdsType: 'secondary',
startIcon: <Icon sdsIcon="Book" sdsSize="s" />,
}}
tooltipPlacement="bottom"
event={{
cite: true,
}}
/>
</div>
}
breadcrumbs={<Breadcrumbs variant="dataset" data={dataset} />}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { Icon } from '@czi-sds/components'

import { Breadcrumbs } from 'app/components/Breadcrumbs'
import { CitationButton } from 'app/components/CitationButton'
import { HeaderKeyPhoto } from 'app/components/HeaderKeyPhoto'
import { PageHeader } from 'app/components/PageHeader'
import { DATA_TYPES } from 'app/constants/dataTypes'
Expand All @@ -20,6 +23,21 @@ export function DepositionHeader() {

return (
<PageHeader
actions={
<div>
<CitationButton
buttonProps={{
sdsStyle: 'rounded',
sdsType: 'secondary',
startIcon: <Icon sdsIcon="Book" sdsSize="s" />,
}}
tooltipPlacement="bottom"
event={{
cite: true,
}}
/>
</div>
}
breadcrumbs={<Breadcrumbs variant="deposition" data={deposition} />}
lastModifiedDate={deposition.lastModifiedDate.split('T')[0]}
metadata={[
Expand Down
15 changes: 14 additions & 1 deletion frontend/packages/data-portal/app/components/Run/RunHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Button, Icon } from '@czi-sds/components'

import { Breadcrumbs } from 'app/components/Breadcrumbs'
import { CitationButton } from 'app/components/CitationButton'
import { CollapsibleList } from 'app/components/CollapsibleList'
import { HeaderKeyPhoto } from 'app/components/HeaderKeyPhoto'
import { I18n } from 'app/components/I18n'
Expand Down Expand Up @@ -61,7 +62,7 @@ export function RunHeader() {
return (
<PageHeader
actions={
<div className="flex items-center gap-2.5">
<div className="flex items-center gap-sds-s">
<ViewTomogramButton
tomogramId={tomogramId}
neuroglancerConfig={neuroglancerConfig}
Expand Down Expand Up @@ -93,6 +94,18 @@ export function RunHeader() {
>
{t('downloadWithAdditionalOptions')}
</Button>

<CitationButton
buttonProps={{
sdsStyle: 'rounded',
sdsType: 'secondary',
startIcon: <Icon sdsIcon="Book" sdsSize="s" />,
}}
tooltipPlacement="bottom"
event={{
cite: true,
}}
/>
</div>
}
releaseDate={run.dataset?.releaseDate.split('T')[0]}
Expand Down
4 changes: 4 additions & 0 deletions frontend/packages/data-portal/app/hooks/usePlausible.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const PLAUSIBLE_ENV_URL_MAP: Record<NodeJS.ProcessEnv['ENV'], string> = {
}

export enum Events {
CitePortal = 'Cite Portal',
ClickBackToConfigureDownload = 'Click back to configure download',
ClickBreadcrumb = 'Click breadcrumb',
ClickBrowseDataTab = 'Click browse data tab',
Expand Down Expand Up @@ -52,6 +53,9 @@ export type PlausibleDownloadModalPayload<T = object> = T & {
export type DownloadModalPropKeys = keyof PlausibleDownloadModalPayload

export type EventPayloads = {
[Events.CitePortal]: {
cite: boolean
}
[Events.ClickBackToConfigureDownload]: PlausibleDownloadModalPayload
[Events.ClickDownloadTab]: PlausibleDownloadModalPayload
[Events.ClickDownloadTomogram]: PlausibleDownloadModalPayload<{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@
"cellLineOrStrainName": "Cell Line or Strain Name",
"cellName": "Cell Name",
"cellularComponent": "Cellular Component",
"citePortal": "Cite",
"citePortalLink": "https://chanzuckerberg.github.io/cryoet-data-portal/stable/#citing-the-cryoet-data-portal",
"citePortalText": "Learn how to cite this data and the Portal",
"clickToDownloadViaBrowser": "Click to download via your browser",
"close": "Close",
"comingFall2024": "Coming in Fall 2024",
Expand Down
Loading