Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Admin: Flag entity-related issues #1287

Merged
merged 5 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 39 additions & 20 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 @@ -315,20 +318,9 @@ class DocumentManagementDocumentComponent extends React.Component {
// Document Header & Footer
const getDocumentHeader = doc => {
return h( 'div.document-management-document-section.meta', [
h( 'div.document-management-document-section-items', [
h( 'div', [
h( 'i.material-icons.hide-by-default.invalid', {
className: makeClassList({ 'show': hasIssues( doc ) })
}, 'warning' ),
// h( 'i.material-icons.hide-by-default.complete', {
// className: makeClassList({ 'show': doc.submitted() || doc.isPublic() })
// }, 'check_circle' ),
h( 'i.material-icons.hide-by-default.mute', {
className: makeClassList({ 'show': doc.trashed() })
}, 'delete' )
]),

])
h( 'i.material-icons.hide-by-default.invalid', {
className: makeClassList({ 'show': hasIssues( doc ) })
}, 'warning' )
]);
};

Expand Down Expand Up @@ -362,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 @@ -401,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 @@ -477,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 @@ -540,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/model/element/complex.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ class Complex extends Entity {
return this.remove( ele, opts );
}

normalized(){
return true;
}

json(){
return _.assign( {}, super.json(), _.pick( this.syncher.get(), _.keys(DEFAULTS) ) );
}
Expand Down
19 changes: 19 additions & 0 deletions src/model/element/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,25 @@ class Entity extends Element {
return update;
}

normalized(){
// normalized := has a name and is associated
const name = this.syncher.get('name');
return name && this.associated() && this.completed();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what 'completed' was supposed to indicate?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

associated true (entity/node only) => grounded

completed (any element / node / edge) => the user has finished specifying the element

E.g. an interaction doesn't have a grounding but it can still be completed by specifying it as phosphorylation.

}

issues(){
const items = [];
if( !this.normalized() ){
items.push({
error: {
name: 'Normalization'
},
message: `Entity with name "${this.name()}" is not normalized`
});
}
return items;
}

organism(){
const assoc = this.association();

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