Skip to content

Commit

Permalink
feat: standardize resource ids #235
Browse files Browse the repository at this point in the history
  • Loading branch information
candicecz committed May 28, 2024
1 parent 3ca39eb commit 2126101
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 20 deletions.
6 changes: 6 additions & 0 deletions configs/repositories.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@
"imageURL": "/assets/resources/lincs.png",
"type": "generalist"
},
{
"id": "MalariaGEN",
"label": "MalariaGEN",
"imageURL": "/assets/resources/malariagen.svg",
"type": "generalist"
},
{
"id": "Mendeley",
"label": "Mendeley",
Expand Down
86 changes: 86 additions & 0 deletions public/assets/resources/malariagen.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 1 addition & 2 deletions src/components/filters/components/filters-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,14 @@ export const FiltersList: React.FC<FiltersList> = React.memo(
.filter(item => {
const repo = REPOS.repositories.find(r => r.id === item.term);
// if repo is undefined, show the item as a generalist
if (repo === undefined) {
if (repo === undefined && !item?.term?.includes('_exists_')) {
return item;
}
return repo && repo.type === 'generalist';
})
.sort((a, b) => a.displayAs.localeCompare(b.displayAs))
.sort((a, b) => b.count - a.count)
: [];

return (
<>
{/* Search through filter terms */}
Expand Down
15 changes: 15 additions & 0 deletions src/components/icon/components/glyph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,21 @@ const Glyph: React.FC<GlyphProps> = ({
transform='translate(0 0)'
/>
);

case 'spatialCoverage':
if (isDisabled) {
return (
<path d='M200,100c0,15.7-3.6,30.6-10.1,43.8l-57.1-57c0.1-0.7,0.5-1.4,1-1.9c2.2-2.2,5.5-3,8.5-2l5.5,1.8 c4.8,1.6,10-0.6,12.3-5.1c1.4-2.7,4.4-4.2,7.4-3.6l10.7,2.1c-9.5-34.3-41-59.5-78.3-59.5c-10.5,0-20.4,2-29.6,5.6L56.1,10.1 C69.4,3.6,84.3,0,100,0C155.2,0,200,44.8,200,100z M137.4,61.8c0-3.4-1.9-6.5-4.9-8l-11.4-5.7c-1.4-0.7-3.2-0.4-4.3,0.7l-1.5,1.5 c-1.8,1.8-4.3,2.8-6.8,2.8c-1.5,0-3-0.4-4.3-1l-5.9-3c-1.2-0.6-2.4-0.8-3.7-0.6l24.7,24.7l11.3-2.8 C134.6,69.5,137.4,65.9,137.4,61.8z M19.2,15.2l166.3,166.2l-17,17l-14.3-14.3C138.6,194.1,120,200,100,200C44.8,200,0,155.2,0,100 c0-20,5.8-38.5,15.9-54.1L2.2,32.2L19.2,15.2z M93.8,125c0.5,0,1.1,0.1,1.5,0.2L62.7,92.7c-0.1,0.9-0.2,1.7-0.2,2.6v10.9 c0,10.4,8.4,18.8,18.8,18.8H93.8z M124.7,154.6l-24.9-24.9c0.1,0.5,0.2,1,0.2,1.6V150c0,6.9,5.6,12.5,12.5,12.5c3.9,0,7.7-1.8,10-5 L124.7,154.6z' />
);
}
return (
<path
fill={fill}
stroke={stroke}
d='M69.5,24.7l3.9,6.8c1.1,1.9,1.6,4,1.6,6.2v16.2c0,1.5,0.6,3,1.7,4.1c2.4,2.4,6.4,2.2,8.6-0.5l5.3-6.6c1.8-2.3,5-3,7.7-1.7 l5.9,3c1.3,0.7,2.8,1,4.3,1c2.5,0,5-1,6.8-2.8l1.5-1.5c1.1-1.1,2.9-1.4,4.3-0.7l11.4,5.7c3,1.5,4.9,4.6,4.9,8 c0,4.1-2.8,7.7-6.8,8.7l-13.8,3.4c-2.9,0.7-5.9,0.6-8.8-0.4l-12.5-4.2c-1.3-0.4-2.6-0.7-4-0.7c-2.7,0-5.4,0.9-7.6,2.5L68.8,82.8 c-3.9,3-6.3,7.6-6.3,12.5v10.9c0,10.4,8.4,18.8,18.8,18.8h12.5c3.4,0,6.3,2.8,6.3,6.3V150c0,6.9,5.6,12.5,12.5,12.5 c3.9,0,7.7-1.8,10-5l10-13.3c3.2-4.3,5-9.6,5-15v-4.7c0-1.5,1-2.9,2.5-3.2l2.1-0.5c4.6-1.2,7.9-5.4,7.9-10.2c0-2.8-1.1-5.4-3-7.4 l-13.1-13.1c-1.4-1.4-1.4-3.8,0-5.2c2.2-2.2,5.5-3,8.5-2l5.5,1.8c4.8,1.6,10-0.6,12.3-5.1c1.4-2.7,4.4-4.2,7.4-3.6l10.7,2.1 c-9.5-34.3-41-59.5-78.3-59.5C89.2,18.8,78.9,20.9,69.5,24.7z M0,100C0,44.8,44.8,0,100,0s100,44.8,100,100s-44.8,100-100,100 S0,155.2,0,100z'
transform='translate(0 0)'
/>
);
case 'species':
if (isDisabled) {
return (
Expand Down
2 changes: 0 additions & 2 deletions src/components/icon/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ export const MetadataIcon = React.forwardRef<HTMLDivElement, IconProps>(
FaIcon = FaFingerprint;
} else if (glyph?.toLowerCase() === 'inlanguage') {
FaIcon = FaLanguage;
} else if (glyph?.toLowerCase() === 'spatialcoverage') {
FaIcon = FaEarthAfrica;
} else if (glyph?.toLowerCase() === 'applicationcategory') {
FaIcon = FaLaptopCode;
} else if (glyph?.toLowerCase() === 'programminglanguage') {
Expand Down
1 change: 1 addition & 0 deletions src/components/search-results-page/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import Empty from 'src/components/empty';
import NextLink from 'next/link';
import Banner from '../banner';
import { formatNumber } from 'src/utils/helpers';

/*
[COMPONENT INFO]:
Search results pages displays the list of records returned by a search.
Expand Down
1 change: 0 additions & 1 deletion src/utils/api/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ export const formatAPIResource = (data: any) => {
processorRequirements: convertToArray(data.processorRequirements),
programmingLanguage: convertToArray(data.programmingLanguage),
publisher: data.publisher || null,
rawData: data,
sameAs: data.sameAs || null,
sdPublisher: convertToArray(data.sdPublisher),
softwareAddOn: convertToArray(data.softwareAddOn),
Expand Down
37 changes: 23 additions & 14 deletions src/utils/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios from 'axios';
import { formatAPIResource, formatISOString } from './helpers';
import { FetchSearchResultsResponse } from './types';
import { FetchSearchResultsResponse, FormattedResource } from './types';
import { Metadata } from 'src/hooks/api/types';

// Get all resources where query term contains the search term.
Expand All @@ -24,26 +24,35 @@ export interface Params {
export const getResourceById = async (
id?: string | string[],
params?: Partial<Params>,
) => {
): Promise<FormattedResource | undefined> => {
if (!id) {
return;
return undefined;
}
if (!process.env.NEXT_PUBLIC_API_URL) {
throw new Error('API url undefined');

const apiUrl = process.env.NEXT_PUBLIC_API_URL;
if (!apiUrl) {
throw new Error('API URL is undefined');
}

try {
const { data } = await axios.get(
`${process.env.NEXT_PUBLIC_API_URL}/query?`,
{
params: { ...params, q: `_id:"${id}"` },
},
);
const _id = Array.isArray(id) ? id.join('') : id;
const query = { ...params, q: `_id:"${_id.toLowerCase()}"` };

const response = await axios.get(`${apiUrl}/query`, { params: query });
const { data } = response;

if (!data.hits || data.hits.length === 0) {
return undefined;
}

const formattedData = await formatAPIResource(data.hits[0]);
if (!formattedData) {
return undefined;
}

return formattedData;
} catch (err: any) {
throw err.response;
return { ...formattedData, rawData: data.hits[0] } as FormattedResource;
} catch (error: any) {
throw error.response ?? error;
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/utils/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ export interface FormattedResource {
processorRequirements: string[] | null;
programmingLanguage: string[] | null;
publisher: Publisher | null;
rawData: any;
rawData?: any;
sameAs: string | null;
softwareAddOn: { identifier: string }[] | null;
softwareHelp: { name?: string; url: string }[] | null;
Expand Down

0 comments on commit 2126101

Please sign in to comment.