Skip to content

Commit

Permalink
CORE-4742: add linking
Browse files Browse the repository at this point in the history
  • Loading branch information
ekachxaidze98 committed Dec 18, 2023
1 parent df940c5 commit d65e78c
Show file tree
Hide file tree
Showing 10 changed files with 280 additions and 71 deletions.
123 changes: 89 additions & 34 deletions modules/dropdown/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import {
Button,
Card,
DataProviderLogo,
Icon,
Link,
} from '@oacore/design/lib/elements'
import classNames from '@oacore/design/lib/utils/class-names'
import { Popover } from '@oacore/design/lib/modules'

import redirect from '../../public/static/images/redirect.svg'
import styles from './styles.module.css'
import { capitalizeFirstLetter } from '../../utils/titleCase'

const DropDown = ({
title,
subtitle,
renderOAI,
children,
className,
Expand All @@ -25,15 +25,18 @@ const DropDown = ({
makeVisible,
dataProviderId,
disableRedirect,
outputRedirect,
metadata,
coreDownloadUrl,
sourceFulltextUrls,
sourceFulltextUrlsUpd,
id,
oai,
doi,
useOtherVersions,
}) => {
const [activeDropdown, setActiveDropdown] = useState(!useExpandButton)
const [logoFetched, setLogoFetched] = useState('')

const onToggleDropdown = (e) => {
e.stopPropagation()
setActiveDropdown(!activeDropdown)
}

const Tag = href ? Link : 'div'

// eslint-disable-next-line consistent-return
Expand All @@ -43,6 +46,10 @@ const DropDown = ({
window.location.href = href
}

const redirectToProviders = () => {
window.location.href = metadata.hrefDataProvider
}

const getLogoLink = () => {
useEffect(() => {
async function fetchData() {
Expand All @@ -64,30 +71,36 @@ const DropDown = ({

return (
<>
{checkBillingType && !makeVisible ? (
<div className={styles.placement}>
<a href="/membership" className={styles.memberType}>
{capitalizeFirstLetter(memberType?.billing_type)} member
</a>
</div>
) : (
<></>
)}
<div
className={classNames
.use(styles.dropdown, {
.use({
[styles.activeClass]: checkBillingType && !makeVisible,
[styles.cardItem]: useOtherVersions,
})
.join(className)}
>
{checkBillingType && !makeVisible ? (
<div className={styles.placement}>
<a
href="https://core.ac.uk/membership"
className={styles.memberType}
>
{capitalizeFirstLetter(memberType?.billing_type)} member
</a>
</div>
) : (
<></>
)}
<div className={styles.header}>
<Tag className={styles.content} onClick={redirectOnClick}>
<Tag className={styles.content}>
<div
className={classNames.use(styles.headerWrapper, {
[styles.headerWrapperClickable]: useExpandButton,
})}
>
<div className={styles.itemWrapper}>
{/* eslint-disable-next-line max-len */}
{/* eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions */}
<div className={styles.itemWrapper} onClick={redirectToProviders}>
<DataProviderLogo
imageSrc={checkBillingType ? getLogoLink() : ''}
useDefault
Expand All @@ -103,33 +116,75 @@ const DropDown = ({
>
{title}
</Card.Title>
<Card.Description className={styles.subtitle} tag="span">
{subtitle}
</Card.Description>
</div>
<img
className={styles.redirectImg}
src={redirect}
alt="redirect"
/>
</div>
{useExpandButton && (
<Button type="button" onClick={onToggleDropdown}>
<Icon
src="#menu-down"
className={classNames.use(styles.iconMenu, {
[styles.iconMenuActive]: activeDropdown,
})}
/>
</Button>
)}
</div>
<Card.Description
className={classNames.use(styles.subtitle, {
[styles.oaiTitle]: renderOAI,
})}
tag="span"
>
{outputRedirect && (
<Button
onClick={redirectOnClick}
className={styles.actionButton}
variant="outlined"
>
See this paper in CORE
</Button>
)}
{oai ? (
<a
className={styles.ellipsis}
href={`https://api.core.ac.uk/oai/${oai}`}
>
<Button className={styles.actionButton} variant="outlined">
Go to the repository landing page
</Button>
</a>
) : (
<a className={styles.ellipsis} href={`https://doi.org/${doi}`}>
<Button className={styles.actionButton} variant="outlined">
Go to the repository landing page
</Button>
</a>
)}
{coreDownloadUrl &&
coreDownloadUrl.match(/core.ac.uk/gm) &&
sourceFulltextUrls ? (
<a
href={sourceFulltextUrlsUpd}
aria-labelledby={`${id}-downloaded-from-title`}
aria-describedby={`${id}-downloaded-from-body`}
target="_blank"
rel="noreferrer"
>
<Button className={styles.actionButton} variant="outlined">
Download from data provider
</Button>
</a>
) : (
<Popover
placement="right"
content="We don't have a full text link from this data provider"
className={styles.popover}
>
<Button className={styles.disabledButton} variant="outlined">
Download from data provider
</Button>
</Popover>
)}
{renderOAI}
</Card.Description>
</Tag>
</div>
{activeDropdown && children}
{children}
</div>
</>
)
Expand Down
62 changes: 55 additions & 7 deletions modules/dropdown/styles.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
display: flex;
align-items: center;
justify-content: space-between;
padding-bottom: 1rem;
border-bottom: 1px solid #e0e0e0;
cursor: pointer;
}

.header-wrapper-clickable {
Expand All @@ -45,25 +48,69 @@
}

.title-colored {
color: var(--primary);
color: var(--gray-900);
}

.redirect-img {
margin-left: 1rem;
}

.subtitle {
display: block;
padding-bottom: 0.3rem;
margin-top: 0.3rem;
color: var(--gray-700);
padding-top: 10px;
}

.action-button {
width: 100%;
margin-bottom: 14px;
text-align: center;
font-size: 14px;
font-style: normal;
font-weight: 500;
line-height: 16px;
letter-spacing: 0.175px;
text-transform: initial;
}

.disabled-button {
width: 100%;
border: 1px solid #9E9E9E;
color: #9E9E9E;
cursor: not-allowed;
margin-bottom: 14px;
letter-spacing: 0.175px;
text-transform: initial;
}

.popover {
padding: 4px;
width: 160px;
color: #FFF;
font-size: 12px;
font-style: normal;
font-weight: 400;
line-height: 12px;
letter-spacing: 0.048px;
}

.disabled-button:hover {
background: unset;
}

.oai-title {
border-top: 1px solid #e0e0e0;
padding-top: 10px;
}

.activeClass {
border: 1px solid #B75400;
.card-item {
background: #F5F5F5;
padding: 0.5rem;
padding: 0.5rem 1rem 1rem;
}

.activeClass {
padding: 0 1rem 1rem;
cursor: pointer;
transition: all 0.5s ease-in-out;
}
Expand All @@ -77,13 +124,14 @@
display: flex;
justify-content: flex-end;
align-items: center;
margin-bottom: -1rem;
margin-bottom: 0.5rem;
margin-right: -1rem;
}

.memberType {
min-width: 113px;
width: max-content;
background: #B75400;
background: #8BC34A;
font-style: normal;
font-weight: 400;
font-size: 12px;
Expand Down
2 changes: 1 addition & 1 deletion pages/outputs/[id].jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Header } from '@oacore/design'
import { useRouter } from 'next/router'

import { checkLogo, checkMembership } from 'utils/data-providers-transform'
import { fetchMetadata, fetchCitations, fetchDataProvider } from 'api/outputs'
import { fetchCitations, fetchDataProvider, fetchMetadata } from 'api/outputs'
import { useStore } from 'store'
import Meta from 'modules/meta'
import Template from 'templates/output'
Expand Down
5 changes: 5 additions & 0 deletions public/static/images/redirect.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 17 additions & 16 deletions templates/output/card-dropdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ const CardDropdown = ({
dataProviderId,
makeVisible,
worksOai,
outputRedirect,
metadata,
doi,
useOtherVersions,
}) => {
const [copyUrlStatus, copyUrl] = useCopyToClipboard(oai)
const [isTooltipVisible, setIsTooltipVisible] = useState(false)
Expand Down Expand Up @@ -128,6 +132,15 @@ const CardDropdown = ({
memberType={memberType}
checkBillingType={checkBillingType}
makeVisible={makeVisible}
outputRedirect={outputRedirect}
metadata={metadata}
coreDownloadUrl={coreDownloadUrl}
sourceFulltextUrls={sourceFulltextUrls}
sourceFulltextUrlsUpd={sourceFulltextUrlsUpd}
id={id}
oai={oai}
doi={doi}
useOtherVersions={useOtherVersions}
>
<div className={styles.dropdownContent}>
{!worksOai && oai && (
Expand Down Expand Up @@ -161,23 +174,11 @@ const CardDropdown = ({
Last time updated on {formatDate(updatedDate || createdDate)}
</Card.Description>
)}
{coreDownloadUrl &&
coreDownloadUrl.match(/core.ac.uk/gm) &&
sourceFulltextUrls && (
<Card.Description className={styles.descriptionLink} tag="span">
<a
href={sourceFulltextUrlsUpd}
aria-labelledby={`${id}-downloaded-from-title`}
aria-describedby={`${id}-downloaded-from-body`}
target="_blank"
rel="noreferrer"
>
View original full text link
</a>
</Card.Description>
)}
{checkBillingType && makeVisible ? (
<a href="/membership" className={styles.memberHighlight}>
<a
href="https://core.ac.uk/membership"
className={styles.memberHighlight}
>
Provided by our {capitalizeFirstLetter(memberType?.billing_type)}{' '}
member
</a>
Expand Down
8 changes: 1 addition & 7 deletions templates/output/card-dropdown.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@
margin-bottom: 1rem;
}

.dropdown-content {
padding-top: 0.5rem;
margin-bottom: 1rem;
border-top: 1px solid var(--gray-100);
}

.identifier {
position: relative;
display: flex;
Expand Down Expand Up @@ -91,7 +85,7 @@
font-weight: 400;
color: #fff;
letter-spacing: 0.004em;
background: #b75400;
background: #8BC34A;
border-radius: 2px;
}

Expand Down
Loading

0 comments on commit d65e78c

Please sign in to comment.