Skip to content

Commit

Permalink
fix: pages have default ordering, remove ordering from navigation links
Browse files Browse the repository at this point in the history
  • Loading branch information
ewan-escience committed Jul 22, 2024
1 parent 9106dea commit 4ef59d6
Show file tree
Hide file tree
Showing 19 changed files with 107 additions and 80 deletions.
2 changes: 1 addition & 1 deletion database/020-row-level-security.sql
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ CREATE POLICY admin_all_rights ON research_domain TO rsd_admin
ALTER TABLE software_for_community ENABLE ROW LEVEL SECURITY;

CREATE POLICY anyone_can_read ON software_for_community FOR SELECT TO rsd_web_anon, rsd_user
USING (software IN (SELECT id FROM software));
USING (software IN (SELECT id FROM software) AND status = 'approved');

CREATE POLICY maintainer_can_read ON software_for_community FOR SELECT TO rsd_user
USING (software IN (SELECT * FROM software_of_current_maintainer()) OR community IN (SELECT * FROM communities_of_current_maintainer()));
Expand Down
12 changes: 6 additions & 6 deletions database/124-community-views.sql
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ SELECT
community.short_description,
community.logo_id,
community.primary_maintainer,
software_count_by_community.software_cnt,
pending_count_by_community.pending_cnt,
rejected_count_by_community.rejected_cnt,
COALESCE(software_count_by_community.software_cnt, 0),
COALESCE(pending_count_by_community.pending_cnt, 0),
COALESCE(rejected_count_by_community.rejected_cnt, 0),
keyword_filter_for_community.keywords,
community.description,
community.created_at
Expand Down Expand Up @@ -487,9 +487,9 @@ SELECT DISTINCT ON (community.id)
community.short_description,
community.logo_id,
community.primary_maintainer,
software_count_by_community.software_cnt,
pending_count_by_community.pending_cnt,
rejected_count_by_community.rejected_cnt,
COALESCE(software_count_by_community.software_cnt, 0),
COALESCE(pending_count_by_community.pending_cnt, 0),
COALESCE(rejected_count_by_community.rejected_cnt, 0),
keyword_filter_for_community.keywords,
community.description,
community.created_at
Expand Down
3 changes: 2 additions & 1 deletion frontend/components/communities/overview/CommunityCard.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// SPDX-FileCopyrightText: 2024 Dusan Mijatovic (Netherlands eScience Center)
// SPDX-FileCopyrightText: 2024 Ewan Cahen (Netherlands eScience Center) <e.cahen@esciencecenter.nl>
// SPDX-FileCopyrightText: 2024 Netherlands eScience Center
//
// SPDX-License-Identifier: Apache-2.0
Expand Down Expand Up @@ -52,7 +53,7 @@ export default function CommunityCard({community}:{community:CommunityListProps}
<div className="flex gap-4 justify-end text-center">
<CommunityMetrics
software_cnt={community.software_cnt ?? 0}
pending_cnt={community.pending_cnt ?? 0}
pending_cnt={community.pending_cnt}
/>
</div>
</CardContentFrame>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// SPDX-FileCopyrightText: 2024 Dusan Mijatovic (Netherlands eScience Center)
// SPDX-FileCopyrightText: 2024 Ewan Cahen (Netherlands eScience Center) <e.cahen@esciencecenter.nl>
// SPDX-FileCopyrightText: 2024 Netherlands eScience Center
//
// SPDX-License-Identifier: Apache-2.0
Expand All @@ -19,7 +20,7 @@ export default function CommunityListItem({community}:{community:CommunityListPr
<Link
data-testid="community-list-item"
key={community.id}
href={`/communities/${community.slug}/software?order=mention_cnt`}
href={`/communities/${community.slug}`}
className='flex-1 flex items-center hover:text-inherit bg-base-100 rounded-sm'
>
<ListImageWithGradientPlaceholder
Expand All @@ -40,7 +41,7 @@ export default function CommunityListItem({community}:{community:CommunityListPr
<div className="flex items-center gap-4 mr-4">
<CommunityMetrics
software_cnt={community.software_cnt ?? 0}
pending_cnt={community.pending_cnt ?? 0}
pending_cnt={community.pending_cnt}
/>
</div>
</div>
Expand Down
18 changes: 11 additions & 7 deletions frontend/components/communities/overview/CommunityMetrics.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// SPDX-FileCopyrightText: 2024 Dusan Mijatovic (Netherlands eScience Center)
// SPDX-FileCopyrightText: 2024 Ewan Cahen (Netherlands eScience Center) <e.cahen@esciencecenter.nl>
// SPDX-FileCopyrightText: 2024 Netherlands eScience Center
//
// SPDX-License-Identifier: Apache-2.0
Expand All @@ -9,7 +10,7 @@ import FlagOutlinedIcon from '@mui/icons-material/FlagOutlined'

type CommunityMetricsProps = {
software_cnt: number
pending_cnt: number
pending_cnt: number | null
}

export default function CommunityMetrics({software_cnt,pending_cnt}:CommunityMetricsProps) {
Expand All @@ -36,12 +37,15 @@ export default function CommunityMetrics({software_cnt,pending_cnt}:CommunityMet
<span className="text-sm">{software_cnt ?? 0}</span>
</div>
</Tooltip>
<Tooltip title={pendingMessage()} placement="top">
<div className="flex gap-2 items-center text-base-content-secondary">
<FlagOutlinedIcon sx={{width:20}} />
<span className="text-sm">{pending_cnt ?? 0}</span>
</div>
</Tooltip>
{
pending_cnt !== null &&
<Tooltip title={pendingMessage()} placement="top">
<div className="flex gap-2 items-center text-base-content-secondary">
<FlagOutlinedIcon sx={{width:20}} />
<span className="text-sm">{pending_cnt}</span>
</div>
</Tooltip>
}
</>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (dv4all)
// SPDX-FileCopyrightText: 2023 dv4all
// SPDX-FileCopyrightText: 2024 Christian Meeßen (GFZ) <christian.meessen@gfz-potsdam.de>
// SPDX-FileCopyrightText: 2024 Ewan Cahen (Netherlands eScience Center) <e.cahen@esciencecenter.nl>
// SPDX-FileCopyrightText: 2024 Helmholtz Centre Potsdam - GFZ German Research Centre for Geosciences
//
// SPDX-License-Identifier: Apache-2.0
Expand Down Expand Up @@ -31,13 +32,18 @@ export function getSoftwareOrderOptions(isMaintainer:boolean) {

export default function OrderCommunitySoftwareBy() {
const {isMaintainer} = useCommunityContext()
const {order} = useSoftwareParams()
let {order} = useSoftwareParams()
const {handleQueryChange} = useFilterQueryChange()
const orderOptions = getSoftwareOrderOptions(isMaintainer)

const allowedOrderings = orderOptions.map(o => o.key)
if (order === null || !allowedOrderings.includes(order)) {
order = 'mention_cnt'
}

return (
<OrderBy
order={order ?? ''}
order={order}
options={orderOptions}
handleQueryChange={handleQueryChange}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// SPDX-FileCopyrightText: 2022 - 2023 Dusan Mijatovic (dv4all)
// SPDX-FileCopyrightText: 2022 - 2023 dv4all
// SPDX-FileCopyrightText: 2022 Dusan Mijatovic (dv4all) (dv4all)
// SPDX-FileCopyrightText: 2023 - 2024 Netherlands eScience Center
// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (Netherlands eScience Center)
// SPDX-FileCopyrightText: 2023 Netherlands eScience Center
// SPDX-FileCopyrightText: 2024 Ewan Cahen (Netherlands eScience Center) <e.cahen@esciencecenter.nl>
//
// SPDX-License-Identifier: Apache-2.0

Expand Down Expand Up @@ -34,7 +35,7 @@ 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`}
href={`/organisations/${organisation.rsd_path}`}
className="flex h-full hover:text-inherit"
passHref
>
Expand Down Expand Up @@ -62,7 +63,7 @@ export default function OrganisationCard({organisation}: { organisation: Organis
project_cnt={organisation.project_cnt}
/>
{/* if is not tenant we render empty placeholder */}
{organisation.is_tenant === false ?
{!organisation.is_tenant ?
<div className="w-[2rem]">&nbsp;</div>
:
<TenantBadge/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-FileCopyrightText: 2023 - 2024 Netherlands eScience Center
// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (dv4all)
// SPDX-FileCopyrightText: 2023 dv4all
// SPDX-FileCopyrightText: 2024 Ewan Cahen (Netherlands eScience Center) <e.cahen@esciencecenter.nl>
//
// SPDX-License-Identifier: Apache-2.0

Expand All @@ -20,13 +21,12 @@ export const adminOptions = [
export function getProjectOrderOptions(isMaintainer:boolean) {
// if maintainer additional order options are added
if (isMaintainer) {
const order = [
return [
...projectOrderOptions,
// organisation specific option
{key: 'is_featured', label: 'Pinned', direction: 'desc.nullslast'},
...adminOptions
]
return order
} else {
return [
...projectOrderOptions,
Expand All @@ -39,13 +39,18 @@ export function getProjectOrderOptions(isMaintainer:boolean) {

export default function OrgOrderProjectsBy() {
const {isMaintainer} = useOrganisationContext()
const {order} = useProjectParams()
let {order} = useProjectParams()
const orderOptions = getProjectOrderOptions(isMaintainer)
const {handleQueryChange} = useQueryChange()

const allowedOrderKeys = orderOptions.map(o => o.key)
if (order === null || !allowedOrderKeys.includes(order)) {
order = 'is_featured'
}

return (
<OrderBy
order={order ?? ''}
order={order}
options={orderOptions}
handleQueryChange={handleQueryChange}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// SPDX-FileCopyrightText: 2023 - 2024 Netherlands eScience Center
// 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-FileCopyrightText: 2024 Ewan Cahen (Netherlands eScience Center) <e.cahen@esciencecenter.nl>
//
// SPDX-License-Identifier: Apache-2.0

Expand Down Expand Up @@ -40,7 +41,7 @@ export default function OrganisationSoftwareOverview({layout,software,loading,ro
// console.log('layout...', layout)
// console.groupEnd()

if (loading===false && (!software || software.length === 0)) {
if (!loading && (!software || software.length === 0)) {
return <NoContent />
}

Expand Down Expand Up @@ -70,7 +71,7 @@ export default function OrganisationSoftwareOverview({layout,software,loading,ro
)
}

if (loading === true) {
if (loading) {
return (
<GridCardSkeleton
count={itemCnt}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-FileCopyrightText: 2023 - 2024 Netherlands eScience Center
// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (dv4all)
// SPDX-FileCopyrightText: 2023 dv4all
// SPDX-FileCopyrightText: 2024 Ewan Cahen (Netherlands eScience Center) <e.cahen@esciencecenter.nl>
//
// SPDX-License-Identifier: Apache-2.0

Expand All @@ -18,13 +19,12 @@ const adminOrderOptions = [

export function getSoftwareOrderOptions(isMaintainer:boolean) {
if (isMaintainer) {
const order = [
return [
...softwareOrderOptions,
// additional organisation option (should be default)
{key: 'is_featured', label: 'Pinned', direction: 'desc.nullslast'},
...adminOrderOptions
]
return order
} else {
return [
...softwareOrderOptions,
Expand All @@ -37,13 +37,18 @@ export function getSoftwareOrderOptions(isMaintainer:boolean) {

export default function OrgOrderSoftwareBy() {
const {isMaintainer} = useOrganisationContext()
const {order} = useSoftwareParams()
let {order} = useSoftwareParams()
const orderOptions = getSoftwareOrderOptions(isMaintainer)
const {handleQueryChange} = useQueryChange()

const allowedOrderKeys = orderOptions.map(o => o.key)
if (order === null || !allowedOrderKeys.includes(order)) {
order = 'is_featured'
}

return (
<OrderBy
order={order ?? ''}
order={order}
options={orderOptions}
handleQueryChange={handleQueryChange}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// SPDX-FileCopyrightText: 2023 - 2024 Netherlands eScience Center
// 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-FileCopyrightText: 2024 Ewan Cahen (Netherlands eScience Center) <e.cahen@esciencecenter.nl>
//
// SPDX-License-Identifier: Apache-2.0

Expand Down Expand Up @@ -62,7 +63,7 @@ export const organistionTabItems:OrganisationTabProps = {
isVisible: ({children_cnt, isMaintainer}) => {
// we do not show this options if no children
// and not a maintainer
if (isMaintainer===false && (children_cnt === 0 || children_cnt===null)) return false
if (!isMaintainer && (children_cnt === 0 || children_cnt===null)) return false
return true
},
},
Expand Down
9 changes: 3 additions & 6 deletions frontend/components/organisation/tabs/OrganisationTabs.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// SPDX-FileCopyrightText: 2023 - 2024 Netherlands eScience Center
// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (Netherlands eScience Center)
// SPDX-FileCopyrightText: 2023 Netherlands eScience Center
// SPDX-FileCopyrightText: 2024 Ewan Cahen (Netherlands eScience Center) <e.cahen@esciencecenter.nl>
//
// SPDX-License-Identifier: Apache-2.0

Expand Down Expand Up @@ -38,10 +39,6 @@ export default function OrganisationTabs({tab_id}:{tab_id:TabKey|null}) {
slug: router.query['slug'],
tab: value,
}
// add default order for software and project tabs
if (value === 'projects' || value === 'software') {
query['order'] = 'is_featured'
}
// push route change
router.push({query},undefined,{scroll:false})
}}
Expand All @@ -56,7 +53,7 @@ export default function OrganisationTabs({tab_id}:{tab_id:TabKey|null}) {
project_cnt,
children_cnt,
description
}) === true) {
})) {
return <Tab
icon={item.icon}
key={key}
Expand Down
17 changes: 4 additions & 13 deletions frontend/components/organisation/tabs/useSelectedTab.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
// SPDX-FileCopyrightText: 2023 - 2024 Netherlands eScience Center
// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (Netherlands eScience Center)
// SPDX-FileCopyrightText: 2023 Netherlands eScience Center
// SPDX-FileCopyrightText: 2024 Ewan Cahen (Netherlands eScience Center) <e.cahen@esciencecenter.nl>
//
// SPDX-License-Identifier: Apache-2.0

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

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

export default function useSelectedTab(tab_id: TabKey|null) {
const {description, isMaintainer} = useOrganisationContext()

export default function useSelectedTab(tab_id: TabKey|null): TabKey {
// default tab is software
let selected:TabKey = 'software'

// if tab provided use it
if (tab_id !== null && organistionTabItems.hasOwnProperty(tab_id) === true) {
if (tab_id !== null && organistionTabItems.hasOwnProperty(tab_id)) {
selected = tab_id
} else if (organistionTabItems['about'].isVisible({description,isMaintainer})===true) {
// if tab is not provided and there is description
// the default tab is about
selected = 'about'
}

return selected
Expand Down
6 changes: 1 addition & 5 deletions frontend/components/software/overview/filters/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (dv4all) (dv4all)
// SPDX-FileCopyrightText: 2023 dv4all
// SPDX-FileCopyrightText: 2024 Christian Meeßen (GFZ) <christian.meessen@gfz-potsdam.de>
// SPDX-FileCopyrightText: 2024 Ewan Cahen (Netherlands eScience Center) <e.cahen@esciencecenter.nl>
// SPDX-FileCopyrightText: 2024 Helmholtz Centre Potsdam - GFZ German Research Centre for Geosciences
//
// SPDX-License-Identifier: Apache-2.0
Expand All @@ -15,11 +16,6 @@ import LicensesFilter, {LicensesFilterOption} from '~/components/filter/Licenses
import useSoftwareOverviewParams from '../useSoftwareOverviewParams'
import OrderSoftwareBy, {OrderHighlightsBy} from './OrderSoftwareBy'

export type LicenseWithCount = {
license: string;
cnt: number;
}

type SoftwareFilterProps = {
keywords: string[]
keywordsList: KeywordFilterOption[]
Expand Down
Loading

0 comments on commit 4ef59d6

Please sign in to comment.