Skip to content

Commit 1e6d6f8

Browse files
Release/v5.1.0 (#356)
* feat-311-disease-card (#354) * feat: add tentative disease overview card * feat: add Strapi data to disease overview card * feat: restyle disease overview card * feat: improve queries to fetch disese data * chore: remove unneeded code * feat: add disease overview counts * chore: rename resource catalog card component * chore: create base compact card component * fix: handle landing page searches successfully * chore: remove unneeded code * chore: remove unneeded code * chore: improve code organization * fix: add removed comment * chore: simplify Markdown handling * feat: change tab and accordion titles * chore: separate API and Strapi resources * chore: improve controller code readability * chore: move compact card components to new directory * chore: create compact card compound components * fix: tab style repetition * fix: disease type banner * refactor: remove disease types in resource formatting helpers * chore: simplify compact card title rendering logic * fix: handle undefined type in the formatting function * chore: update counts handling * chore: remove AllResource type * fix: remove extra accordion * feat: standardize Other Resources --------- Co-authored-by: candicecz <[email protected]> * feat(features): add features content * chore(deps): upgrade tar-fs to 3.1.1 to fix security issue --------- Co-authored-by: candicecz <[email protected]>
1 parent dacdf45 commit 1e6d6f8

File tree

21 files changed

+704
-256
lines changed

21 files changed

+704
-256
lines changed

configs/site.config.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,7 @@
199199
"nav": {
200200
"label": "Features",
201201
"description": "Featured content for the portal."
202-
},
203-
"env": ["development", "staging"]
202+
}
204203
},
205204
"/ontology-browser": {
206205
"seo": {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
"nanoid": "^3.3.8",
116116
"path-to-regexp": "^6.3.0",
117117
"semver": "^7.5.2",
118-
"tar-fs": "^3.0.9",
118+
"tar-fs": "^3.1.1",
119119
"tough-cookie": "^4.1.3",
120120
"tmp": "0.2.4",
121121
"ws": "^8.17.1",

src/components/advanced-search/components/Search/components/SearchInput/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { QueryValue } from 'src/components/advanced-search/types';
1111
import { SearchInputProps } from './types';
1212
import {
1313
APIResourceType,
14-
formatResourceTypeForDisplay,
14+
formatAPIResourceTypeForDisplay,
1515
} from 'src/utils/formatting/formatResourceType';
1616

1717
export const SearchInput: React.FC<SearchInputProps> = ({
@@ -134,7 +134,7 @@ export const SearchInput: React.FC<SearchInputProps> = ({
134134
// [@type] needs to be formatted to the terms we use in the UI.
135135
if (selectedFieldDetails.property === '@type') {
136136
const type = value as APIResourceType;
137-
return { label: formatResourceTypeForDisplay(type), value };
137+
return { label: formatAPIResourceTypeForDisplay(type), value };
138138
}
139139
return { label: value, value };
140140
})}

src/components/resource-sections/components/banner/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import TypeBanner from '../type-banner';
55
import { FormattedResource } from 'src/utils/api/types';
66
import { isSourceFundedByNiaid } from 'src/utils/helpers/sources';
77
import { operatingSystemIcons } from 'src/utils/helpers/operating-system-icons';
8+
import { formatAPIResourceTypeForDisplay } from 'src/utils/formatting/formatResourceType';
89

910
interface DateTagProps extends FlexProps {
1011
type?: string;
@@ -68,6 +69,7 @@ const ResourceBanner: React.FC<ResourceBannerProps> = ({ data }) => {
6869

6970
return (
7071
<TypeBanner
72+
label={formatAPIResourceTypeForDisplay(type)}
7173
type={type}
7274
bg='status.info_lt'
7375
isNiaidFunded={isSourceFundedByNiaid(data.includedInDataCatalog)}

src/components/resource-sections/components/type-banner/index.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@ import { Flex, FlexProps, Icon, Text } from '@chakra-ui/react';
33
import { FaRegClock } from 'react-icons/fa6';
44
import { FormattedResource } from 'src/utils/api/types';
55
import { StyledLabel } from './styles';
6-
import { formatResourceTypeForDisplay } from 'src/utils/formatting/formatResourceType';
6+
import { APIResourceType } from 'src/utils/formatting/formatResourceType';
77
import Tooltip from 'src/components/tooltip';
88
import SCHEMA_DEFINITIONS from 'configs/schema-definitions.json';
99

10-
interface TypeBannerProps extends FlexProps {
11-
type?: FormattedResource['@type'];
10+
export interface TypeBannerProps extends FlexProps {
11+
label: string;
12+
type?: APIResourceType | 'Disease';
1213
date?: FormattedResource['date'];
1314
sourceName?: string[] | null;
1415
isNiaidFunded?: boolean;
1516
}
1617

17-
export const getTypeColor = (type?: FormattedResource['@type']) => {
18+
export const getTypeColor = (type?: APIResourceType | string) => {
1819
const typeLower = type?.toLowerCase();
1920
let lt = 'status.info';
2021
let dk = 'niaid.500';
@@ -27,13 +28,17 @@ export const getTypeColor = (type?: FormattedResource['@type']) => {
2728
dk = 'primary.700';
2829
} else if (typeLower?.includes('tool') || typeLower?.includes('software')) {
2930
lt = 'primary.800';
31+
} else if (typeLower === 'disease') {
32+
lt = 'purple.600';
33+
dk = 'purple.800';
3034
} else {
3135
lt = 'niaid.500';
3236
}
3337
return { lt, dk };
3438
};
3539

3640
const TypeBanner: React.FC<TypeBannerProps> = ({
41+
label,
3742
type,
3843
date,
3944
children,
@@ -84,7 +89,7 @@ const TypeBanner: React.FC<TypeBannerProps> = ({
8489
whiteSpace='nowrap'
8590
textTransform='uppercase'
8691
>
87-
{type ? formatResourceTypeForDisplay(type) : 'Unknown'}
92+
{label || 'Unknown'}
8893
</Text>
8994
</Tooltip>
9095
</StyledLabel>

src/pages/features/[[...slug]].tsx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import React, { useEffect } from 'react';
1+
import React from 'react';
22
import type { GetStaticProps, NextPage } from 'next';
3-
import { useRouter } from 'next/router';
43
import { Flex, Skeleton, Text } from '@chakra-ui/react';
54
import { useQuery } from '@tanstack/react-query';
65
import { Error } from 'src/components/error';
@@ -48,14 +47,6 @@ const FeaturedPage: NextPage<{
4847
refetchOnMount: true,
4948
});
5049

51-
// If the app is in production, redirect to a 404 page until search is fully implemented and approved.
52-
const router = useRouter();
53-
useEffect(() => {
54-
if (process.env.NEXT_PUBLIC_APP_ENV === 'production') {
55-
router.replace('/404');
56-
}
57-
}, [router]);
58-
5950
const pageTitle = data?.title || 'Features';
6051
return (
6152
<PageContainer

src/utils/formatting/formatResourceType.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ export type APIResourceType =
22
| 'Dataset'
33
| 'ResourceCatalog'
44
| 'ComputationalTool';
5-
// | 'Software'
6-
// | 'ScholarlyArticle'
7-
// | 'Other';
85

96
export type CollectionType =
107
| 'Knowledge Base'
@@ -34,10 +31,14 @@ export type DisplayResourceType =
3431
| 'Scholarly Article'
3532
| 'Other';
3633

37-
// Format the resource type for display.
38-
export const formatResourceTypeForDisplay = (
39-
str: APIResourceType,
34+
// Format API resource types for display
35+
export const formatAPIResourceTypeForDisplay = (
36+
str: APIResourceType | undefined,
4037
): DisplayResourceType => {
38+
if (!str) {
39+
return 'Other';
40+
}
41+
4142
if (str.toLowerCase() === 'dataset') {
4243
return 'Dataset';
4344
} else if (str.toLowerCase() === 'resourcecatalog') {
@@ -49,7 +50,7 @@ export const formatResourceTypeForDisplay = (
4950
}
5051
};
5152

52-
// Format the dataset type(if changed for display) to the @type accepted in the API.
53+
// Format the dataset type (if changed for display) to the @type accepted in the API
5354
export const formatResourceTypeForAPI = (
5455
str: string,
5556
): APIResourceType | string => {
@@ -69,3 +70,8 @@ export const formatResourceTypeForAPI = (
6970
return str;
7071
}
7172
};
73+
74+
// Type guard to check if a type is an API resource type
75+
export const isAPIResourceType = (type: string): type is APIResourceType => {
76+
return ['Dataset', 'ResourceCatalog', 'ComputationalTool'].includes(type);
77+
};

src/views/diseases/disease/components/data-types.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { fetchSearchResults } from 'src/utils/api';
77
import { FacetTerm, FetchSearchResultsResponse } from 'src/utils/api/types';
88
import {
99
APIResourceType,
10-
formatResourceTypeForDisplay,
10+
formatAPIResourceTypeForDisplay,
1111
} from 'src/utils/formatting/formatResourceType';
1212
import {
1313
getFillColor,
@@ -114,7 +114,7 @@ export const DataTypes = ({ query, topic }: TopicQueryProps) => {
114114
labelStyles={{
115115
fill: '#2f2f2f',
116116
transformLabel: term =>
117-
formatResourceTypeForDisplay(term as APIResourceType),
117+
formatAPIResourceTypeForDisplay(term as APIResourceType),
118118
}}
119119
getRoute={term => {
120120
return getSearchResultsRoute({
@@ -144,7 +144,7 @@ export const DataTypes = ({ query, topic }: TopicQueryProps) => {
144144
})
145145
.map(({ term, count }) => {
146146
if (!term) return null; // Skip if term is undefined
147-
const label = formatResourceTypeForDisplay(
147+
const label = formatAPIResourceTypeForDisplay(
148148
term as APIResourceType,
149149
);
150150
return (
@@ -171,7 +171,11 @@ export const DataTypes = ({ query, topic }: TopicQueryProps) => {
171171
})}
172172
passHref
173173
>
174-
<Link as='p'>{label}</Link>
174+
<Link as='p'>
175+
{formatAPIResourceTypeForDisplay(
176+
term as APIResourceType,
177+
)}
178+
</Link>
175179
</NextLink>
176180
</LegendItem>
177181
);

src/views/features/helpers.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ export const fetchFeaturedContent = async (
77
): Promise<FeaturedPageProps | null> => {
88
try {
99
const isProd = process.env.NEXT_PUBLIC_APP_ENV === 'production';
10-
// In production, we do not features. Remove when approved.
11-
if (isProd) {
12-
return null;
13-
}
10+
1411
const featured = await axios.get(
1512
`${
1613
process.env.NEXT_PUBLIC_STRAPI_API_URL
@@ -34,10 +31,6 @@ export const fetchFeaturedContent = async (
3431
export const fetchAllFeaturedPages = async (params?: FeaturedQueryParams) => {
3532
try {
3633
const isProd = process.env.NEXT_PUBLIC_APP_ENV === 'production';
37-
// In production, we do not features. Remove when approved.
38-
if (isProd) {
39-
return [];
40-
}
4134

4235
const featuredPages = await axios.get<{ data: FeaturedPageProps[] }>(
4336
`${process.env.NEXT_PUBLIC_STRAPI_API_URL}/api/features`,

src/views/search-results-page-archived/components/card/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { filterWords } from './helpers';
3131
import { SchemaDefinitions } from 'scripts/generate-schema-definitions/types';
3232
import SCHEMA_DEFINITIONS from 'configs/schema-definitions.json';
3333
import { InfoLabel } from 'src/components/info-label';
34+
import { formatAPIResourceTypeForDisplay } from 'src/utils/formatting/formatResourceType';
3435

3536
interface SearchResultCardProps {
3637
isLoading?: boolean;
@@ -85,6 +86,7 @@ const SearchResultCard: React.FC<SearchResultCardProps> = ({
8586
// {/* Banner with resource type + date of publication */}
8687
<Card ref={cardRef} variant='niaid' my={4} mb={8}>
8788
<TypeBanner
89+
label={formatAPIResourceTypeForDisplay(type || 'Dataset')}
8890
type={type || 'Dataset'}
8991
p={0}
9092
pl={[2, 4, 6]}

0 commit comments

Comments
 (0)