Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: implement sonar suggestions in admin, projects, software, u… #969

Merged
merged 1 commit into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions frontend/auth/RsdAdminContent.tsx
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion frontend/auth/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
1 change: 0 additions & 1 deletion frontend/auth/permissions/useOrganisationMaintainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ export default function useOrganisationMaintainer({organisation}: UseOrganisatio
} else {
logger('useOrganisationMaintainer...organisation UNDEFINED', 'warn')
setIsMaintainer(false)
// if (loading) setLoading(false)
}
}
if (organisation &&
Expand Down
4 changes: 2 additions & 2 deletions frontend/components/AppHeader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export default function AppHeader() {
{menuItems.map(item => {
const isActive = isActiveMenuItem({item, activePath})
return (
<Link key={item.path} href={item.path || ''} className={`${isActive ? 'nav-active' : ''}`}>
<Link key={item.path} href={item.path ?? ''} className={`${isActive ? 'nav-active' : ''}`}>
{item.label}
</Link>
)
Expand Down Expand Up @@ -137,7 +137,7 @@ export default function AppHeader() {
const isActive = isActiveMenuItem({item, activePath})
return (
<MenuItem onClick={handleCloseResponsiveMenu} key={item.path}>
<Link href={item.path || ''} className={`${isActive ? 'nav-active' : ''}`}>
<Link href={item.path ?? ''} className={`${isActive ? 'nav-active' : ''}`}>
{item.label}
</Link>
</MenuItem>
Expand Down
4 changes: 3 additions & 1 deletion frontend/components/GoBackLink.tsx
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -14,7 +16,7 @@ export const GoBackLink = (props: Props) => {
const router = useRouter()
return (
<a className={props.className} onClick={() => router.back()}>
{props.text || 'Go back'}
{props.text ?? 'Go back'}
</a>
)
}
2 changes: 1 addition & 1 deletion frontend/components/admin/AdminNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export default function AdminNav() {
<ListItemButton
data-testid="admin-nav-item"
key={`step-${pos}`}
selected={item.path === router.route ?? false}
selected={item.path === router.route}
onClick={() => router.push(item.path)}
>
<ListItemIcon>
Expand Down
4 changes: 3 additions & 1 deletion frontend/components/admin/pages/edit/SortableNav.tsx
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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 (
Expand Down
7 changes: 5 additions & 2 deletions frontend/components/admin/pages/edit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,19 @@ export default function EditMarkdownPages({links}:{links:RsdLink[]}) {
}

async function patchPositions(newList: RsdLink[]) {
const orgItems = [
...navItems
]
// update ui first
setNavItems(newList)
const resp = await updatePagePositions({
items: newList,
token:session.token
})
if (resp.status !== 200) {
// revert back
setNavItems(navItems)
showErrorMessage(`Failed to update page positions. ${resp?.message}`)
// revert back
setNavItems(orgItems)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -51,6 +53,7 @@ export function useContributors({token, orderBy}:useContributorsProps) {

if (abort === false) {
if (orderBy) {
// update columns order
columns.forEach(col => {
if (col.key === orderBy.column) {
col.order = {
Expand All @@ -64,8 +67,6 @@ export function useContributors({token, orderBy}:useContributorsProps) {
}
}
})
// update columns order
setColumns(columns)
}
setContributors(contributors)
setCount(count)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export default function AddSoftwareHighlights({onAddSoftware,highlights}:AddSoft
}

function onAdd(selected:AutocompleteOption<SoftwareOverviewItemProps>) {
if (selected && selected.data) {
if (selected?.data) {
onAddSoftware(selected.data.id)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<ListItem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ export function useSoftwareHighlights(token: string) {
}

async function sortHighlights(items: SoftwareHighlight[]) {
const orgItems = [
...highlights
]
// visually confirm position change
setHighlights(items)
// make all request
Expand All @@ -106,7 +109,7 @@ export function useSoftwareHighlights(token: string) {
if (resp.status !== 200) {
showErrorMessage(`Failed to sort highlight. ${resp.message}`)
// revert back in case of error
setHighlights(highlights)
setHighlights(orgItems)
}
}

Expand Down
4 changes: 3 additions & 1 deletion frontend/components/cards/CardContentFrame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
//
// SPDX-License-Identifier: Apache-2.0

export default function CardContentFrame({children}:{children:JSX.Element[]}) {
import React from 'react'

export default function CardContentFrame({children}:{children:React.JSX.Element[]}) {
return (
<div className="h-[63%] flex flex-col p-4 relative">
{children}
Expand Down
4 changes: 3 additions & 1 deletion frontend/components/cards/CardImageFrame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<div className="h-[37%] flex overflow-hidden relative bg-base-100">
{children}
Expand Down
4 changes: 2 additions & 2 deletions frontend/components/cards/KeywordList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ export default function KeywordList({keywords=[], visibleNumberOfKeywords = 3}:
<ul className="flex flex-wrap items-start gap-2 text-base-content text-xs">
{// limits the keywords to 'visibleNumberOfKeywords' per software.
keywords?.slice(0, visibleNumberOfKeywords)
.map((keyword:string, index: number) => (
.map((keyword:string) => (
<li
title={keyword}
key={index}
key={keyword}
className="bg-base-200 px-2 py-1 rounded capitalize line-clamp-1"
>{keyword}</li>
))}
Expand Down
3 changes: 2 additions & 1 deletion frontend/components/form/ControlledTextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -24,7 +25,7 @@ export type ControlledTextFieldOptions<T> = {
variant?: 'outlined'|'standard'
useNull?: boolean,
defaultValue?: string | number | null
helperTextMessage?: string | JSX.Element
helperTextMessage?: string | React.JSX.Element
helperTextCnt?: string
disabled?: boolean
muiProps?: TextFieldProps
Expand Down
7 changes: 5 additions & 2 deletions frontend/components/form/HelperTextWithCounter.tsx
Original file line number Diff line number Diff line change
@@ -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) <[email protected]>
// 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 (
<>
<span className="mr-2">{message}</span>
Expand Down
5 changes: 4 additions & 1 deletion frontend/components/layout/ConfirmDeleteModal.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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
}
Expand Down
4 changes: 3 additions & 1 deletion frontend/components/layout/ContentContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 5 additions & 1 deletion frontend/components/layout/SortableList.tsx
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -19,7 +23,7 @@ export type RequiredListProps = {
type SortableListProps<T extends RequiredListProps>={
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<T extends RequiredListProps>({
Expand Down
5 changes: 4 additions & 1 deletion frontend/components/mention/editMentionContext.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/menu/IconBtnMenuOnAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export type IconBtnMenuOption<T> = {
type: 'divider' | 'action'
key: string,
label: string,
icon?: JSX.Element,
icon?: React.JSX.Element,
action: T
disabled?: boolean,
}
Expand Down
5 changes: 2 additions & 3 deletions frontend/components/organisation/apiOrganisations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion frontend/components/organisation/metadata/Links.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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[]}) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export default function OrgProjectFilters() {
// debugger
function clearDisabled() {
if (filterCnt && filterCnt > 0) return false
// if (order) return false
return true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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++
Expand Down
Loading