From f8cc58053b7d17ef09b868982814f6c777ab643a Mon Sep 17 00:00:00 2001 From: Stefano Ricci Date: Wed, 13 Nov 2024 14:38:55 +0100 Subject: [PATCH 1/2] Schema summary: added validation_message_LANG columns --- .../service/schemaSummary/schemaSummary.js | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/server/modules/survey/service/schemaSummary/schemaSummary.js b/server/modules/survey/service/schemaSummary/schemaSummary.js index f0de2875f8..26cb880a78 100644 --- a/server/modules/survey/service/schemaSummary/schemaSummary.js +++ b/server/modules/survey/service/schemaSummary/schemaSummary.js @@ -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 = [] @@ -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 } }) From d7b494ba53c1fd5e9419113eaddea4732b707097 Mon Sep 17 00:00:00 2001 From: Stefano Ricci Date: Wed, 13 Nov 2024 14:55:46 +0100 Subject: [PATCH 2/2] fixed tests --- test/e2e/tests/surveySchemaSummary.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/e2e/tests/surveySchemaSummary.js b/test/e2e/tests/surveySchemaSummary.js index 1e35cfd3e7..206c3b517c 100644 --- a/test/e2e/tests/surveySchemaSummary.js +++ b/test/e2e/tests/surveySchemaSummary.js @@ -98,6 +98,8 @@ export default () => 'minCount', 'maxCount', 'validations', + 'validation_message_en', + 'validation_message_fr', 'cycle', ]) await expect(nodeDefData.uuid).toBeDefined()