-
Notifications
You must be signed in to change notification settings - Fork 41
components: adds toggle filter component #145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
zzacharo
merged 1 commit into
inveniosoftware:master
from
Glignos:add_toggle_filter_element
Oct 26, 2020
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,31 @@ | ||
| --- | ||
| id: toggle | ||
| title: Toggle | ||
| --- | ||
|
|
||
| `Toggle` renders a Toggle Checkbox in a Card element providing a filter for the performed search. | ||
|
|
||
| ## Usage | ||
|
|
||
| ```jsx | ||
| <Toggle | ||
| title="Versions" | ||
| label="View all versions" | ||
| filterValue={['all_versions', 'true']} | ||
| /> | ||
| ``` | ||
|
|
||
| ## Props | ||
|
|
||
| * **title** `String` *optional* | ||
|
|
||
| The optional title for the Card element. | ||
|
|
||
| * **label** `label` *optional* | ||
|
|
||
| An optional label to for the Checkbox element. | ||
|
|
||
| - **filterValue** `Array` | ||
|
|
||
| An array containing the filter to be applied to the search query when active. | ||
|
|
This file contains hidden or 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,70 @@ | ||
| /* | ||
| * This file is part of React-SearchKit. | ||
| * Copyright (C) 2020 CERN. | ||
| * | ||
| * React-SearchKit is free software; you can redistribute it and/or modify it | ||
| * under the terms of the MIT License; see LICENSE file for more details. | ||
| */ | ||
|
|
||
| import React, { Component } from 'react'; | ||
| import { Checkbox } from 'semantic-ui-react'; | ||
| import Overridable from 'react-overridable'; | ||
| import _get from 'lodash/get'; | ||
| import { Card } from 'semantic-ui-react'; | ||
| import PropTypes from 'prop-types'; | ||
|
|
||
| class ToggleComponent extends Component{ | ||
|
|
||
| _isChecked = (userSelectionFilters) => { | ||
| const isFilterActive = userSelectionFilters.filter( | ||
| (filter) => filter[0] === this.props.filterValue[0] | ||
| ).length > 0 | ||
| return isFilterActive | ||
| }; | ||
|
|
||
| onToggleClicked = () => { | ||
| this.props.updateQueryFilters(this.props.filterValue); | ||
| }; | ||
|
|
||
| render() { | ||
| const { | ||
| userSelectionFilters, | ||
| overridableId, | ||
| ...props | ||
| } = this.props; | ||
| var isChecked = this._isChecked(userSelectionFilters); | ||
| return( | ||
| <Overridable id={'SearchFilters.ToggleComponent', this.props.overridableId} {...this.props}> | ||
|
|
||
| <Card> | ||
| <Card.Content> | ||
| <Card.Header>{this.props.title}</Card.Header> | ||
| </Card.Content> | ||
| <Card.Content> | ||
| <Checkbox | ||
| toggle | ||
| label={this.props.label} | ||
| onClick={this.onToggleClicked} | ||
| checked={isChecked} | ||
| /> | ||
| </Card.Content> | ||
| </Card> | ||
| </Overridable> | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| ToggleComponent.propTypes = { | ||
| title: PropTypes.string, | ||
| label: PropTypes.string, | ||
| userSelectionFilters: PropTypes.array.isRequired, | ||
| updateQueryFilters: PropTypes.func.isRequired, | ||
| overridableId: PropTypes.string, | ||
| }; | ||
|
|
||
| ToggleComponent.defaultProps = { | ||
| overridableId: '', | ||
| }; | ||
|
|
||
| export default Overridable.component( | ||
| 'SearchFilters.ToggleComponent', ToggleComponent); |
This file contains hidden or 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,22 @@ | ||
| /* | ||
| * This file is part of React-SearchKit. | ||
| * Copyright (C) 2020 CERN. | ||
| * | ||
| * React-SearchKit is free software; you can redistribute it and/or modify it | ||
| * under the terms of the MIT License; see LICENSE file for more details. | ||
| */ | ||
|
|
||
| import { connect } from '../../store'; | ||
| import { updateQueryFilters } from '../../state/actions'; | ||
| import ToggleComponent from './Toggle'; | ||
|
|
||
| const mapDispatchToProps = dispatch => ({ | ||
| updateQueryFilters: filter => dispatch(updateQueryFilters(filter)), | ||
| }); | ||
|
|
||
| export const Toggle = connect( | ||
| state => ({ | ||
| userSelectionFilters: state.query.filters | ||
| }), | ||
| mapDispatchToProps, | ||
| )(ToggleComponent); | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.