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

Schema summary: added validation_message_LANG columns #3649

Merged
merged 3 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
22 changes: 22 additions & 0 deletions server/modules/survey/service/schemaSummary/schemaSummary.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ const getValidationsSummary = ({ nodeDef }) => {
.join('\n')
}

const getValidationMessages = ({ nodeDef, lang }) => {
const validations = NodeDef.getValidations(nodeDef)
const expressions = NodeDefValidations.getExpressions(validations)
return expressions
.reduce((acc, expression) => {
const message = NodeDefExpression.getMessage(lang)(expression)
if (message) {
acc.push(message)
}
return acc
}, [])
.join('\n')
}

export const generateSchemaSummaryItems = async ({ surveyId, cycle }) => {
const survey = await SurveyManager.fetchSurveyAndNodeDefsBySurveyId({ surveyId, draft: true, advanced: true })
const nodeDefs = []
Expand Down Expand Up @@ -141,6 +155,14 @@ export const generateSchemaSummaryItems = async ({ surveyId, cycle }) => {
minCount: String(NodeDefValidations.getMinCount(NodeDef.getValidations(nodeDef))),
maxCount: String(NodeDefValidations.getMaxCount(NodeDef.getValidations(nodeDef))),
validations: getValidationsSummary({ nodeDef }),
// validation messages
...languages.reduce(
(acc, lang) => ({
...acc,
[`validation_message_${lang}`]: getValidationMessages({ nodeDef, lang }),
}),
{}
),
cycle: String(NodeDef.getCycles(nodeDef).map(RecordCycle.getLabel)), // this is to show the user the value that they see into the UI -> https://github.com/openforis/arena/issues/1677
}
})
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/tests/surveySchemaSummary.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ export default () =>
'minCount',
'maxCount',
'validations',
'validation_message_en',
'validation_message_fr',
'cycle',
])
await expect(nodeDefData.uuid).toBeDefined()
Expand Down
Loading