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
}