Skip to content

Commit

Permalink
[FEATURE BRANCH] 902 E&A breakout (#1154)
Browse files Browse the repository at this point in the history
**Related Ticket:** #902

### Description of Changes
**Related NextJs PR/Branch:**
developmentseed/next-veda-ui#4

**GHG Preview** with this branch pulled in generated here =>
US-GHG-Center/veda-config-ghg#659

**Iteration 1** - Issue
#902, changes by
@sandrahoang686
* Exposed `ExplorationAndAnalysis` component
* Exposed `timelineDatasetsAtom` to be used NextJs side
* Exposed & Moved/decoupled `DatasetSelectorModal` out of
`ExplorationAndAnalysis`. ExplorationAndAnalysis only needs to know the
dataset layers to be displayed. DatasetSelectorModal or whatever layer
selection method should be controlled at the parent level above
`ExplorationAndAnalysis`.
* Commented out certain controls that were breaking
`ExplorationAndAnalysis` in NextJs instance
   * `AnalysisMessageControl`
   * `CustomAoIControl`

### Notes & Questions About Changes
_{Add additonal notes and outstanding questions here related to changes
in this pull request}_

### Validation / Testing
* Validate that Datalayer Selection Modal works as expected
* Validate that E&A features work as expected - aois, analyzation,
adding/removing cards
* Validate that all card linking works as expected
  • Loading branch information
sandrahoang686 authored Nov 14, 2024
2 parents 6e929e8 + 387401f commit a8311c2
Show file tree
Hide file tree
Showing 46 changed files with 313 additions and 272 deletions.
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`
Expand All @@ -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
Expand All @@ -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>
Expand Down
41 changes: 17 additions & 24 deletions app/scripts/components/common/card/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { lazy, MouseEventHandler, ComponentType } from 'react';
import React, { lazy, MouseEventHandler } from 'react';
import styled, { css } from 'styled-components';
import { format } from 'date-fns';
import format from 'date-fns/format';
import { CollecticonExpandTopRight } from '@devseed-ui/collecticons';
import {
glsp,
Expand All @@ -25,6 +25,7 @@ import HorizontalInfoCard, {
import { variableBaseType, variableGlsp } from '$styles/variable-utils';
import { ElementInteractive } from '$components/common/element-interactive';
import { Figure } from '$components/common/figure';
import { LinkProperties } from '$types/veda';

type CardType = 'classic' | 'cover' | 'featured' | 'horizontal-info';

Expand Down Expand Up @@ -230,12 +231,6 @@ export function ExternalLinkFlag() {
);
}

export interface LinkProperties {
LinkElement: string | ComponentType<any> | undefined;
pathAttributeKeyName: string;
onLinkClick?: MouseEventHandler;
}

export interface LinkWithPathProperties extends LinkProperties {
linkTo: string;
}
Expand All @@ -255,16 +250,17 @@ export interface CardComponentBaseProps {
footerContent?: JSX.Element;
hideExternalLinkBadge?: boolean;
onCardClickCapture?: MouseEventHandler;
onClick?: MouseEventHandler;
}

// @TODO: Consolidate these props when the instance adapts the new syntax
// @TODO: Created because GHG uses the card component directly and passes in "linkTo" prop. Consolidate these props when the instance adapts the new syntax
// Specifically: https://github.com/US-GHG-Center/veda-config-ghg/blob/develop/custom-pages/news-and-events/component.tsx#L108
export interface CardComponentPropsDeprecated extends CardComponentBaseProps {
linkTo: string;
onLinkClick?: MouseEventHandler;
}

export interface CardComponentProps extends CardComponentBaseProps {
linkProperties: LinkWithPathProperties;
linkProperties?: LinkWithPathProperties;
}

type CardComponentPropsType = CardComponentProps | CardComponentPropsDeprecated;
Expand All @@ -291,40 +287,37 @@ function CardComponent(props: CardComponentPropsType) {
parentTo,
footerContent,
hideExternalLinkBadge,
onCardClickCapture
onCardClickCapture,
onClick,
} = props;
// @TODO: This process is not necessary once all the instances adapt the linkProperties syntax
// Consolidate them to use LinkProperties only
let linkProperties: LinkWithPathProperties;
let linkProperties: LinkWithPathProperties | undefined;

if (hasLinkProperties(props)) {
// Handle new props with linkProperties
const { linkProperties: linkPropertiesProps } = props;
linkProperties = linkPropertiesProps;
} else {
const { linkTo, onLinkClick } = props;
linkProperties = {
const { linkTo } = props;
linkProperties = linkTo ? {
linkTo,
onLinkClick,
pathAttributeKeyName: 'to',
LinkElement: SmartLink
};
} : undefined;
}

const isExternalLink = /^https?:\/\//.test(linkProperties.linkTo);
const isExternalLink = linkProperties ? /^https?:\/\//.test(linkProperties.linkTo) : false;

return (
<ElementInteractive
linkProps={{
as: linkProperties.LinkElement,
[linkProperties.pathAttributeKeyName]: linkProperties.linkTo,
onLinkClick: linkProperties.onLinkClick
}}
{...(linkProperties ? {linkProps: {as: linkProperties.LinkElement, [linkProperties.pathAttributeKeyName]: linkProperties.linkTo}} : {})}
as={CardItem}
cardType={cardType}
className={className}
linkLabel={linkLabel ?? 'View more'}
onClickCapture={onCardClickCapture}
onClick={onClick}
>
{cardType !== 'horizontal-info' && (
<>
Expand All @@ -340,7 +333,7 @@ function CardComponent(props: CardComponentPropsType) {
parentTo &&
tagLabels.map((label) => (
<CardLabel
as={linkProperties.LinkElement}
as={linkProperties?.LinkElement}
to={parentTo}
key={label}
>
Expand Down
48 changes: 18 additions & 30 deletions app/scripts/components/common/catalog/catalog-card.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
import React from 'react';
import styled, { css } from 'styled-components';
import {
CollecticonPlus,
CollecticonTickSmall,
iconDataURI
} from '@devseed-ui/collecticons';
import { glsp, themeVal } from '@devseed-ui/theme-provider';

import { Card, LinkProperties } from '../card';
import { CardMeta, CardTopicsList } from '../card/styles';
import { DatasetClassification } from '../dataset-classification';
import { CardSourcesList } from '../card-sources';
import TextHighlight from '../text-highlight';
import React from "react";
import styled, { css } from "styled-components";
import { CollecticonPlus, CollecticonTickSmall, iconDataURI } from "@devseed-ui/collecticons";
import { glsp, themeVal } from "@devseed-ui/theme-provider";
import { Card } from "../card";
import { CardMeta, CardTopicsList } from "../card/styles";
import { DatasetClassification } from "../dataset-classification";
import { CardSourcesList } from "../card-sources";
import TextHighlight from "../text-highlight";
import { getDatasetDescription, getMediaProperty } from './utils';
import { DatasetData, DatasetLayer } from '$types/veda';
import { getDatasetPath } from '$utils/routes';
import {
TAXONOMY_SOURCE,
TAXONOMY_TOPICS,
getAllTaxonomyValues,
getTaxonomy
} from '$utils/veda-data/taxonomies';
import { Pill } from '$styles/pill';
import { LinkProperties } from '$types/veda';
import { DatasetData, DatasetLayer } from "$types/veda";
import { getDatasetPath } from "$utils/routes";
import { TAXONOMY_SOURCE, TAXONOMY_TOPICS, getAllTaxonomyValues, getTaxonomy } from "$utils/veda-data/taxonomies";
import { Pill } from "$styles/pill";

interface CatalogCardProps {
dataset: DatasetData;
Expand All @@ -31,7 +22,7 @@ interface CatalogCardProps {
selected?: boolean;
onDatasetClick?: () => void;
pathname?: string;
linkProperties: LinkProperties;
linkProperties?: LinkProperties;
}

const CardSelectable = styled(Card)<{
Expand Down Expand Up @@ -142,10 +133,11 @@ export const CatalogCard = (props: CatalogCardProps) => {
overline={
<CardMeta>
<DatasetClassification dataset={dataset} />
<CardSourcesList sources={sources} />
<CardSourcesList sources={sources} linkProperties={linkProperties} />
</CardMeta>
}
linkLabel='View dataset'
onClick={handleClick}
title={
<TextHighlight value={searchTerm} disabled={searchTerm.length < 3}>
{title}
Expand Down Expand Up @@ -179,11 +171,7 @@ export const CatalogCard = (props: CatalogCardProps) => {
) : null}
</>
}
linkProperties={{
...linkProperties,
linkTo: linkTo,
onLinkClick: handleClick
}}
{...(linkProperties ? {linkProperties: {...linkProperties, linkTo: linkTo}} : {})}
/>
);
};
3 changes: 1 addition & 2 deletions app/scripts/components/common/catalog/catalog-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import styled from 'styled-components';
import { glsp, themeVal } from '@devseed-ui/theme-provider';
import TextHighlight from '../text-highlight';
import { CollecticonDatasetLayers } from '../icons/dataset-layers';
import { LinkProperties } from '../card';
import { prepareDatasets } from './prepare-datasets';
import FiltersControl from './filters-control';
import { CatalogCard } from './catalog-card';
import CatalogTagsContainer from './catalog-tags';

import { FilterActions } from './utils';
import { LinkProperties } from '$types/veda';
import { DatasetData, DatasetDataWithEnhancedLayers } from '$types/veda';
import { CardList } from '$components/common/card/styles';
import EmptyHub from '$components/common/empty-hub';
Expand Down Expand Up @@ -264,7 +264,6 @@ function CatalogContent({
selectable={true}
selected={selectedIds.includes(datasetLayer.id)}
onDatasetClick={() => onCardSelect(datasetLayer.id, currentDataset)}
linkProperties={linkProperties}
pathname={pathname}
/>
</li>
Expand Down
3 changes: 1 addition & 2 deletions app/scripts/components/common/catalog/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import React from 'react';
import styled from 'styled-components';
import { themeVal } from '@devseed-ui/theme-provider';
import { LinkProperties } from '../card';
import CatalogContent from './catalog-content';
import { DatasetData } from '$types/veda';
import { DatasetData, LinkProperties } from '$types/veda';
import {
useSlidingStickyHeaderProps
} from '$components/common/layout-root/useSlidingStickyHeaderProps';
Expand Down
12 changes: 10 additions & 2 deletions app/scripts/components/common/element-interactive.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,13 @@ const InteractiveLink = styled.a`
*/
export const ElementInteractive = React.forwardRef(
function ElementInteractiveFwd(props, ref) {
const { linkProps = {}, linkLabel = 'View', children, ...rest } = props;
const {
linkProps = {},
linkLabel = 'View',
children,
onClick,
...rest
} = props;
const [isStateOver, setStateOver] = useState(false);
const [isStateActive, setStateActive] = useState(false);
const [isStateFocus, setStateFocus] = useState(false);
Expand All @@ -92,6 +98,7 @@ export const ElementInteractive = React.forwardRef(
setStateOver(false);
setStateActive(false);
}, [])}
onClick={onClick}
>
{children}
<InteractiveLink
Expand All @@ -111,7 +118,8 @@ export const ElementInteractive = React.forwardRef(
ElementInteractive.propTypes = {
children: T.node.isRequired,
linkLabel: T.string.isRequired,
linkProps: T.object
linkProps: T.object,
onClick: T.func
};

/**
Expand Down
11 changes: 7 additions & 4 deletions app/scripts/components/common/featured-slider-section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,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
Expand All @@ -112,9 +115,8 @@ function FeaturedSliderSection(props: FeaturedSliderSectionProps) {
cardType='featured'
linkLabel='View more'
linkProperties={{
linkTo: `${d.asLink?.url ?? getItemPath(d)}`,
pathAttributeKeyName: 'to',
LinkElement: SmartLink
...linkProperties,
linkTo: `${d.asLink?.url ?? getItemPath(d)}`
}}
title={d.name}
overline={
Expand All @@ -123,6 +125,7 @@ function FeaturedSliderSection(props: FeaturedSliderSectionProps) {
<DatasetClassification dataset={d} />
)}
<CardSourcesList
linkProperties={linkProperties}
sources={getTaxonomy(d, TAXONOMY_SOURCE)?.values}
/>
<VerticalDivider variation='light' />
Expand Down
Loading

0 comments on commit a8311c2

Please sign in to comment.