Skip to content

Commit

Permalink
Merge branch 'main' into upgrade-dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
AliceR committed Dec 19, 2024
2 parents b3a4c4f + 872c53a commit 5f83fd0
Show file tree
Hide file tree
Showing 32 changed files with 531 additions and 185 deletions.
25 changes: 23 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,20 @@ jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Generate a token
id: generate-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PEM }}
owner: ${{ github.repository_owner }}
repositories: |
veda-ui
veda-config
- uses: actions/checkout@v4
with:
fetch-depth: 0
ssh-key: ${{ secrets.DEPLOY_KEY }}
token: ${{ steps.generate-token.outputs.token }}
- name: git config
run: |
git config user.name "${GITHUB_ACTOR}"
Expand All @@ -29,4 +39,15 @@ jobs:
- run: yarn
- run: yarn release --ci --verbose
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
preview-build:
runs-on: ubuntu-latest
needs: "release"
steps:
- name: Repository Dispatch
uses: peter-evans/repository-dispatch@v3
with:
token: ${{ steps.generate-token.outputs.token }}
repository: nasa-impact/veda-config
event-type: update-version
client-payload: '{"ref": "${{ github.ref }}", "VERSION_NUMBER": "${{ env.VERSION_NUMBER }}"}'
4 changes: 3 additions & 1 deletion .release-it.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"hooks": {},
"hooks": {
"after:release": "echo \"VERSION_NUMBER=v${version}\" >> \"$GITHUB_ENV\" "
},
"plugins": {
"@release-it/conventional-changelog": {
"preset": {
Expand Down
3 changes: 3 additions & 0 deletions app/scripts/components/common/banner/banner.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.usa-banner__button:after {
top: 3px;
}
170 changes: 114 additions & 56 deletions app/scripts/components/common/banner/index.tsx
Original file line number Diff line number Diff line change
@@ -1,78 +1,136 @@
import React, { useState } from 'react';
import { Icon } from '@trussworks/react-uswds';
import { decode } from 'he';
import {
USWDSBanner,
USWDSBannerContent
USWDSBannerContent,
USWDSBannerButton,
USWDSBannerFlag,
USWDSBannerHeader,
USWDSBannerIcon,
USWDSBannerGuidance,
USWDSMediaBlockBody
} from '$components/common/uswds/banner';

const BANNER_KEY = 'dismissedBannerUrl';

function hasExpired(expiryDatetime) {
const expiryDate = new Date(expiryDatetime);
const currentDate = new Date();
return !!(currentDate > expiryDate);
interface Guidance {
left?: GuidanceContent;
right?: GuidanceContent;
}

enum BannerType {
info = 'info',
warning = 'warning'
interface GuidanceContent {
icon?: string;
iconAlt?: string;
title?: string;
text?: string;
}

const infoTypeFlag = BannerType.info;
interface BannerProps {
appTitle: string;
expires: Date;
url: string;
text: string;
type?: BannerType;
headerText?: string;
headerActionText?: string;
ariaLabel?: string;
flagImgAlt?: string;
leftGuidance?: GuidanceContent;
rightGuidance?: GuidanceContent;
className?: string;
defaultIsOpen?: boolean;
contentId?: string;
}

const DEFAULT_HEADER_TEXT =
'An official website of the United States government';

const DEFAULT_HEADER_ACTION_TEXT = "Here's how you know";

const DEFAULT_GUIDANCE: Guidance = {
left: {
title: 'Official websites use .gov',
text: 'A .gov website belongs to an official government organization in the United States.',
iconAlt: 'Dot gov icon',
icon: '/img/icon-dot-gov.svg'
},
right: {
title: 'Secure .gov websites use HTTPS',
text: `
A <strong>lock</strong> or <strong>https://</strong> means you've safely
connected to the .gov website. Share sensitive information only on
official, secure websites.
`,
iconAlt: 'HTTPS icon',
icon: '/img/icon-https.svg'
}
};

const GuidanceBlock = ({
content,
className
}: {
content: GuidanceContent;
className?: string;
}) => (
<USWDSBannerGuidance className={className}>
<USWDSBannerIcon src={content.icon} alt={content.iconAlt ?? ''} />
<USWDSMediaBlockBody>
<p>
<strong>{content.title}</strong>
<br />
<span
dangerouslySetInnerHTML={{ __html: decode(content.text ?? '') }}
/>
</p>
</USWDSMediaBlockBody>
</USWDSBannerGuidance>
);

export default function Banner({
appTitle,
expires,
url,
text,
type = infoTypeFlag
headerText,
headerActionText,
ariaLabel,
flagImgAlt = '',
leftGuidance,
rightGuidance,
className = '',
defaultIsOpen = false,
contentId = 'gov-banner-content'
}: BannerProps) {
const [isOpen, setIsOpen] = useState(defaultIsOpen);

const showBanner = localStorage.getItem(BANNER_KEY) !== url;
const [isOpen, setIsOpen] = useState(showBanner && !hasExpired(expires));
const leftContent = {
...DEFAULT_GUIDANCE.left,
...leftGuidance
} as GuidanceContent;

function onClose() {
localStorage.setItem(BANNER_KEY, url);
setIsOpen(false);
}
const rightContent = {
...DEFAULT_GUIDANCE.right,
...rightGuidance
} as GuidanceContent;

return (
<div>
{isOpen && (
<div className='position-relative'>
<USWDSBanner
aria-label={appTitle}
className={type !== infoTypeFlag ? 'bg-secondary-lighter' : ''}
>
<a href={url} target='_blank' rel='noreferrer'>
<USWDSBannerContent
className='padding-top-1 padding-bottom-1'
isOpen={true}
>
<div dangerouslySetInnerHTML={{ __html: text }} />
<USWDSBanner
aria-label={ariaLabel ?? DEFAULT_HEADER_TEXT}
className={className}
>
<USWDSBannerHeader
isOpen={isOpen}
flagImg={
<USWDSBannerFlag src='/img/us_flag_small.png' alt={flagImgAlt} />
}
headerText={headerText ?? DEFAULT_HEADER_TEXT}
headerActionText={headerActionText ?? DEFAULT_HEADER_ACTION_TEXT}
>
<USWDSBannerButton
isOpen={isOpen}
onClick={() => setIsOpen((prev) => !prev)}
aria-controls={contentId}
>
{headerActionText ?? DEFAULT_HEADER_ACTION_TEXT}
</USWDSBannerButton>
</USWDSBannerHeader>

</USWDSBannerContent>
</a>
</USWDSBanner>
<div className='position-absolute top-0 right-0 margin-right-3 height-full display-flex'>
<button
className='usa-button usa-button--unstyled'
type='button'
aria-label='Close Banner'
onClick={onClose}
>
<Icon.Close />
</button>
</div>
<USWDSBannerContent id={contentId} isOpen={isOpen}>
<div className='grid-row grid-gap-lg'>
<GuidanceBlock content={leftContent} className='tablet:grid-col-6' />
<GuidanceBlock content={rightContent} className='tablet:grid-col-6' />
</div>
)}
</div>
</USWDSBannerContent>
</USWDSBanner>
);
}
1 change: 1 addition & 0 deletions app/scripts/components/common/card/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ function CardComponent(props: CardComponentPropsType) {
const { linkProperties: linkPropertiesProps } = props;
linkProperties = linkPropertiesProps;
} else {
// @NOTE: This currently just exists for GHG which uses the Card component
const { linkTo } = props;
linkProperties = linkTo
? {
Expand Down
25 changes: 3 additions & 22 deletions app/scripts/components/common/catalog/catalog-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,12 @@ 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 { CardTopicsList } from "../card/styles";
import TextHighlight from "../text-highlight";
import { getDatasetDescription, getMediaProperty } from './utils';
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 { TAXONOMY_TOPICS, getAllTaxonomyValues, getTaxonomy } from "$utils/veda-data/taxonomies";
import { Pill } from "$styles/pill";
import { usePathname } from "$utils/use-pathname";

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

const CardSelectable = styled(Card)<{
Expand Down Expand Up @@ -101,14 +95,10 @@ export const CatalogCard = (props: CatalogCardProps) => {
searchTerm,
selectable,
selected,
onDatasetClick,
linkProperties
onDatasetClick
} = props;

const pathname = usePathname();

const topics = getTaxonomy(dataset, TAXONOMY_TOPICS)?.values;
const sources = getTaxonomy(dataset, TAXONOMY_SOURCE)?.values;
const allTaxonomyValues = getAllTaxonomyValues(dataset).map((v) => v.name);

const title = layer ? layer.name : dataset.name;
Expand All @@ -123,20 +113,12 @@ export const CatalogCard = (props: CatalogCardProps) => {
}
};

const linkTo = getDatasetPath(dataset, pathname);

return (
<CardSelectable
cardType='horizontal-info'
checked={selectable ? selected : undefined}
selectable={selectable}
tagLabels={allTaxonomyValues}
overline={
<CardMeta>
<DatasetClassification dataset={dataset} />
<CardSourcesList sources={sources} linkProperties={linkProperties} />
</CardMeta>
}
linkLabel='View dataset'
onClick={handleClick}
title={
Expand Down Expand Up @@ -172,7 +154,6 @@ export const CatalogCard = (props: CatalogCardProps) => {
) : null}
</>
}
{...(linkProperties ? {linkProperties: {...linkProperties, linkTo: linkTo}} : {})}
/>
);
};
11 changes: 7 additions & 4 deletions app/scripts/components/common/catalog/catalog-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ 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 All @@ -22,6 +21,8 @@ import {
import { OptionItem } from '$components/common/form/checkable-filter';
import { Pill } from '$styles/pill';
import { usePreviousValue } from '$utils/use-effect-previous';
import { getDatasetPath } from '$utils/routes';
import { usePathname } from "$utils/use-pathname";

const EXCLUSIVE_SOURCE_WARNING = "Can only be analyzed with layers from the same source";

Expand All @@ -34,7 +35,7 @@ export interface CatalogContentProps {
search: string;
taxonomies: Record<string, string[]>;
onAction: (action: FilterActions, value?: any) => void;
linkProperties: LinkProperties;
onCardNavigate?: (path: string) => void;
}

const DEFAULT_SORT_OPTION = 'asc';
Expand Down Expand Up @@ -71,7 +72,7 @@ function CatalogContent({
search,
taxonomies,
onAction,
linkProperties
onCardNavigate
}: CatalogContentProps) {
const [exclusiveSourceSelected, setExclusiveSourceSelected] = useState<string | null>(null);
const isSelectable = selectedIds !== undefined;
Expand All @@ -95,6 +96,8 @@ function CatalogContent({

const prevSelectedFilters = usePreviousValue(selectedFilters) ?? [];

const pathname = usePathname();

// Handlers
const updateSelectedFilters = useCallback((item: OptionItem, action: 'add' | 'remove') => {
if (action == 'add') {
Expand Down Expand Up @@ -275,7 +278,7 @@ function CatalogContent({
<CatalogCard
dataset={d}
searchTerm={search}
linkProperties={linkProperties}
{...(onCardNavigate && {onDatasetClick: () => onCardNavigate(getDatasetPath(d, pathname))})}
/>
</li>
))}
Expand Down
Loading

0 comments on commit 5f83fd0

Please sign in to comment.