Skip to content
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

Give an option to be an 'external link' for story #735

Merged
merged 8 commits into from
Nov 10, 2023
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
50 changes: 43 additions & 7 deletions app/scripts/components/common/card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { MouseEventHandler, ReactNode } from 'react';
import styled, { css } from 'styled-components';
import { Link } from 'react-router-dom';
import { format } from 'date-fns';
import { CollecticonExpandTopRight } from '@devseed-ui/collecticons';
import { VerticalDivider } from '@devseed-ui/toolbar';

import {
Expand Down Expand Up @@ -198,11 +199,11 @@ export const CardMeta = styled.div`
}
}

> ${/* sc-selector */VerticalDivider}:last-child {
> ${/* sc-selector */ VerticalDivider}:last-child {
display: none;
}

> ${/* sc-selector */VerticalDivider}:first-child {
> ${/* sc-selector */ VerticalDivider}:first-child {
display: none;
}
`;
Expand Down Expand Up @@ -284,6 +285,38 @@ const CardFigure = styled(Figure)`
}
`;

const ExternalLinkMark = styled.div`
display: flex;
align-items: center;
position: absolute;
top: ${variableGlsp(0.25)};
right: ${variableGlsp(0.25)};
padding: ${variableGlsp(0.125)} ${variableGlsp(0.25)};
background-color: ${themeVal('color.primary')};
color: ${themeVal('color.surface')};
text-transform: none;
border-radius: calc(
${multiply(themeVal('shape.rounded'), 2)} - ${variableGlsp(0.125)}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So @faustoperez shared this cool trick on how to derive the value for nested border-radius, which should be (outside border-radius - gap ): https://www.30secondsofcode.org/css/s/nested-border-radius/ But if we take it as it is, the value becomes 0, so I halved the value for the gap here. :[

);
z-index: 1;
`;

const FlagText = styled.div`
display: inline;
font-weight: bold;
font-size: 0.825rem;
margin-right: ${variableGlsp(0.25)};
`;

export function ExternalLinkFlag() {
return (
<ExternalLinkMark>
<FlagText>External Link</FlagText>
<CollecticonExpandTopRight size='small' meaningful={false} />
</ExternalLinkMark>
);
}

interface CardComponentProps {
title: ReactNode;
linkLabel: string;
Expand Down Expand Up @@ -319,23 +352,26 @@ function CardComponent(props: CardComponentProps) {
onCardClickCapture
} = props;

const isExternalLink = linkTo.match(/^https?:\/\//);
const linkProps = isExternalLink
? { href: linkTo }
: { as: Link, to: linkTo };

return (
<ElementInteractive
as={CardSelf}
cardType={cardType}
className={className}
linkLabel={linkLabel || 'View more'}
linkProps={{
as: Link,
to: linkTo
}}
linkProps={linkProps}
onClickCapture={onCardClickCapture}
>
<CardHeader>
<CardHeadline>
<CardTitle>{title}</CardTitle>
<CardOverline as='div'>
{parentName && parentTo && (
{isExternalLink && <ExternalLinkFlag />}
{!isExternalLink && parentName && parentTo && (
<CardLabel as={Link} to={parentTo}>
{parentName}
</CardLabel>
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/components/common/featured-slider-section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function FeaturedSliderSection(props: FeaturedSliderSectionProps) {
}}
cardType='featured'
linkLabel='View more'
linkTo={getItemPath(d)}
linkTo={d.asLink?.url ?? getItemPath(d)}
title={d.name}
overline={
<CardMeta>
Expand Down
7 changes: 6 additions & 1 deletion app/scripts/components/common/related-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
datasets,
Media,
RelatedContentData,
LinkContentData,
StoryData
} from 'veda';
import { utcString2userTzDate } from '$utils/date';
Expand Down Expand Up @@ -48,6 +49,7 @@ interface FormatBlock {
description: string;
date: string;
link: string;
asLink?: LinkContentData;
parentLink: string;
media: Media;
parent: RelatedContentData['type'];
Expand Down Expand Up @@ -76,6 +78,7 @@ function formatBlock({
description,
date,
media,
asLink,
type
}): FormatBlock {
return {
Expand All @@ -84,6 +87,7 @@ function formatBlock({
description,
date,
media,
asLink,
...formatUrl(id, type),
parent: type
};
Expand All @@ -109,6 +113,7 @@ function formatContents(relatedData: RelatedContentData[]) {
id,
name,
description,
asLink: (matchingContent as StoryData).asLink,
date: (matchingContent as StoryData).pubDate,
media,
type
Expand Down Expand Up @@ -141,7 +146,7 @@ export default function RelatedContent(props: RelatedContentProps) {
<Card
cardType='cover'
linkLabel={`View ${t.parent} ${t.name}`}
linkTo={t.link}
linkTo={t.asLink?.url ?? t.link}
title={t.name}
date={
t.parent === storyString
Expand Down
10 changes: 2 additions & 8 deletions app/scripts/components/data-catalog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,11 @@ function DataCatalog() {
<PageMainContent>
<LayoutProps
title='Data Catalog'
description={
getString('dataCatalogBanner')?.other ||
hanbyul-here marked this conversation as resolved.
Show resolved Hide resolved
'This dashboard explores key indicators to track and compare changes over time.'
}
description={getString('dataCatalogBanner').other}
/>
<PageHero
title='Data Catalog'
description={
getString('dataCatalogBanner')?.other ||
'This dashboard explores key indicators to track and compare changes over time.'
}
description={getString('dataCatalogBanner').other}
/>

<FeaturedDatasets />
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/components/home/featured-stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function FeaturedStories() {
<Card
cardType='cover'
linkLabel='View more'
linkTo={getStoryPath(d)}
linkTo={d.asLink?.url ?? getStoryPath(d)}
title={d.name}
parentName={getString('stories').one}
parentTo={STORIES_PATH}
Expand Down
4 changes: 2 additions & 2 deletions app/scripts/components/home/value-propostion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ function ValueProposition() {
<ContentBlockProseAlt>
<h3>Science communication platform</h3>
<p>
Share your {getString('stories').other.toLocaleLowerCase()} with others through the VEDA Dashboard.
Submit a{' '}
Share your {getString('stories').other.toLocaleLowerCase()} with
others through the VEDA Dashboard. Submit a{' '}
<a
href='#'
onClick={(e) => {
Expand Down
6 changes: 3 additions & 3 deletions app/scripts/components/stories/hub/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,11 @@ function StoriesHub() {
<PageMainContent>
<LayoutProps
title={getString('stories').other}
description={getString('storiesBanner')?.other || 'Explore the guided narratives below to discover how NASA satellites and other Earth observing resources reveal a changing planet.'}
description={getString('storiesBanner').other}
/>
<PageHero
title={getString('stories').other}
description={getString('storiesBanner')?.other || 'Explore the guided narratives below to discover how NASA satellites and other Earth observing resources reveal a changing planet.'}
description={getString('storiesBanner').other}
/>

<FeaturedStories />
Expand Down Expand Up @@ -243,7 +243,7 @@ function StoriesHub() {
</CardMeta>
}
linkLabel='View more'
linkTo={getStoryPath(d)}
linkTo={d.asLink?.url ?? getStoryPath(d)}
title={
<TextHighlight
value={search}
Expand Down
7 changes: 5 additions & 2 deletions app/scripts/components/stories/single/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const MdxContent = lazy(() => import('$components/common/mdx-content'));
function StoriesSingle() {
const story = useStory();

if (!story) throw resourceNotFound();
if (!story || story.data.asLink) throw resourceNotFound();

const { media, related } = story.data;

Expand Down Expand Up @@ -45,7 +45,10 @@ function StoriesSingle() {
attributionAuthor={media?.author?.name}
attributionUrl={media?.author?.url}
renderDetailsBlock={() => (
<ContentTaxonomy taxonomy={story.data.taxonomy} linkBase={STORIES_PATH} />
<ContentTaxonomy
taxonomy={story.data.taxonomy}
linkBase={STORIES_PATH}
/>
)}
/>

Expand Down
27 changes: 27 additions & 0 deletions mock/stories/external-link-example.stories.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
featured: true
id: 'external-link-test'
name: External Link Test
description: Story to test external link
media:
src: ::file ./img-placeholder-6.jpg
alt: Generic placeholder by Unsplash
author:
name: Unsplash
url: https://unsplash.com/
pubDate: 2023-02-09
taxonomy:
- name: Topics
values:
- Agriculture
- name: Source
values:
- Development Seed
related:
- type: dataset
id: no2
- type: story
id: air-quality-and-covid-19
asLink:
url: 'https://developmentseed.org'
---
27 changes: 27 additions & 0 deletions mock/stories/internal-link-example.stories.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
featured: true
id: 'internal-link-test'
name: Internal Link Test
description: Story to test internal link. Link to cata catalog.
media:
src: ::file ./img-placeholder-6.jpg
alt: Generic placeholder by Unsplash
author:
name: Unsplash
url: https://unsplash.com/
pubDate: 2023-02-09
taxonomy:
- name: Topics
values:
- Agriculture
- name: Source
values:
- Development Seed
related:
- type: dataset
id: no2
- type: story
id: air-quality-and-covid-19
asLink:
url: '/data-catalog'
---
2 changes: 1 addition & 1 deletion mock/stories/life-of-water.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ related:
- type: dataset
id: no2
- type: story
id: air-quality-and-covid-19
id: external-link-test
---

<Block>
Expand Down
20 changes: 14 additions & 6 deletions parcel-resolver-veda/defaults.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
const { defaults, mapValues } = require('lodash');

const defaultStrings = {
const defaultStrings = ensureOneOther({
stories: {
one: 'Story',
other: 'Stories'
}
};
},
storiesBanner:
'Explore the guided narratives below to discover how NASA satellites and other Earth observing resources reveal a changing planet.',
dataCatalogBanner:
'This dashboard explores key indicators to track and compare changes over time.'
});

/**
* Combine the default strings with the user-provided strings, while converting
* single string values to an object with `one` and `other` keys.
* @param {object} strings
*/
module.exports.withDefaultStrings = (strings) => {
const objectifiedStrings = mapValues(strings, (value) =>
typeof value === 'string' ? { one: value, other: value } : value
);
const objectifiedStrings = ensureOneOther(strings);
return defaults({}, objectifiedStrings, defaultStrings);
};

function ensureOneOther(objectWithStrings) {
return mapValues(objectWithStrings, (value) =>
typeof value === 'string' ? { one: value, other: value } : value
);
}
12 changes: 10 additions & 2 deletions parcel-resolver-veda/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ declare module 'veda' {
analysis?: {
metrics: string[];
exclude: boolean;
}
};
}

// A normalized compare layer is the result after the compare definition is
Expand Down Expand Up @@ -136,6 +136,14 @@ declare module 'veda' {
id: string;
thematic?: string;
}
/**
* Link Content
* When the story is a link out to the external/internal content
*/

export interface LinkContentData {
url: string;
}

export interface DatasetUsage {
url: string;
Expand Down Expand Up @@ -174,6 +182,7 @@ declare module 'veda' {
media?: Media;
taxonomy: Taxonomy[];
related?: RelatedContentData[];
asLink?: LinkContentData;
}

// ///////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -258,7 +267,6 @@ declare module 'veda' {
one: string;
hanbyul-here marked this conversation as resolved.
Show resolved Hide resolved
other: string;
};

/**
* List of custom user defined pages.
*/
Expand Down
Loading