From c167f1887a280c942d440bea5749c79af94f0b4b Mon Sep 17 00:00:00 2001 From: Adam Caouette Date: Thu, 9 Jun 2022 16:51:59 -0400 Subject: [PATCH 1/5] CSR-480: clean up some faulty logic I discovered that was only clearing answers if multi-select --- .../button-question/button-question.spec.js | 3 ++- .../button-question/button-question.vue | 11 ++++------- .../list-button-horizontal/list-button-horizontal.vue | 2 +- src/ux-components/list-button/list-button.vue | 2 +- src/ux-components/list-card/list-card.vue | 2 +- 5 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/common-components/button-question/button-question.spec.js b/src/common-components/button-question/button-question.spec.js index b70304035..9cf75368e 100644 --- a/src/common-components/button-question/button-question.spec.js +++ b/src/common-components/button-question/button-question.spec.js @@ -112,7 +112,8 @@ describe("buttonQuestion.vue", () => { const wrapper = shallowMount(buttonQuestion, setupMocks({})); await wrapper.setProps({ answers: ["2022", "2021", "2020"], - isMultiSelect: false + isMultiSelect: false, + modelValue: [] }); const val = { checkValue: true, value: "2021", } wrapper.vm.handleCheckedChanged(val); diff --git a/src/common-components/button-question/button-question.vue b/src/common-components/button-question/button-question.vue index 07efe470e..de00d3ce0 100644 --- a/src/common-components/button-question/button-question.vue +++ b/src/common-components/button-question/button-question.vue @@ -133,17 +133,14 @@ export default { return answer.Name ? answer.Name : answer; }, handleCheckedChanged(val) { - - if(this.isMultiSelect && this.selectedValues) { - // Add or remove item to array of data to emit - const newSelectedValues = this.selectedValues; - + if(this.selectingInitiatesLoad) { + this.selectedValues = [val.value]; + } else { if(Array.isArray(this.selectedValues)) { + const newSelectedValues = this.selectedValues; val.checkValue ? newSelectedValues.push(val.value) : newSelectedValues.splice(newSelectedValues.indexOf(val.value), 1); this.selectedValues = newSelectedValues; } - } else { - this.selectedValues = [val.value]; } }, }, diff --git a/src/ux-components/list-button-horizontal/list-button-horizontal.vue b/src/ux-components/list-button-horizontal/list-button-horizontal.vue index eef4be443..0938bf62d 100644 --- a/src/ux-components/list-button-horizontal/list-button-horizontal.vue +++ b/src/ux-components/list-button-horizontal/list-button-horizontal.vue @@ -92,7 +92,7 @@ export default { : this.selectedValues[0]; } }, - unmounted() { // needed to clear this button's selectedValues if it is removed + unmounted() { // needed to clear this button's selectedValues if it is removed to keep validation in sync this.checkValue = false; this.handleCheckChange(); }, diff --git a/src/ux-components/list-button/list-button.vue b/src/ux-components/list-button/list-button.vue index f09384934..a15cbb38c 100644 --- a/src/ux-components/list-button/list-button.vue +++ b/src/ux-components/list-button/list-button.vue @@ -92,7 +92,7 @@ export default { : this.selectedValues[0]; } }, - unmounted() { // needed to clear this button's selectedValues if it is removed + unmounted() { // needed to clear this button's selectedValues if it is removed to keep validation in sync this.checkValue = false; this.handleCheckChange(); }, diff --git a/src/ux-components/list-card/list-card.vue b/src/ux-components/list-card/list-card.vue index 264d7c299..ac88c9b8e 100644 --- a/src/ux-components/list-card/list-card.vue +++ b/src/ux-components/list-card/list-card.vue @@ -99,7 +99,7 @@ export default { : this.selectedValues[0]; } }, - unmounted() { // needed to clear this button's selectedValues if it is removed + unmounted() { // needed to clear this button's selectedValues if it is removed to keep validation in sync this.checkValue = false; this.handleCheckChange(); }, From 4b9700716f5192fe95db90f09dfd9b3214a61e4c Mon Sep 17 00:00:00 2001 From: Adam Caouette Date: Mon, 13 Jun 2022 20:47:47 -0400 Subject: [PATCH 2/5] minor logic updates to shared list- buttons, new question-chain component --- jest.config.js | 1 + .../button-question/button-question.vue | 5 + .../question-chain/question-chain.vue | 130 ++++++++++++++++++ .../list-button-horizontal.vue | 10 +- src/ux-components/list-button/list-button.vue | 10 +- src/ux-components/list-card/list-card.vue | 10 +- 6 files changed, 160 insertions(+), 6 deletions(-) create mode 100644 src/common-components/question-chain/question-chain.vue diff --git a/jest.config.js b/jest.config.js index 0dd06d9be..3eb317d81 100644 --- a/jest.config.js +++ b/jest.config.js @@ -26,6 +26,7 @@ module.exports = { "!src/ux-components/alert\alert.vue", "!src/helpers/validation-rules.js", "!src/common-components/menu-modal/menu-modal.vue", + "!src/common-components/question-chain/question-chain", // END ], // ! means exclude from coverage. testMatch: ["**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)"], diff --git a/src/common-components/button-question/button-question.vue b/src/common-components/button-question/button-question.vue index de00d3ce0..7bf4d56c8 100644 --- a/src/common-components/button-question/button-question.vue +++ b/src/common-components/button-question/button-question.vue @@ -36,6 +36,7 @@ data-test="button" :validationRules="validationRules" :class="[suppressError ? 'alertError' : '']" + :clearOnUnmount="clearOnUnmount" /> @@ -84,6 +85,10 @@ export default { validationRules: String, suppressError: Boolean, useTextForValue: Boolean, + clearOnUnmount: { + type: Boolean, + default: true + } }, computed: { getFieldSetClasses() { diff --git a/src/common-components/question-chain/question-chain.vue b/src/common-components/question-chain/question-chain.vue new file mode 100644 index 000000000..fb61608d5 --- /dev/null +++ b/src/common-components/question-chain/question-chain.vue @@ -0,0 +1,130 @@ + + + \ No newline at end of file diff --git a/src/ux-components/list-button-horizontal/list-button-horizontal.vue b/src/ux-components/list-button-horizontal/list-button-horizontal.vue index 0938bf62d..dfd322cb3 100644 --- a/src/ux-components/list-button-horizontal/list-button-horizontal.vue +++ b/src/ux-components/list-button-horizontal/list-button-horizontal.vue @@ -78,6 +78,10 @@ export default { validationRules: String, selectedValues: [Array, String], hasError: Boolean, + clearOnUnmount: { + type: Boolean, + default: true + } }, data() { return { @@ -93,8 +97,10 @@ export default { } }, unmounted() { // needed to clear this button's selectedValues if it is removed to keep validation in sync - this.checkValue = false; - this.handleCheckChange(); + if (this.clearOnUnmount) { + this.checkValue = false; + this.handleCheckChange(); + } }, methods: { displayLoader() { diff --git a/src/ux-components/list-button/list-button.vue b/src/ux-components/list-button/list-button.vue index a15cbb38c..861619093 100644 --- a/src/ux-components/list-button/list-button.vue +++ b/src/ux-components/list-button/list-button.vue @@ -78,6 +78,10 @@ export default { validationRules: String, selectedValues: [Array, String], hasError: Boolean, + clearOnUnmount: { + type: Boolean, + default: true + } }, data() { return { @@ -93,8 +97,10 @@ export default { } }, unmounted() { // needed to clear this button's selectedValues if it is removed to keep validation in sync - this.checkValue = false; - this.handleCheckChange(); + if (this.clearOnUnmount) { + this.checkValue = false; + this.handleCheckChange(); + } }, methods: { displayLoader() { diff --git a/src/ux-components/list-card/list-card.vue b/src/ux-components/list-card/list-card.vue index ac88c9b8e..88aad0b6a 100644 --- a/src/ux-components/list-card/list-card.vue +++ b/src/ux-components/list-card/list-card.vue @@ -86,6 +86,10 @@ export default { selectedValues: [Array, String], modelValue: Object, hasError: Boolean, + clearOnUnmount: { + type: Boolean, + default: true + } }, data() { return { @@ -100,8 +104,10 @@ export default { } }, unmounted() { // needed to clear this button's selectedValues if it is removed to keep validation in sync - this.checkValue = false; - this.handleCheckChange(); + if (this.clearOnUnmount) { + this.checkValue = false; + this.handleCheckChange(); + } }, computed: { getLabelClasses() { From 6164be582b1f5e49aa9f9f81fff6d6f0cd1be8fd Mon Sep 17 00:00:00 2001 From: Adam Caouette Date: Mon, 13 Jun 2022 20:58:38 -0400 Subject: [PATCH 3/5] CSR-480: remove unused computeds, formatting --- .../question-chain/question-chain.vue | 83 +++++++++---------- 1 file changed, 37 insertions(+), 46 deletions(-) diff --git a/src/common-components/question-chain/question-chain.vue b/src/common-components/question-chain/question-chain.vue index fb61608d5..0be09fabf 100644 --- a/src/common-components/question-chain/question-chain.vue +++ b/src/common-components/question-chain/question-chain.vue @@ -55,15 +55,6 @@ export default { questions.unshift({}); return questions; }, - questionText() { - return this.questions[this.currentQuestion]?.questionText; - }, - questionAnswers() { - return this.questions[this.currentQuestion]?.answers; - }, - questionGroupname() { - return `${this.questionData.glassName}-${this.questionData.glassLocation}-${this.currentQuestion}`; - }, selectedValue: { get: function() { return this.modelValue; @@ -78,50 +69,50 @@ export default { } }, methods: { - getNewModelValue(returnedAnswer) { - if (!returnedAnswer || !Array.isArray(returnedAnswer)) { return false } - const lastAnswer = returnedAnswer[returnedAnswer.length - 1]; - const currentQuestion = this.questions[this.currentQuestion]; - console.log('currentQuestion: ', currentQuestion) - console.log('currentQuestion.answers: ', currentQuestion.answers) + getNewModelValue(returnedAnswer) { + if (!returnedAnswer || !Array.isArray(returnedAnswer)) { return false } + const lastAnswer = returnedAnswer[returnedAnswer.length - 1]; + const currentQuestion = this.questions[this.currentQuestion]; + console.log('currentQuestion: ', currentQuestion) + console.log('currentQuestion.answers: ', currentQuestion.answers) - if (lastAnswer.indexOf("answer-") === 0) { - // if it is an answerResult - const finalAnswer = lastAnswer.slice(7); + if (lastAnswer.indexOf("answer-") === 0) { + // if it is an answerResult + const finalAnswer = lastAnswer.slice(7); - const currentQuestionSelectedAnswer = currentQuestion.answers.find( - ({ answerResult }) => answerResult === finalAnswer - ); + const currentQuestionSelectedAnswer = currentQuestion.answers.find( + ({ answerResult }) => answerResult === finalAnswer + ); - // add current item to list of answered questions - this.answeredQuestions.push( - { - questionText: currentQuestion.questionText, - selectedAnswerText: currentQuestionSelectedAnswer.Text, - } - ); + // add current item to list of answered questions + this.answeredQuestions.push( + { + questionText: currentQuestion.questionText, + selectedAnswerText: currentQuestionSelectedAnswer.Text, + } + ); - return { - answerResult: finalAnswer, - answeredQuestions: this.answeredQuestions, - }; - } else { - const currentQuestionSelectedAnswer = currentQuestion.answers.find( - ({ nextQuestionSequence }) => nextQuestionSequence === parseInt(lastAnswer) - ); + return { + answerResult: finalAnswer, + answeredQuestions: this.answeredQuestions, + }; + } else { + const currentQuestionSelectedAnswer = currentQuestion.answers.find( + ({ nextQuestionSequence }) => nextQuestionSequence === parseInt(lastAnswer) + ); - // add current item to list of answered questions - this.answeredQuestions.push( - { - questionText: currentQuestion.questionText, - selectedAnswerText: currentQuestionSelectedAnswer.Text, - } - ); + // add current item to list of answered questions + this.answeredQuestions.push( + { + questionText: currentQuestion.questionText, + selectedAnswerText: currentQuestionSelectedAnswer.Text, + } + ); - this.currentQuestion = parseInt(lastAnswer); // update count to display next question - return false; - } + this.currentQuestion = parseInt(lastAnswer); // update count to display next question + return false; } + } }, components: { buttonQuestion, From 168a4fe5aa4ec3b3b614f2193ab0c8c823a26a62 Mon Sep 17 00:00:00 2001 From: Adam Caouette Date: Tue, 14 Jun 2022 09:27:23 -0400 Subject: [PATCH 4/5] CSR-480: remove unnecessary await/async --- src/common-components/question-chain/question-chain.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common-components/question-chain/question-chain.vue b/src/common-components/question-chain/question-chain.vue index 0be09fabf..531cf7a8a 100644 --- a/src/common-components/question-chain/question-chain.vue +++ b/src/common-components/question-chain/question-chain.vue @@ -59,8 +59,8 @@ export default { get: function() { return this.modelValue; }, - set: async function(returnedAnswer) { - const isNewModelValueComplete = await this.getNewModelValue(returnedAnswer); + set: function(returnedAnswer) { + const isNewModelValueComplete = this.getNewModelValue(returnedAnswer); if (isNewModelValueComplete) { this.$emit("update:modelValue", isNewModelValueComplete); From 52e2290034fabdac0249744c10f81bc8a9a738ed Mon Sep 17 00:00:00 2001 From: Adam Caouette Date: Tue, 14 Jun 2022 09:29:14 -0400 Subject: [PATCH 5/5] CSR-480: remove console logs --- src/common-components/question-chain/question-chain.vue | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/common-components/question-chain/question-chain.vue b/src/common-components/question-chain/question-chain.vue index 531cf7a8a..d605d7fde 100644 --- a/src/common-components/question-chain/question-chain.vue +++ b/src/common-components/question-chain/question-chain.vue @@ -73,8 +73,6 @@ export default { if (!returnedAnswer || !Array.isArray(returnedAnswer)) { return false } const lastAnswer = returnedAnswer[returnedAnswer.length - 1]; const currentQuestion = this.questions[this.currentQuestion]; - console.log('currentQuestion: ', currentQuestion) - console.log('currentQuestion.answers: ', currentQuestion.answers) if (lastAnswer.indexOf("answer-") === 0) { // if it is an answerResult