Skip to content

Commit

Permalink
Merge pull request #929 from research-software-directory/rsd-v2-relea…
Browse files Browse the repository at this point in the history
…se-cleanup

Fix and cleanup rsd-v2-release
  • Loading branch information
dmijatovic authored Jul 7, 2023
2 parents ca50ffd + ad25605 commit f402d4b
Show file tree
Hide file tree
Showing 68 changed files with 650 additions and 620 deletions.
5 changes: 3 additions & 2 deletions database/112-organisation-views.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ CREATE FUNCTION projects_by_organisation(organisation_id UUID) RETURNS TABLE (
output_cnt INTEGER
) LANGUAGE sql STABLE AS
$$
SELECT
SELECT DISTINCT ON (project.id)
project.id,
project.slug,
project.title,
Expand Down Expand Up @@ -89,7 +89,7 @@ CREATE FUNCTION projects_by_organisation_search(
output_cnt INTEGER
) LANGUAGE sql STABLE AS
$$
SELECT
SELECT DISTINCT ON (project.id)
project.id,
project.slug,
project.title,
Expand Down Expand Up @@ -136,6 +136,7 @@ WHERE
research_domain_filter_for_project.research_domain_text ILIKE CONCAT('%', search, '%')
)
ORDER BY
project.id,
CASE
WHEN title ILIKE search THEN 0
WHEN title ILIKE CONCAT(search, '%') THEN 1
Expand Down
33 changes: 33 additions & 0 deletions frontend/.unimportedrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"ignorePatterns": [
"**/node_modules/**",
"**/*.tests.{js,jsx,ts,tsx}",
"**/*.test.{js,jsx,ts,tsx}",
"**/*.spec.{js,jsx,ts,tsx}",
"**/tests/**",
"**/__tests__/**",
"**/*.d.ts",
"**/coverage/**",
"**/__mocks__/**",
"utils/jest/**"
],
"ignoreUnimported": [
"jest.config.js",
"jest.setup.js",
"next.config.js",
"next.headers.js",
"next.rewrites.js",
"postcss.config.js",
"tailwind.config.js"
],
"ignoreUnused": [
"next",
"react",
"react-dom",
"@tailwindcss/typography",
"sharp"
],
"ignoreUnresolved": [
"pages/api/fe/auth"
]
}
4 changes: 4 additions & 0 deletions frontend/.unimportedrc.json.license
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SPDX-FileCopyrightText: 2023 Dusan Mijatovic (Netherlands eScience Center)
SPDX-FileCopyrightText: 2023 Netherlands eScience Center

SPDX-License-Identifier: Apache-2.0
95 changes: 85 additions & 10 deletions frontend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ SPDX-FileCopyrightText: 2021 - 2023 Dusan Mijatovic (dv4all)
SPDX-FileCopyrightText: 2021 - 2023 dv4all
SPDX-FileCopyrightText: 2022 Christian Meeßen (GFZ) <[email protected]>
SPDX-FileCopyrightText: 2022 Helmholtz Centre Potsdam - GFZ German Research Centre for Geosciences
SPDX-FileCopyrightText: 2023 Dusan Mijatovic (Netherlands eScience Center)
SPDX-FileCopyrightText: 2023 Ewan Cahen (Netherlands eScience Center) <[email protected]>
SPDX-FileCopyrightText: 2023 Netherlands eScience Center
Expand Down Expand Up @@ -151,15 +152,7 @@ import "@testing-library/jest-dom/extend-expect";

This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `pages/index.tsx`. The page auto-updates as you edit the file.

[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.ts`.

The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages.

## Learn More
### Learn More

To learn more about Next.js, take a look at the following resources:

Expand All @@ -168,7 +161,7 @@ To learn more about Next.js, take a look at the following resources:

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!

## Major version updates
## Updates and upgrades

Upgrading minor version changes can be usally done using `yarn outdated` and `yarn upgrade`. Major updates are more demanding and might require changes in the source code.

Expand Down Expand Up @@ -205,3 +198,85 @@ yarn add cookie
# type
yarn add -D @types/cookie
```

## Maintenance

For the maintenance we use [unimported](https://github.com/smeijer/unimported#readme). It will show a list of unused files and dependencies. Additional exclude definitions, specific to this project, are in `unimportedrc.json`. Unimported is able to identify next and use pages folder as entry points.

```bash
# execute in the frontend folder
yarn unimported
```

- Removing unused files:
Based on report validate that file are unused/not needed. To validate always run `yarn test` and `yarn build` to confirm that test are working and application can be build

- Example report

```bash
RSD-as-a-service/frontend$ npx unimported

summary unimported v1.29.2 (next)
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
entry file 1 : ./pages/_app.tsx
entry file 2 : ./pages/_document.tsx
entry file 3 : ./pages/admin/keywords.tsx
entry file 4 : ./pages/admin/orcid-users.tsx
entry file 5 : ./pages/admin/organisations.tsx
entry file 6 : ./pages/admin/public-pages.tsx
entry file 7 : ./pages/admin/rsd-contributors.tsx
entry file 8 : ./pages/admin/rsd-users.tsx
entry file 9 : ./pages/admin/software-highlights.tsx
entry file 10 : ./pages/api/fe/auth/helmholtzaai.ts
entry file 11 : ./pages/api/fe/auth/index.ts
entry file 12 : ./pages/api/fe/auth/local.ts
entry file 13 : ./pages/api/fe/auth/orcid.ts
entry file 14 : ./pages/api/fe/auth/surfconext.ts
entry file 15 : ./pages/api/fe/cite/index.ts
entry file 16 : ./pages/api/fe/index.ts
entry file 17 : ./pages/api/fe/mention/impact.ts
entry file 18 : ./pages/api/fe/mention/output.ts
entry file 19 : ./pages/api/fe/mention/software.ts
entry file 20 : ./pages/api/fe/token/refresh.ts
entry file 21 : ./pages/cookies.tsx
entry file 22 : ./pages/index.tsx
entry file 23 : ./pages/invite/organisation/[id].tsx
entry file 24 : ./pages/invite/project/[id].tsx
entry file 25 : ./pages/invite/software/[id].tsx
entry file 26 : ./pages/login/failed.tsx
entry file 27 : ./pages/login/local.tsx
entry file 28 : ./pages/logout.tsx
entry file 29 : ./pages/organisations/[...slug].tsx
entry file 30 : ./pages/organisations/index.tsx
entry file 31 : ./pages/page/[slug].tsx
entry file 32 : ./pages/projects/[slug]/edit/[page].tsx
entry file 33 : ./pages/projects/[slug]/edit/index.tsx
entry file 34 : ./pages/projects/[slug]/index.tsx
entry file 35 : ./pages/projects/add.tsx
entry file 36 : ./pages/projects/index.tsx
entry file 37 : ./pages/robots.txt.tsx
entry file 38 : ./pages/sitemap/organisations.xml.tsx
entry file 39 : ./pages/sitemap/projects.xml.tsx
entry file 40 : ./pages/sitemap/software.xml.tsx
entry file 41 : ./pages/software/[slug]/edit/[page].tsx
entry file 42 : ./pages/software/[slug]/edit/index.tsx
entry file 43 : ./pages/software/[slug]/index.tsx
entry file 44 : ./pages/software/add.tsx
entry file 45 : ./pages/software/index.tsx
entry file 46 : ./pages/user/[section].tsx

unresolved imports : 0
unused dependencies : 0
unimported files : 5


─────┬─────────────────────────────────────────────────────────────────────────────────────────────────────────────
│ 5 unimported files
─────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────
1 │ components/admin/organisations/OrganisationsPage.tsx
2 │ components/projects/edit/editProjectSteps.tsx
3 │ utils/nextRouterWithLink.ts
4 │ utils/useMentionsForSoftware.tsx
5 │ utils/useOrganisationSoftware.tsx
─────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────────
```
6 changes: 4 additions & 2 deletions frontend/__tests__/ProjectEditPage.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (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
Expand All @@ -10,7 +12,7 @@ import {WithFormContext} from '~/utils/jest/WithFormContext'
import {WithProjectContext} from '~/utils/jest/WithProjectContext'

import ProjectEditPage from '../pages/projects/[slug]/edit/[page]'
import {editProjectSteps} from '~/components/projects/edit/editProjectSteps'
import {editProjectPage} from '~/components/projects/edit/editProjectPages'
import editProjectState from '~/components/projects/edit/__mocks__/editProjectState'
import {projectInformation as config} from '~/components/projects/edit/information/config'
import mockProjectToEdit from '~/components/projects/edit/information/__mocks__/useProjectToEditData.json'
Expand Down Expand Up @@ -114,7 +116,7 @@ describe('pages/projects/[slug]/edit/index.tsx', () => {

//validate all nav items shown
const navItems = screen.getAllByTestId('edit-project-nav-item')
expect(navItems.length).toEqual(editProjectSteps.length)
expect(navItems.length).toEqual(editProjectPage.length)

// wait for info loader to be removed
// await waitForElementToBeRemoved(screen.getByRole('progressbar'))
Expand Down
3 changes: 2 additions & 1 deletion frontend/auth/locationCookie.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// 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

import {saveLocationCookie} from './locationCookie'

const orgLocation = window.location
const orgCookie = document.cookie

beforeAll(() => {
// mock location
Expand Down
3 changes: 2 additions & 1 deletion frontend/auth/refreshSession.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// 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

import {refreshSession} from './refreshSession'
import {mockResolvedValueOnce} from '../utils/jest/mockFetch'
import {mockSession} from '~/utils/jest/WithAppContext'
import {Session} from '.'

// mock console log
global.console = {
Expand Down
4 changes: 2 additions & 2 deletions frontend/components/AppFooter/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// SPDX-FileCopyrightText: 2021 - 2022 Dusan Mijatovic (dv4all)
// SPDX-FileCopyrightText: 2021 - 2022 dv4all
// SPDX-FileCopyrightText: 2022 - 2023 Netherlands eScience Center
// SPDX-FileCopyrightText: 2022 Jesús García Gonzalez (Netherlands eScience Center) <[email protected]>
// SPDX-FileCopyrightText: 2022 Netherlands eScience Center
// SPDX-FileCopyrightText: 2023 Christian Meeßen (GFZ) <[email protected]>
// 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
Expand All @@ -14,7 +15,6 @@ import OrganisationLogo from './OrganisationLogo'
import ContactEmail from './ContactEmail'

export default function AppFooter () {
const isDev = process.env.NODE_ENV === 'development'
const {pages,links,embedMode,host} = useRsdSettings()
if (embedMode === true) return null

Expand Down
34 changes: 20 additions & 14 deletions frontend/components/AppHeader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import LogoAppSmall from '~/assets/LogoAppSmall.svg'
import GlobalSearchAutocomplete from '~/components/GlobalSearchAutocomplete'
import FeedbackPanelButton from '~/components/feedback/FeedbackPanelButton'
import useDisableScrollLock from '~/utils/useDisableScrollLock'
import isActiveMenuItem from './isActiveMenuItem'

export default function AppHeader() {
const [activePath, setActivePath] = useState('/')
Expand All @@ -37,8 +38,7 @@ export default function AppHeader() {
useEffect(() => {
// set activePath to currently loaded route/page
if (typeof window != 'undefined') {
const paths = window.location.pathname.split('/')
if (paths.length > 0) setActivePath(`/${paths[1]}`)
setActivePath(window.location.pathname)
}
}, [])

Expand Down Expand Up @@ -73,11 +73,14 @@ export default function AppHeader() {
{/* Large menu*/}
<div
className="justify-center xl:justify-start hidden md:flex text-lg ml-4 gap-5 text-center opacity-90 font-normal flex-1">
{menuItems.map(item =>
<Link key={item.path} href={item.path || ''} className={`${activePath === item.path ? 'nav-active' : ''}`}>
{item.label}
</Link>
)}
{menuItems.map(item => {
const isActive = isActiveMenuItem({item, activePath})
return (
<Link key={item.path} href={item.path || ''} className={`${isActive ? 'nav-active' : ''}`}>
{item.label}
</Link>
)
})}
</div>

<div className="text-primary-content flex gap-2 justify-end items-center min-w-[8rem] text-right ml-4">
Expand Down Expand Up @@ -130,13 +133,16 @@ export default function AppHeader() {
// disable adding styles to body (overflow:hidden & padding-right)
disableScrollLock = {disable}
>
{menuItems.map(item =>
<MenuItem onClick={handleCloseResponsiveMenu} key={item.path}>
<Link href={item.path || ''} className={`${activePath === item.path && 'nav-active'}`}>
{item.label}
</Link>
</MenuItem>
)}
{menuItems.map(item => {
const isActive = isActiveMenuItem({item, activePath})
return (
<MenuItem onClick={handleCloseResponsiveMenu} key={item.path}>
<Link href={item.path || ''} className={`${isActive ? 'nav-active' : ''}`}>
{item.label}
</Link>
</MenuItem>
)
})}
<li>
{host.feedback?.enabled
? <FeedbackPanelButton feedback_email={host.feedback.url} issues_page_url={host.feedback.issues_page_url} />
Expand Down
20 changes: 20 additions & 0 deletions frontend/components/AppHeader/isActiveMenuItem.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (Netherlands eScience Center)
// SPDX-FileCopyrightText: 2023 Netherlands eScience Center
//
// SPDX-License-Identifier: Apache-2.0

import {MenuItemType} from '~/config/menuItems'

type IsActiveMenuItemProps = {
item: MenuItemType
activePath: string
}

export default function isActiveMenuItem({item, activePath}:IsActiveMenuItemProps) {

if (activePath && item.match) {
return activePath.includes(item.match)
}

return false
}
12 changes: 0 additions & 12 deletions frontend/components/admin/organisations/OrganisationsPage.tsx

This file was deleted.

3 changes: 2 additions & 1 deletion frontend/components/admin/pages/edit/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// 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

Expand All @@ -10,7 +12,6 @@ import Button from '@mui/material/Button'
import AddIcon from '@mui/icons-material/Add'

import {useAuth} from '~/auth'
import logger from '~/utils/logger'
import useSnackbar from '~/components/snackbar/useSnackbar'
import ConfirmDeleteModal from '~/components/layout/ConfirmDeleteModal'
import {PageTitleSticky} from '~/components/layout/PageTitle'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// 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

import {render, screen} from '@testing-library/react'
import {render} from '@testing-library/react'
import {useEffect, useRef, useState} from 'react'

import useResizeObserver from './useResizeObserver'
Expand Down
Loading

0 comments on commit f402d4b

Please sign in to comment.