Commit 2c6bb6a7 authored by Audrey Hamelers's avatar Audrey Hamelers
parent 3fd90ee1
Pipeline #13417 failed with stages
in 26 seconds
import React from 'react'
import { Query } from 'react-apollo'
import styled from 'styled-components'
import styled, { withTheme } from 'styled-components'
import { th } from '@pubsweet/ui-toolkit'
import { Link, H3, Icon } from '@pubsweet/ui'
import { Loading, LoadingIcon, Table, Notification } from '../ui'
import { COUNT_MANUSCRIPTS } from './operations'
import { COUNT_MANUSCRIPTS, ALERT_MANUSCRIPTS } from './operations'
import DashboardBase from './DashboardBase'
const ListTable = styled(Table)`
......@@ -39,7 +39,40 @@ const Completed = {
deleted: ['deleted'],
}
const QueueTable = ({ title, queue, data }) => {
const AlertIcon = withTheme(({ theme, interval }) => (
<Icon
color={theme.colorError}
size={2}
style={{ cursor: 'help', float: 'right' }}
title={`Manuscripts older than ${interval}`}
>
alert-octagon
</Icon>
))
const AlertQuery = ({ states, interval }) => (
<Query
fetchPolicy="cache-and-network"
query={ALERT_MANUSCRIPTS}
variables={{ states, interval }}
>
{({ data, loading }) => {
if (loading) {
return (
<Loading>
<LoadingIcon />
</Loading>
)
}
if (data.checkAge && data.checkAge.alert) {
return <AlertIcon interval={interval} />
}
return null
}}
</Query>
)
const QueueTable = ({ title, queue, data, alerts }) => {
let total = 0
const tableData = Object.keys(queue).map(label => {
const items = data.filter(s => queue[label].includes(s.type))
......@@ -69,6 +102,7 @@ const QueueTable = ({ title, queue, data }) => {
) : (
row.label
)}
{alerts && <AlertQuery interval={alerts} states={row.states} />}
</td>
</tr>
))}
......@@ -130,6 +164,7 @@ const Dashboard = ({ currentUser }) => (
title="Submitter/Reviewer queue"
/>
<QueueTable
alerts="5 days"
data={data.countByStatus}
queue={TaggerQueue}
title="Tagger queue"
......
......@@ -24,6 +24,13 @@ export const COUNT_MANUSCRIPTS = gql`
}
}
`
export const ALERT_MANUSCRIPTS = gql`
query CheckAge($states: [String], $interval: String) {
checkAge(states: $states, interval: $interval) {
alert
}
}
`
export const GET_MANUSCRIPT = gql`
query SearchArticleIds($id: String!) {
searchArticleIds(id: $id) {
......
......@@ -361,6 +361,17 @@ class Manuscript extends EpmcBaseModel {
return parseInt(count[0].count, 10)
}
static async checkAge(statuses, interval) {
const rawString = `"updated" < NOW() - INTERVAL '${interval}'`
const alert =
(await knex('manuscript')
.count('*')
.whereIn('status', statuses)
.whereRaw(rawString)
.whereNull('deleted')) || '0'
return parseInt(alert[0].count, 10) > 0
}
static async countDeleted(user) {
const { isAdmin } = await Manuscript.isAdmin(user)
......
......@@ -187,6 +187,11 @@ const Manuscript = {
return counts
},
checkAge: async (states, interval) => {
const older = await ManuscriptAccess.checkAge(states, interval)
return { alert: older }
},
search: async (query, page, pageSize, user) => {
const manuscripts = await ManuscriptAccess.searchByTitleOrUser(
query,
......
......@@ -31,6 +31,12 @@ const resolvers = {
}
return ManuscriptManager.countByStatus(user)
},
async checkAge(_, { states, interval }, { user }) {
if (!user) {
throw new Error('You are not authenticated!')
}
return ManuscriptManager.checkAge(states, interval)
},
async adminManuscripts(_, { external }, { user }) {
if (!user) {
throw new Error('You are not authenticated!')
......
......@@ -3,6 +3,10 @@ type Count {
count: Int
}
type Older {
alert: Boolean
}
type Error {
message: String
}
......@@ -28,6 +32,7 @@ extend type Query {
manuscripts: [Manuscript]!
adminManuscripts(external: Boolean): ManuscriptSearchResult!
countByStatus: [Count]!
checkAge(states: [String], interval: String): Older!
checkDuplicates(id: ID!, articleIds: [String], title: String!): ManuscriptSearchResult!
searchArticleIds(id: String!): ManuscriptResult!
findByStatus(query: String!, page: Int, pageSize: Int): ManuscriptSearchResult!
......
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