Skip to content

Commit

Permalink
Merge pull request #294 from JeffreyMFarley/hotfix-1073
Browse files Browse the repository at this point in the history
[patch] Also remove hidden children when unchecking a parent
  • Loading branch information
JeffreyMFarley authored Jun 30, 2020
2 parents 3b0ea5a + 6a5c729 commit 196ddce
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 13 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ jobs:
python -m pip install --upgrade pip
pip install tox
- name: Set up Node
uses: actions/setup-node@v1
with:
node-version: 10.x

- name: Install Node dependencies
run: |
npm config set package-lock false
- name: Run back-end tests
run: |
tox
30 changes: 19 additions & 11 deletions src/components/Filters/AggregationBranch.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,23 @@ export class AggregationBranch extends React.Component {
}

_decideClickAction() {
const { item, subitems, fieldName, checkedState } = this.props

// List all the filters
const values = [ item.key ]
subitems.forEach( sub => {
values.push( slugify( item.key, sub.key ) )
} )
const {
activeChildren, item, subitems, fieldName, checkedState
} = this.props

const values = new Set()
// Add the parent
values.add( item.key )
// Add the shown subitems
subitems.forEach( sub => { values.add( slugify( item.key, sub.key ) ) } )
// Add the active filters (that might be hidden)
activeChildren.forEach( child => values.add( child ) )

const action = checkedState === CHECKED ?
this.props.uncheckParent :
this.props.checkParent

action( fieldName, values )
action( fieldName, [ ...values ] )
}

_toggleChildDisplay() {
Expand Down Expand Up @@ -128,6 +132,7 @@ export class AggregationBranch extends React.Component {
}

AggregationBranch.propTypes = {
activeChildren: PropTypes.array,
checkParent: PropTypes.func.isRequired,
checkedState: PropTypes.string,
fieldName: PropTypes.string.isRequired,
Expand Down Expand Up @@ -155,19 +160,22 @@ export const mapStateToProps = ( state, ownProps ) => {
const hasKey = candidates.filter( x => x.indexOf( ownProps.item.key ) === 0 )

// Does the key contain the separator?
const activeChild = hasKey.filter( x => x.indexOf( SLUG_SEPARATOR ) !== -1 )
const activeChildren = hasKey.filter(
x => x.indexOf( SLUG_SEPARATOR ) !== -1
)
const activeParent = hasKey.filter( x => x === ownProps.item.key )

let checkedState = UNCHECKED
if ( activeParent.length === 0 && activeChild.length > 0 ) {
if ( activeParent.length === 0 && activeChildren.length > 0 ) {
checkedState = INDETERMINATE
} else if ( activeParent.length > 0 ) {
checkedState = CHECKED
}

return {
activeChildren,
checkedState,
showChildren: activeChild.length > 0
showChildren: activeChildren.length > 0
}
}

Expand Down
10 changes: 8 additions & 2 deletions src/components/Filters/__tests__/AggregationBranch.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ const subitems = [

function setupEnzyme(checkedState=UNCHECKED) {
const props = {
activeChildren: [
// not hidden
slugify( 'foo', 'bar' ),
// hidden
slugify( 'foo', 'quux' )
],
checkedState,
checkParent: jest.fn(),
fieldName: "issue",
Expand Down Expand Up @@ -111,7 +117,7 @@ describe('component::AggregationBranch', () => {
const checkbox = target.find('li.parent input[type="checkbox"]')
checkbox.simulate('change')
expect(props.uncheckParent).toHaveBeenCalledWith(
'issue', ['foo', 'foo•bar', 'foo•baz', 'foo•qaz']
'issue', ['foo', 'foo•bar', 'foo•baz', 'foo•qaz', 'foo•quux']
)
expect(props.checkParent).not.toHaveBeenCalled()
})
Expand All @@ -122,7 +128,7 @@ describe('component::AggregationBranch', () => {
checkbox.simulate('change')
expect(props.uncheckParent).not.toHaveBeenCalled()
expect(props.checkParent).toHaveBeenCalledWith(
'issue', ['foo', 'foo•bar', 'foo•baz', 'foo•qaz']
'issue', ['foo', 'foo•bar', 'foo•baz', 'foo•qaz', 'foo•quux']
)
})
})
Expand Down

0 comments on commit 196ddce

Please sign in to comment.