Merge pull request #191 from Safelite/feature/v-model_refactoring

Feature/v model refactoring
This commit is contained in:
max-dempsey 2022-02-03 13:06:45 -05:00 committed by GitHub
commit 788750bc66
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 103 additions and 52 deletions

View file

@ -30,7 +30,7 @@
:altText="answer.Name ? answer.Name : answer" :altText="answer.Name ? answer.Name : answer"
screenReaderOnlyText="(opens new window)" screenReaderOnlyText="(opens new window)"
:colLength="this.answers.length < 3 ? '' : '-4'" :colLength="this.answers.length < 3 ? '' : '-4'"
v-model="modelValue" v-model="selectedValues"
data-test="button" data-test="button"
/> />
</div> </div>
@ -98,6 +98,14 @@ export default {
} }
return classes; return classes;
}, },
selectedValues: {
get: function() {
return this.modelValue;
},
set: function(newValue) {
this.$emit("update:modelValue", newValue);
}
},
}, },
data(){ data(){
return { return {

View file

@ -7,7 +7,7 @@
:answers="answersToDisplay" :answers="answersToDisplay"
:groupName="groupName" :groupName="groupName"
buttonType="listCard" buttonType="listCard"
v-model="modelValue" v-model="selectedValues"
/> />
</div> </div>
</template> </template>
@ -39,6 +39,14 @@ export default ({
} }
}, },
computed: { computed: {
selectedValues: {
get: function() {
return this.modelValue;
},
set: function(newValue) {
this.$emit("update:modelValue", newValue);
}
},
damageOptionsMap(){ damageOptionsMap(){
return { return {
Windshield: true, Windshield: true,
@ -56,11 +64,6 @@ export default ({
: []; : [];
}, },
}, },
watch: {
modelValue(val) {
this.$emit("update:modelValue", val);
}
},
components: { components: {
buttonQuestion, buttonQuestion,
} }

View file

@ -8,7 +8,7 @@
:answers="answersToDisplay" :answers="answersToDisplay"
:groupName="groupName" :groupName="groupName"
buttonType="listCard" buttonType="listCard"
v-model="modelValue" v-model="selectedValues"
/> />
</div> </div>
</transition> </transition>
@ -43,6 +43,14 @@ export default ({
} }
}, },
computed: { computed: {
selectedValues: {
get: function() {
return this.modelValue;
},
set: function(newValue) {
this.$emit("update:modelValue", newValue);
}
},
answersToDisplay(){ answersToDisplay(){
return Array.isArray(this.answersFromCms) return Array.isArray(this.answersFromCms)
? this.answersFromCms.filter(ans => ? this.answersFromCms.filter(ans =>
@ -53,11 +61,6 @@ export default ({
: []; : [];
}, },
}, },
watch: {
modelValue(val) {
this.$emit("update:modelValue", val);
}
},
components: { components: {
buttonQuestion, buttonQuestion,
} }

View file

@ -7,7 +7,7 @@
groupName="Choose Vehicle Make" groupName="Choose Vehicle Make"
textPosition="text-start" textPosition="text-start"
:loaderEnabled="true" :loaderEnabled="true"
v-model="modelValue" v-model="selectedValueAsArray"
isRequired=true isRequired=true
/> />
</template> </template>
@ -28,7 +28,19 @@ export default {
}; };
}, },
props: { props: {
modelValue: Array, modelValue: String,
},
computed: {
selectedValueAsArray: {
get: function() {
const modelValueAsArray = this.modelValue ? [this.modelValue] : null;
return modelValueAsArray;
},
set: function(newValue) {
const newValueAsScalar = newValue && newValue.length > 0 ? newValue[0] : null;
this.$emit("update:modelValue", newValueAsScalar);
}
}
}, },
components: { components: {
buttonQuestion, buttonQuestion,
@ -45,10 +57,5 @@ export default {
this.makes = initialData; this.makes = initialData;
}, },
}, },
watch: {
modelValue(val) {
this.$emit("update:modelValue", val);
},
},
}; };
</script> </script>

View file

@ -33,7 +33,7 @@ export default {
name: "vehicle-make", name: "vehicle-make",
data() { data() {
return { return {
selectedMake: [], selectedMake: String,
}; };
}, },
computed: {}, computed: {},

View file

@ -7,7 +7,7 @@
groupName="Choose Vehicle Model" groupName="Choose Vehicle Model"
textPosition="text-start" textPosition="text-start"
:loaderEnabled="true" :loaderEnabled="true"
v-model="modelValue" v-model="selectedValueAsArray"
isRequired=true isRequired=true
/> />
</template> </template>
@ -28,7 +28,19 @@ export default {
}; };
}, },
props: { props: {
modelValue: Array, modelValue: String,
},
computed: {
selectedValueAsArray: {
get: function() {
const modelValueAsArray = this.modelValue ? [this.modelValue] : null;
return modelValueAsArray;
},
set: function(newValue) {
const newValueAsScalar = newValue && newValue.length > 0 ? newValue[0] : null;
this.$emit("update:modelValue", newValueAsScalar);
}
}
}, },
components: { components: {
buttonQuestion, buttonQuestion,
@ -45,10 +57,5 @@ export default {
this.models = initialData; this.models = initialData;
}, },
}, },
watch: {
modelValue(val) {
this.$emit("update:modelValue", val);
},
},
}; };
</script> </script>

View file

@ -33,7 +33,7 @@ export default {
name: "vehicle-model", name: "vehicle-model",
data() { data() {
return { return {
selectedModel: [], selectedModel: String,
}; };
}, },
computed: {}, computed: {},

View file

@ -7,7 +7,7 @@
groupName="Choose Vehicle Style" groupName="Choose Vehicle Style"
textPosition="text-start" textPosition="text-start"
:loaderEnabled="true" :loaderEnabled="true"
v-model="modelValue" v-model="selectedValueAsArray"
isRequired=true isRequired=true
/> />
</template> </template>
@ -28,7 +28,19 @@ export default {
}; };
}, },
props: { props: {
modelValue: Array, modelValue: String,
},
computed: {
selectedValueAsArray: {
get: function() {
const modelValueAsArray = this.modelValue ? [this.modelValue] : null;
return modelValueAsArray;
},
set: function(newValue) {
const newValueAsScalar = newValue && newValue.length > 0 ? newValue[0] : null;
this.$emit("update:modelValue", newValueAsScalar);
}
}
}, },
components: { components: {
buttonQuestion, buttonQuestion,
@ -49,10 +61,5 @@ export default {
this.styles = initialData; this.styles = initialData;
}, },
}, },
watch: {
modelValue(val) {
this.$emit("update:modelValue", val);
},
},
}; };
</script> </script>

View file

@ -32,7 +32,7 @@ export default {
name: "vehicle-style", name: "vehicle-style",
data() { data() {
return { return {
selectedStyle: [], selectedStyle: String,
}; };
}, },
computed: {}, computed: {},

View file

@ -28,7 +28,7 @@ export default {
name: "vehicle-year", name: "vehicle-year",
data() { data() {
return { return {
selectedYear: [], selectedYear: String,
}; };
}, },
computed: {}, computed: {},
@ -73,7 +73,7 @@ export default {
watch: { watch: {
selectedYear(year) { selectedYear(year) {
this.$store.commit(this.storeMutations.UPDATE_YEAR, year); this.$store.commit(this.storeMutations.UPDATE_YEAR, year);
this.$router.navigateAfterSave( this.$router.navigateAfterSave(
this.navigationScenarios.SELECTED_YEAR, this.navigationScenarios.SELECTED_YEAR,

View file

@ -7,7 +7,7 @@
groupName="Choose Vehicle Year" groupName="Choose Vehicle Year"
textPosition="text-start" textPosition="text-start"
:loaderEnabled="true" :loaderEnabled="true"
v-model="modelValue" v-model="selectedValueAsArray"
isRequired=true isRequired=true
/> />
</template> </template>
@ -26,12 +26,24 @@ export default {
}; };
}, },
props: { props: {
modelValue: Array, modelValue: String,
}, },
emits: ['update:modelValue'], emits: ['update:modelValue'],
components: { components: {
buttonQuestion, buttonQuestion,
}, },
computed: {
selectedValueAsArray: {
get: function() {
const modelValueAsArray = this.modelValue ? [this.modelValue] : null;
return modelValueAsArray;
},
set: function(newValue) {
const newValueAsScalar = newValue && newValue.length > 0 ? newValue[0] : null;
this.$emit("update:modelValue", newValueAsScalar);
}
}
},
methods: { methods: {
loadInitialData() { loadInitialData() {
return baseMixin.methods.dispatchNonBlockingStoreAction( return baseMixin.methods.dispatchNonBlockingStoreAction(
@ -44,10 +56,5 @@ export default {
this.years = initialData; this.years = initialData;
}, },
}, },
watch: {
modelValue(val) {
this.$emit("update:modelValue", val);
},
},
}; };
</script> </script>

View file

@ -92,8 +92,11 @@ export default {
}, },
}, },
watch: { watch: {
checkValue(){ checkValue(newValue, oldValue){
this.$emit('isCheckedChanged', {isChecked: this.checkValue, buttonId: this.buttonID}); const isInitialization = typeof(oldValue) !== 'function';
if (isInitialization) {
this.$emit('isCheckedChanged', { isChecked: this.checkValue, buttonId: this.buttonID + '' });
}
} }
}, },
components: { components: {

View file

@ -94,8 +94,11 @@ export default {
}, },
}, },
watch: { watch: {
checkValue(){ checkValue(newValue, oldValue){
this.$emit('isCheckedChanged', {isChecked: this.checkValue, buttonId: this.buttonID}); const isInitialization = typeof(oldValue) !== 'function';
if (isInitialization) {
this.$emit('isCheckedChanged', { isChecked: this.checkValue, buttonId: this.buttonID + '' });
}
} }
}, },
components: { components: {

View file

@ -94,8 +94,11 @@ export default {
}, },
}, },
watch: { watch: {
checkValue(){ checkValue(newValue, oldValue){
this.$emit('isCheckedChanged', {isChecked: this.checkValue, buttonId: this.buttonID}); const isInitialization = typeof(oldValue) !== 'function';
if (isInitialization) {
this.$emit('isCheckedChanged', { isChecked: this.checkValue, buttonId: this.buttonID + '' });
}
} }
}, },
setup(props) { setup(props) {