From a277928727fdd3ed5e9840691a95ce4abce833d7 Mon Sep 17 00:00:00 2001 From: Ellen Wright Date: Tue, 27 Feb 2024 12:17:36 +0000 Subject: [PATCH 1/2] Change file upload error message --- apps/e2e/cypress/e2e/templatesAdvanced.cy.ts | 4 +--- .../FileUpload/FileUploadDefinition.tsx | 4 ++-- .../createFileUploadValidationSchema.ts | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 apps/frontend/src/components/questionary/questionaryComponents/FileUpload/createFileUploadValidationSchema.ts diff --git a/apps/e2e/cypress/e2e/templatesAdvanced.cy.ts b/apps/e2e/cypress/e2e/templatesAdvanced.cy.ts index 5d25f6dcd3..5e30bcf203 100644 --- a/apps/e2e/cypress/e2e/templatesAdvanced.cy.ts +++ b/apps/e2e/cypress/e2e/templatesAdvanced.cy.ts @@ -475,9 +475,7 @@ context('Template tests', () => { cy.contains(fileQuestion); cy.contains('Save and continue').click(); - cy.contains(fileQuestion) - .parent() - .contains('field must have at least 1 items'); + cy.contains(fileQuestion).parent().contains('Please upload a file'); cy.intercept({ method: 'POST', diff --git a/apps/frontend/src/components/questionary/questionaryComponents/FileUpload/FileUploadDefinition.tsx b/apps/frontend/src/components/questionary/questionaryComponents/FileUpload/FileUploadDefinition.tsx index cdf3a5f61f..ffd94364c6 100644 --- a/apps/frontend/src/components/questionary/questionaryComponents/FileUpload/FileUploadDefinition.tsx +++ b/apps/frontend/src/components/questionary/questionaryComponents/FileUpload/FileUploadDefinition.tsx @@ -1,11 +1,11 @@ import AttachFileIcon from '@mui/icons-material/AttachFile'; -import { fileUploadQuestionValidationSchema } from '@user-office-software/duo-validation'; import React from 'react'; import defaultRenderer from 'components/questionary/DefaultQuestionRenderer'; import { DataType } from 'generated/sdk'; import { QuestionaryComponentDefinition } from '../../QuestionaryComponentRegistry'; +import { createFileUploadValidationSchema } from '../FileUpload/createFileUploadValidationSchema'; import FilesAnswerRenderer from './FilesAnswerRenderer'; import FileUploadSearchCriteriaInput from './FileUploadSearchCriteriaInput'; import { QuestionaryComponentFileUpload } from './QuestionaryComponentFileUpload'; @@ -25,7 +25,7 @@ export const fileUploadDefinition: QuestionaryComponentDefinition = { answerRenderer: FilesAnswerRenderer, questionRenderer: defaultRenderer.questionRenderer, }, - createYupValidationSchema: fileUploadQuestionValidationSchema, + createYupValidationSchema: createFileUploadValidationSchema, getYupInitialValue: ({ answer }) => answer.value || [], searchCriteriaComponent: FileUploadSearchCriteriaInput, }; diff --git a/apps/frontend/src/components/questionary/questionaryComponents/FileUpload/createFileUploadValidationSchema.ts b/apps/frontend/src/components/questionary/questionaryComponents/FileUpload/createFileUploadValidationSchema.ts new file mode 100644 index 0000000000..2161c31de6 --- /dev/null +++ b/apps/frontend/src/components/questionary/questionaryComponents/FileUpload/createFileUploadValidationSchema.ts @@ -0,0 +1,15 @@ +import * as Yup from 'yup'; + +import { QuestionaryComponentDefinition } from 'components/questionary/QuestionaryComponentRegistry'; +import { FileUploadConfig } from 'generated/sdk'; + +export const createFileUploadValidationSchema: QuestionaryComponentDefinition['createYupValidationSchema'] = + (answer) => { + const config = answer.config as FileUploadConfig; + let schema = Yup.array(); + if (config.required) { + schema = schema.min(1, `Please upload a file.`); + } + + return schema; + }; From 5310cc407b679bb12182a962925d461e5bba9c9c Mon Sep 17 00:00:00 2001 From: Ellen Wright Date: Tue, 26 Mar 2024 12:19:09 +0000 Subject: [PATCH 2/2] Change duo-validation version --- apps/backend/package-lock.json | 8 ++++---- apps/backend/package.json | 2 +- apps/frontend/package-lock.json | 14 +++++++------- apps/frontend/package.json | 2 +- .../FileUpload/FileUploadDefinition.tsx | 4 ++-- .../createFileUploadValidationSchema.ts | 15 --------------- 6 files changed, 15 insertions(+), 30 deletions(-) delete mode 100644 apps/frontend/src/components/questionary/questionaryComponents/FileUpload/createFileUploadValidationSchema.ts diff --git a/apps/backend/package-lock.json b/apps/backend/package-lock.json index bb3aef5a76..1796cffda8 100644 --- a/apps/backend/package-lock.json +++ b/apps/backend/package-lock.json @@ -15,7 +15,7 @@ "@user-office-software/duo-localisation": "^1.2.0", "@user-office-software/duo-logger": "^2.1.1", "@user-office-software/duo-message-broker": "^1.6.0", - "@user-office-software/duo-validation": "^4.0.4", + "@user-office-software/duo-validation": "^5.0.1", "@user-office-software/openid": "^1.4.0", "await-to-js": "^2.1.1", "bcryptjs": "^2.4.3", @@ -3076,9 +3076,9 @@ } }, "node_modules/@user-office-software/duo-validation": { - "version": "4.0.4", - "resolved": "https://registry.npmjs.org/@user-office-software/duo-validation/-/duo-validation-4.0.4.tgz", - "integrity": "sha512-e42tI8eu+pZTqImraLYG73pqQtmQWDd0oMkogmoZppm2Bx8if/aZkeeLcT/imggL0QUbmYV7FOb7HWIQ/8t1dQ==", + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/@user-office-software/duo-validation/-/duo-validation-5.0.1.tgz", + "integrity": "sha512-o9fB332zV+MJzzPQJsUPDyolo/ygR77SjAyLaEItnws5ze7+EiH9Mqwec7t2pnXFEajHlg7VrAUoK0bsXxLd6A==", "dependencies": { "luxon": "^2.5.0", "sanitize-html": "^2.7.1", diff --git a/apps/backend/package.json b/apps/backend/package.json index 458a8f8ec1..c0cf3df24f 100644 --- a/apps/backend/package.json +++ b/apps/backend/package.json @@ -39,7 +39,7 @@ "@user-office-software/duo-localisation": "^1.2.0", "@user-office-software/duo-logger": "^2.1.1", "@user-office-software/duo-message-broker": "^1.6.0", - "@user-office-software/duo-validation": "^4.0.4", + "@user-office-software/duo-validation": "^5.0.1", "@user-office-software/openid": "^1.4.0", "await-to-js": "^2.1.1", "bcryptjs": "^2.4.3", diff --git a/apps/frontend/package-lock.json b/apps/frontend/package-lock.json index d7c0ebc9bb..e151d098f6 100644 --- a/apps/frontend/package-lock.json +++ b/apps/frontend/package-lock.json @@ -34,7 +34,7 @@ "@types/yup": "^0.29.13", "@uiw/react-codemirror": "^4.21.7", "@user-office-software/duo-localisation": "^1.2.0", - "@user-office-software/duo-validation": "^4.0.4", + "@user-office-software/duo-validation": "^5.0.1", "clsx": "^1.1.1", "formik": "^2.2.9", "formik-mui": "^4.0.0-alpha.3", @@ -5061,9 +5061,9 @@ "integrity": "sha512-9axYsEtg5rr7FDibUTIaGxd1+sRpvreytLuhEQBZdzA+MXL5TxZcDGAqSQarrTklHP4mcJTWvDzyMV/yCKmYOw==" }, "node_modules/@user-office-software/duo-validation": { - "version": "4.0.4", - "resolved": "https://registry.npmjs.org/@user-office-software/duo-validation/-/duo-validation-4.0.4.tgz", - "integrity": "sha512-e42tI8eu+pZTqImraLYG73pqQtmQWDd0oMkogmoZppm2Bx8if/aZkeeLcT/imggL0QUbmYV7FOb7HWIQ/8t1dQ==", + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/@user-office-software/duo-validation/-/duo-validation-5.0.1.tgz", + "integrity": "sha512-o9fB332zV+MJzzPQJsUPDyolo/ygR77SjAyLaEItnws5ze7+EiH9Mqwec7t2pnXFEajHlg7VrAUoK0bsXxLd6A==", "dependencies": { "luxon": "^2.5.0", "sanitize-html": "^2.7.1", @@ -16757,9 +16757,9 @@ "integrity": "sha512-9axYsEtg5rr7FDibUTIaGxd1+sRpvreytLuhEQBZdzA+MXL5TxZcDGAqSQarrTklHP4mcJTWvDzyMV/yCKmYOw==" }, "@user-office-software/duo-validation": { - "version": "4.0.4", - "resolved": "https://registry.npmjs.org/@user-office-software/duo-validation/-/duo-validation-4.0.4.tgz", - "integrity": "sha512-e42tI8eu+pZTqImraLYG73pqQtmQWDd0oMkogmoZppm2Bx8if/aZkeeLcT/imggL0QUbmYV7FOb7HWIQ/8t1dQ==", + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/@user-office-software/duo-validation/-/duo-validation-5.0.1.tgz", + "integrity": "sha512-o9fB332zV+MJzzPQJsUPDyolo/ygR77SjAyLaEItnws5ze7+EiH9Mqwec7t2pnXFEajHlg7VrAUoK0bsXxLd6A==", "requires": { "luxon": "^2.5.0", "sanitize-html": "^2.7.1", diff --git a/apps/frontend/package.json b/apps/frontend/package.json index 69941a51c7..570b107316 100644 --- a/apps/frontend/package.json +++ b/apps/frontend/package.json @@ -34,7 +34,7 @@ "@types/yup": "^0.29.13", "@uiw/react-codemirror": "^4.21.7", "@user-office-software/duo-localisation": "^1.2.0", - "@user-office-software/duo-validation": "^4.0.4", + "@user-office-software/duo-validation": "^5.0.1", "clsx": "^1.1.1", "formik": "^2.2.9", "formik-mui": "^4.0.0-alpha.3", diff --git a/apps/frontend/src/components/questionary/questionaryComponents/FileUpload/FileUploadDefinition.tsx b/apps/frontend/src/components/questionary/questionaryComponents/FileUpload/FileUploadDefinition.tsx index ffd94364c6..cdf3a5f61f 100644 --- a/apps/frontend/src/components/questionary/questionaryComponents/FileUpload/FileUploadDefinition.tsx +++ b/apps/frontend/src/components/questionary/questionaryComponents/FileUpload/FileUploadDefinition.tsx @@ -1,11 +1,11 @@ import AttachFileIcon from '@mui/icons-material/AttachFile'; +import { fileUploadQuestionValidationSchema } from '@user-office-software/duo-validation'; import React from 'react'; import defaultRenderer from 'components/questionary/DefaultQuestionRenderer'; import { DataType } from 'generated/sdk'; import { QuestionaryComponentDefinition } from '../../QuestionaryComponentRegistry'; -import { createFileUploadValidationSchema } from '../FileUpload/createFileUploadValidationSchema'; import FilesAnswerRenderer from './FilesAnswerRenderer'; import FileUploadSearchCriteriaInput from './FileUploadSearchCriteriaInput'; import { QuestionaryComponentFileUpload } from './QuestionaryComponentFileUpload'; @@ -25,7 +25,7 @@ export const fileUploadDefinition: QuestionaryComponentDefinition = { answerRenderer: FilesAnswerRenderer, questionRenderer: defaultRenderer.questionRenderer, }, - createYupValidationSchema: createFileUploadValidationSchema, + createYupValidationSchema: fileUploadQuestionValidationSchema, getYupInitialValue: ({ answer }) => answer.value || [], searchCriteriaComponent: FileUploadSearchCriteriaInput, }; diff --git a/apps/frontend/src/components/questionary/questionaryComponents/FileUpload/createFileUploadValidationSchema.ts b/apps/frontend/src/components/questionary/questionaryComponents/FileUpload/createFileUploadValidationSchema.ts deleted file mode 100644 index 2161c31de6..0000000000 --- a/apps/frontend/src/components/questionary/questionaryComponents/FileUpload/createFileUploadValidationSchema.ts +++ /dev/null @@ -1,15 +0,0 @@ -import * as Yup from 'yup'; - -import { QuestionaryComponentDefinition } from 'components/questionary/QuestionaryComponentRegistry'; -import { FileUploadConfig } from 'generated/sdk'; - -export const createFileUploadValidationSchema: QuestionaryComponentDefinition['createYupValidationSchema'] = - (answer) => { - const config = answer.config as FileUploadConfig; - let schema = Yup.array(); - if (config.required) { - schema = schema.min(1, `Please upload a file.`); - } - - return schema; - };