Skip to content

Commit

Permalink
refactor: disable software options on project and organisation pages
Browse files Browse the repository at this point in the history
tests: update tests to support removed/disabled software module
chore: remove unused imports
  • Loading branch information
dmijatovic committed Jul 2, 2024
1 parent 5d60235 commit e168654
Show file tree
Hide file tree
Showing 23 changed files with 168 additions and 144 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ RSD_AUTH_COUPLE_PROVIDERS=ORCID

# SURFCONEXT - TEST ENVIRONMENT
# consumed by: authentication, frontend/utils/loginHelpers
SURFCONEXT_CLIENT_ID=www.research-software.nl
SURFCONEXT_CLIENT_ID=kin-rpd-demo-test.com
# consumed by: authentication, frontend/utils/loginHelpers
SURFCONEXT_REDIRECT=http://localhost/auth/login/surfconext
# consumed by: authentication, frontend/utils/loginHelpers
Expand Down
53 changes: 27 additions & 26 deletions frontend/__tests__/OrganisationPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,32 +105,33 @@ describe('pages/organisations/[...slug].tsx', () => {
// screen.debug(aboutPage)
})

it('renders organisation software page as default when organisation.description=null', async () => {
// not a maintainer - public page
mockIsMaintainerOfOrganisation.mockResolvedValueOnce(false)
// when no about page content, software is default landing page
mockProps.organisation.description = null
mockProps.tab = null
// mockProps.tab = 'software'
// mock software list response
mockSoftwareForOrganisation.mockResolvedValue({
status: 206,
count: mockSoftware.length,
data: mockSoftware as any
})
render(
<WithAppContext options={{session:mockSession}}>
<OrganisationPage {...mockProps} />
</WithAppContext>
)
// wait loader to be removed
// await waitForElementToBeRemoved(screen.getByRole('progressbar'))
// we need to await for all events to run
const software = await screen.findAllByTestId('software-grid-card')
expect(software.length).toEqual(mockSoftware.length)
// validate api call - TODO! FIGURE WHY IS CALLED TWICE!!!
expect(mockSoftwareForOrganisation).toBeCalledTimes(1)
})
// disable software option, 2024-07-02
// it('renders organisation software page as default when organisation.description=null', async () => {
// // not a maintainer - public page
// mockIsMaintainerOfOrganisation.mockResolvedValueOnce(false)
// // when no about page content, software is default landing page
// mockProps.organisation.description = null
// mockProps.tab = null
// // mockProps.tab = 'software'
// // mock software list response
// mockSoftwareForOrganisation.mockResolvedValue({
// status: 206,
// count: mockSoftware.length,
// data: mockSoftware as any
// })
// render(
// <WithAppContext options={{session:mockSession}}>
// <OrganisationPage {...mockProps} />
// </WithAppContext>
// )
// // wait loader to be removed
// // await waitForElementToBeRemoved(screen.getByRole('progressbar'))
// // we need to await for all events to run
// const software = await screen.findAllByTestId('software-grid-card')
// expect(software.length).toEqual(mockSoftware.length)
// // validate api call - TODO! FIGURE WHY IS CALLED TWICE!!!
// expect(mockSoftwareForOrganisation).toBeCalledTimes(1)
// })

it('renders organisation projects page when page=projects', async () => {
// not a maintainer - public page
Expand Down
3 changes: 2 additions & 1 deletion frontend/__tests__/UserPages.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ describe('pages/user/[section].tsx', () => {
)

const navItems = screen.getAllByTestId('user-nav-item')
expect(navItems.length).toEqual(5)
// KIN-RPD has 4 items
expect(navItems.length).toEqual(4)
})

it('renders user settings section', async() => {
Expand Down
4 changes: 2 additions & 2 deletions frontend/auth/locationCookie.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ it('ignores these paths', () => {
})
})

it('when root write cookie to redirect to software', () => {
it('when root write cookie to redirect to projects', () => {
// should ignore this path
window.location.pathname = '/'
const expectedCookie = 'rsd_pathname=http://localhost/software?order=mention_cnt;path=/auth;SameSite=None;Secure'
const expectedCookie = 'rsd_pathname=http://localhost/projects?order=mention_cnt;path=/auth;SameSite=None;Secure'
document.cookie = ''
// call function
saveLocationCookie()
Expand Down
8 changes: 4 additions & 4 deletions frontend/auth/locationCookie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ export function saveLocationCookie() {
if (typeof location == 'undefined') return
// for specific routes
switch (location.pathname.toLowerCase()) {
// ingnore these paths
// ignore these paths
case '/auth':
case '/login':
case '/logout':
case '/login/local':
case '/login/failed':
break
case '/':
// root is send to /software
document.cookie = `rsd_pathname=${location.href}software?order=mention_cnt;path=/auth;SameSite=None;Secure`
// root is send to /projects
document.cookie = `rsd_pathname=${location.href}projects?order=mention_cnt;path=/auth;SameSite=None;Secure`
break
default:
// write simple browser cookie
// auth module use this cookie to redirect
// after succefull authentications
// after successful authentications
document.cookie = `rsd_pathname=${location.href};path=/auth;SameSite=None;Secure`
}
}
4 changes: 2 additions & 2 deletions frontend/components/AppHeader/AddMenu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ it('should have AddMenu options',async()=>{
fireEvent.click(menuButton as HTMLElement)
// select all menu options
const menuOptions = screen.queryAllByTestId('add-menu-option')
// assert only 2 items
expect(menuOptions.length).toEqual(2)
// assert only 1 item
expect(menuOptions.length).toEqual(1)
// screen.debug()
})
5 changes: 3 additions & 2 deletions frontend/components/AppHeader/AddMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,13 @@ export default function AddMenu() {
// disable adding styles to body (overflow:hidden & padding-right)
disableScrollLock={disable}
>
<MenuItem data-testid="add-menu-option" onClick={() => handleClose('/software/add')}>
{/* disable software option, 2024-07-02 */}
{/* <MenuItem data-testid="add-menu-option" onClick={() => handleClose('/software/add')}>
<ListItemIcon>
<TerminalIcon/>
</ListItemIcon>
New Software
</MenuItem>
</MenuItem> */}

<MenuItem data-testid="add-menu-option" onClick={() => handleClose('/projects/add')}>
<ListItemIcon>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ it('shows 3 navigation option on focus', async () => {
})

it('calls search api on input', async () => {
const expectedUrl = '/api/v1/rpc/global_search?query=Search text&limit=30&order=rank.asc,index_found.asc'
const expectedUrl = '/api/v1/rpc/global_search?query=Search text&source=in.("projects","organisations")&limit=30&order=rank.asc,index_found.asc'
const expectPayload = {
'headers': {
'Content-Type': 'application/json'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// SPDX-License-Identifier: Apache-2.0

import logger from '~/utils/logger'
import {createJsonHeaders} from '~/utils/fetchHelpers'
import {createJsonHeaders, getBaseUrl} from '~/utils/fetchHelpers'
import {sortBySearchFor} from '~/utils/sortFn'

export type GlobalSearchResults = {
Expand All @@ -24,9 +24,10 @@ export type GlobalSearchResults = {
*/
export async function getGlobalSearch(searchText: string, token: string,) {
try {
// disable software search, 2024-07-02
// call the function query
const query = `rpc/global_search?query=${searchText}&limit=30&order=rank.asc,index_found.asc`
let url = `/api/v1/${query}`
const query = `query=${searchText}&source=in.("projects","organisations")&limit=30&order=rank.asc,index_found.asc`
let url = `${getBaseUrl()}/rpc/global_search?${query}`

const resp = await fetch(url, {
method: 'GET',
Expand Down
39 changes: 21 additions & 18 deletions frontend/components/admin/AdminNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ export const adminPages = {
icon: <DescriptionIcon />,
path: '/admin/public-pages',
},
softwareHighlights:{
title: 'Software highlights',
subtitle: '',
icon: <FluorescentIcon />,
path: '/admin/software-highlights',
},
// disable software option, 2024-07-02
// softwareHighlights:{
// title: 'Software highlights',
// subtitle: '',
// icon: <FluorescentIcon />,
// path: '/admin/software-highlights',
// },
orcid:{
title: 'ORCID users',
subtitle: '',
Expand All @@ -68,24 +69,26 @@ export const adminPages = {
icon: <DomainAddIcon />,
path: '/admin/organisations',
},
communities: {
title: 'Communities',
subtitle: '',
icon: <Diversity3Icon />,
path: '/admin/communities',
},
// disable software option, 2024-07-02
// communities: {
// title: 'Communities',
// subtitle: '',
// icon: <Diversity3Icon />,
// path: '/admin/communities',
// },
keywords:{
title: 'Keywords',
subtitle: '',
icon: <SpellcheckIcon />,
path: '/admin/keywords',
},
categories:{
title: 'Categories',
subtitle: '',
icon: <CategoryIcon />,
path: '/admin/categories',
},
// disable software option, 2024-07-02
// categories:{
// title: 'Categories',
// subtitle: '',
// icon: <CategoryIcon />,
// path: '/admin/categories',
// },
mentions: {
title: 'Mentions',
subtitle: '',
Expand Down
4 changes: 2 additions & 2 deletions frontend/components/feedback/FeedbackPanelButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ export default function FeedbackPanelButton({feedback_email, issues_page_url, cl
function mailBody(): string | undefined {
if (typeof location === 'undefined') return

return encodeURIComponent(`Hi RSD Team,
return encodeURIComponent(`Hi Team,
I would like to give some feedback about the RSD for the browser ${browserNameAndVersion()} on the page ${location.href}:
I would like to give some feedback about the KIN-RPD for the browser ${browserNameAndVersion()} on the page ${location.href}:
---
${text}
---
Expand Down
5 changes: 3 additions & 2 deletions frontend/components/organisation/apiOrganisations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ import {baseQueryString, paginationUrlParams} from '~/utils/postgrestUrl'

export function organisationListUrl({search, rows = 12, page = 0}:
{ search: string | undefined, rows: number, page: number }) {
// NOTE 1! selectList need to include all colums used in filtering
// NOTE 1! selectList need to include all columns used in filtering
// NOTE 2! ensure selectList uses identical props as defined in OrganisationList type
// NOTE 3! for KIN we use order on project
const selectList = 'id,parent,name,short_description,country,website,is_tenant,rsd_path,logo_id,software_cnt,project_cnt,score'
let url = `${getBaseUrl()}/rpc/organisations_overview?parent=is.null&score=gt.0&order=is_tenant.desc,score.desc.nullslast,name.asc&select=${selectList}`
let url = `${getBaseUrl()}/rpc/organisations_overview?parent=is.null&score=gt.0&order=project_cnt.desc.nullslast,name.asc&select=${selectList}`
// add search params
if (search) {
url += `&or=(name.ilike.*${search}*, website.ilike.*${search}*)`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export default function OrganisationCard({organisation}: { organisation: Organis
<div className="relative">
<Link
data-testid="organisation-card-link"
href={`/organisations/${organisation.rsd_path}?tab=software&order=is_featured`}
// default projects option, 2024-07-02
href={`/organisations/${organisation.rsd_path}?tab=projects&order=is_featured`}
className="flex h-full hover:text-inherit"
passHref
>
Expand All @@ -61,12 +62,13 @@ export default function OrganisationCard({organisation}: { organisation: Organis
software_cnt={organisation.software_cnt}
project_cnt={organisation.project_cnt}
/>
{/* disable tenant for KIN-RPD instance, 2024-07-02 */}
{/* if is not tenant we render empty placeholder */}
{organisation.is_tenant === false ?
{/* {organisation.is_tenant === false ?
<div className="w-[2rem]">&nbsp;</div>
:
<TenantBadge/>
}
} */}
</div>
</CardContentFrame>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ type OrganisationMetricsProps = {
export default function OrganisationCardMetrics({software_cnt,project_cnt}:OrganisationMetricsProps) {
return (
<>
{/* Counter */}
<div>
{/* Counter disable software option, 2024-07-02 */}
{/* <div>
<div className='text-5xl font-light'>
{software_cnt ?? 0}
</div>
<div className='text-center text-sm'>
software <br />package{software_cnt === 1 ? '' : 's'}
</div>
</div>
</div> */}
{/* Counter */}
<div>
<div className='text-5xl font-light'>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,26 @@ export type OrganisationTabProps = {
* NOTE! When changing the tab options also update
* TabContent.tsx file to load proper component.
*/
export const organistionTabItems:OrganisationTabProps = {
export const organisationTabItems:OrganisationTabProps = {
// disable software option, 2024-07-02
software: {
id:'software',
label:({software_cnt})=>`Software (${software_cnt ?? 0})`,
icon: <TerminalIcon />,
isVisible: (props) => true,
isVisible: (props) => false,
},
projects:{
id:'projects',
label: ({project_cnt})=>`Projects (${project_cnt ?? 0})`,
icon: <ListAltIcon />,
isVisible: (props) => true,
},
// disable releases option, 2024-07-02
releases: {
id:'releases',
label:({release_cnt})=>`Releases (${release_cnt ?? 0})`,
icon: <StyleOutlinedIcon />,
isVisible: (props) => true,
isVisible: (props) => false,
},
units:{
id:'units',
Expand Down
6 changes: 3 additions & 3 deletions frontend/components/organisation/tabs/OrganisationTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import Tab from '@mui/material/Tab'
import Tabs from '@mui/material/Tabs'
import {useRouter} from 'next/router'

import {TabKey, organistionTabItems} from './OrganisationTabItems'
import {TabKey, organisationTabItems} from './OrganisationTabItems'
import useOrganisationContext from '../context/useOrganisationContext'
import useSelectedTab from './useSelectedTab'

// extract tab items (object keys)
const tabItems = Object.keys(organistionTabItems) as TabKey[]
const tabItems = Object.keys(organisationTabItems) as TabKey[]

export default function OrganisationTabs({tab_id}:{tab_id:TabKey|null}) {
const router = useRouter()
Expand Down Expand Up @@ -48,7 +48,7 @@ export default function OrganisationTabs({tab_id}:{tab_id:TabKey|null}) {
aria-label="organisation tabs"
>
{tabItems.map(key => {
const item = organistionTabItems[key]
const item = organisationTabItems[key]
if (item.isVisible({
isMaintainer,
software_cnt,
Expand Down
11 changes: 8 additions & 3 deletions frontend/components/organisation/tabs/TabContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,23 @@ export default function TabContent({tab_id}: TabContentProps) {
switch (select_tab) {
case 'about':
return <AboutOrganisation />
// IGNORE software and use projects
// disable software option, 2024-07-02
case 'software':
case 'projects':
return <OrganisationProjects />
case 'releases':
return <SoftwareReleases />
case 'settings':
return <OrganisationSettings />
case 'software':
return <OrganisationSoftware />
// disable software option, 2024-07-02
// case 'software':
// return <OrganisationSoftware />
case 'units':
return <OrganisationUnits />
default:
logger(`Unknown tab_id ${tab_id}...returning default software tab`,'warn')
return <OrganisationSoftware />
// projects as default option, 2024-07-02
return <OrganisationProjects />
}
}
Loading

0 comments on commit e168654

Please sign in to comment.