From 56d833511a2f5eccddb22557ac7c7aabfd0f7804 Mon Sep 17 00:00:00 2001 From: "Dusan Mijatovic (PC2020)" Date: Mon, 21 Aug 2023 10:54:59 +0200 Subject: [PATCH] refactor: implement sonar suggestions in admin, projects, software, user and utils section --- frontend/auth/RsdAdminContent.tsx | 4 ++-- frontend/auth/index.tsx | 2 +- .../auth/permissions/useOrganisationMaintainer.tsx | 1 - frontend/components/AppHeader/index.tsx | 4 ++-- frontend/components/GoBackLink.tsx | 4 +++- frontend/components/admin/AdminNav.tsx | 2 +- frontend/components/admin/pages/edit/SortableNav.tsx | 4 +++- frontend/components/admin/pages/edit/index.tsx | 7 +++++-- .../admin/rsd-contributors/apiContributors.tsx | 7 ++++--- .../software-highlights/AddSoftwareHighlights.tsx | 2 +- .../software-highlights/SortableHightlightItem.tsx | 2 +- .../software-highlights/apiSoftwareHighlights.tsx | 5 ++++- frontend/components/cards/CardContentFrame.tsx | 4 +++- frontend/components/cards/CardImageFrame.tsx | 4 +++- frontend/components/cards/KeywordList.tsx | 4 ++-- frontend/components/form/ControlledTextField.tsx | 3 ++- frontend/components/form/HelperTextWithCounter.tsx | 7 +++++-- frontend/components/layout/ConfirmDeleteModal.tsx | 5 ++++- frontend/components/layout/ContentContainer.tsx | 4 +++- frontend/components/layout/SortableList.tsx | 6 +++++- frontend/components/mention/editMentionContext.tsx | 5 ++++- frontend/components/menu/IconBtnMenuOnAction.tsx | 2 +- frontend/components/organisation/apiOrganisations.ts | 5 ++--- frontend/components/organisation/metadata/Links.tsx | 3 ++- .../projects/filters/OrgProjectFilters.tsx | 1 - .../organisation/projects/useProjectParams.tsx | 2 -- .../components/organisation/releases/ReleaseList.tsx | 2 +- .../settings/OrganisationSettingsIndex.test.tsx | 4 ++-- .../organisation/settings/SettingsNavItems.tsx | 3 ++- .../about-page/AutosaveOrganisationDescription.tsx | 2 +- .../organisation/settings/about-page/index.tsx | 1 - .../organisation/settings/general/index.tsx | 6 +++--- .../maintainers/OrganisationMaintainersList.tsx | 2 +- .../maintainers/getMaintainersOfOrganisation.test.ts | 2 +- .../software/filters/useSoftwareParams.tsx | 2 -- .../organisation/tabs/OrganisationTabItems.tsx | 4 +++- .../organisation/units/ResearchUnitItem.tsx | 1 - frontend/components/projects/edit/EditProjectNav.tsx | 4 +++- .../components/projects/edit/editProjectPages.tsx | 8 ++++++-- .../edit/information/AutosaveProjectLinks.tsx | 7 +++++-- .../projects/edit/information/useResearchDomains.tsx | 4 +++- .../projects/overview/cards/ProjectCardContent.tsx | 2 +- .../projects/overview/cards/ProjectMetrics.tsx | 4 ++-- .../projects/overview/cards/ProjectOverviewGrid.tsx | 4 +++- .../projects/overview/filters/ProjectStatusFilter.tsx | 1 - .../projects/overview/list/ProjectListItemContent.tsx | 3 ++- .../projects/overview/list/ProjectOverviewList.tsx | 4 +++- frontend/components/software/AboutLanguages.tsx | 7 ++++--- frontend/components/software/edit/EditSoftwareNav.tsx | 4 +++- .../components/software/edit/editSoftwarePages.tsx | 7 +++++-- .../organisations/organisationForSoftware.test.ts | 4 +++- .../edit/testimonials/SortableTestimonialList.tsx | 4 +++- .../software/overview/SoftwareOverviewContent.tsx | 4 ++-- .../overview/cards/ProgrammingLanguageList.tsx | 2 +- .../software/overview/cards/SoftwareCardContent.tsx | 2 +- .../software/overview/cards/SoftwareMetrics.tsx | 4 ++-- .../software/overview/cards/SoftwareOverviewGrid.tsx | 4 +++- .../overview/cards/SoftwareOverviewMasonry.tsx | 4 +++- .../overview/highlights/HighlightsCarousel.tsx | 2 +- .../software/overview/list/OverviewListItem.tsx | 4 +++- .../overview/list/SoftwareListItemContent.tsx | 3 ++- .../software/overview/list/SoftwareOverviewList.tsx | 4 +++- frontend/components/table/EditableTable.tsx | 5 ++++- frontend/components/user/UserNavItems.tsx | 6 ++++-- .../components/user/project-quality/SortableTable.tsx | 6 ++---- frontend/config/menuItems.ts | 4 +++- frontend/pages/organisations/[...slug].tsx | 1 - frontend/pages/software/index.tsx | 1 - frontend/pages/user/[section].tsx | 4 +++- frontend/utils/getSlugFromString.ts | 4 ++-- frontend/utils/jest/WithAppContext.tsx | 4 +++- frontend/utils/jest/WithFormContext.tsx | 4 +++- frontend/utils/postgrestUrl.ts | 11 ++++++----- frontend/utils/sortFn.ts | 10 +++++++++- 74 files changed, 183 insertions(+), 105 deletions(-) diff --git a/frontend/auth/RsdAdminContent.tsx b/frontend/auth/RsdAdminContent.tsx index daccef640..74770a78a 100644 --- a/frontend/auth/RsdAdminContent.tsx +++ b/frontend/auth/RsdAdminContent.tsx @@ -1,12 +1,13 @@ // SPDX-FileCopyrightText: 2022 Dusan Mijatovic (dv4all) // SPDX-FileCopyrightText: 2022 Dusan Mijatovic (dv4all) (dv4all) // SPDX-FileCopyrightText: 2022 dv4all +// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (Netherlands eScience Center) +// SPDX-FileCopyrightText: 2023 Netherlands eScience Center // // SPDX-License-Identifier: Apache-2.0 import {useEffect, useState} from 'react' import {useAuth} from '~/auth' -import logger from '~/utils/logger' import ContentLoader from '~/components/layout/ContentLoader' import PageErrorMessage from '~/components/layout/PageErrorMessage' @@ -28,7 +29,6 @@ export default function RsdAdminContent({children}:{children:any}) { if (status === 'authenticated' && session.token && session.user?.role === 'rsd_admin') { - logger('RsdAdminContent...authenticated user...protected section', 'info') return children } diff --git a/frontend/auth/index.tsx b/frontend/auth/index.tsx index bb12e4c5b..abdec9540 100644 --- a/frontend/auth/index.tsx +++ b/frontend/auth/index.tsx @@ -15,7 +15,7 @@ import {refreshSession} from './refreshSession' // refresh schedule margin 5min. before expiration time // REFRESH_MARGIN_MSEC env variable is used for test purposes ONLY const testMargin = process.env.REFRESH_MARGIN_MSEC ? parseInt(process.env.REFRESH_MARGIN_MSEC) : undefined -export const REFRESH_MARGIN = testMargin || 5 * 60 * 1000 +export const REFRESH_MARGIN = testMargin ?? 5 * 60 * 1000 export type RsdRole = 'rsd_admin' | 'rsd_user' export type RsdUser = { iss: 'rsd_auth' diff --git a/frontend/auth/permissions/useOrganisationMaintainer.tsx b/frontend/auth/permissions/useOrganisationMaintainer.tsx index a9a7b73ad..ae1343c46 100644 --- a/frontend/auth/permissions/useOrganisationMaintainer.tsx +++ b/frontend/auth/permissions/useOrganisationMaintainer.tsx @@ -64,7 +64,6 @@ export default function useOrganisationMaintainer({organisation}: UseOrganisatio } else { logger('useOrganisationMaintainer...organisation UNDEFINED', 'warn') setIsMaintainer(false) - // if (loading) setLoading(false) } } if (organisation && diff --git a/frontend/components/AppHeader/index.tsx b/frontend/components/AppHeader/index.tsx index f00dd48e0..03dd722a1 100644 --- a/frontend/components/AppHeader/index.tsx +++ b/frontend/components/AppHeader/index.tsx @@ -76,7 +76,7 @@ export default function AppHeader() { {menuItems.map(item => { const isActive = isActiveMenuItem({item, activePath}) return ( - + {item.label} ) @@ -137,7 +137,7 @@ export default function AppHeader() { const isActive = isActiveMenuItem({item, activePath}) return ( - + {item.label} diff --git a/frontend/components/GoBackLink.tsx b/frontend/components/GoBackLink.tsx index abc7be121..bff01327c 100644 --- a/frontend/components/GoBackLink.tsx +++ b/frontend/components/GoBackLink.tsx @@ -1,5 +1,7 @@ // SPDX-FileCopyrightText: 2022 Dusan Mijatovic (dv4all) // SPDX-FileCopyrightText: 2022 dv4all +// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (Netherlands eScience Center) +// SPDX-FileCopyrightText: 2023 Netherlands eScience Center // // SPDX-License-Identifier: Apache-2.0 @@ -14,7 +16,7 @@ export const GoBackLink = (props: Props) => { const router = useRouter() return ( router.back()}> - ⃪ {props.text || 'Go back'} + ⃪ {props.text ?? 'Go back'} ) } diff --git a/frontend/components/admin/AdminNav.tsx b/frontend/components/admin/AdminNav.tsx index 8570bd8e4..db9d8d07d 100644 --- a/frontend/components/admin/AdminNav.tsx +++ b/frontend/components/admin/AdminNav.tsx @@ -85,7 +85,7 @@ export default function AdminNav() { router.push(item.path)} > diff --git a/frontend/components/admin/pages/edit/SortableNav.tsx b/frontend/components/admin/pages/edit/SortableNav.tsx index d52b451e6..bec0f93dc 100644 --- a/frontend/components/admin/pages/edit/SortableNav.tsx +++ b/frontend/components/admin/pages/edit/SortableNav.tsx @@ -1,5 +1,7 @@ // SPDX-FileCopyrightText: 2022 - 2023 Dusan Mijatovic (dv4all) // SPDX-FileCopyrightText: 2022 - 2023 dv4all +// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (Netherlands eScience Center) +// SPDX-FileCopyrightText: 2023 Netherlands eScience Center // // SPDX-License-Identifier: Apache-2.0 @@ -44,7 +46,7 @@ export default function SortableNav({selected, links, onSelect, onSorted}: Pages * rendering of custom sortable items * @param item * @param index - * @returns JSX.Element + * @returns React.JSX.Element */ function renderListItem(item: RsdLink, index: number) { return ( diff --git a/frontend/components/admin/pages/edit/index.tsx b/frontend/components/admin/pages/edit/index.tsx index a77ad55b8..95787ac40 100644 --- a/frontend/components/admin/pages/edit/index.tsx +++ b/frontend/components/admin/pages/edit/index.tsx @@ -133,6 +133,9 @@ export default function EditMarkdownPages({links}:{links:RsdLink[]}) { } async function patchPositions(newList: RsdLink[]) { + const orgItems = [ + ...navItems + ] // update ui first setNavItems(newList) const resp = await updatePagePositions({ @@ -140,9 +143,9 @@ export default function EditMarkdownPages({links}:{links:RsdLink[]}) { token:session.token }) if (resp.status !== 200) { - // revert back - setNavItems(navItems) showErrorMessage(`Failed to update page positions. ${resp?.message}`) + // revert back + setNavItems(orgItems) } } diff --git a/frontend/components/admin/rsd-contributors/apiContributors.tsx b/frontend/components/admin/rsd-contributors/apiContributors.tsx index 49d1fce7d..93620afe3 100644 --- a/frontend/components/admin/rsd-contributors/apiContributors.tsx +++ b/frontend/components/admin/rsd-contributors/apiContributors.tsx @@ -1,4 +1,6 @@ +// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (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 @@ -51,7 +53,8 @@ export function useContributors({token, orderBy}:useContributorsProps) { if (abort === false) { if (orderBy) { - columns.forEach(col => { + // update columns order + columns.map(col => { if (col.key === orderBy.column) { col.order = { active: true, @@ -64,8 +67,6 @@ export function useContributors({token, orderBy}:useContributorsProps) { } } }) - // update columns order - setColumns(columns) } setContributors(contributors) setCount(count) diff --git a/frontend/components/admin/software-highlights/AddSoftwareHighlights.tsx b/frontend/components/admin/software-highlights/AddSoftwareHighlights.tsx index 751de6858..ebe48d5e4 100644 --- a/frontend/components/admin/software-highlights/AddSoftwareHighlights.tsx +++ b/frontend/components/admin/software-highlights/AddSoftwareHighlights.tsx @@ -87,7 +87,7 @@ export default function AddSoftwareHighlights({onAddSoftware,highlights}:AddSoft } function onAdd(selected:AutocompleteOption) { - if (selected && selected.data) { + if (selected?.data) { onAddSoftware(selected.data.id) } } diff --git a/frontend/components/admin/software-highlights/SortableHightlightItem.tsx b/frontend/components/admin/software-highlights/SortableHightlightItem.tsx index 1a5bfb131..72a4e7b6e 100644 --- a/frontend/components/admin/software-highlights/SortableHightlightItem.tsx +++ b/frontend/components/admin/software-highlights/SortableHightlightItem.tsx @@ -31,7 +31,7 @@ export default function SortableHighlightItem({pos, item, onEdit, onDelete}: Hig attributes,listeners,setNodeRef, transform,transition,isDragging } = useSortable({id: item.id ?? ''}) - const {brand_name, contributor_cnt, mention_cnt, slug, image_id, is_published} = item + const {brand_name, contributor_cnt, mention_cnt, image_id, is_published} = item return ( {children} diff --git a/frontend/components/cards/CardImageFrame.tsx b/frontend/components/cards/CardImageFrame.tsx index 816dee2fa..c2c0b793f 100644 --- a/frontend/components/cards/CardImageFrame.tsx +++ b/frontend/components/cards/CardImageFrame.tsx @@ -3,7 +3,9 @@ // // SPDX-License-Identifier: Apache-2.0 -export default function CardImageFrame({children}:{children:JSX.Element}) { +import React from 'react' + +export default function CardImageFrame({children}:{children:React.JSX.Element}) { return (
{children} diff --git a/frontend/components/cards/KeywordList.tsx b/frontend/components/cards/KeywordList.tsx index b14a531cc..f41d7db62 100644 --- a/frontend/components/cards/KeywordList.tsx +++ b/frontend/components/cards/KeywordList.tsx @@ -18,10 +18,10 @@ export default function KeywordList({keywords=[], visibleNumberOfKeywords = 3}:
    {// limits the keywords to 'visibleNumberOfKeywords' per software. keywords?.slice(0, visibleNumberOfKeywords) - .map((keyword:string, index: number) => ( + .map((keyword:string) => (
  • {keyword}
  • ))} diff --git a/frontend/components/form/ControlledTextField.tsx b/frontend/components/form/ControlledTextField.tsx index 19625e28b..4f9119c5a 100644 --- a/frontend/components/form/ControlledTextField.tsx +++ b/frontend/components/form/ControlledTextField.tsx @@ -6,6 +6,7 @@ // // SPDX-License-Identifier: Apache-2.0 +import React from 'react' import {useEffect, useRef} from 'react' import {Controller} from 'react-hook-form' import TextField, {TextFieldProps} from '@mui/material/TextField' @@ -24,7 +25,7 @@ export type ControlledTextFieldOptions = { variant?: 'outlined'|'standard' useNull?: boolean, defaultValue?: string | number | null - helperTextMessage?: string | JSX.Element + helperTextMessage?: string | React.JSX.Element helperTextCnt?: string disabled?: boolean muiProps?: TextFieldProps diff --git a/frontend/components/form/HelperTextWithCounter.tsx b/frontend/components/form/HelperTextWithCounter.tsx index c5e7b34cc..3d0124f56 100644 --- a/frontend/components/form/HelperTextWithCounter.tsx +++ b/frontend/components/form/HelperTextWithCounter.tsx @@ -1,11 +1,14 @@ +// SPDX-FileCopyrightText: 2022 - 2023 Netherlands eScience Center // SPDX-FileCopyrightText: 2022 Dusan Mijatovic (dv4all) // SPDX-FileCopyrightText: 2022 Ewan Cahen (Netherlands eScience Center) -// SPDX-FileCopyrightText: 2022 Netherlands eScience Center // SPDX-FileCopyrightText: 2022 dv4all +// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (Netherlands eScience Center) // // SPDX-License-Identifier: Apache-2.0 -export default function HelperTextWithCounter({message,count}:{message:string|undefined|JSX.Element,count:string}) { +import React from 'react' + +export default function HelperTextWithCounter({message,count}:{message:string|undefined|React.JSX.Element,count:string}) { return ( <> {message} diff --git a/frontend/components/layout/ConfirmDeleteModal.tsx b/frontend/components/layout/ConfirmDeleteModal.tsx index edd9ac918..4f5a8dcef 100644 --- a/frontend/components/layout/ConfirmDeleteModal.tsx +++ b/frontend/components/layout/ConfirmDeleteModal.tsx @@ -1,9 +1,12 @@ // SPDX-FileCopyrightText: 2022 - 2023 Dusan Mijatovic (dv4all) // SPDX-FileCopyrightText: 2022 - 2023 dv4all // SPDX-FileCopyrightText: 2022 Dusan Mijatovic (dv4all) (dv4all) +// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (Netherlands eScience Center) +// SPDX-FileCopyrightText: 2023 Netherlands eScience Center // // SPDX-License-Identifier: Apache-2.0 +import React from 'react' import Button from '@mui/material/Button' import Dialog from '@mui/material/Dialog' import DialogActions from '@mui/material/DialogActions' @@ -16,7 +19,7 @@ import WarningIcon from '@mui/icons-material/Warning' type ConfirmDeleteModalProps = { open: boolean, title: string, - body: JSX.Element, + body: React.JSX.Element, onCancel: () => void, onDelete: () => void } diff --git a/frontend/components/layout/ContentContainer.tsx b/frontend/components/layout/ContentContainer.tsx index eed06bf44..14e6a5e63 100644 --- a/frontend/components/layout/ContentContainer.tsx +++ b/frontend/components/layout/ContentContainer.tsx @@ -3,10 +3,12 @@ // // SPDX-License-Identifier: Apache-2.0 +import React from 'react' + type ContentContainerProps = { element?: 'section' | 'article' | 'main' | 'div' className?: string - children: JSX.Element | JSX.Element[] + children: React.JSX.Element | React.JSX.Element[] } export default function ContentContainer(props: ContentContainerProps) { diff --git a/frontend/components/layout/SortableList.tsx b/frontend/components/layout/SortableList.tsx index ee249bbd2..07268397c 100644 --- a/frontend/components/layout/SortableList.tsx +++ b/frontend/components/layout/SortableList.tsx @@ -1,8 +1,11 @@ // SPDX-FileCopyrightText: 2022 - 2023 Dusan Mijatovic (dv4all) // SPDX-FileCopyrightText: 2022 - 2023 dv4all +// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (Netherlands eScience Center) +// SPDX-FileCopyrightText: 2023 Netherlands eScience Center // // SPDX-License-Identifier: Apache-2.0 +import React from 'react' import { DndContext, DragEndEvent, useSensor, useSensors, TouchSensor, MouseSensor @@ -11,6 +14,7 @@ import {restrictToParentElement, restrictToVerticalAxis} from '@dnd-kit/modifier import {arrayMove, SortableContext, verticalListSortingStrategy} from '@dnd-kit/sortable' import List from '@mui/material/List' + export type RequiredListProps = { id: string | null, position: number | null @@ -19,7 +23,7 @@ export type RequiredListProps = { type SortableListProps={ items:T[], onSorted: (items: T[]) => void - onRenderItem:(item:T,index:number) => JSX.Element + onRenderItem:(item:T,index:number) => React.JSX.Element } export default function SortableList({ diff --git a/frontend/components/mention/editMentionContext.tsx b/frontend/components/mention/editMentionContext.tsx index b292840fc..a76708668 100644 --- a/frontend/components/mention/editMentionContext.tsx +++ b/frontend/components/mention/editMentionContext.tsx @@ -1,9 +1,12 @@ // SPDX-FileCopyrightText: 2022 Dusan Mijatovic (dv4all) // SPDX-FileCopyrightText: 2022 Dusan Mijatovic (dv4all) (dv4all) // SPDX-FileCopyrightText: 2022 dv4all +// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (Netherlands eScience Center) +// SPDX-FileCopyrightText: 2023 Netherlands eScience Center // // SPDX-License-Identifier: Apache-2.0 +import React from 'react' import {createContext} from 'react' import {MentionItemProps} from '~/types/Mention' import {EditMentionAction, EditMentionState} from './editMentionReducer' @@ -12,7 +15,7 @@ import NoMentionItems from './NoMentionItems' export type EditMentionSettings = { editModalTitle: string, confirmDeleteModalTitle: string, - noItemsComponent:()=>JSX.Element + noItemsComponent:()=>React.JSX.Element } export type EditModalProps = { diff --git a/frontend/components/menu/IconBtnMenuOnAction.tsx b/frontend/components/menu/IconBtnMenuOnAction.tsx index ea8700061..3247335c5 100644 --- a/frontend/components/menu/IconBtnMenuOnAction.tsx +++ b/frontend/components/menu/IconBtnMenuOnAction.tsx @@ -16,7 +16,7 @@ export type IconBtnMenuOption = { type: 'divider' | 'action' key: string, label: string, - icon?: JSX.Element, + icon?: React.JSX.Element, action: T disabled?: boolean, } diff --git a/frontend/components/organisation/apiOrganisations.ts b/frontend/components/organisation/apiOrganisations.ts index b0abe6ec9..110923aa1 100644 --- a/frontend/components/organisation/apiOrganisations.ts +++ b/frontend/components/organisation/apiOrganisations.ts @@ -7,7 +7,6 @@ // SPDX-License-Identifier: Apache-2.0 import {RsdUser} from '~/auth' -import {getMaintainerOrganisations} from '~/auth/permissions/isMaintainerOfOrganisation' import {isOrganisationMaintainer} from '~/auth/permissions/useOrganisationMaintainer' import { Organisation, OrganisationForOverview, @@ -216,8 +215,8 @@ export async function getOrganisationDescription({uuid, token}: { uuid: string, export type OrganisationApiParams = { organisation: string, - searchFor?: string | undefined - project_status?: string | undefined + searchFor?: string + project_status?: string keywords?: string[] | null prog_lang?: string[] | null licenses?: string[] | null diff --git a/frontend/components/organisation/metadata/Links.tsx b/frontend/components/organisation/metadata/Links.tsx index 55a135ce2..a654eb476 100644 --- a/frontend/components/organisation/metadata/Links.tsx +++ b/frontend/components/organisation/metadata/Links.tsx @@ -5,12 +5,13 @@ // // SPDX-License-Identifier: Apache-2.0 +import React from 'react' import Link from 'next/link' export type LinksProps = { title: string, url: string - icon: JSX.Element, + icon: React.JSX.Element, } export default function Links({links=[]}:{links:LinksProps[]}) { diff --git a/frontend/components/organisation/projects/filters/OrgProjectFilters.tsx b/frontend/components/organisation/projects/filters/OrgProjectFilters.tsx index e7d88884c..8cd7866d4 100644 --- a/frontend/components/organisation/projects/filters/OrgProjectFilters.tsx +++ b/frontend/components/organisation/projects/filters/OrgProjectFilters.tsx @@ -35,7 +35,6 @@ export default function OrgProjectFilters() { // debugger function clearDisabled() { if (filterCnt && filterCnt > 0) return false - // if (order) return false return true } diff --git a/frontend/components/organisation/projects/useProjectParams.tsx b/frontend/components/organisation/projects/useProjectParams.tsx index 6e72cbf3e..870b6ab40 100644 --- a/frontend/components/organisation/projects/useProjectParams.tsx +++ b/frontend/components/organisation/projects/useProjectParams.tsx @@ -20,8 +20,6 @@ export default function useProjectParams() { params.rows = rsd_page_rows } - // if (params.search==='') params.search = null - function getFilterCount() { let count = 0 if (params?.keywords_json) count++ diff --git a/frontend/components/organisation/releases/ReleaseList.tsx b/frontend/components/organisation/releases/ReleaseList.tsx index b1af00d87..46d8a9512 100644 --- a/frontend/components/organisation/releases/ReleaseList.tsx +++ b/frontend/components/organisation/releases/ReleaseList.tsx @@ -52,7 +52,7 @@ export default function ReleaseList({release_year}: ReleaseYearProps) {
- {releases.map((release,pos)=>)} + {releases.map((release,pos)=>)} ) diff --git a/frontend/components/organisation/settings/OrganisationSettingsIndex.test.tsx b/frontend/components/organisation/settings/OrganisationSettingsIndex.test.tsx index 091dfd3b8..206bf12ec 100644 --- a/frontend/components/organisation/settings/OrganisationSettingsIndex.test.tsx +++ b/frontend/components/organisation/settings/OrganisationSettingsIndex.test.tsx @@ -104,7 +104,7 @@ describe('frontend/components/organisation/settings/index.tsx', () => { if (mockSession.user) { mockSession.user.role = 'rsd_admin' } - const {container} = render( + render( @@ -127,7 +127,7 @@ describe('frontend/components/organisation/settings/index.tsx', () => { // expect(descriptionInput).toBeInTheDocument() }) - it.only('updates name and slug onBlur', () => { + it('updates name and slug onBlur', () => { // it is maintainer of this organisation mockUseOrganisationMaintainer.mockReturnValue({ loading: false, diff --git a/frontend/components/organisation/settings/SettingsNavItems.tsx b/frontend/components/organisation/settings/SettingsNavItems.tsx index df0f7ad2f..e1a5b25dc 100644 --- a/frontend/components/organisation/settings/SettingsNavItems.tsx +++ b/frontend/components/organisation/settings/SettingsNavItems.tsx @@ -5,6 +5,7 @@ // // SPDX-License-Identifier: Apache-2.0 +import React from 'react' import InfoIcon from '@mui/icons-material/Info' import PersonIcon from '@mui/icons-material/Person' import SettingsIcon from '@mui/icons-material/Settings' @@ -13,7 +14,7 @@ export type SettingsMenuProps = { id: string, status: string, label: (props?:any)=>string, - icon: JSX.Element + icon: React.JSX.Element } export const settingsMenu: SettingsMenuProps[] = [ diff --git a/frontend/components/organisation/settings/about-page/AutosaveOrganisationDescription.tsx b/frontend/components/organisation/settings/about-page/AutosaveOrganisationDescription.tsx index c774f1444..283d0af63 100644 --- a/frontend/components/organisation/settings/about-page/AutosaveOrganisationDescription.tsx +++ b/frontend/components/organisation/settings/about-page/AutosaveOrganisationDescription.tsx @@ -39,7 +39,7 @@ export default function AutosaveOrganisationDescription(props: AutosaveControlle const resp = await patchOrganisationTable({ id: id ?? '', data: { - [name]:value + [name]: description }, token }) diff --git a/frontend/components/organisation/settings/about-page/index.tsx b/frontend/components/organisation/settings/about-page/index.tsx index 89e0b625a..caf657923 100644 --- a/frontend/components/organisation/settings/about-page/index.tsx +++ b/frontend/components/organisation/settings/about-page/index.tsx @@ -27,7 +27,6 @@ export default function AboutPageSettings() { } }) - {/* About page section */} return ( @@ -75,7 +75,7 @@ export default function OrganisationGeneralSettings() { useNull: true, defaultValue: short_description, helperTextMessage: config.short_description.help, - helperTextCnt: `${short_description?.length || 0}/${config.short_description.validation.maxLength.value}`, + helperTextCnt: `${short_description?.length ?? 0}/${config.short_description.validation.maxLength.value}`, }} rules={config.short_description.validation} /> @@ -88,7 +88,7 @@ export default function OrganisationGeneralSettings() { useNull: true, defaultValue: website, helperTextMessage: config.website.help, - helperTextCnt: `${website?.length || 0}/${config.website.validation.maxLength.value}`, + helperTextCnt: `${website?.length ?? 0}/${config.website.validation.maxLength.value}`, }} rules={config.website.validation} /> diff --git a/frontend/components/organisation/settings/maintainers/OrganisationMaintainersList.tsx b/frontend/components/organisation/settings/maintainers/OrganisationMaintainersList.tsx index 4037521e7..b4a3f5d9c 100644 --- a/frontend/components/organisation/settings/maintainers/OrganisationMaintainersList.tsx +++ b/frontend/components/organisation/settings/maintainers/OrganisationMaintainersList.tsx @@ -37,7 +37,7 @@ export default function OrganisationMaintainersList({maintainers,onDelete}:Proje return maintainers.map((item, pos) => { return ( { statusText: 'OK' }) - const resp = await getMaintainersOfOrganisation(mockProps) + await getMaintainersOfOrganisation(mockProps) expect(global.fetch).toBeCalledTimes(1) expect(global.fetch).toBeCalledWith(expectedUrl, expectedHeaders) diff --git a/frontend/components/organisation/software/filters/useSoftwareParams.tsx b/frontend/components/organisation/software/filters/useSoftwareParams.tsx index e2dbbd9d5..70f86155c 100644 --- a/frontend/components/organisation/software/filters/useSoftwareParams.tsx +++ b/frontend/components/organisation/software/filters/useSoftwareParams.tsx @@ -22,8 +22,6 @@ export default function useSoftwareParams() { params.rows = rsd_page_rows } - // if (params.search==='') params.search = null - function getFilterCount() { let count = 0 if (params?.keywords_json) count++ diff --git a/frontend/components/organisation/tabs/OrganisationTabItems.tsx b/frontend/components/organisation/tabs/OrganisationTabItems.tsx index 85504e0bf..3590e6d88 100644 --- a/frontend/components/organisation/tabs/OrganisationTabItems.tsx +++ b/frontend/components/organisation/tabs/OrganisationTabItems.tsx @@ -3,6 +3,7 @@ // // SPDX-License-Identifier: Apache-2.0 +import React from 'react' import InfoIcon from '@mui/icons-material/Info' import TerminalIcon from '@mui/icons-material/Terminal' import AccountTreeIcon from '@mui/icons-material/AccountTree' @@ -12,6 +13,7 @@ import StyleOutlinedIcon from '@mui/icons-material/StyleOutlined' import {OrganisationForOverview} from '~/types/Organisation' + type IsVisibleProps = Partial & { isMaintainer: boolean } @@ -19,7 +21,7 @@ type IsVisibleProps = Partial & { export type OrganisationTabItemProps = { id: string, label: (props:any)=>string, - icon: JSX.Element, + icon: React.JSX.Element, isVisible: (props: IsVisibleProps) => boolean } diff --git a/frontend/components/organisation/units/ResearchUnitItem.tsx b/frontend/components/organisation/units/ResearchUnitItem.tsx index 99edcbb02..09a30b883 100644 --- a/frontend/components/organisation/units/ResearchUnitItem.tsx +++ b/frontend/components/organisation/units/ResearchUnitItem.tsx @@ -41,7 +41,6 @@ export default function UnitItem({pos,slug,name,website,logo_id,isMaintainer,onE slug ) } - const rsdUrl = `${baseUrl[0]}/${slug}` // console.group('UnitItem') // console.log('isMaintainer...', isMaintainer) diff --git a/frontend/components/projects/edit/EditProjectNav.tsx b/frontend/components/projects/edit/EditProjectNav.tsx index 6837f5fc4..8af05e642 100644 --- a/frontend/components/projects/edit/EditProjectNav.tsx +++ b/frontend/components/projects/edit/EditProjectNav.tsx @@ -1,6 +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 Dusan Mijatovic (dv4all) (dv4all) +// SPDX-FileCopyrightText: 2023 Netherlands eScience Center // // SPDX-License-Identifier: Apache-2.0 @@ -24,7 +26,7 @@ export default function EditProjectNav({slug,pageId}:{slug:string,pageId:string} { const location = `/projects/${slug}/edit/${item.id}` router.push(location) diff --git a/frontend/components/projects/edit/editProjectPages.tsx b/frontend/components/projects/edit/editProjectPages.tsx index 556b821d0..800e37e00 100644 --- a/frontend/components/projects/edit/editProjectPages.tsx +++ b/frontend/components/projects/edit/editProjectPages.tsx @@ -1,8 +1,11 @@ // SPDX-FileCopyrightText: 2022 - 2023 Dusan Mijatovic (dv4all) // SPDX-FileCopyrightText: 2022 - 2023 dv4all +// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (Netherlands eScience Center) +// SPDX-FileCopyrightText: 2023 Netherlands eScience Center // // SPDX-License-Identifier: Apache-2.0 +import React from 'react' import dynamic from 'next/dynamic' import InfoIcon from '@mui/icons-material/Info' @@ -14,6 +17,7 @@ import ShareIcon from '@mui/icons-material/Share' import PersonAddIcon from '@mui/icons-material/PersonAdd' import ContentLoader from '~/components/layout/ContentLoader' + // import ProjectInformation from './information' // import ProjectTeam from './team' // import ProjectOrganisations from './organisations' @@ -49,8 +53,8 @@ export type EditProjectPageProps = { id: string, status: string, label: string, - icon: JSX.Element, - render: () => JSX.Element + icon: React.JSX.Element, + render: () => React.JSX.Element } export const editProjectPage: EditProjectPageProps[] = [ diff --git a/frontend/components/projects/edit/information/AutosaveProjectLinks.tsx b/frontend/components/projects/edit/information/AutosaveProjectLinks.tsx index e81a4c201..67172ef29 100644 --- a/frontend/components/projects/edit/information/AutosaveProjectLinks.tsx +++ b/frontend/components/projects/edit/information/AutosaveProjectLinks.tsx @@ -1,5 +1,7 @@ // SPDX-FileCopyrightText: 2022 - 2023 Dusan Mijatovic (dv4all) // SPDX-FileCopyrightText: 2022 - 2023 dv4all +// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (Netherlands eScience Center) +// SPDX-FileCopyrightText: 2023 Netherlands eScience Center // // SPDX-License-Identifier: Apache-2.0 @@ -90,16 +92,17 @@ export default function AutosaveProjectLinks({project_id, url_for_project}: Proj async function sortedLinks(newList: ProjectLink[]) { // patch only if there are items left if (newList.length > 0) { + const orgLinks = [...links] setLinks(newList) const resp = await patchProjectLinkPositions({ links:newList, token }) if (resp.status !== 200) { - // revert back - setLinks(links) // show error message showErrorMessage(`Failed to update project link positions. ${resp.message}`) + // revert back + setLinks(orgLinks) } } else { // reset links diff --git a/frontend/components/projects/edit/information/useResearchDomains.tsx b/frontend/components/projects/edit/information/useResearchDomains.tsx index 1cea2a4de..f33822d53 100644 --- a/frontend/components/projects/edit/information/useResearchDomains.tsx +++ b/frontend/components/projects/edit/information/useResearchDomains.tsx @@ -1,5 +1,7 @@ // SPDX-FileCopyrightText: 2022 Dusan Mijatovic (dv4all) // SPDX-FileCopyrightText: 2022 dv4all +// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (Netherlands eScience Center) +// SPDX-FileCopyrightText: 2023 Netherlands eScience Center // // SPDX-License-Identifier: Apache-2.0 @@ -75,7 +77,7 @@ export default function useResearchDomains({l1Selected, l2Selected}: UseResearch if (abort === false) { getResearchDomains() } - ()=>{abort=true} + return ()=>{abort=true} },[]) useEffect(() => { diff --git a/frontend/components/projects/overview/cards/ProjectCardContent.tsx b/frontend/components/projects/overview/cards/ProjectCardContent.tsx index 6465b7b01..f31149cab 100644 --- a/frontend/components/projects/overview/cards/ProjectCardContent.tsx +++ b/frontend/components/projects/overview/cards/ProjectCardContent.tsx @@ -38,7 +38,7 @@ type ProjectCardProps = { } export default function ProjectCardContent(item:ProjectCardProps){ - {/* Card content */} + return (
- {impact_cnt || 0} + {impact_cnt ?? 0}
- {output_cnt || 0} + {output_cnt ?? 0}
diff --git a/frontend/components/projects/overview/cards/ProjectOverviewGrid.tsx b/frontend/components/projects/overview/cards/ProjectOverviewGrid.tsx index d1d390b36..1897d5306 100644 --- a/frontend/components/projects/overview/cards/ProjectOverviewGrid.tsx +++ b/frontend/components/projects/overview/cards/ProjectOverviewGrid.tsx @@ -6,7 +6,9 @@ // // SPDX-License-Identifier: Apache-2.0 -export default function ProjectOverviewGrid({children}: { children: JSX.Element | JSX.Element[] }) { +import React from 'react' + +export default function ProjectOverviewGrid({children}: { children: React.JSX.Element | React.JSX.Element[] }) { // console.log('ProjectOverviewGrid') return (
-// SPDX-FileCopyrightText: 2022 Netherlands eScience Center // SPDX-FileCopyrightText: 2023 Christian Meeßen (GFZ) +// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (Netherlands eScience Center) // SPDX-FileCopyrightText: 2023 Dusan Mijatovic (dv4all) (dv4all) // SPDX-FileCopyrightText: 2023 Helmholtz Centre Potsdam - GFZ German Research Centre for Geosciences // @@ -29,12 +30,12 @@ function calculateStats(languages: ProgramingLanguages) { let total = 0, totPct=0, totVal=0, totLang=[] // calculate total - keys.map((key) => { + keys.forEach((key) => { total+=languages[key] }) // calculate stats const stats: {language: string, val: number, pct: number}[] = [] - keys.map(key => { + keys.forEach(key => { const pct = Math.round((languages[key] / total) * 100) if (pct > 0) { totPct += pct diff --git a/frontend/components/software/edit/EditSoftwareNav.tsx b/frontend/components/software/edit/EditSoftwareNav.tsx index c5c3e6ccf..918b3e4ee 100644 --- a/frontend/components/software/edit/EditSoftwareNav.tsx +++ b/frontend/components/software/edit/EditSoftwareNav.tsx @@ -1,6 +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 Dusan Mijatovic (dv4all) (dv4all) +// SPDX-FileCopyrightText: 2023 Netherlands eScience Center // // SPDX-License-Identifier: Apache-2.0 @@ -25,7 +27,7 @@ export default function EditSoftwareNav({slug,pageId}:{slug:string,pageId:string { const location = `/software/${slug}/edit/${item.id}` router.push(location) diff --git a/frontend/components/software/edit/editSoftwarePages.tsx b/frontend/components/software/edit/editSoftwarePages.tsx index e5df39dbb..9ada026e5 100644 --- a/frontend/components/software/edit/editSoftwarePages.tsx +++ b/frontend/components/software/edit/editSoftwarePages.tsx @@ -1,8 +1,11 @@ // SPDX-FileCopyrightText: 2022 - 2023 Dusan Mijatovic (dv4all) // SPDX-FileCopyrightText: 2022 - 2023 dv4all +// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (Netherlands eScience Center) +// SPDX-FileCopyrightText: 2023 Netherlands eScience Center // // SPDX-License-Identifier: Apache-2.0 +import React from 'react' import dynamic from 'next/dynamic' import InfoIcon from '@mui/icons-material/Info' @@ -53,8 +56,8 @@ export type EditSoftwarePageProps = { id: string status: string, label: string, - icon: JSX.Element, - render: () => JSX.Element + icon: React.JSX.Element, + render: () => React.JSX.Element } export const editSoftwarePage:EditSoftwarePageProps[] = [{ diff --git a/frontend/components/software/edit/organisations/organisationForSoftware.test.ts b/frontend/components/software/edit/organisations/organisationForSoftware.test.ts index a3503ef78..c795590d5 100644 --- a/frontend/components/software/edit/organisations/organisationForSoftware.test.ts +++ b/frontend/components/software/edit/organisations/organisationForSoftware.test.ts @@ -1,4 +1,6 @@ +// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (Netherlands eScience Center) // SPDX-FileCopyrightText: 2023 Dusan Mijatovic (dv4all) (dv4all) +// SPDX-FileCopyrightText: 2023 Netherlands eScience Center // SPDX-FileCopyrightText: 2023 dv4all // // SPDX-License-Identifier: Apache-2.0 @@ -75,7 +77,7 @@ it('patchOrganisationPositions', async () => { } // resolve addOrganisationToSoftware - organisationOfSoftware.map(item => { + organisationOfSoftware.forEach(item => { // resove OK for all items to patch mockResolvedValueOnce('OK') }) diff --git a/frontend/components/software/edit/testimonials/SortableTestimonialList.tsx b/frontend/components/software/edit/testimonials/SortableTestimonialList.tsx index 79842d961..73e80d37f 100644 --- a/frontend/components/software/edit/testimonials/SortableTestimonialList.tsx +++ b/frontend/components/software/edit/testimonials/SortableTestimonialList.tsx @@ -1,5 +1,7 @@ // SPDX-FileCopyrightText: 2022 Dusan Mijatovic (dv4all) // SPDX-FileCopyrightText: 2022 dv4all +// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (Netherlands eScience Center) +// SPDX-FileCopyrightText: 2023 Netherlands eScience Center // // SPDX-License-Identifier: Apache-2.0 @@ -30,7 +32,7 @@ export default function SortableTestimonialList({items, onEdit, onDelete, onSort * rendering of custom sortable items * @param item * @param index - * @returns JSX.Element + * @returns React.JSX.Element */ function renderListItem(item:Testimonial,index?:number) { return ( diff --git a/frontend/components/software/overview/SoftwareOverviewContent.tsx b/frontend/components/software/overview/SoftwareOverviewContent.tsx index 8dcde33df..7b9349fe2 100644 --- a/frontend/components/software/overview/SoftwareOverviewContent.tsx +++ b/frontend/components/software/overview/SoftwareOverviewContent.tsx @@ -33,8 +33,8 @@ export default function SoftwareOverviewContent({layout, software}: SoftwareOver // Masonry layout (software only) return ( - {software.map((item, index) => ( -
+ {software.map((item) => ( +
))} diff --git a/frontend/components/software/overview/cards/ProgrammingLanguageList.tsx b/frontend/components/software/overview/cards/ProgrammingLanguageList.tsx index 999c47d57..80f836566 100644 --- a/frontend/components/software/overview/cards/ProgrammingLanguageList.tsx +++ b/frontend/components/software/overview/cards/ProgrammingLanguageList.tsx @@ -18,7 +18,7 @@ export default function ProgrammingLanguageList({ {// limits the keywords to 'visibleNumberOfProgLang' per software. prog_lang?.slice(0, visibleNumberOfProgLang) .map((lang:string, index: number) => ( -
  • {lang}
  • +
  • {lang}
  • ))} { // Show the number of keywords that are not visible. (prog_lang?.length > 0) diff --git a/frontend/components/software/overview/cards/SoftwareCardContent.tsx b/frontend/components/software/overview/cards/SoftwareCardContent.tsx index e8db0ccc8..8818965ff 100644 --- a/frontend/components/software/overview/cards/SoftwareCardContent.tsx +++ b/frontend/components/software/overview/cards/SoftwareCardContent.tsx @@ -25,7 +25,7 @@ type SoftwareCardContentProps = { } export default function SoftwareCardContent(item:SoftwareCardContentProps) { - {/* Card content */} + return (
    - {contributor_cnt || 0} + {contributor_cnt ?? 0}
    - {mention_cnt || 0} + {mention_cnt ?? 0}
    {/* TODO Add download counts to the cards */} diff --git a/frontend/components/software/overview/cards/SoftwareOverviewGrid.tsx b/frontend/components/software/overview/cards/SoftwareOverviewGrid.tsx index 06a104f3b..bafa7bc78 100644 --- a/frontend/components/software/overview/cards/SoftwareOverviewGrid.tsx +++ b/frontend/components/software/overview/cards/SoftwareOverviewGrid.tsx @@ -6,7 +6,9 @@ // // SPDX-License-Identifier: Apache-2.0 -export default function SoftwareOverviewGrid({children}: { children: JSX.Element | JSX.Element[] }) { +import React from 'react' + +export default function SoftwareOverviewGrid({children}: { children: React.JSX.Element | React.JSX.Element[] }) { return (
    { useEffect(() => { const calculateDistance = () => { const rect = divRef.current?.getBoundingClientRect() - setDistance(Math.ceil(rect?.left || 0) + 16) + setDistance(Math.ceil(rect?.left ?? 0) + 16) } if (typeof window !== 'undefined') { calculateDistance() diff --git a/frontend/components/software/overview/list/OverviewListItem.tsx b/frontend/components/software/overview/list/OverviewListItem.tsx index 1acec174f..9c9f2b743 100644 --- a/frontend/components/software/overview/list/OverviewListItem.tsx +++ b/frontend/components/software/overview/list/OverviewListItem.tsx @@ -3,8 +3,10 @@ // // SPDX-License-Identifier: Apache-2.0 +import React from 'react' + type OverviewListItemProps = { - children: JSX.Element | JSX.Element[], + children: React.JSX.Element | React.JSX.Element[], className?: string } diff --git a/frontend/components/software/overview/list/SoftwareListItemContent.tsx b/frontend/components/software/overview/list/SoftwareListItemContent.tsx index c3cd5009f..993b066e2 100644 --- a/frontend/components/software/overview/list/SoftwareListItemContent.tsx +++ b/frontend/components/software/overview/list/SoftwareListItemContent.tsx @@ -3,6 +3,7 @@ // // SPDX-License-Identifier: Apache-2.0 +import React from 'react' import {getImageUrl} from '~/utils/editImage' import useValidateImageSrc from '~/utils/useValidateImageSrc' import SoftwareMetrics from '../cards/SoftwareMetrics' @@ -21,7 +22,7 @@ type SoftwareOverviewListItemProps = { // prog_lang: string[], // licenses: string, downloads?: number - statusBanner?: JSX.Element + statusBanner?: React.JSX.Element } export default function SoftwareListItemContent(item:SoftwareOverviewListItemProps) { diff --git a/frontend/components/software/overview/list/SoftwareOverviewList.tsx b/frontend/components/software/overview/list/SoftwareOverviewList.tsx index 5aac5e711..a56004ab5 100644 --- a/frontend/components/software/overview/list/SoftwareOverviewList.tsx +++ b/frontend/components/software/overview/list/SoftwareOverviewList.tsx @@ -6,7 +6,9 @@ // // SPDX-License-Identifier: Apache-2.0 -export default function SoftwareOverviewList({children}: { children: JSX.Element | JSX.Element[] }) { +import React from 'react' + +export default function SoftwareOverviewList({children}: { children: React.JSX.Element | React.JSX.Element[] }) { return (
    = { sx?: SxProps order?: OrderProps patchFn?: (props: UpdateProps) => Promise<{ status: number, message: string }> - renderFn?: (data:T) => JSX.Element + renderFn?: (data:T) => React.JSX.Element } export type OrderByProps = { diff --git a/frontend/components/user/UserNavItems.tsx b/frontend/components/user/UserNavItems.tsx index 5d3f51b60..a3f25d985 100644 --- a/frontend/components/user/UserNavItems.tsx +++ b/frontend/components/user/UserNavItems.tsx @@ -3,10 +3,12 @@ // SPDX-FileCopyrightText: 2022 - 2023 Netherlands eScience Center // SPDX-FileCopyrightText: 2022 - 2023 dv4all // SPDX-FileCopyrightText: 2023 Christian Meeßen (GFZ) +// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (Netherlands eScience Center) // SPDX-FileCopyrightText: 2023 Helmholtz Centre Potsdam - GFZ German Research Centre for Geosciences // // SPDX-License-Identifier: Apache-2.0 +import React from 'react' import dynamic from 'next/dynamic' import TerminalIcon from '@mui/icons-material/Terminal' @@ -42,8 +44,8 @@ export type UserMenuProps = { id: string, status: string, label: (props:any)=>string, - icon: JSX.Element, - component: (props: any) => JSX.Element + icon: React.JSX.Element, + component: (props: any) => React.JSX.Element showSearch: boolean } diff --git a/frontend/components/user/project-quality/SortableTable.tsx b/frontend/components/user/project-quality/SortableTable.tsx index 9478756a5..f6ed3a870 100644 --- a/frontend/components/user/project-quality/SortableTable.tsx +++ b/frontend/components/user/project-quality/SortableTable.tsx @@ -1,3 +1,4 @@ +// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (Netherlands eScience Center) // SPDX-FileCopyrightText: 2023 Dusan Mijatovic (dv4all) // SPDX-FileCopyrightText: 2023 Ewan Cahen (Netherlands eScience Center) // SPDX-FileCopyrightText: 2023 Netherlands eScience Center @@ -123,9 +124,7 @@ export default function SortableTable({metadata, initialData, initialOrder=''}: else nowAscending = !ascending const type = properties.type - // if (type === 'link') { - // // data.sort((a, b) => nowAscending ? a[label]['text'].localeCompare(b[label]['text']) : b[label]['text'].localeCompare(a[label]['text'])) - // } else + // update sort in existing data object if (type === 'boolean' || type === 'number' || type === 'pct') { data.sort((a, b) => nowAscending ? a[label] - b[label] : b[label] - a[label]) } else { @@ -133,7 +132,6 @@ export default function SortableTable({metadata, initialData, initialOrder=''}: } setAscending(nowAscending) setSortColumn(label) - setData(data) } function compareStringNullsAware(s1: string | null, s2: string | null, ascending: boolean): number { diff --git a/frontend/config/menuItems.ts b/frontend/config/menuItems.ts index 3d874ba88..95aaf511d 100644 --- a/frontend/config/menuItems.ts +++ b/frontend/config/menuItems.ts @@ -7,6 +7,8 @@ // // SPDX-License-Identifier: Apache-2.0 +import React from 'react' + export type MenuItemType = { type?: 'link' | 'function' |'divider' label: string, @@ -16,7 +18,7 @@ export type MenuItemType = { match?: string, // used to customize menu items per user/profile active?: boolean - icon?: JSX.Element, + icon?: React.JSX.Element, // optional, but fn is provided it will have higher priority // than path fn?: Function, diff --git a/frontend/pages/organisations/[...slug].tsx b/frontend/pages/organisations/[...slug].tsx index f5306437c..28990363d 100644 --- a/frontend/pages/organisations/[...slug].tsx +++ b/frontend/pages/organisations/[...slug].tsx @@ -9,7 +9,6 @@ import {GetServerSidePropsContext} from 'next/types' import {app} from '~/config/app' import {getUserFromToken} from '~/auth' -import {isOrganisationMaintainer} from '~/auth/permissions/useOrganisationMaintainer' import {getOrganisationMetadata, RORItem} from '~/utils/getROR' import {getUserSettings} from '~/utils/userSettings' import {OrganisationForOverview} from '~/types/Organisation' diff --git a/frontend/pages/software/index.tsx b/frontend/pages/software/index.tsx index c1f2fff29..25a31a112 100644 --- a/frontend/pages/software/index.tsx +++ b/frontend/pages/software/index.tsx @@ -107,7 +107,6 @@ export default function SoftwareOverviewPage({ function getFilterCount() { let count = 0 - // if (order) count++ if (keywords) count++ if (prog_lang) count++ if (licenses) count++ diff --git a/frontend/pages/user/[section].tsx b/frontend/pages/user/[section].tsx index 9f6ac6272..ccbab75ea 100644 --- a/frontend/pages/user/[section].tsx +++ b/frontend/pages/user/[section].tsx @@ -2,7 +2,9 @@ // SPDX-FileCopyrightText: 2022 Dusan Mijatovic (dv4all) // SPDX-FileCopyrightText: 2022 Helmholtz Centre Potsdam - GFZ German Research Centre for Geosciences // SPDX-FileCopyrightText: 2022 Matthias Rüster (GFZ) +// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (Netherlands eScience Center) // SPDX-FileCopyrightText: 2023 Dusan Mijatovic (dv4all) (dv4all) +// SPDX-FileCopyrightText: 2023 Netherlands eScience Center // // SPDX-License-Identifier: Apache-2.0 @@ -42,7 +44,7 @@ export default function UserPages({section,counts}:UserPagesProps) { if (newSection && abort===false) { setPageSection(userMenu[section]) } - ()=>{abort=true} + return ()=>{abort=true} },[section]) function renderStepComponent() { diff --git a/frontend/utils/getSlugFromString.ts b/frontend/utils/getSlugFromString.ts index f9433771b..c980e3922 100644 --- a/frontend/utils/getSlugFromString.ts +++ b/frontend/utils/getSlugFromString.ts @@ -24,6 +24,6 @@ export function getSlugFromString(title: string, separator:string='-') { .replace(/[^a-z0-9\- ]/g, '') .trim() .replace(/[-\s]+/g, separator) - // remove first and last - - .replace(/^-+|-+$/g, '') + // remove first and last - exclude from sonar analyses - TEST + .replace(/^-+|-+$/g, '') // NOSONAR } diff --git a/frontend/utils/jest/WithAppContext.tsx b/frontend/utils/jest/WithAppContext.tsx index 911f7b193..0d66c1fbb 100644 --- a/frontend/utils/jest/WithAppContext.tsx +++ b/frontend/utils/jest/WithAppContext.tsx @@ -1,5 +1,7 @@ // SPDX-FileCopyrightText: 2022 Dusan Mijatovic (dv4all) // SPDX-FileCopyrightText: 2022 dv4all +// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (Netherlands eScience Center) +// SPDX-FileCopyrightText: 2023 Netherlands eScience Center // // SPDX-License-Identifier: Apache-2.0 @@ -39,7 +41,7 @@ export const mockSession:Session = { * Wraps the component with main app contexts: ThemeProvider, AuthProvider and RsdSettingsProvider * Component is provided as children * @param children, options - * @returns JSX.Element + * @returns React.JSX.Element */ export function WithAppContext({children,options}:WithAppContextProps) { const session = options?.session ?? defaultSession diff --git a/frontend/utils/jest/WithFormContext.tsx b/frontend/utils/jest/WithFormContext.tsx index 92f5e6eeb..f1ffe9649 100644 --- a/frontend/utils/jest/WithFormContext.tsx +++ b/frontend/utils/jest/WithFormContext.tsx @@ -1,6 +1,8 @@ // SPDX-FileCopyrightText: 2022 Dusan Mijatovic (dv4all) // SPDX-FileCopyrightText: 2022 Dusan Mijatovic (dv4all) (dv4all) // SPDX-FileCopyrightText: 2022 dv4all +// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (Netherlands eScience Center) +// SPDX-FileCopyrightText: 2023 Netherlands eScience Center // // SPDX-License-Identifier: Apache-2.0 @@ -18,7 +20,7 @@ type WithFormContextProps = { * Default mode is onChange (required for autosave feature). * Pass defaultValues if you need form to have some values present. * @param children, mode - * @returns JSX.Element + * @returns React.JSX.Element */ export function WithFormContext({children,mode='onChange',defaultValues}:WithFormContextProps) { const methods = useForm({ diff --git a/frontend/utils/postgrestUrl.ts b/frontend/utils/postgrestUrl.ts index d77fafab4..4f9f2d5b1 100644 --- a/frontend/utils/postgrestUrl.ts +++ b/frontend/utils/postgrestUrl.ts @@ -8,6 +8,7 @@ import {rowsPerPageOptions} from '~/config/pagination' import {encodeUrlQuery} from './extractQueryParam' +import {localeSort} from './sortFn' export type OrderByProps = { column: K, @@ -186,7 +187,7 @@ export function baseQueryString(props: baseQueryStringProps) { // and all keywords should be present (AND). // and it needs to be enclosed in {} uri encoded see // https://postgrest.org/en/v9.0/api.html?highlight=filter#calling-functions-with-array-parameters - const keywordsAll = keywords.sort().map((item: string) => `"${encodeURIComponent(item)}"`).join(',') + const keywordsAll = keywords.sort(localeSort).map((item: string) => `"${encodeURIComponent(item)}"`).join(',') // use cs. command to find query = `keywords=cs.%7B${keywordsAll}%7D` } @@ -195,7 +196,7 @@ export function baseQueryString(props: baseQueryStringProps) { typeof domains === 'object') { // sort and convert research domains array to comma separated string // we need to sort because search is on ARRAY field in pgSql - const domainsAll = domains.sort().map((item: string) => `"${encodeURIComponent(item)}"`).join(',') + const domainsAll = domains.sort(localeSort).map((item: string) => `"${encodeURIComponent(item)}"`).join(',') // use cs. command to find if (query) { query = `${query}&research_domain=cs.%7B${domainsAll}%7D` @@ -211,7 +212,7 @@ export function baseQueryString(props: baseQueryStringProps) { // and all prog_lang should be present (AND). // and it needs to be enclosed in {} uri encoded see // https://postgrest.org/en/v9.0/api.html?highlight=filter#calling-functions-with-array-parameters - const languagesAll = prog_lang.sort().map((item: string) => `"${encodeURIComponent(item)}"`).join(',') + const languagesAll = prog_lang.sort(localeSort).map((item: string) => `"${encodeURIComponent(item)}"`).join(',') // use cs. command to find if (query) { query = `${query}&prog_lang=cs.%7B${languagesAll}%7D` @@ -223,7 +224,7 @@ export function baseQueryString(props: baseQueryStringProps) { licenses !== null && typeof licenses === 'object') { // sort and convert array to comma separated string - const licensesAll = licenses.sort().map((item: string) => `"${encodeURIComponent(item)}"`).join(',') + const licensesAll = licenses.sort(localeSort).map((item: string) => `"${encodeURIComponent(item)}"`).join(',') // use cs. command to find if (query) { query = `${query}&licenses=cs.%7B${licensesAll}%7D` @@ -236,7 +237,7 @@ export function baseQueryString(props: baseQueryStringProps) { typeof organisations === 'object') { // sort and convert array to comma separated string // we need to sort because search is on ARRAY field in pgSql - const organisationsAll = organisations.sort().map((item: string) => `"${encodeURIComponent(item)}"`).join(',') + const organisationsAll = organisations.sort(localeSort).map((item: string) => `"${encodeURIComponent(item)}"`).join(',') // use cs. command to find if (query) { query = `${query}&participating_organisations=cs.%7B${organisationsAll}%7D` diff --git a/frontend/utils/sortFn.ts b/frontend/utils/sortFn.ts index 0c986d399..277f57ac4 100644 --- a/frontend/utils/sortFn.ts +++ b/frontend/utils/sortFn.ts @@ -1,5 +1,7 @@ // SPDX-FileCopyrightText: 2022 - 2023 Dusan Mijatovic (dv4all) // SPDX-FileCopyrightText: 2022 - 2023 dv4all +// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (Netherlands eScience Center) +// SPDX-FileCopyrightText: 2023 Netherlands eScience Center // // SPDX-License-Identifier: Apache-2.0 @@ -14,7 +16,7 @@ export function sortOnStrProp(itemA: any, itemB: any, prop: string, sortDir: 'as // ignore case const nameA = itemA[prop].toUpperCase() const nameB = itemB[prop].toUpperCase() - return sortItems(nameA,nameB,sortDir) + return localeSort(nameA,nameB,sortDir) } catch (e: any) { // on error we log and return neutral score logger(`sortOnStrProp failed. Error: ${e.message}`) @@ -35,6 +37,12 @@ export function sortOnNumProp(itemA: any, itemB: any, prop: string, sortDir: 'as return sortItems(valA,valB,sortDir) } +export function localeSort(a: string, b: string, sortDir: 'asc' | 'desc' = 'asc') { + if (sortDir === 'desc') return b.localeCompare(a) + // default is ascending + return a.localeCompare(b) +} + function sortItems(valA: any, valB: any, sortDir: 'asc' | 'desc' = 'asc'){ if (valA < valB) { if (sortDir === 'asc'){