diff --git a/invenio_app_ils/facets.py b/invenio_app_ils/facets.py index 448d0f4b9..6566d5854 100644 --- a/invenio_app_ils/facets.py +++ b/invenio_app_ils/facets.py @@ -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 diff --git a/ui/src/components/SearchControls/components/SearchDateRange/SearchDateRange.js b/ui/src/components/SearchControls/components/SearchDateRange/SearchDateRange.js index b5a8bb955..b5edadfcb 100644 --- a/ui/src/components/SearchControls/components/SearchDateRange/SearchDateRange.js +++ b/ui/src/components/SearchControls/components/SearchDateRange/SearchDateRange.js @@ -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 { @@ -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); }; @@ -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) + } /> diff --git a/ui/src/pages/backoffice/Loan/LoanSearch/LoanSearch.js b/ui/src/pages/backoffice/Loan/LoanSearch/LoanSearch.js index 17269d665..b4e80850b 100644 --- a/ui/src/pages/backoffice/Loan/LoanSearch/LoanSearch.js +++ b/ui/src/pages/backoffice/Loan/LoanSearch/LoanSearch.js @@ -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 }, },