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 (