-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement communities overview (#1188)
* feat: implement communities overview, grid and list incl. search on name and short description * chore: add communities to data generation and small SQL style fixes --------- Co-authored-by: Ewan Cahen <[email protected]>
- Loading branch information
1 parent
fedca31
commit b09d5b2
Showing
33 changed files
with
1,423 additions
and
215 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
-- SPDX-FileCopyrightText: 2024 Dusan Mijatovic (Netherlands eScience Center) | ||
-- SPDX-FileCopyrightText: 2024 Ewan Cahen (Netherlands eScience Center) <[email protected]> | ||
-- SPDX-FileCopyrightText: 2024 Netherlands eScience Center | ||
-- | ||
-- SPDX-License-Identifier: Apache-2.0 | ||
|
||
CREATE TABLE community ( | ||
id UUID DEFAULT gen_random_uuid() PRIMARY KEY, | ||
slug VARCHAR(200) UNIQUE NOT NULL CHECK (slug ~ '^[a-z0-9]+(-[a-z0-9]+)*$'), | ||
slug VARCHAR(200) UNIQUE NOT NULL CHECK (slug ~ '^[a-z0-9]+(-[a-z0-9]+)*$'), | ||
name VARCHAR(200) NOT NULL, | ||
short_description VARCHAR(300), | ||
description VARCHAR(10000), | ||
primary_maintainer UUID REFERENCES account (id), | ||
logo_id VARCHAR(40) REFERENCES image(id), | ||
created_at TIMESTAMPTZ NOT NULL, | ||
primary_maintainer UUID REFERENCES account (id), | ||
logo_id VARCHAR(40) REFERENCES image(id), | ||
created_at TIMESTAMPTZ NOT NULL, | ||
updated_at TIMESTAMPTZ NOT NULL | ||
); | ||
|
||
|
@@ -91,17 +92,17 @@ CREATE TYPE request_status AS ENUM ( | |
); | ||
|
||
CREATE TABLE software_for_community ( | ||
community UUID REFERENCES community (id), | ||
software UUID REFERENCES software (id), | ||
community UUID REFERENCES community (id), | ||
status request_status NOT NULL DEFAULT 'pending', | ||
PRIMARY KEY (community, software) | ||
PRIMARY KEY (software, community) | ||
); | ||
|
||
CREATE FUNCTION sanitise_update_software_for_community() RETURNS TRIGGER LANGUAGE plpgsql AS | ||
$$ | ||
BEGIN | ||
NEW.community = OLD.community; | ||
NEW.software = OLD.software; | ||
NEW.community = OLD.community; | ||
return NEW; | ||
END | ||
$$; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
-- SPDX-FileCopyrightText: 2024 Dusan Mijatovic (Netherlands eScience Center) | ||
-- SPDX-FileCopyrightText: 2024 Ewan Cahen (Netherlands eScience Center) <[email protected]> | ||
-- SPDX-FileCopyrightText: 2024 Netherlands eScience Center | ||
-- | ||
-- SPDX-License-Identifier: Apache-2.0 | ||
|
||
-- Software count by community | ||
CREATE FUNCTION software_count_by_community() RETURNS TABLE ( | ||
community UUID, | ||
software_cnt BIGINT | ||
) LANGUAGE sql STABLE AS | ||
$$ | ||
SELECT | ||
community.id, | ||
COUNT(software_for_community.software) AS software_cnt | ||
FROM | ||
community | ||
LEFT JOIN | ||
software_for_community ON community.id = software_for_community.community | ||
GROUP BY | ||
community.id | ||
; | ||
$$; | ||
|
||
-- rpc for community overview page | ||
-- incl. software count | ||
CREATE FUNCTION communities_overview() RETURNS TABLE ( | ||
id UUID, | ||
slug VARCHAR, | ||
name VARCHAR, | ||
short_description VARCHAR, | ||
logo_id VARCHAR, | ||
software_cnt BIGINT, | ||
created_at TIMESTAMPTZ | ||
) LANGUAGE sql STABLE AS | ||
$$ | ||
SELECT | ||
community.id, | ||
community.slug, | ||
community."name", | ||
community.short_description, | ||
community.logo_id, | ||
software_count_by_community.software_cnt, | ||
community.created_at | ||
FROM | ||
community | ||
LEFT JOIN | ||
software_count_by_community() ON community.id = software_count_by_community.community | ||
; | ||
$$; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// SPDX-FileCopyrightText: 2024 Dusan Mijatovic (Netherlands eScience Center) | ||
// SPDX-FileCopyrightText: 2024 Netherlands eScience Center | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import {RsdRole} from '~/auth/index' | ||
import logger from '~/utils/logger' | ||
|
||
type isCommunityMaintainerProps = { | ||
community: string | ||
role?: RsdRole | ||
account?: string | ||
token?: string | ||
} | ||
|
||
export async function isCommunityMaintainer({community, role, account, token}: isCommunityMaintainerProps) { | ||
// if no account, token, role provided | ||
if ( typeof account == 'undefined' || | ||
typeof token == 'undefined' || | ||
typeof role == 'undefined' | ||
) { | ||
return false | ||
} | ||
|
||
// if community provided and user role rsd_admin | ||
if (community && role === 'rsd_admin' && account) { | ||
return true | ||
} | ||
|
||
const isMaintainer = await isMaintainerOfCommunity({ | ||
community, | ||
account, | ||
token | ||
}) | ||
|
||
return isMaintainer | ||
} | ||
|
||
export async function isMaintainerOfCommunity({community, account, token}: isCommunityMaintainerProps) { | ||
try { | ||
if ( typeof account == 'undefined' || | ||
typeof token == 'undefined' | ||
) { | ||
// if no account, token, role provided | ||
return false | ||
} | ||
console.error('isMaintainerOfCommunity...NOT IMPLEMENTED') | ||
// const organisations = await getMaintainerOrganisations({ | ||
// token | ||
// }) | ||
// // debugger | ||
// if (organisations.length > 0) { | ||
// const isMaintainer = organisations.includes(organisation) | ||
// return isMaintainer | ||
// } | ||
return false | ||
} catch (e:any) { | ||
logger(`isMaintainerOfCommunity: ${e?.message}`, 'error') | ||
// ERRORS AS NOT MAINTAINER | ||
return false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// SPDX-FileCopyrightText: 2024 Dusan Mijatovic (Netherlands eScience Center) | ||
// SPDX-FileCopyrightText: 2024 Netherlands eScience Center | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import {menuItems} from '~/config/menuItems' | ||
import Link from 'next/link' | ||
|
||
import isActiveMenuItem from './isActiveMenuItem' | ||
|
||
export default function DesktopMenu({activePath}:{activePath:string}) { | ||
// console.group('DesktopMenu') | ||
// console.log('activePath...',activePath) | ||
// console.groupEnd() | ||
return ( | ||
<div | ||
className="hidden lg:flex-1 lg:flex lg:justify-center text-lg ml-4 gap-5 text-center opacity-90 font-normal "> | ||
{menuItems.map(item => { | ||
const isActive = isActiveMenuItem({item, activePath}) | ||
return ( | ||
<Link key={item.path} href={item.path ?? ''} className={`${isActive ? 'nav-active' : ''}`}> | ||
{item.label} | ||
</Link> | ||
) | ||
})} | ||
</div> | ||
) | ||
} |
Oops, something went wrong.