diff --git a/client/src/components/assessments/instant/InstantAssessmentsContainerField.js b/client/src/components/assessments/instant/InstantAssessmentsContainerField.js index ca451788d9..fc04695601 100644 --- a/client/src/components/assessments/instant/InstantAssessmentsContainerField.js +++ b/client/src/components/assessments/instant/InstantAssessmentsContainerField.js @@ -105,31 +105,58 @@ const InstantAssessmentsContainerField = ({ formikProps, canRead, canWrite, - readonly + readonly, + showEntitiesWithoutAssessments }) => { const { values } = formikProps + function sortEntries(e1, e2) { + let e1HasAssessments = false + const e1entityInstantAssessments = e1.getInstantAssessments() + e1entityInstantAssessments.forEach(([ak, ac]) => { + const filteredAssessment = Model.filterAssessmentConfig( + ac, + e1, + relatedObject + ) + if ( + !_isEmpty(filteredAssessment.questions) || + !_isEmpty(filteredAssessment.questionSets) + ) { + e1HasAssessments = true + } + }) + if (e1HasAssessments) { + return 1 + } + return -1 + } + function getEntitiesWithAssessments(entity) { + const entityInstantAssessments = entity.getInstantAssessments() + let hasAssessments = false + entityInstantAssessments.forEach(([ak, ac]) => { + const filteredAssessment = Model.filterAssessmentConfig( + ac, + entity, + relatedObject + ) + if ( + !_isEmpty(filteredAssessment.questions) || + !_isEmpty(filteredAssessment.questionSets) + ) { + hasAssessments = true + } + }) + return hasAssessments + } + // Sort entities to display the ones without any assessment at the end + const filteredEntities = showEntitiesWithoutAssessments + ? entities.sort(sortEntries) + : entities.filter(getEntitiesWithAssessments) return ( - {entities.map(entity => { + {filteredEntities.map(entity => { const entityInstantAssessments = entity.getInstantAssessments() - let hasAssessments = false - entityInstantAssessments.forEach(([ak, ac]) => { - const filteredAssessment = Model.filterAssessmentConfig( - ac, - entity, - relatedObject - ) - if ( - !_isEmpty(filteredAssessment.questions) || - !_isEmpty(filteredAssessment.questionSets) - ) { - hasAssessments = true - } - }) - if (!hasAssessments) { - return null - } return ( @@ -172,7 +199,8 @@ InstantAssessmentsContainerField.propTypes = { }), canRead: PropTypes.bool, canWrite: PropTypes.bool, - readonly: PropTypes.bool + readonly: PropTypes.bool, + showEntitiesWithoutAssessments: PropTypes.bool } InstantAssessmentsContainerField.defaultProps = { entities: [], diff --git a/client/src/pages/reports/Compact.js b/client/src/pages/reports/Compact.js index b6ea9c679e..bb12274452 100644 --- a/client/src/pages/reports/Compact.js +++ b/client/src/pages/reports/Compact.js @@ -484,6 +484,7 @@ const CompactReportView = ({ pageDispatchers }) => { }} canRead={canReadAssessments} readonly + showEntitiesWithoutAssessments /> ) : ( attendees.map(attendee => (