-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
closes #168
- Loading branch information
Showing
8 changed files
with
109 additions
and
8 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
72 changes: 72 additions & 0 deletions
72
ui/src/components/SearchControls/components/SearchDateRange/SearchDateRange.js
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,72 @@ | ||
import React, { Component } from 'react'; | ||
import { Card } from 'semantic-ui-react'; | ||
import { DatePicker } from '@components'; | ||
import { withState, onQueryChanged } from 'react-searchkit'; | ||
import _fromPairs from 'lodash/fromPairs'; | ||
import _toPairs from 'lodash/toPairs'; | ||
import _cloneDeep from 'lodash/cloneDeep'; | ||
|
||
class _SearchDateRange extends Component { | ||
constructor(props) { | ||
super(props); | ||
const [fromDate, toDate] = this.parseUrlDates(); | ||
this.state = { fromDate, toDate }; | ||
} | ||
|
||
parseUrlDates = () => { | ||
const { filters } = this.props.currentQueryState; | ||
const filtersObj = _fromPairs(filters); | ||
const dateFilter = filtersObj['loan.start_date']; | ||
if (dateFilter) return dateFilter.split(','); | ||
return ['', '']; | ||
}; | ||
|
||
updateFilters = () => { | ||
const newQuery = _cloneDeep(this.props.currentQueryState); | ||
const filtersObj = _fromPairs(newQuery.filters); | ||
filtersObj[ | ||
'loan.start_date' | ||
] = `${this.state.fromDate},${this.state.toDate}`; | ||
newQuery.filters = _toPairs(filtersObj); | ||
|
||
// NOTE: since its wrapped with `withState` when the pr is merged | ||
// (https://github.com/inveniosoftware/react-searchkit/pull/100) we could | ||
// use this.props.updateStateQuery(newQuery) instead of the events. | ||
onQueryChanged({ searchQuery: newQuery }); | ||
}; | ||
|
||
render() { | ||
return ( | ||
<Card> | ||
<Card.Content> | ||
<Card.Header>Date</Card.Header> | ||
<Card.Meta> | ||
<span>*Loan start date</span> | ||
</Card.Meta> | ||
</Card.Content> | ||
<Card.Content> | ||
<DatePicker | ||
maxDate={this.state.toDate} | ||
defaultValue={this.state.fromDate} | ||
placeholder="From" | ||
handleDateChange={value => | ||
this.setState({ fromDate: value }, this.updateFilters) | ||
} | ||
/> | ||
</Card.Content> | ||
<Card.Content> | ||
<DatePicker | ||
minDate={this.state.fromDate} | ||
defaultValue={this.state.toDate} | ||
placeholder="To" | ||
handleDateChange={value => | ||
this.setState({ toDate: value }, this.updateFilters) | ||
} | ||
/> | ||
</Card.Content> | ||
</Card> | ||
); | ||
} | ||
} | ||
|
||
export const SearchDateRange = withState(_SearchDateRange); |
1 change: 1 addition & 0 deletions
1
ui/src/components/SearchControls/components/SearchDateRange/index.js
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 @@ | ||
export { SearchDateRange } from './SearchDateRange'; |
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
export { SearchAggregationsCards } from './SearchAggregations'; | ||
export { SearchAggregationsMenu } from './SearchAggregations'; | ||
export { SearchDateRange } from './SearchDateRange'; | ||
export { SearchFooter } from './SearchFooter'; | ||
export { SearchPagination } from './SearchPagination'; | ||
export { SearchEmptyResults } from './SearchEmptyResults'; |
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