-
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.
- Loading branch information
Showing
6 changed files
with
80 additions
and
81 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
72 changes: 0 additions & 72 deletions
72
ui/src/components/SearchControls/components/SearchDateRange/SearchDateRange.js
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
ui/src/components/SearchControls/components/SearchDateRange/index.js
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
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
77 changes: 77 additions & 0 deletions
77
ui/src/pages/backoffice/Loan/LoanSearch/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,77 @@ | ||
import React, { Component } from 'react'; | ||
import { Card } from 'semantic-ui-react'; | ||
import { DatePicker } from '@components'; | ||
import { withState } from 'react-searchkit'; | ||
import _isEmpty from 'lodash/isEmpty'; | ||
|
||
class _SearchDateRange extends Component { | ||
getCurrentDates() { | ||
const { filters } = this.props.currentQueryState; | ||
let loans_from_date = ''; | ||
let loans_to_date = ''; | ||
|
||
filters.forEach(([name, value]) => { | ||
if (name === 'loans_from_date') loans_from_date = value; | ||
if (name === 'loans_to_date') loans_to_date = value; | ||
}); | ||
return [loans_from_date, loans_to_date]; | ||
} | ||
|
||
onDateChange = newFilter => { | ||
const [name, value] = newFilter; | ||
let result = newFilter; | ||
|
||
if (_isEmpty(value)) { | ||
this.props.updateQueryState({ filters: result }); | ||
return; | ||
} | ||
|
||
const { filters } = this.props.currentQueryState; | ||
const existingFilters = filters.filter(filter => filter[0] === name); | ||
|
||
if (!_isEmpty(existingFilters)) { | ||
result = existingFilters.push(newFilter); | ||
} | ||
// NOTE: react-searchkit allows having the same filter multiple times. | ||
// For the range dates filters we want each filter one time only so we have | ||
// to we have to add also the existing filters we want to remove. | ||
this.props.updateQueryState({ filters: result }); | ||
}; | ||
|
||
render() { | ||
const [fromDate, toDate] = this.getCurrentDates(); | ||
|
||
return ( | ||
<Card> | ||
<Card.Content> | ||
<Card.Header>Date</Card.Header> | ||
<Card.Meta> | ||
<span>*Loan start date</span> | ||
</Card.Meta> | ||
</Card.Content> | ||
<Card.Content> | ||
<DatePicker | ||
maxDate={toDate} | ||
defaultValue={fromDate} | ||
placeholder="From" | ||
handleDateChange={value => | ||
this.onDateChange(['loans_from_date', value]) | ||
} | ||
/> | ||
</Card.Content> | ||
<Card.Content> | ||
<DatePicker | ||
minDate={fromDate} | ||
defaultValue={toDate} | ||
placeholder="To" | ||
handleDateChange={value => | ||
this.onDateChange(['loans_to_date', value]) | ||
} | ||
/> | ||
</Card.Content> | ||
</Card> | ||
); | ||
} | ||
} | ||
|
||
export const SearchDateRange = withState(_SearchDateRange); |