Skip to content

Commit

Permalink
Improved: code by reducing loops for preparing picker IDs and names a…
Browse files Browse the repository at this point in the history
…nd added comments (hotwax#237)
  • Loading branch information
k2maan committed Aug 31, 2023
1 parent aa0f764 commit e1d0388
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/components/EditPickersModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -190,22 +190,24 @@ export default defineComponent({
{
text: this.$t("Replace"),
handler: () => {
this.save();
this.resetPicker().then(() => {
this.closeModal()
})
}
}
],
});
return alert.present();
},
save() {
this.resetPicker().then(() => {
this.closeModal()
})
},
async resetPicker() {
// remove the 'System Generated' entry through filtering based on ID
const pickerIds = this.selectedPickers.map((picker: any) => picker.id).filter((id: any) => id !== null)
const pickersNameArray = this.selectedPickers.filter((picker: any) => pickerIds.includes(picker.id)).map((picker: any) => picker.name.split(' ')[0])
let pickersNameArray = [] as any;
const pickerIds = this.selectedPickers.map((picker: any) => {
if (picker.id) {
pickersNameArray.push(picker.name.split(' ')[0])
}
return picker.id
}).filter((id: any) => id)
try {
const resp = await UtilService.resetPicker({
Expand Down Expand Up @@ -246,7 +248,10 @@ export default defineComponent({
// for default selection of pickers already associated with the picklist
this.selectedPickers = this.pickers.filter((picker: any) => this.selectedPicklist.pickerIds.includes(picker.id))
// case for 'System Generated' picker
// case for 'System Generated' picker -
// 'System Generated' picker will be visible only if no pickers are associated with the
// picklist. Hence, either 'System Generated' will be shown or all names will be shown
// and not both
if (!this.selectedPickers.length) {
// as selectedPickers will be empty, we manually add the entry
this.selectedPickers = [{
Expand Down

0 comments on commit e1d0388

Please sign in to comment.