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

Various fixes for E&A #1229

Merged
merged 10 commits into from
Nov 6, 2024
Prev Previous commit
Next Next commit
Use linkproperties for sources (but is this necessary?)
hanbyul-here committed Oct 30, 2024
commit e01d03e2f2e1265faa0d0432f0ff9b7eb35893c2
16 changes: 8 additions & 8 deletions app/scripts/components/common/card-sources.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import React from 'react';
import styled from 'styled-components';
import { Link } from 'react-router-dom';
import { listReset } from '@devseed-ui/theme-provider';
import { TaxonomyItem } from '$types/veda';
import { LinkProperties, TaxonomyItem } from '$types/veda';
import { FilterActions } from '$components/common//catalog/utils';

const SourcesUl = styled.ul`
@@ -23,11 +22,12 @@ interface SourcesListProps {
sources?: TaxonomyItem[];
onSourceClick?: (v: string) => void;
rootPath?: string;
linkProperties: LinkProperties;
}

export function CardSourcesList(props: SourcesListProps) {
const { sources, onSourceClick, rootPath } = props;

const { sources, onSourceClick, linkProperties, rootPath } = props;
const { LinkElement, pathAttributeKeyName } = linkProperties as { LinkElement: React.ElementType, pathAttributeKeyName: string };
if (!sources?.length) return null;

// No link rendering
@@ -50,19 +50,19 @@ export function CardSourcesList(props: SourcesListProps) {
<SourcesUl>
{sources.map((source) => (
<li key={source.id}>
<Link
to={`${rootPath}?${FilterActions.TAXONOMY}=${encodeURIComponent(
<LinkElement
{...{[pathAttributeKeyName]:`${rootPath}?${FilterActions.TAXONOMY}=${encodeURIComponent(
JSON.stringify({
Source: source.id
})
)}`}
)}`}}
onClick={(e) => {
e.preventDefault();
onSourceClick(source.id);
}}
>
{source.name}
</Link>
</LinkElement>
</li>
))}
</SourcesUl>
2 changes: 1 addition & 1 deletion app/scripts/components/common/catalog/catalog-card.tsx
Original file line number Diff line number Diff line change
@@ -121,7 +121,7 @@ export const CatalogCard = (props: CatalogCardProps) => {
overline={
<CardMeta>
<DatasetClassification dataset={dataset} />
<CardSourcesList sources={sources} />
<CardSourcesList sources={sources} linkProperties={linkProperties} />
</CardMeta>
}
linkLabel='View dataset'
9 changes: 6 additions & 3 deletions app/scripts/components/common/featured-slider-section.tsx
Original file line number Diff line number Diff line change
@@ -93,7 +93,10 @@ function FeaturedSliderSection(props: FeaturedSliderSectionProps) {
return sortedFeaturedItems.map((d) => {
const date = new Date(d[dateProperty ?? '']);
const topics = getTaxonomy(d, TAXONOMY_TOPICS)?.values;

const linkProperties = {
pathAttributeKeyName: 'to',
LinkElement: SmartLink
};
return (
<ContinuumGridItem {...bag} key={d.id}>
<Card
@@ -108,9 +111,8 @@ function FeaturedSliderSection(props: FeaturedSliderSectionProps) {
cardType='featured'
linkLabel='View more'
linkProperties={{
...linkProperties,
linkTo: `${d.asLink?.url ?? getItemPath(d)}`,
pathAttributeKeyName: 'to',
LinkElement: SmartLink,
isLinkExternal: d.isLinkExternal
}}
title={d.name}
@@ -120,6 +122,7 @@ function FeaturedSliderSection(props: FeaturedSliderSectionProps) {
<DatasetClassification dataset={d} />
)}
<CardSourcesList
linkProperties={linkProperties}
sources={getTaxonomy(d, TAXONOMY_SOURCE)?.values}
/>
<VerticalDivider variation='light' />
4 changes: 2 additions & 2 deletions app/scripts/components/stories/hub/hub-content.tsx
Original file line number Diff line number Diff line change
@@ -149,6 +149,7 @@ export default function HubContent(props:HubContentProps) {
<CardSourcesList
sources={getTaxonomy(d, TAXONOMY_SOURCE)?.values}
rootPath={pathname}
linkProperties={linkProperties}
onSourceClick={(id) => {
onAction(FilterActions.TAXONOMY_MULTISELECT, {
key: TAXONOMY_SOURCE,
@@ -166,9 +167,8 @@ export default function HubContent(props:HubContentProps) {
}
linkLabel='View more'
linkProperties={{
...linkProperties,
linkTo: `${d.asLink?.url ?? d.path}`,
LinkElement,
pathAttributeKeyName,
isLinkExternal: d.isLinkExternal
}}
title={