Skip to content

Commit

Permalink
feat: software and project maintainer can select organisation specifi…
Browse files Browse the repository at this point in the history
…c categories
  • Loading branch information
dmijatovic committed Oct 10, 2024
1 parent 9c1ee20 commit a6cbf7a
Show file tree
Hide file tree
Showing 18 changed files with 968 additions and 117 deletions.
34 changes: 25 additions & 9 deletions database/014-create-keyword-and-category.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
-- SPDX-FileCopyrightText: 2023 - 2024 Felix Mühlbauer (GFZ) <[email protected]>
-- SPDX-FileCopyrightText: 2023 - 2024 Helmholtz Centre Potsdam - GFZ German Research Centre for Geosciences
-- SPDX-FileCopyrightText: 2024 Christian Meeßen (GFZ) <[email protected]>
-- SPDX-FileCopyrightText: 2024 Dusan Mijatovic (Netherlands eScience Center)
--
-- SPDX-License-Identifier: Apache-2.0

Expand Down Expand Up @@ -107,15 +108,6 @@ CREATE INDEX category_parent_idx ON category(parent);
CREATE INDEX category_community_idx ON category(community);


CREATE TABLE category_for_software (
software_id UUID REFERENCES software (id),
category_id UUID REFERENCES category (id),
PRIMARY KEY (software_id, category_id)
);

CREATE INDEX category_for_software_category_id_idx ON category_for_software(category_id);


-- sanitize categories

CREATE FUNCTION sanitise_insert_category()
Expand Down Expand Up @@ -228,6 +220,19 @@ $$
$$;


-- TABLE FOR software categories
-- includes organisation, community and general categories
-- Note! to filter specific categories of an community or organisation use join with community table

CREATE TABLE category_for_software (
software_id UUID REFERENCES software (id),
category_id UUID REFERENCES category (id),
PRIMARY KEY (software_id, category_id)
);

CREATE INDEX category_for_software_category_id_idx ON category_for_software(category_id);

-- RPC for software page to show all software categories
CREATE FUNCTION category_paths_by_software_expanded(software_id UUID)
RETURNS JSON
LANGUAGE SQL STABLE AS
Expand All @@ -242,3 +247,14 @@ $$
ELSE '[]'::json
END AS result
$$;


-- TABLE FOR project categories
-- currently used only for organisation categories
CREATE TABLE category_for_project (
project_id UUID REFERENCES project (id),
category_id UUID REFERENCES category (id),
PRIMARY KEY (project_id, category_id)
);

CREATE INDEX category_for_project_category_id_idx ON category_for_project(category_id);
31 changes: 31 additions & 0 deletions database/109-category-functions.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
-- SPDX-FileCopyrightText: 2024 Dusan Mijatovic (Netherlands eScience Center)
-- SPDX-FileCopyrightText: 2024 Ewan Cahen (Netherlands eScience Center) <[email protected]>
-- SPDX-FileCopyrightText: 2024 Netherlands eScience Center
--
Expand All @@ -11,3 +12,33 @@ DELETE FROM category_for_software
USING category
WHERE category_for_software.category_id = category.id AND category_for_software.software_id = software_id AND category.community = community_id;
$$;


-- DELETE organisation categories for specific software
CREATE FUNCTION delete_organisation_categories_from_software(software_id UUID, organisation_id UUID)
RETURNS VOID
LANGUAGE sql AS
$$
DELETE FROM category_for_software
USING
category
WHERE
category_for_software.category_id = category.id AND
category_for_software.software_id = software_id AND
category.organisation = organisation_id;
$$;


-- DELETE organisation categories for specific project
CREATE FUNCTION delete_organisation_categories_from_project(project_id UUID, organisation_id UUID)
RETURNS VOID
LANGUAGE sql AS
$$
DELETE FROM category_for_project
USING
category
WHERE
category_for_project.category_id = category.id AND
category_for_project.project_id = project_id AND
category.organisation = organisation_id;
$$;
18 changes: 10 additions & 8 deletions frontend/components/category/CategoryEditForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ export default function CategoryEditForm({

const [parent] = watch(['parent'])

console.group('CategoryEditForm')
console.log('createNew...',createNew)
// console.group('CategoryEditForm')
// console.log('createNew...',createNew)
// console.log('data...',data)
// console.log('disableSave...',disableSave)
// console.log('community...',community)
// console.log('organisation...',organisation)
console.log('parent...',parent)
console.groupEnd()
// console.log('parent...',parent)
// console.groupEnd()


function onSubmit(formData: CategoryEntry){
Expand Down Expand Up @@ -181,7 +181,7 @@ export default function CategoryEditForm({

{/*
Organisation categories can be used for software or project items
We show software/project switch only at top level
We show software/project switch only at top level (root nodes)
*/}
{
organisation && !parent ?
Expand All @@ -203,9 +203,11 @@ export default function CategoryEditForm({
</div>
:
<>
{/* By default categories are used by software in communities and by project for organisations */}
<input type="hidden" {...register('allow_software', {value: data?.allow_software ?? community!==null})} />
<input type="hidden" {...register('allow_projects', {value: data?.allow_projects ?? organisation!==null})} />
{/*
for children nodes we use false as default value
*/}
<input type="hidden" {...register('allow_software', {value: false})} />
<input type="hidden" {...register('allow_projects', {value: false})} />
</>
}

Expand Down
28 changes: 28 additions & 0 deletions frontend/components/category/__mocks__/apiCategories.ts
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 Ewan Cahen (Netherlands eScience Center) <[email protected]>
// SPDX-FileCopyrightText: 2024 Netherlands eScience Center
//
// SPDX-License-Identifier: Apache-2.0

import {CategoryEntry} from '~/types/Category'
import {TreeNode} from '~/types/TreeNode'

type LoadCategoryProps={
community?: string | null,
organisation?: string | null,
allow_software?: boolean,
allow_projects?: boolean
}


// DEFAULT mock return empty array of categories
export async function loadCategoryRoots({community, organisation, allow_software, allow_projects}:LoadCategoryProps){
const result: TreeNode<CategoryEntry>[] = []
return result
}

// DEFAULT mock return empty array of categories
export function categoryEntriesToRoots(categoriesArr: CategoryEntry[]): TreeNode<CategoryEntry>[] {
const result: TreeNode<CategoryEntry>[] = []
return result
}
14 changes: 12 additions & 2 deletions frontend/components/category/apiCategories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import {TreeNode} from '~/types/TreeNode'

type LoadCategoryProps={
community?: string | null,
organisation?: string | null
organisation?: string | null,
allow_software?: boolean,
allow_projects?: boolean
}

export async function loadCategoryRoots({community, organisation}:LoadCategoryProps){
export async function loadCategoryRoots({community, organisation, allow_software, allow_projects}:LoadCategoryProps){
// global categories is default
let categoryFilter = 'community=is.null&organisation=is.null'
// community filter
Expand All @@ -24,6 +26,14 @@ export async function loadCategoryRoots({community, organisation}:LoadCategoryPr
if (organisation){
categoryFilter = `organisation=eq.${organisation}`
}
// software specific categories
if (allow_software){
categoryFilter+='&allow_software=eq.true'
}
// project specific categories
if (allow_projects){
categoryFilter+='&allow_projects=eq.true'
}

const resp = await fetch(`${getBaseUrl()}/category?${categoryFilter}`)

Expand Down
26 changes: 25 additions & 1 deletion frontend/components/layout/SortableListItemActions.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: 2024 Dusan Mijatovic (Netherlands eScience Center)
// SPDX-FileCopyrightText: 2024 Netherlands eScience Center
//
// SPDX-License-Identifier: Apache-2.0

Expand All @@ -8,16 +10,37 @@ import DeleteIcon from '@mui/icons-material/Delete'
import EditIcon from '@mui/icons-material/Edit'
import IconButton from '@mui/material/IconButton'
import DragIndicatorIcon from '@mui/icons-material/DragIndicator'
import CategoryIcon from '@mui/icons-material/Category'

type SortableListItemActionsProps = {
pos: number
listeners?: SyntheticListenerMap
onEdit?:(pos:number)=>void,
onDelete?:(pos:number)=>void,
onCategory?:(pos:number)=>void
}

export default function SortableListItemActions({pos,listeners,onEdit,onDelete,onCategory}:SortableListItemActionsProps){

export default function SortableListItemActions({pos,listeners,onEdit,onDelete}:SortableListItemActionsProps){
function categoryAction() {
if (typeof onCategory !== 'undefined') {
return (
<IconButton
title="Edit categories"
edge="end"
aria-label="edit"
sx={{marginRight: '1rem'}}
onClick={() => {
// alert(`Edit...${item.id}`)
onCategory(pos)
}}
>
<CategoryIcon />
</IconButton>
)
}
return null
}

function editAction() {
if (typeof onEdit !== 'undefined') {
Expand Down Expand Up @@ -76,6 +99,7 @@ export default function SortableListItemActions({pos,listeners,onEdit,onDelete}:

return (
<>
{categoryAction()}
{editAction()}
{deleteAction()}
{dragAction()}
Expand Down
Loading

0 comments on commit a6cbf7a

Please sign in to comment.