From 0820384b9d4bbc8cd460145654191c788562e7c5 Mon Sep 17 00:00:00 2001 From: "Dusan Mijatovic (PC2020)" Date: Mon, 2 Dec 2024 11:11:21 +0100 Subject: [PATCH] feat: include all software sources in the software overview --- frontend/components/cards/SourceRsd.tsx | 18 ++++++ frontend/components/layout/CardTitleMuted.tsx | 20 +++++++ .../software/list/AdminSoftwareListItem.tsx | 10 ++-- .../overview/cards/ResearchDomainTitle.tsx | 19 ++++--- .../overview/SoftwareOverviewContent.tsx | 48 +++++++++++----- .../overview/cards/SoftwareCardContent.tsx | 16 +++--- .../overview/cards/SoftwareGridCard.tsx | 22 ++++--- .../overview/cards/SoftwareMasonryCard.tsx | 31 +++++----- .../overview/list/SoftwareListItemContent.tsx | 12 ++-- .../overview/useSoftwareOverviewProps.tsx | 57 +++++++++++++++++++ frontend/types/SoftwareTypes.ts | 8 ++- frontend/utils/postgrestUrl.test.ts | 10 ++-- frontend/utils/postgrestUrl.ts | 4 +- 13 files changed, 203 insertions(+), 72 deletions(-) create mode 100644 frontend/components/cards/SourceRsd.tsx create mode 100644 frontend/components/layout/CardTitleMuted.tsx create mode 100644 frontend/components/software/overview/useSoftwareOverviewProps.tsx diff --git a/frontend/components/cards/SourceRsd.tsx b/frontend/components/cards/SourceRsd.tsx new file mode 100644 index 000000000..501dce24d --- /dev/null +++ b/frontend/components/cards/SourceRsd.tsx @@ -0,0 +1,18 @@ +// SPDX-FileCopyrightText: 2024 Dusan Mijatovic (Netherlands eScience Center) +// SPDX-FileCopyrightText: 2024 Netherlands eScience Center +// +// SPDX-License-Identifier: Apache-2.0 + +import CardTitleMuted from '~/components/layout/CardTitleMuted' + +export default function SourceRsd({source,domain}:Readonly<{source?:string|null,domain?:string|null}>){ + + if (!source) return null + + return ( + + ) +} diff --git a/frontend/components/layout/CardTitleMuted.tsx b/frontend/components/layout/CardTitleMuted.tsx new file mode 100644 index 000000000..54c4582e7 --- /dev/null +++ b/frontend/components/layout/CardTitleMuted.tsx @@ -0,0 +1,20 @@ +// SPDX-FileCopyrightText: 2024 Dusan Mijatovic (Netherlands eScience Center) +// SPDX-FileCopyrightText: 2024 Netherlands eScience Center +// +// SPDX-License-Identifier: Apache-2.0 + +type CardTitleMutedProps=Readonly<{ + title: string + label: string +}> + +export default function CardTitleMuted({title,label}:CardTitleMutedProps) { + return ( +
+ {label} +
+ ) +} diff --git a/frontend/components/organisation/software/list/AdminSoftwareListItem.tsx b/frontend/components/organisation/software/list/AdminSoftwareListItem.tsx index 671cd0a32..8e271151f 100644 --- a/frontend/components/organisation/software/list/AdminSoftwareListItem.tsx +++ b/frontend/components/organisation/software/list/AdminSoftwareListItem.tsx @@ -1,15 +1,15 @@ -// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (Netherlands eScience Center) -// SPDX-FileCopyrightText: 2023 Netherlands eScience Center +// SPDX-FileCopyrightText: 2023 - 2024 Dusan Mijatovic (Netherlands eScience Center) +// SPDX-FileCopyrightText: 2023 - 2024 Netherlands eScience Center // // SPDX-License-Identifier: Apache-2.0 import Link from 'next/link' import {SoftwareOfOrganisation} from '~/types/Organisation' -import {useSoftwareCardActions} from '../card/useSoftwareCardActions' -import SoftwareListItemContent from '~/components/software/overview/list/SoftwareListItemContent' import IconBtnMenuOnAction from '~/components/menu/IconBtnMenuOnAction' -import OverviewListItem from '~/components/software/overview/list/OverviewListItem' import StatusBanner from '~/components/cards/StatusBanner' +import SoftwareListItemContent from '~/components/software/overview/list/SoftwareListItemContent' +import OverviewListItem from '~/components/software/overview/list/OverviewListItem' +import {useSoftwareCardActions} from '~/components/organisation/software/card/useSoftwareCardActions' type AdminSoftwareListItem = { item: SoftwareOfOrganisation diff --git a/frontend/components/projects/overview/cards/ResearchDomainTitle.tsx b/frontend/components/projects/overview/cards/ResearchDomainTitle.tsx index b365e2869..be06f2d9d 100644 --- a/frontend/components/projects/overview/cards/ResearchDomainTitle.tsx +++ b/frontend/components/projects/overview/cards/ResearchDomainTitle.tsx @@ -1,10 +1,12 @@ -// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (Netherlands eScience Center) +// SPDX-FileCopyrightText: 2023 - 2024 Dusan Mijatovic (Netherlands eScience Center) +// SPDX-FileCopyrightText: 2023 - 2024 Netherlands eScience Center // SPDX-FileCopyrightText: 2023 Dusan Mijatovic (dv4all) -// SPDX-FileCopyrightText: 2023 Netherlands eScience Center // SPDX-FileCopyrightText: 2023 dv4all // // SPDX-License-Identifier: Apache-2.0 +import CardTitleMuted from '~/components/layout/CardTitleMuted' + export default function ResearchDomainTitle({domains=[]}:{domains: string[]}) { const mainDomain:string[] = [] domains.forEach(domain => { @@ -25,12 +27,13 @@ export default function ResearchDomainTitle({domains=[]}:{domains: string[]}) { if (mainDomain.length===0) return null + const mainDomains = mainDomain.join(', ') + return ( -
- {mainDomain.join(', ')} -
+ ) + } diff --git a/frontend/components/software/overview/SoftwareOverviewContent.tsx b/frontend/components/software/overview/SoftwareOverviewContent.tsx index 8449e6f96..f360be011 100644 --- a/frontend/components/software/overview/SoftwareOverviewContent.tsx +++ b/frontend/components/software/overview/SoftwareOverviewContent.tsx @@ -1,6 +1,6 @@ -// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (Netherlands eScience Center) +// SPDX-FileCopyrightText: 2023 - 2024 Dusan Mijatovic (Netherlands eScience Center) +// SPDX-FileCopyrightText: 2023 - 2024 Netherlands eScience Center // SPDX-FileCopyrightText: 2023 Dusan Mijatovic (dv4all) -// SPDX-FileCopyrightText: 2023 Netherlands eScience Center // SPDX-FileCopyrightText: 2023 dv4all // // SPDX-License-Identifier: Apache-2.0 @@ -9,6 +9,7 @@ import Link from 'next/link' import {SoftwareOverviewItemProps} from '~/types/SoftwareTypes' import NoContent from '~/components/layout/NoContent' +import SourceRsd from '~/components/cards/SourceRsd' import {LayoutType} from './search/ViewToggleGroup' import SoftwareOverviewList from './list/SoftwareOverviewList' import SoftwareOverviewMasonry from './cards/SoftwareOverviewMasonry' @@ -17,6 +18,7 @@ import SoftwareGridCard from './cards/SoftwareGridCard' import SoftwareMasonryCard from './cards/SoftwareMasonryCard' import SoftwareListItemContent from './list/SoftwareListItemContent' import OverviewListItem from './list/OverviewListItem' +import {getItemKey, getPageUrl} from './useSoftwareOverviewProps' type SoftwareOverviewContentProps = { layout: LayoutType @@ -33,11 +35,14 @@ export default function SoftwareOverviewContent({layout, software}: SoftwareOver // Masonry layout (software only) return ( - {software.map((item) => ( -
- -
- ))} + {software.map((item) => { + const cardKey = getItemKey({id:item.id,domain:item.domain}) + return ( +
+ +
+ ) + })}
) } @@ -46,16 +51,30 @@ export default function SoftwareOverviewContent({layout, software}: SoftwareOver return ( {software.map(item => { + const listKey = getItemKey({id:item.id,domain:item.domain}) + const pageUrl = getPageUrl({domain:item.domain,slug:item.slug}) return ( - - + + + + + } + {...item} + /> ) @@ -67,9 +86,10 @@ export default function SoftwareOverviewContent({layout, software}: SoftwareOver // GRID as default return ( - {software.map((item) => ( - - ))} + {software.map((item) => { + const cardKey = getItemKey({id:item.id,domain:item.domain}) + return + })} ) } diff --git a/frontend/components/software/overview/cards/SoftwareCardContent.tsx b/frontend/components/software/overview/cards/SoftwareCardContent.tsx index ded6343aa..165e53956 100644 --- a/frontend/components/software/overview/cards/SoftwareCardContent.tsx +++ b/frontend/components/software/overview/cards/SoftwareCardContent.tsx @@ -1,19 +1,19 @@ -// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (Netherlands eScience Center) -// SPDX-FileCopyrightText: 2023 Netherlands eScience Center +// SPDX-FileCopyrightText: 2023 - 2024 Dusan Mijatovic (Netherlands eScience Center) +// SPDX-FileCopyrightText: 2023 - 2024 Netherlands eScience Center // // SPDX-License-Identifier: Apache-2.0 -import {getImageUrl} from '~/utils/editImage' import KeywordList from '~/components/cards/KeywordList' import CardTitleSubtitle from '~/components/cards/CardTitleSubtitle' import ImageWithPlaceholder from '~/components/layout/ImageWithPlaceholder' import CardContentFrame from '~/components/cards/CardContentFrame' import CardImageFrame from '~/components/cards/CardImageFrame' +import SourceRsd from '~/components/cards/SourceRsd' import ProgrammingLanguageList from './ProgrammingLanguageList' import SoftwareMetrics from './SoftwareMetrics' +import {getImgUrl} from '../useSoftwareOverviewProps' type SoftwareCardContentProps = { - // slug:string brand_name: string short_statement: string image_id: string | null @@ -24,10 +24,12 @@ type SoftwareCardContentProps = { downloads?: number visibleKeywords?: number visibleProgLang?: number + domain?: string|null + source?: string|null } export default function SoftwareCardContent(item:SoftwareCardContentProps) { - + const imgUrl = getImgUrl({domain:item.domain,image_id:item.image_id}) return (
+ - {/* keywords */}
diff --git a/frontend/components/software/overview/cards/SoftwareMasonryCard.tsx b/frontend/components/software/overview/cards/SoftwareMasonryCard.tsx index e3189c117..92e42f7d6 100644 --- a/frontend/components/software/overview/cards/SoftwareMasonryCard.tsx +++ b/frontend/components/software/overview/cards/SoftwareMasonryCard.tsx @@ -1,36 +1,40 @@ -// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (Netherlands eScience Center) +// SPDX-FileCopyrightText: 2023 - 2024 Dusan Mijatovic (Netherlands eScience Center) +// SPDX-FileCopyrightText: 2023 - 2024 Netherlands eScience Center // SPDX-FileCopyrightText: 2023 Dusan Mijatovic (dv4all) // SPDX-FileCopyrightText: 2023 Dusan Mijatovic (dv4all) (dv4all) -// SPDX-FileCopyrightText: 2023 Netherlands eScience Center // SPDX-FileCopyrightText: 2023 dv4all // // SPDX-License-Identifier: Apache-2.0 import Link from 'next/link' import {SoftwareOverviewItemProps} from '~/types/SoftwareTypes' -import {getImageUrl} from '~/utils/editImage' -import useValidateImageSrc from '~/utils/useValidateImageSrc' import KeywordList from '~/components/cards/KeywordList' import CardTitleSubtitle from '~/components/cards/CardTitleSubtitle' +import SourceRsd from '~/components/cards/SourceRsd' import ProgrammingLanguageList from './ProgrammingLanguageList' import SoftwareMetrics from './SoftwareMetrics' +import useSoftwareOverviewProps from '../useSoftwareOverviewProps' type SoftwareCardProps = { item: SoftwareOverviewItemProps } export default function SoftwareMasonryCard({item}:SoftwareCardProps){ - const imgSrc = getImageUrl(item.image_id ?? null) - const validImg = useValidateImageSrc(imgSrc) - - const visibleNumberOfKeywords: number = 3 - const visibleNumberOfProgLang: number = 3 + const { + imgUrl,pageUrl, + validImg,visibleNumberOfKeywords, + visibleNumberOfProgLang + } = useSoftwareOverviewProps({ + id: item.id, + domain:item.domain, + image_id: item.image_id, + slug: item.slug + }) return (
{/* Cover image, show only if valid image link */} @@ -38,9 +42,9 @@ export default function SoftwareMasonryCard({item}:SoftwareCardProps){ : {`Cover +
diff --git a/frontend/components/software/overview/useSoftwareOverviewProps.tsx b/frontend/components/software/overview/useSoftwareOverviewProps.tsx new file mode 100644 index 000000000..5cccfd497 --- /dev/null +++ b/frontend/components/software/overview/useSoftwareOverviewProps.tsx @@ -0,0 +1,57 @@ +// SPDX-FileCopyrightText: 2024 Dusan Mijatovic (Netherlands eScience Center) +// SPDX-FileCopyrightText: 2024 Netherlands eScience Center +// +// SPDX-License-Identifier: Apache-2.0 + +import {getImageUrl} from '~/utils/editImage' +import useValidateImageSrc from '~/utils/useValidateImageSrc' + +type useSoftwareOverviewLinksProps={ + id: string, + domain: string | null + image_id: string | null + slug: string | null +} + +export function getImgUrl({image_id,domain}:{image_id:string|null,domain?:string|null}){ + const imgSrc = getImageUrl(image_id ?? null) + if (domain && image_id){ + return `${domain}${imgSrc}` + } + return imgSrc +} + +export function getPageUrl({slug,domain}:{slug:string|null,domain?:string|null}){ + if (domain && domain?.endsWith('/')===true){ + return `${domain}software/${slug}` + } + if (domain && domain?.endsWith('/')===false){ + return `${domain}/software/${slug}` + } + return `/software/${slug}` +} + +export function getItemKey({id,domain}:{id:string,domain?:string|null}){ + if (domain) return `${domain}${id}` + return id +} + +export const visibleNumberOfKeywords: number = 3 +export const visibleNumberOfProgLang: number = 3 + + +export default function useSoftwareOverviewProps({id,domain,image_id,slug}:useSoftwareOverviewLinksProps) { + const imgUrl = getImgUrl({domain,image_id}) + const validImg = useValidateImageSrc(imgUrl) + const pageUrl = getPageUrl({domain,slug}) + const cardKey = getItemKey({id,domain}) + + return { + cardKey, + imgUrl, + pageUrl, + validImg, + visibleNumberOfKeywords, + visibleNumberOfProgLang + } +} diff --git a/frontend/types/SoftwareTypes.ts b/frontend/types/SoftwareTypes.ts index 8c27c2635..475728651 100644 --- a/frontend/types/SoftwareTypes.ts +++ b/frontend/types/SoftwareTypes.ts @@ -77,6 +77,8 @@ export type SoftwareItemFromDB = SoftwareTableItem & { export type SoftwareOverviewItemProps = { id:string + domain: string | null + source: string | null slug:string brand_name: string short_statement: string @@ -85,9 +87,9 @@ export type SoftwareOverviewItemProps = { mention_cnt: number | null is_published: boolean image_id: string | null - keywords: string[], - prog_lang: string[], - licenses: string, + keywords: string[] + prog_lang: string[] + licenses: string downloads?: number } diff --git a/frontend/utils/postgrestUrl.test.ts b/frontend/utils/postgrestUrl.test.ts index 491ae6d61..595f1b7f0 100644 --- a/frontend/utils/postgrestUrl.test.ts +++ b/frontend/utils/postgrestUrl.test.ts @@ -1,8 +1,8 @@ // SPDX-FileCopyrightText: 2022 - 2023 Dusan Mijatovic (dv4all) // SPDX-FileCopyrightText: 2022 - 2023 dv4all -// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (Netherlands eScience Center) +// SPDX-FileCopyrightText: 2023 - 2024 Dusan Mijatovic (Netherlands eScience Center) +// SPDX-FileCopyrightText: 2023 - 2024 Netherlands eScience Center // SPDX-FileCopyrightText: 2023 Dusan Mijatovic (dv4all) (dv4all) -// SPDX-FileCopyrightText: 2023 Netherlands eScience Center // // SPDX-License-Identifier: Apache-2.0 @@ -92,7 +92,7 @@ describe('ssrSoftwareUrl', () => { describe('softwareListUrl', () => { it('returns overview rpc endpoint url when only baseUrl provided', () => { const baseUrl = 'http://test-base-url' - const expectUrl = `${baseUrl}/rpc/software_overview?limit=12&offset=0` + const expectUrl = `${baseUrl}/rpc/aggregated_software_overview?limit=12&offset=0` const url = softwareListUrl({ baseUrl } as PostgrestParams) @@ -103,7 +103,7 @@ describe('softwareListUrl', () => { const baseUrl = 'http://test-base-url' const searchTerm = 'test-search' // if you change search value then change expectedUrl values too - const expectUrl = `${baseUrl}/rpc/software_search?limit=12&offset=0&search=${searchTerm}` + const expectUrl = `${baseUrl}/rpc/aggregated_software_search?limit=12&offset=0&search=${searchTerm}` const url = softwareListUrl({ baseUrl, // if you change search value then change expectedUrl values too @@ -115,7 +115,7 @@ describe('softwareListUrl', () => { it('returns overview rpc endpoint url with keywords params', () => { const baseUrl = 'http://test-base-url' // if you change search value then change expectedUrl values too - const expectUrl = `${baseUrl}/rpc/software_overview?keywords=cs.%7B\"test-filter\"%7D&limit=12&offset=0` + const expectUrl = `${baseUrl}/rpc/aggregated_software_overview?keywords=cs.%7B\"test-filter\"%7D&limit=12&offset=0` const url = softwareListUrl({ baseUrl, keywords: ['test-filter'] diff --git a/frontend/utils/postgrestUrl.ts b/frontend/utils/postgrestUrl.ts index 42db00fe1..1171d5bee 100644 --- a/frontend/utils/postgrestUrl.ts +++ b/frontend/utils/postgrestUrl.ts @@ -308,12 +308,12 @@ export function softwareListUrl(props: PostgrestParams) { // check rpc in 105-project-views.sql for exact filtering query += `&search=${encodedSearch}` - const url = `${baseUrl}/rpc/software_search?${query}` + const url = `${baseUrl}/rpc/aggregated_software_search?${query}` // console.log('softwareListUrl...', url) return url } - const url = `${baseUrl}/rpc/software_overview?${query}` + const url = `${baseUrl}/rpc/aggregated_software_overview?${query}` // console.log('softwareListUrl...', url) return url }