minor logic updates to shared list- buttons, new question-chain component
This commit is contained in:
parent
c167f1887a
commit
4b9700716f
6 changed files with 160 additions and 6 deletions
|
|
@ -26,6 +26,7 @@ module.exports = {
|
||||||
"!src/ux-components/alert\alert.vue",
|
"!src/ux-components/alert\alert.vue",
|
||||||
"!src/helpers/validation-rules.js",
|
"!src/helpers/validation-rules.js",
|
||||||
"!src/common-components/menu-modal/menu-modal.vue",
|
"!src/common-components/menu-modal/menu-modal.vue",
|
||||||
|
"!src/common-components/question-chain/question-chain",
|
||||||
// END
|
// END
|
||||||
], // ! means exclude from coverage.
|
], // ! means exclude from coverage.
|
||||||
testMatch: ["**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)"],
|
testMatch: ["**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)"],
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@
|
||||||
data-test="button"
|
data-test="button"
|
||||||
:validationRules="validationRules"
|
:validationRules="validationRules"
|
||||||
:class="[suppressError ? 'alertError' : '']"
|
:class="[suppressError ? 'alertError' : '']"
|
||||||
|
:clearOnUnmount="clearOnUnmount"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
@ -84,6 +85,10 @@ export default {
|
||||||
validationRules: String,
|
validationRules: String,
|
||||||
suppressError: Boolean,
|
suppressError: Boolean,
|
||||||
useTextForValue: Boolean,
|
useTextForValue: Boolean,
|
||||||
|
clearOnUnmount: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
getFieldSetClasses() {
|
getFieldSetClasses() {
|
||||||
|
|
|
||||||
130
src/common-components/question-chain/question-chain.vue
Normal file
130
src/common-components/question-chain/question-chain.vue
Normal file
|
|
@ -0,0 +1,130 @@
|
||||||
|
<template>
|
||||||
|
<div v-for="(q, i) in questions" :key="i">
|
||||||
|
<transition appear name="fade" mode="out-in">
|
||||||
|
<buttonQuestion
|
||||||
|
v-if="q.questionSequence === currentQuestion"
|
||||||
|
class="radioQuestion"
|
||||||
|
:questionText="q.questionText"
|
||||||
|
:answers="q.answers"
|
||||||
|
:groupName="`${questionData.glassName}-${questionData.glassLocation}-${i}`"
|
||||||
|
textPosition="text-start"
|
||||||
|
v-model="selectedValue"
|
||||||
|
isRequired=true
|
||||||
|
:validationRules="validationRules"
|
||||||
|
:clearOnUnmount=false
|
||||||
|
/>
|
||||||
|
</transition>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import buttonQuestion from "@/common-components/button-question/button-question";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: "questionChain",
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
models: Array,
|
||||||
|
currentQuestion: 1,
|
||||||
|
answeredQuestions: [],
|
||||||
|
};
|
||||||
|
},
|
||||||
|
props: {
|
||||||
|
questionData: Array,
|
||||||
|
validationRules: String,
|
||||||
|
modelValue: String,
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
questions() {
|
||||||
|
const questions = this.questionData.partQuestions.map((q, i) => {
|
||||||
|
return {
|
||||||
|
questionText: q.questionText,
|
||||||
|
questionSequence: q.questionSequence,
|
||||||
|
answers: q.answers.map((a) => {
|
||||||
|
return {
|
||||||
|
Text: a.answerText,
|
||||||
|
// Name will either be nextQuestionSequence or answerResult
|
||||||
|
Name: a.nextQuestionSequence ? a.nextQuestionSequence : "answer-" + a.answerResult,
|
||||||
|
nextQuestionSequence: a.nextQuestionSequence,
|
||||||
|
answerResult: a.answerResult,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// add an empty item to be array[0] since we start with 1
|
||||||
|
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;
|
||||||
|
},
|
||||||
|
set: async function(returnedAnswer) {
|
||||||
|
const isNewModelValueComplete = await this.getNewModelValue(returnedAnswer);
|
||||||
|
|
||||||
|
if (isNewModelValueComplete) {
|
||||||
|
this.$emit("update:modelValue", isNewModelValueComplete);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
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)
|
||||||
|
|
||||||
|
if (lastAnswer.indexOf("answer-") === 0) {
|
||||||
|
// if it is an answerResult
|
||||||
|
const finalAnswer = lastAnswer.slice(7);
|
||||||
|
|
||||||
|
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,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
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,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
this.currentQuestion = parseInt(lastAnswer); // update count to display next question
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
components: {
|
||||||
|
buttonQuestion,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
@ -78,6 +78,10 @@ export default {
|
||||||
validationRules: String,
|
validationRules: String,
|
||||||
selectedValues: [Array, String],
|
selectedValues: [Array, String],
|
||||||
hasError: Boolean,
|
hasError: Boolean,
|
||||||
|
clearOnUnmount: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
}
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
|
@ -93,8 +97,10 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
unmounted() { // needed to clear this button's selectedValues if it is removed to keep validation in sync
|
unmounted() { // needed to clear this button's selectedValues if it is removed to keep validation in sync
|
||||||
this.checkValue = false;
|
if (this.clearOnUnmount) {
|
||||||
this.handleCheckChange();
|
this.checkValue = false;
|
||||||
|
this.handleCheckChange();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
displayLoader() {
|
displayLoader() {
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,10 @@ export default {
|
||||||
validationRules: String,
|
validationRules: String,
|
||||||
selectedValues: [Array, String],
|
selectedValues: [Array, String],
|
||||||
hasError: Boolean,
|
hasError: Boolean,
|
||||||
|
clearOnUnmount: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
}
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
|
@ -93,8 +97,10 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
unmounted() { // needed to clear this button's selectedValues if it is removed to keep validation in sync
|
unmounted() { // needed to clear this button's selectedValues if it is removed to keep validation in sync
|
||||||
this.checkValue = false;
|
if (this.clearOnUnmount) {
|
||||||
this.handleCheckChange();
|
this.checkValue = false;
|
||||||
|
this.handleCheckChange();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
displayLoader() {
|
displayLoader() {
|
||||||
|
|
|
||||||
|
|
@ -86,6 +86,10 @@ export default {
|
||||||
selectedValues: [Array, String],
|
selectedValues: [Array, String],
|
||||||
modelValue: Object,
|
modelValue: Object,
|
||||||
hasError: Boolean,
|
hasError: Boolean,
|
||||||
|
clearOnUnmount: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
}
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
|
@ -100,8 +104,10 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
unmounted() { // needed to clear this button's selectedValues if it is removed to keep validation in sync
|
unmounted() { // needed to clear this button's selectedValues if it is removed to keep validation in sync
|
||||||
this.checkValue = false;
|
if (this.clearOnUnmount) {
|
||||||
this.handleCheckChange();
|
this.checkValue = false;
|
||||||
|
this.handleCheckChange();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
getLabelClasses() {
|
getLabelClasses() {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue