Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
topless committed Mar 31, 2020
1 parent 71ee6e9 commit fc6ac64
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
4 changes: 1 addition & 3 deletions invenio_app_ils/facets.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,5 @@ def date_range_filter(field, comparator):
:param comparator: Comparison we want with the supplied date.
"""
def inner(values):
return Range(**{
field: {comparator: str(arrow.get(values[0]).date())}
})
return Range(**{field: {comparator: str(arrow.get(values[0]).date())}})
return inner
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
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';
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 {
Expand All @@ -14,21 +15,23 @@ class _SearchDateRange extends Component {

parseUrlDates = () => {
const { filters } = this.props.currentQueryState;
let fromDate = '';
let toDate = '';
filters.map(filter => {
if (filter[0] === 'loans_from_date') fromDate = filter[1];
if (filter[0] === 'loans_to_date') toDate = filter[1];
});
return [fromDate, toDate];
const filtersObj = _fromPairs(filters);
const dateFilter = filtersObj['loan.start_date'];
if (dateFilter) return dateFilter.split(',');
return ['', ''];
};

updateFilters = () => {
const newQuery = _cloneDeep(this.props.currentQueryState);
if (!_isEmpty(this.state.fromDate))
newQuery.filters.push(['loans_from_date', `${this.state.fromDate}`]);
if (!_isEmpty(this.state.toDate))
newQuery.filters.push(['loans_to_date', `${this.state.toDate}`]);
newQuery.filters.push(['loan_from_date', '2020-03-03']);
// const filtersObj = _fromPairs(newQuery.filters);
// filtersObj[
// 'loan.start_date'
// ] = `${this.state.fromDate},${this.state.toDate}`;
// newQuery.filters = _toPairs(filtersObj);

// onQueryChanged(newQuery);
debugger;
this.props.updateQueryState(newQuery);
};

Expand All @@ -46,9 +49,9 @@ class _SearchDateRange extends Component {
maxDate={this.state.toDate}
defaultValue={this.state.fromDate}
placeholder="From"
handleDateChange={value => {
this.setState({ fromDate: value }, this.updateFilters);
}}
handleDateChange={value =>
this.setState({ fromDate: value }, this.updateFilters)
}
/>
</Card.Content>
<Card.Content>
Expand Down
3 changes: 1 addition & 2 deletions ui/src/pages/backoffice/Loan/LoanSearch/LoanSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ import { SearchDateRange } from '@components/SearchControls/components';

export class LoanSearch extends Component {
searchApi = new InvenioSearchApi({
url: loanApi.searchBaseURL,
withCredentials: true,
axios: { url: loanApi.searchBaseURL, withCredentials: true },
interceptors: {
response: { reject: responseRejectInterceptor },
},
Expand Down

0 comments on commit fc6ac64

Please sign in to comment.