Skip to content

Commit

Permalink
clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
fembau committed Sep 7, 2023
1 parent 92b7603 commit 829b3af
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 27 deletions.
1 change: 0 additions & 1 deletion database/007-create-keyword-and-category.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
-- SPDX-FileCopyrightText: 2023 Helmholtz Centre Potsdam - GFZ German Research Centre for Geosciences
--
-- SPDX-License-Identifier: Apache-2.0
-- SPDX-License-Identifier: EUPL-1.2

--------------
-- Keywords --
Expand Down
2 changes: 1 addition & 1 deletion database/020-row-level-security.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
-- SPDX-FileCopyrightText: 2021 - 2023 Netherlands eScience Center
-- SPDX-FileCopyrightText: 2022 - 2023 Dusan Mijatovic (dv4all)
-- SPDX-FileCopyrightText: 2022 - 2023 dv4all
-- SPDX-FileCopyrightText: 2022 - 2023 Helmholtz Centre Potsdam - GFZ German Research Centre for Geosciences
-- SPDX-FileCopyrightText: 2022 Christian Meeßen (GFZ) <[email protected]>
-- SPDX-FileCopyrightText: 2023 Dusan Mijatovic (Netherlands eScience Center)
-- SPDX-FileCopyrightText: 2023 Felix Mühlbauer (GFZ) <[email protected]>
-- SPDX-FileCopyrightText: 2023 Helmholtz Centre Potsdam - GFZ German Research Centre for Geosciences
--
-- SPDX-License-Identifier: Apache-2.0

Expand Down
3 changes: 0 additions & 3 deletions frontend/components/category/CategoriesWithHeadlines.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,3 @@ export const CategoriesWithHeadlines = ({categories, onRemove}: CategoriesWithHe
</React.Fragment>
})
}

// nested menu
// https://medium.com/@modularcoder/reactjs-multi-level-sidebar-navigation-menu-with-typescrip-materialui-251943c12dda
4 changes: 2 additions & 2 deletions frontend/components/category/CategoryTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export type CategoryTreeLevelProps = {
}
export const CategoryTreeLevel = ({items, onRemove}: CategoryTreeLevelProps) => {

const onClickHandler = (event: React.MouseEvent<HTMLElement>) => {
const onRemoveHandler = (event: React.MouseEvent<HTMLElement>) => {
event.stopPropagation()
const categoryId = event.currentTarget.dataset.id!
onRemove?.(categoryId)
Expand All @@ -32,7 +32,7 @@ export const CategoryTreeLevel = ({items, onRemove}: CategoryTreeLevelProps) =>
<Tooltip title={item.category.name} placement='left'>
<span className='pb-1'>{item.category.short_name}</span>
</Tooltip>
{onRemove && item.children.length === 0 && <IconButton sx={{top:'-0.25rem'}} data-id={item.category.id} size='small' onClick={onClickHandler}><CancelIcon fontSize='small' /></IconButton>}
{onRemove && item.children.length === 0 && <IconButton sx={{top:'-0.25rem'}} data-id={item.category.id} size='small' onClick={onRemoveHandler}><CancelIcon fontSize='small' /></IconButton>}
</div>
{item.children.length > 0 && <TreeLevel items={item.children}/> }
</li>
Expand Down
1 change: 0 additions & 1 deletion frontend/components/software/AboutSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// SPDX-FileCopyrightText: 2023 Felix Mühlbauer (GFZ) <[email protected]>
//
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: EUPL-1.2

import {License, ProgramingLanguages, CodePlatform, KeywordForSoftware, CategoriesForSoftware} from '../../types/SoftwareTypes'
import PageContainer from '../layout/PageContainer'
Expand Down
1 change: 0 additions & 1 deletion frontend/components/software/edit/editSoftwareConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
// SPDX-FileCopyrightText: 2023 Felix Mühlbauer (GFZ) <[email protected]>
//
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: EUPL-1.2

export const softwareInformation = {
slug: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// SPDX-FileCopyrightText: 2023 dv4all
//
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: EUPL-1.2

import {FormProvider, useForm} from 'react-hook-form'
import {EditSoftwareItem} from '~/types/SoftwareTypes'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
// SPDX-FileCopyrightText: 2023 Felix Mühlbauer (GFZ) <[email protected]>
//
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: EUPL-1.2

import {useEffect, useState} from 'react'
import {AutocompleteOption} from '../../../../types/AutocompleteOptions'
Expand Down
3 changes: 1 addition & 2 deletions frontend/types/SoftwareTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
// SPDX-FileCopyrightText: 2023 Felix Mühlbauer (GFZ) <[email protected]>
//
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: EUPL-1.2

/**
* Types used in software pages (view/add/edit)
Expand Down Expand Up @@ -111,7 +110,7 @@ export const SoftwarePropsToSave = [

export type EditSoftwareItem = SoftwareItem & {
keywords: KeywordForSoftware[]
categories: CategoryPath[]
categories: CategoriesForSoftware
licenses: AutocompleteOption<License>[]
image_b64: string | null
image_mime_type: string | null
Expand Down
15 changes: 14 additions & 1 deletion frontend/utils/categories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,20 @@
// SPDX-License-Identifier: Apache-2.0

import {useMemo} from 'react'
import {CategoryPath, CategoryTree, CategoryTreeLevel} from '~/types/Category'
import {CategoryEntry, CategoryPath, CategoryTree, CategoryTreeLevel} from '~/types/Category'

export const leaf = <T>(list: T[]) => list[list.length - 1]

const compareCategoryEntry = (p1: CategoryEntry, p2: CategoryEntry) => p1.short_name.localeCompare(p2.short_name)
const compareCategoryTreeLevel = (p1: CategoryTreeLevel, p2: CategoryTreeLevel) => compareCategoryEntry(p1.category, p2.category)

const categoryTreeSort = (tree: CategoryTree) => {
tree.sort(compareCategoryTreeLevel)
for (const item of tree) {
categoryTreeSort(item.children)
}
}

export const genCategoryTree = (categories: CategoryPath[]) : CategoryTree => {
const tree: CategoryTree = []
if (!Array.isArray(categories)) return tree
Expand All @@ -25,6 +35,9 @@ export const genCategoryTree = (categories: CategoryPath[]) : CategoryTree => {
}
}
}

categoryTreeSort(tree)

return tree
}

Expand Down
14 changes: 1 addition & 13 deletions frontend/utils/getSoftware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
//
// SPDX-License-Identifier: Apache-2.0

import logger from './logger'
import {CategoriesForSoftware, KeywordForSoftware, RepositoryInfo, SoftwareItem, SoftwareOverviewItemProps} from '../types/SoftwareTypes'
import {extractCountFromHeader} from './extractCountFromHeader'
import logger from './logger'
import {createJsonHeaders, getBaseUrl} from './fetchHelpers'
import {RelatedProjectForSoftware} from '~/types/Project'
import {CategoryID, CategoryPath} from '~/types/Category'
Expand Down Expand Up @@ -212,15 +212,6 @@ export async function getCategoriesForSoftware(software_id: string, token?: stri
return []
}

function compareCategoryPath(p1: CategoryPath, p2: CategoryPath) {
if (p1.length != p2.length) return p1.length - p2.length
for (let index = 0; index < p1.length; index++) {
const diff = p1[index].short_name.localeCompare(p2[index].short_name)
if (diff != 0) return diff
}
return 0
}

export async function getAvailableCategories(): Promise<CategoryPath[]> {
try {
const url = prepareQueryURL('/rpc/available_categories_expanded')
Expand All @@ -229,9 +220,6 @@ export async function getAvailableCategories(): Promise<CategoryPath[]> {
})
if (resp.status === 200) {
const data = await resp.json()
// logger(`getAvailableCategories response: ${JSON.stringify(data)}`)
// FIXME: sorting should be done by backend
data.sort(compareCategoryPath)
return data
} else if (resp.status === 404) {
logger(`getAvailableCategories: 404 [${url}]`, 'error')
Expand Down

0 comments on commit 829b3af

Please sign in to comment.