From 413eea019732c61ddeb2f796e5428091e5d39648 Mon Sep 17 00:00:00 2001 From: Ian Bolton Date: Tue, 19 Dec 2023 15:06:26 -0500 Subject: [PATCH] :bug: Update close messsage when no questions answered (#1641) https://issues.redhat.com/browse/MTA-1940 Signed-off-by: ibolton336 --- client/public/locales/en/translation.json | 4 +++- .../assessment-wizard/assessment-wizard.tsx | 19 +++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/client/public/locales/en/translation.json b/client/public/locales/en/translation.json index 6d37a4925..cefc254cc 100644 --- a/client/public/locales/en/translation.json +++ b/client/public/locales/en/translation.json @@ -212,7 +212,9 @@ "selectOwnerFromStakeholdersList": "Select owner from list of stakeholders", "suggestedAdoptionPlanHelpText": "The suggested approach to migration based on effort, priority, and dependencies.", "taskInProgressForTags": "A new analysis is in-progress. Tags may be updated upon completion.", - "toTagApplication": "Either no tags exist yet or you may not have permission to view any. If you have permission, try creating a new custom tag." + "toTagApplication": "Either no tags exist yet or you may not have permission to view any. If you have permission, try creating a new custom tag.", + "unsavedChanges": "Are you sure you want to close the assessment? Any unsaved changes will be lost.", + "noAnswers": "Are you sure you want to close the assessment? There are no answers to save." }, "proposedActions": { "refactor": "Refactor", diff --git a/client/src/app/pages/assessment/components/assessment-wizard/assessment-wizard.tsx b/client/src/app/pages/assessment/components/assessment-wizard/assessment-wizard.tsx index 9a62eb9df..5fabca265 100644 --- a/client/src/app/pages/assessment/components/assessment-wizard/assessment-wizard.tsx +++ b/client/src/app/pages/assessment/components/assessment-wizard/assessment-wizard.tsx @@ -198,7 +198,11 @@ export const AssessmentWizard: React.FC = ({ return section.questions.every((question) => !questionHasValue(question)); }); - return noAnswers; + const allQuestionsAnswered = sections.every((section) => + areAllQuestionsAnswered(section) + ); + + return noAnswers || allQuestionsAnswered; }; const shouldNextBtnBeEnabled = ( @@ -435,6 +439,13 @@ export const AssessmentWizard: React.FC = ({ } }; + const haveAnyQuestionBeenAnswered = () => { + const questions = values[QUESTIONS_KEY]; + return Object.values(questions).some( + (answer) => answer !== null && answer !== "" + ); + }; + const handleCancelAssessment = () => { if (assessment) { if (isArchetype) { @@ -562,7 +573,11 @@ export const AssessmentWizard: React.FC = ({ onCancel={() => setAssessmentToCancel(null)} onClose={() => setAssessmentToCancel(null)} onConfirm={() => handleCancelAssessment()} - message="Are you sure you want to close the assessment? Any unsaved changes will be lost." + message={ + haveAnyQuestionBeenAnswered() + ? t("message.unsavedChanges") + : t("message.noAnswers") + } /> )}