Skip to content

Commit

Permalink
Improved: diff logic for filter and sort options(#146)
Browse files Browse the repository at this point in the history
When having same fieldName in sort and filter options and adding/removing that field in both filter and sort, then always the sort option is honored and the filter option is ignored, as the filter field key gets overridden by the sort key inside the object.
Updated the keys after finding the diff to include filter and sort string in the respective options, to handle the override property issue.
  • Loading branch information
ymaheshwari1 committed Apr 3, 2024
1 parent 4efc7a2 commit 3a8ef27
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/views/BrokeringQuery.vue
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ function findRulesDiff(previousSeq: any, updatedSeq: any) {
}
function findSortDiff(previousSeq: any, updatedSeq: any) {
let seqToUpdate = {}
let seqToUpdate = {} as any
let seqToRemove = {} as any
seqToUpdate = Object.keys(previousSeq).reduce((diff, key) => {
Expand All @@ -860,11 +860,22 @@ function findSortDiff(previousSeq: any, updatedSeq: any) {
return diff
}, seqToUpdate)
// Updated the keys of the object as there are some cases in which the field is same for both filter and sort options thus causing issue when doing same kind operation (addtion or deletion) of fields
seqToUpdate = Object.keys(seqToUpdate).reduce((updatedSeq: any, key) => {
updatedSeq[key + 'sort'] = seqToUpdate[key]
return updatedSeq
}, {})
seqToRemove = Object.keys(seqToRemove).reduce((updatedSeq: any, key) => {
updatedSeq[key + 'sort'] = seqToRemove[key]
return updatedSeq
}, {})
return { seqToUpdate, seqToRemove };
}
function findFilterDiff(previousSeq: any, updatedSeq: any) {
let seqToUpdate = {}
let seqToUpdate = {} as any
let seqToRemove = {} as any
seqToUpdate = Object.keys(previousSeq).reduce((diff, key) => {
Expand Down Expand Up @@ -893,6 +904,17 @@ function findFilterDiff(previousSeq: any, updatedSeq: any) {
return diff
}, seqToUpdate)
// Updated the keys of the object as there are some cases in which the field is same for both filter and sort options thus causing issue when doing same kind operation (addtion or deletion) of fields
seqToUpdate = Object.keys(seqToUpdate).reduce((updatedSeq: any, key) => {
updatedSeq[key + 'filter'] = seqToUpdate[key]
return updatedSeq
}, {})
seqToRemove = Object.keys(seqToRemove).reduce((updatedSeq: any, key) => {
updatedSeq[key + 'filter'] = seqToRemove[key]
return updatedSeq
}, {})
return { seqToUpdate, seqToRemove };
}
Expand Down

0 comments on commit 3a8ef27

Please sign in to comment.