Skip to content

Commit

Permalink
Display warnings and errors for entities.
Browse files Browse the repository at this point in the history
  • Loading branch information
jvwong committed Jul 24, 2024
1 parent 419ea14 commit 4d59ce6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
42 changes: 36 additions & 6 deletions src/client/components/document-management-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ import {

const DOCUMENT_STATUS_FIELDS = Document.statusFields();

const hasIssues = doc => _.values( doc.issues() ).some( i => !_.isNull( i ) );
const hasIssue = ( doc, key ) => _.has( doc.issues(), key ) && !_.isNull( _.get( doc.issues(), key ) );
const issuesPresent = e => _.values( e.issues() ).some( i => !_.isNull( i ) );
const hasEntityIssues = doc => doc.entities().some( issuesPresent );
const hasDocIssues = doc => issuesPresent( doc );
const hasIssues = doc => hasEntityIssues( doc ) || hasDocIssues( doc );
const hasIssue = ( e, key ) => _.has( e.issues(), key ) && !_.isNull( _.get( e.issues(), key ) );

/**
* sendMail
Expand Down Expand Up @@ -351,9 +354,7 @@ class DocumentManagementDocumentComponent extends React.Component {

if( hasIssue( doc, 'paperId' ) ){
const { paperId: paperIdIssue } = doc.issues();
const err = h( 'div', {
className: makeClassList({ 'issue': true })
}, `${paperIdIssue.error.name}: ${paperIdIssue.message}` );
const err = h( 'div', `${paperIdIssue.error.name}: ${paperIdIssue.message}` );
items.push( err );
}

Expand Down Expand Up @@ -390,6 +391,34 @@ class DocumentManagementDocumentComponent extends React.Component {
]);
};

// Entities
const getEntityInfo = doc => {
const numEntities = doc.entities().length;
let items = [ h('div', { key: 'total' }, `Total: ${numEntities}`)];
const mixedOrganisms = doc.organisms().length > 1;
const hasIssue = hasEntityIssues( doc );
const hasWarning = mixedOrganisms; // orphaned nodes

if( hasIssue ){
const issues = doc.entities().filter( issuesPresent ).map( e => e.issues() );
const errors = _.flatten( issues ).map( i => i.error.name );
const errorTypes = _.toPairs( _.countBy( errors ) ).map( ([ error, count ], key) => h('div', { key }, `${error}: ${count}`) );
items.push( errorTypes );
}
if( hasWarning ){
if( mixedOrganisms ) items.push( h('div', { key: 'organism' }, 'Mixed organisms' ) );
}

return h( 'div.document-management-document-section', [
h( 'div.document-management-document-section-label', {
className: makeClassList({'issue': hasIssue, 'warning': hasWarning})
},[
h( 'div.document-management-document-section-label-text', 'Entities')
]),
h( 'div.document-management-document-section-items', items )
]);
};

// Correspondence
const getVerified = doc => {
let radios = [];
Expand Down Expand Up @@ -466,7 +495,7 @@ class DocumentManagementDocumentComponent extends React.Component {
return h( 'div.document-management-document-section', [
h( 'div.document-management-document-section-label', {
className: makeClassList({ 'issue': hasIssue( doc, 'authorEmail' ) })
}, 'Correspondence:' ),
}, 'Correspondence' ),
content
]);
};
Expand Down Expand Up @@ -529,6 +558,7 @@ class DocumentManagementDocumentComponent extends React.Component {
getDocumentHeader( doc ),
getDocumentArticle( doc ),
getDocumentInfo( doc ),
getEntityInfo( doc ),
getDocumentCorrespondence( doc ),
getDocumentStats( doc )
]);
Expand Down
4 changes: 4 additions & 0 deletions src/styles/document-management.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
& .issue {
color: var(--invalidColor);
}

& .warning {
color: var(--brandColorDark);
}
}

.document-management-hidden {
Expand Down

0 comments on commit 4d59ce6

Please sign in to comment.