From 2578b56e6d1fa167003ce36f90b48fe108b9e6d6 Mon Sep 17 00:00:00 2001 From: Eric Gauzens Date: Sun, 20 Aug 2023 05:10:59 -0400 Subject: [PATCH] fixed selection bug --- .../src/DropdownMultiselect.vue | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/components/DropdownMultiselect/src/DropdownMultiselect.vue b/src/components/DropdownMultiselect/src/DropdownMultiselect.vue index 3f83b168..99dc6e8a 100644 --- a/src/components/DropdownMultiselect/src/DropdownMultiselect.vue +++ b/src/components/DropdownMultiselect/src/DropdownMultiselect.vue @@ -243,6 +243,21 @@ export default { this.$refs.tree.filter() }, updateParentFacetsSelectedStatus() { + let visibleCheckedParents = this.visibleCheckedNodes.filter(visibleNode => { + return !visibleNode.label.includes('.') + }) + let visibleCheckedChildren = this.visibleCheckedNodes.filter(visibleNode => { + return visibleNode.label.includes('.') + }) + + // First check for any subfacets that have a parent that is not set + visibleCheckedChildren.forEach(checkedChild => { + const parentLabel = checkedChild.label.split('.')[0] + if (!visibleCheckedParents.some(parent => parent.label == parentLabel)) { + this.$refs.tree.setChecked(checkedChild.id, true, true) + } + }) + const halfCheckedNodes = this.$refs.tree.getHalfCheckedNodes() // set the half checked nodes checked status based upon what facets are actually visible since navigating between tabs might // cause some to be hidden so the parent facet should now possibly be checked/unchecked instead of half checked @@ -265,21 +280,13 @@ export default { } }) - const visibleCheckedParents = this.visibleCheckedNodes.filter(visibleNode => { + visibleCheckedParents = this.visibleCheckedNodes.filter(visibleNode => { return !visibleNode.label.includes('.') }) - const visibleCheckedChildren = this.visibleCheckedNodes.filter(visibleNode => { + visibleCheckedChildren = this.visibleCheckedNodes.filter(visibleNode => { return visibleNode.label.includes('.') }) - // Check for any subfacets that have a parent that is not set - visibleCheckedChildren.forEach(checkedChild => { - const parentLabel = checkedChild.label.split('.')[0] - if (!visibleCheckedParents.some(parent => parent.label == parentLabel)) { - this.$refs.tree.setChecked(checkedChild.id, true, true) - } - }) - visibleCheckedParents.forEach(checkedParent => { // If any children are unselected then select one deep so that the parent is half-checked const visibleChildren = checkedParent.children.filter(child => this.allVisibleDataIds.includes(child.label)) @@ -299,6 +306,8 @@ export default { }) if (alreadyCheckedChild != undefined) { this.$refs.tree.setChecked(alreadyCheckedChild.id, true, true) + } else { + this.$refs.tree.setChecked(checkedParent.id, false) } } })