Skip to content

Commit

Permalink
WIP: reference papers
Browse files Browse the repository at this point in the history
  • Loading branch information
dmijatovic authored and ewan-escience committed Oct 11, 2023
1 parent bd8911b commit d181665
Show file tree
Hide file tree
Showing 24 changed files with 1,226 additions and 31 deletions.
59 changes: 59 additions & 0 deletions database/109-mention-views.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
-- SPDX-FileCopyrightText: 2023 Dusan Mijatovic (Netherlands eScience Center)
-- SPDX-FileCopyrightText: 2023 Ewan Cahen (Netherlands eScience Center) <[email protected]>
-- SPDX-FileCopyrightText: 2023 Netherlands eScience Center
--
Expand All @@ -17,3 +18,61 @@ $$
SELECT mention FROM reference_paper_for_software
)
$$;

-- UNIQUE CITATIONS BY SOFTWARE ID
CREATE FUNCTION citation_by_software() RETURNS TABLE (
software UUID,
id UUID,
doi CITEXT,
url VARCHAR,
title VARCHAR,
authors VARCHAR,
publisher VARCHAR,
publication_year SMALLINT,
journal VARCHAR,
page VARCHAR,
image_url VARCHAR,
mention_type mention_type,
source VARCHAR,
reference_papers UUID[]
)LANGUAGE sql STABLE AS
$$
SELECT
reference_paper_for_software.software,
mention.id,
mention.doi,
mention.url,
mention.title,
mention.authors,
mention.publisher,
mention.publication_year,
mention.journal,
mention.page,
mention.image_url,
mention.mention_type,
mention.source,
ARRAY_AGG(
reference_paper_for_software.mention
) AS reference_paper
FROM
reference_paper_for_software
INNER JOIN
citation_for_mention ON citation_for_mention.mention = reference_paper_for_software.mention
INNER JOIN
mention ON mention.id = citation_for_mention.citation
GROUP BY
reference_paper_for_software.software,
mention.id,
mention.doi,
mention.url,
mention.title,
mention.authors,
mention.publisher,
mention.publication_year,
mention.journal,
mention.page,
mention.image_url,
mention.mention_type,
mention.source
;
$$;
2 changes: 1 addition & 1 deletion frontend/components/mention/MentionItemBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export default function MentionItemBase({item,pos,nav,type,role='find'}:MentionI
className="text-sm"
role={role}
/>
<MentionNote note={item.note} />
<MentionNote note={item.note ?? null} />
</article>
)
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/mention/MentionViewItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default function MentionViewItem({item, pos}: {item: MentionItemProps, po
doi={item?.doi}
className="text-sm"
/>
<MentionNote note={item.note} />
<MentionNote note={item.note ?? null} />
</div>
<div className="flex justify-center items-center">
{item?.url ? <LinkIcon /> : null}
Expand Down
44 changes: 24 additions & 20 deletions frontend/components/mention/useEditMentionReducer.tsx
Original file line number Diff line number Diff line change
@@ -1,68 +1,72 @@
// SPDX-FileCopyrightText: 2022 Dusan Mijatovic (dv4all)
// SPDX-FileCopyrightText: 2022 dv4all
// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (Netherlands eScience Center)
// SPDX-FileCopyrightText: 2023 Netherlands eScience Center
//
// SPDX-License-Identifier: Apache-2.0

import {useContext} from 'react'
import {useCallback, useContext} from 'react'
import {EditMentionActionType} from './editMentionReducer'
import EditMentionContext from './editMentionContext'
import {MentionItemProps} from '~/types/Mention'

export default function useEditMentionReducer() {
const {state, dispatch} = useContext(EditMentionContext)

function setLoading(loading: boolean) {
const setLoading = useCallback((loading:boolean)=>{
dispatch({
type: EditMentionActionType.SET_LOADING,
payload: loading
})
}
// eslint-disable-next-line react-hooks/exhaustive-deps
},[])

function setMentions(mentions: MentionItemProps[]) {
const setMentions = useCallback((mentions: MentionItemProps[])=>{
dispatch({
type: EditMentionActionType.SET_MENTIONS,
payload: mentions
})
}
// eslint-disable-next-line react-hooks/exhaustive-deps
},[])

function onAdd(item: MentionItemProps) {
const onAdd = useCallback((item: MentionItemProps)=>{
dispatch({
type: EditMentionActionType.ON_ADD,
payload: item
})
}
},[dispatch])

function onNewItem() {
const onNewItem = useCallback(()=>{
dispatch({
type: EditMentionActionType.SET_EDIT_MODAL,
payload: {
open:true
}
})
}
},[dispatch])

function onSubmit(item:MentionItemProps) {
const onSubmit = useCallback((item:MentionItemProps)=>{
dispatch({
type: EditMentionActionType.ON_SUBMIT,
payload: item
})
}
},[dispatch])

function onUpdate(item:MentionItemProps) {
const onUpdate = useCallback((item:MentionItemProps)=>{
dispatch({
type: EditMentionActionType.ON_UPDATE,
payload: item
})
}
},[dispatch])

function onDelete(item:MentionItemProps) {
const onDelete = useCallback((item:MentionItemProps)=>{
dispatch({
type: EditMentionActionType.ON_DELETE,
payload: item
})
}
},[dispatch])

function confirmDelete(item?: MentionItemProps) {
const confirmDelete = useCallback((item?: MentionItemProps)=>{
if (item) {
// open modal
dispatch({
Expand All @@ -81,9 +85,9 @@ export default function useEditMentionReducer() {
}
})
}
}
},[dispatch])

function setEditModal(item?: MentionItemProps) {
const setEditModal = useCallback((item?: MentionItemProps)=>{
if (item) {
// show modal when item provided
dispatch({
Expand All @@ -102,9 +106,9 @@ export default function useEditMentionReducer() {
}
})
}
}
},[dispatch])

// console.group('useOutputContext')
// console.group('useEditMentionReducer')
// console.log('state...', state)
// console.groupEnd()

Expand Down
23 changes: 17 additions & 6 deletions frontend/components/software/edit/editSoftwarePages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import PersonAddIcon from '@mui/icons-material/PersonAdd'
import ContentLoader from '~/components/layout/ContentLoader'
import HomeRepairServiceIcon from '@mui/icons-material/HomeRepairService'
import PendingActionsIcon from '@mui/icons-material/PendingActions'
import PostAddIcon from '@mui/icons-material/PostAdd'

// import SoftwareInformation from './information'
// import SoftwareContributors from './contributors'
Expand All @@ -28,22 +29,25 @@ import PendingActionsIcon from '@mui/icons-material/PendingActions'
// import SoftwareMaintainers from './maintainers'

// use dynamic imports instead
const SoftwareContributors = dynamic(() => import('./contributors'),{
loading: ()=><ContentLoader />
})
const SoftwareInformation = dynamic(() => import('./information'),{
loading: ()=><ContentLoader />
})
const SoftwareContributors = dynamic(() => import('./contributors'),{
const SoftwareMaintainers = dynamic(() => import('./maintainers'),{
loading: ()=><ContentLoader />
})
const SoftwareOgranisations = dynamic(() => import('./organisations'),{
const SoftwareMentions = dynamic(() => import('./mentions'),{
loading: ()=><ContentLoader />
})
const PackageManagers = dynamic(() => import('./package-managers'),{
const SoftwareOgranisations = dynamic(() => import('./organisations'),{
loading: ()=><ContentLoader />
})
const SoftwareMentions = dynamic(() => import('./mentions'),{
const PackageManagers = dynamic(() => import('./package-managers'),{
loading: ()=><ContentLoader />
})
const SoftwareTestimonials = dynamic(() => import('./testimonials'),{
const ReferencePapers = dynamic(() => import('./reference-papers'),{
loading: ()=><ContentLoader />
})
const RelatedSoftware = dynamic(() => import('./related-software'),{
Expand All @@ -52,10 +56,11 @@ const RelatedSoftware = dynamic(() => import('./related-software'),{
const RelatedProjects = dynamic(() => import('./related-projects'),{
loading: ()=><ContentLoader />
})
const SoftwareMaintainers = dynamic(() => import('./maintainers'),{
const SoftwareTestimonials = dynamic(() => import('./testimonials'),{
loading: ()=><ContentLoader />
})


export type EditSoftwarePageProps = {
id: string
status: string,
Expand All @@ -82,6 +87,12 @@ export const editSoftwarePage:EditSoftwarePageProps[] = [{
icon: <FactoryIcon />,
render: () => <SoftwareOgranisations />,
status: 'Optional information'
},{
id: 'reference-paper',
label: 'Reference papers',
icon: <PostAddIcon />,
render: () => <ReferencePapers />,
status: 'Optional information'
},{
id: 'mentions',
label: 'Mentions',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-FileCopyrightText: 2022 Dusan Mijatovic (dv4all)
// SPDX-FileCopyrightText: 2022 Dusan Mijatovic (dv4all) (dv4all)
// SPDX-FileCopyrightText: 2022 dv4all
// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (Netherlands eScience Center)
// SPDX-FileCopyrightText: 2023 Netherlands eScience Center
//
// SPDX-License-Identifier: Apache-2.0

Expand Down Expand Up @@ -112,7 +114,7 @@ export default function EditMentionsProvider(props: any) {
}
}
if (item.id) {
// existing RSD mention item to be added to project
// existing RSD mention item to be added to software
const resp = await addToMentionForSoftware({
software,
mention: item.id,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (Netherlands eScience Center)
// SPDX-FileCopyrightText: 2023 Netherlands eScience Center
//
// SPDX-License-Identifier: Apache-2.0

import {MentionItemProps} from '~/types/Mention'
import {getMentionType} from '~/components/mention/config'
import MentionAuthors from '~/components/mention/MentionAuthors'
import MentionDoi from '~/components/mention/MentionDoi'
import {MentionTitle} from '~/components/mention/MentionItemBase'
import MentionPublisherItem from '~/components/mention/MentionPublisherItem'
import useEditMentionReducer from '~/components/mention/useEditMentionReducer'

export type CitationItemProps = MentionItemProps & {
reference_papers: string[]
}

function ReferencePapers({papers}:{papers:string[]}){
const {mentions} = useEditMentionReducer()
const reference:{doi:string,url:string}[] =[]

if (papers?.length===0 || mentions?.length===0){
return (
<div className="text-sm">
Referenced paper:
</div>
)
}

papers.forEach(uuid=>{
const found = mentions.find(item=>item.id === uuid)
if (found?.doi && found.url) reference.push({doi:found.doi, url:found.url})
})

if (reference.length === 0){
return (
<div className="text-sm">
Referenced: <i>None</i>
</div>
)
}

return(
<div className="flex flex-wrap gap-2 text-sm text-base-content-secondary">
Referenced: {
reference.map(item=>{
return (
<a
key={item.url}
href={item.url} target="_blank" rel="noreferrer"
className="text-sm "
>
{item.doi}
</a>
)
})
}
</div>
)
}


export default function CitationItem({item}:{item:CitationItemProps}){
const title = getMentionType(item?.mention_type,'singular')
return (
<div data-testid="citation-view-item-body" className="py-2 px-4 hover:bg-base-200">
<div className="text-base-content-disabled">
{title}
</div>
<MentionTitle
title={item?.title ?? ''}
role="list"
url={item.url}
className="text-base"
/>
<MentionAuthors
authors={item.authors}
className="text-sm text-base-content-secondary"
/>
<MentionPublisherItem
publisher={item?.publisher ?? ''}
page={item?.page ?? ''}
publication_year={item.publication_year}
journal = {item.journal}
className="text-sm text-base-content-secondary"
/>
<MentionDoi
url={item?.url}
doi={item?.doi}
className="text-sm"
/>
<ReferencePapers papers={item.reference_papers} />
</div>
)
}
Loading

0 comments on commit d181665

Please sign in to comment.