-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Creating
AccessOptions
and separating checkbox
type from `Advance…
…dFilter`.
- Loading branch information
1 parent
6c8ea5b
commit c839a8e
Showing
3 changed files
with
58 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import React, { useCallback, useMemo } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { setAdvancedFilter } from '../../../advanced'; | ||
import { useDispatch } from 'react-redux'; | ||
|
||
const AccessOptions = ({ advancedFilter, datastoreUid, filterGroupUid }) => { | ||
const dispatch = useDispatch(); | ||
|
||
const isChecked = useMemo(() => { | ||
return (!advancedFilter.activeFilters?.length && advancedFilter.conditions.default === 'checked') | ||
|| (advancedFilter.activeFilters?.[0] === advancedFilter.conditions.checked); | ||
}, [advancedFilter]); | ||
|
||
const value = isChecked ? advancedFilter.conditions.unchecked : advancedFilter.conditions.checked; | ||
|
||
const changeAdvancedFilter = useCallback(() => { | ||
dispatch(setAdvancedFilter({ | ||
datastoreUid, | ||
filterGroupUid, | ||
filterValue: value, | ||
onlyOneFilterValue: true | ||
})); | ||
}, [dispatch, datastoreUid, filterGroupUid, value]); | ||
|
||
return ( | ||
<label> | ||
<input | ||
type='checkbox' | ||
checked={isChecked} | ||
onChange={changeAdvancedFilter} | ||
/> | ||
<span>{advancedFilter.name}</span> | ||
</label> | ||
); | ||
}; | ||
|
||
AccessOptions.propTypes = { | ||
advancedFilter: PropTypes.object.isRequired, | ||
datastoreUid: PropTypes.string.isRequired, | ||
filterGroupUid: PropTypes.string.isRequired | ||
}; | ||
|
||
export default AccessOptions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters