Commit 470b0879 authored by nickstiffler's avatar nickstiffler Committed by Yannis Barlas

feat(dashboard): let admin delete manuscripts

parent 0d19cbd9
......@@ -220,6 +220,15 @@ const Dashboard = props => {
}
}
const deleteFilterArticle = articleId => {
deleteArticle({ variables: { id: articleId } }).then(() => {
const filteredArticles = state.filteredArticles.filter(
article => article.id !== articleId,
)
setState({ filteredArticles })
})
}
const editorActions = [
<Select
closeMenuOnSelect={false}
......@@ -255,6 +264,8 @@ const Dashboard = props => {
actions={editorActions}
allEditors={allEditors}
allScienceOfficers={allScienceOfficers}
deleteArticle={deleteFilterArticle}
isAdmin={isAdmin}
itemComponent={EditorSectionItem}
items={state.filteredArticles}
label="Editor Section"
......
......@@ -2,12 +2,14 @@
import React from 'react'
import styled from 'styled-components'
import { Toggle } from 'react-powerplug'
import { Action, ActionGroup } from '@pubsweet/ui'
import { th } from '@pubsweet/ui-toolkit'
import { isEditableByAuthor } from '../../helpers/status'
import SectionItemWithStatus from './SectionItemWithStatus'
import ConfirmManuscriptDelete from '../../../ui/src/modals/ConfirmManuscriptDelete'
const Wrapper = styled.div`
border-bottom: ${th('borderWidth')} ${th('borderStyle')}
......@@ -21,8 +23,11 @@ const ActionsWrapper = styled.div`
`
const Actions = props => {
const { articleId, deleteArticle, status } = props
const { articleId, deleteArticle, status, title } = props
const isEditable = isEditableByAuthor(status)
const confirmDelete = () => {
deleteArticle({ variables: { id: articleId } })
}
return (
<ActionsWrapper>
......@@ -35,11 +40,22 @@ const Actions = props => {
</Action>
{isEditable && (
<Action
onClick={() => deleteArticle({ variables: { id: articleId } })}
>
Delete
</Action>
<Toggle intial={false}>
{({ on, toggle }) => (
<React.Fragment>
<Action onClick={toggle} primary>
Delete
</Action>
<ConfirmManuscriptDelete
isOpen={on}
onConfirm={confirmDelete}
onRequestClose={toggle}
title={title}
/>
</React.Fragment>
)}
</Toggle>
)}
</ActionGroup>
</ActionsWrapper>
......@@ -47,10 +63,15 @@ const Actions = props => {
}
const AuthorSectionItem = props => {
const { deleteArticle, id, status } = props
const { deleteArticle, id, status, title } = props
const ActionsComponent = (
<Actions articleId={id} deleteArticle={deleteArticle} status={status} />
<Actions
articleId={id}
deleteArticle={deleteArticle}
status={status}
title={title}
/>
)
return (
......
......@@ -2,12 +2,14 @@
import React from 'react'
import styled from 'styled-components'
import { Toggle } from 'react-powerplug'
import { Action, ActionGroup } from '@pubsweet/ui'
import { th } from '@pubsweet/ui-toolkit'
// import AssignToManuscript from './AssignToManuscript'
import SectionItemWithStatus from './SectionItemWithStatus'
import ConfirmManuscriptDelete from '../../../ui/src/modals/ConfirmManuscriptDelete'
const Wrapper = styled.div`
border-bottom: ${th('borderWidth')} ${th('borderStyle')}
......@@ -29,18 +31,42 @@ const ActionsWrapper = styled.div`
// width: calc(${th('gridUnit')} * 2);
// `
const Actions = ({ articleId }) => (
<ActionsWrapper>
<ActionGroup>
<Action
data-test-id={`go-to-article-link-${articleId}`}
to={`/article/${articleId}`}
>
Go to Article
</Action>
</ActionGroup>
</ActionsWrapper>
)
const Actions = ({ articleId, deleteArticle, isAdmin, title }) => {
const confirmDelete = () => {
deleteArticle(articleId)
}
return (
<ActionsWrapper>
<ActionGroup>
<Action
data-test-id={`go-to-article-link-${articleId}`}
to={`/article/${articleId}`}
>
Go to Article
</Action>
{isAdmin && (
<Toggle intial={false}>
{({ on, toggle }) => (
<React.Fragment>
<Action onClick={toggle} primary>
Delete
</Action>
<ConfirmManuscriptDelete
isOpen={on}
onConfirm={confirmDelete}
onRequestClose={toggle}
title={title}
/>
</React.Fragment>
)}
</Toggle>
)}
</ActionGroup>
</ActionsWrapper>
)
}
const EditorSectionItem = props => {
const {
......@@ -50,14 +76,24 @@ const EditorSectionItem = props => {
author,
// authorIds,
curator,
deleteArticle,
editor,
isAdmin,
sectionEditor,
scienceOfficer,
title,
// updateAssignedEditor,
// updateAssignedScienceOfficer,
// variant,
} = props
const ActionsComponent = <Actions articleId={articleId} />
const ActionsComponent = (
<Actions
articleId={articleId}
deleteArticle={deleteArticle}
isAdmin={isAdmin}
title={title}
/>
)
return (
<Wrapper>
......
......@@ -5,6 +5,7 @@ const sortBy = require('lodash/sortBy')
const {
ChatThread,
ChatMessage,
CuratorReview,
Manuscript,
ManuscriptVersion,
Review,
......@@ -109,7 +110,6 @@ const deleteManuscript = async (_, { id }) => {
await transaction(Manuscript.knex(), async trx => {
// Delete chat thread and their messages
const threads = await ChatThread.query(trx)
.delete()
.where({ manuscriptId: id })
.returning('id')
......@@ -119,19 +119,29 @@ const deleteManuscript = async (_, { id }) => {
.delete()
.whereIn('chatThreadId', threadIds)
// Delete versions
const deletedVersions = await ManuscriptVersion.query(trx)
await ChatThread.query(trx)
.delete()
.where({ manuscriptId: id })
.returning('id')
const deletedVersionIds = deletedVersions.map(v => v.id)
const versions = await ManuscriptVersion.query(trx).where({
manuscriptId: id,
})
const versionIds = versions.map(v => v.id)
await CuratorReview.query(trx)
.delete()
.whereIn('manuscriptVersionId', versionIds)
await ManuscriptVersion.query(trx)
.delete()
.whereIn('id', versionIds)
// Delete all teams and team members that belong to the manuscript,
// its versions or its chat threads
const deletedTeams = await Team.query(trx)
.delete()
.whereIn('objectId', [...deletedVersionIds, id])
.whereIn('objectId', [...versionIds, id])
.returning('id')
const deletedTeamIds = deletedTeams.map(t => t.id)
......
import React from 'react'
import PropTypes from 'prop-types'
import WarningModal from './WarningModal'
import { stripHTML } from '../_helpers'
const ConfirmManuscriptDelete = props => {
const { title, ...rest } = props
return (
<WarningModal headerText="confirm delete" textSuccess="delete" {...rest}>
{`You are about to delete the article "${stripHTML(
title,
)}". Are you sure?`}
</WarningModal>
)
}
ConfirmManuscriptDelete.propTypes = {
title: PropTypes.string.isRequired,
}
export default ConfirmManuscriptDelete
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment