From feafdf8fca89e4291f26d6fef4711e6ea82bd25a Mon Sep 17 00:00:00 2001 From: Tomasz Date: Wed, 22 Apr 2020 11:20:11 +0200 Subject: [PATCH 1/7] change time range filter from/to into date of last change --- .../concerns/cclow/filter_controller.rb | 2 +- app/javascript/components/TimeRangeFilter.js | 36 +++++++++---------- .../pages/cclow/LegislationAndPolicies.js | 7 ++-- app/javascript/components/pages/cclow/List.js | 19 +++++----- .../components/pages/cclow/LitigationCases.js | 7 ++-- app/services/queries/cclow/common_filters.rb | 12 +++---- .../queries/cclow/legislation_query.rb | 4 +-- .../queries/cclow/litigation_query.rb | 4 +-- app/services/queries/cclow/target_query.rb | 4 +-- .../queries/cclow/legislation_query_spec.rb | 8 ++--- .../queries/cclow/litigation_query_spec.rb | 10 +++--- .../queries/cclow/target_query_spec.rb | 2 +- 12 files changed, 59 insertions(+), 56 deletions(-) diff --git a/app/controllers/concerns/cclow/filter_controller.rb b/app/controllers/concerns/cclow/filter_controller.rb index 8bbc040df..2e54ca735 100644 --- a/app/controllers/concerns/cclow/filter_controller.rb +++ b/app/controllers/concerns/cclow/filter_controller.rb @@ -97,7 +97,7 @@ def target_years_options end def filter_params - params.permit(:q, :from_date, :to_date, :recent, :ids, + params.permit(:q, :last_change_from, :last_change_to, :recent, :ids, target_year: [], region: [], geography: [], jurisdiction: [], status: [], type: [], keywords: [], responses: [], frameworks: [], natural_hazards: [], party_type: [], diff --git a/app/javascript/components/TimeRangeFilter.js b/app/javascript/components/TimeRangeFilter.js index 64779823b..3f5fee2eb 100644 --- a/app/javascript/components/TimeRangeFilter.js +++ b/app/javascript/components/TimeRangeFilter.js @@ -40,8 +40,8 @@ class TimeRangeFilter extends Component { super(props); this.state = { isShowOptions: false, - from_date: null, - to_date: null, + last_change_from: null, + last_change_to: null, defFromDate: minDate, defToDate: maxDate }; @@ -71,10 +71,10 @@ class TimeRangeFilter extends Component { handleChange = (value) => { const {onChange} = this.props; - const {from_date, to_date} = this.state; + const {last_change_from, last_change_to} = this.state; onChange({ - from_date, - to_date, + last_change_from, + last_change_to, ...value }); this.setState(value); @@ -82,9 +82,9 @@ class TimeRangeFilter extends Component { renderOptions = () => { const {filterName, minDate, maxDate} = this.props; - const {from_date, to_date, defFromDate, defToDate} = this.state; - const currentToDate = to_date || defToDate; - const currentFromDate = from_date || defFromDate; + const {last_change_from, last_change_to, defFromDate, defToDate} = this.state; + const currentToDate = last_change_to || defToDate; + const currentFromDate = last_change_from || defFromDate; return (
@@ -106,9 +106,9 @@ class TimeRangeFilter extends Component { { backgroundColor: redColor, border: 'none', height: '12px', width: '12px', marginTop: '-4px' }, { backgroundColor: redColor, border: 'none', height: '18px', width: '18px', marginTop: '-7px' } ]} - value={[from_date || defFromDate, to_date || defToDate]} - onChange={(e) => this.setState({from_date: e[0], to_date: e[1]})} - onAfterChange={(e) => this.handleChange({from_date: e[0], to_date: e[1]})} + value={[last_change_from || defFromDate, last_change_to || defToDate]} + onChange={(e) => this.setState({last_change_from: e[0], last_change_to: e[1]})} + onAfterChange={(e) => this.handleChange({last_change_from: e[0], last_change_to: e[1]})} railStyle={{ backgroundColor: greyColor, maxHeight: '2px', marginTop: '1px' }} activeDotStyle={{border: 'none'}} /> @@ -127,8 +127,8 @@ class TimeRangeFilter extends Component { } styles={customStyles} isSearchable={false} - value={{label: from_date || defFromDate, value: from_date || defFromDate}} - onChange={(e) => this.handleChange({from_date: e.value})} + value={{label: last_change_from || defFromDate, value: last_change_from || defFromDate}} + onChange={(e) => this.handleChange({last_change_from: e.value})} components={{IndicatorSeparator: () => null}} />
@@ -141,8 +141,8 @@ class TimeRangeFilter extends Component { } styles={customStyles} isSearchable={false} - value={{label: to_date || defToDate, value: to_date || defToDate}} - onChange={(e) => this.handleChange({to_date: e.value})} + value={{label: last_change_to || defToDate, value: last_change_to || defToDate}} + onChange={(e) => this.handleChange({last_change_to: e.value})} components={{IndicatorSeparator: () => null}} />
@@ -152,11 +152,11 @@ class TimeRangeFilter extends Component { }; render() { - const {isShowOptions, from_date, to_date} = this.state; + const {isShowOptions, last_change_from, last_change_to} = this.state; const {filterName, className} = this.props; let selectedCount = 0; - if (from_date) selectedCount += 1; - if (to_date) selectedCount += 1; + if (last_change_from) selectedCount += 1; + if (last_change_to) selectedCount += 1; return (
diff --git a/app/javascript/components/pages/cclow/LegislationAndPolicies.js b/app/javascript/components/pages/cclow/LegislationAndPolicies.js index 3e11e149c..6fbc6ccb0 100644 --- a/app/javascript/components/pages/cclow/LegislationAndPolicies.js +++ b/app/javascript/components/pages/cclow/LegislationAndPolicies.js @@ -39,12 +39,13 @@ function LegislationAndPolicies(props) { } }, { - name: 'timeRange', + name: 'dateOfLastChange', + title: 'Date of last change', timeRange: true, mainFilter: true, params: { - from_date: paramInteger, - to_date: paramInteger + last_change_from: paramInteger, + last_change_to: paramInteger } }, { diff --git a/app/javascript/components/pages/cclow/List.js b/app/javascript/components/pages/cclow/List.js index 678a32592..065ce7810 100644 --- a/app/javascript/components/pages/cclow/List.js +++ b/app/javascript/components/pages/cclow/List.js @@ -162,6 +162,7 @@ class List extends Component { @@ -229,11 +230,11 @@ class List extends Component { renderTagsGroup = (filterConfig) => { const { filters } = this.state; - const { name, options, timeRange } = filterConfig; + const { name, options, title, timeRange } = filterConfig; const activeTags = pick(filters, Object.keys(filterConfig.params)); const filterEl = this.filterRefs[name]; - if (timeRange) return this.renderTimeRangeTags(activeTags, filterEl); + if (timeRange) return this.renderTimeRangeTags(activeTags, title, filterEl); return Object.keys(activeTags).map((keyBlock) => ( activeTags[keyBlock].filter(x => x).map((key, i) => ( @@ -245,24 +246,24 @@ class List extends Component { )); } - renderTimeRangeTags = (value, filterEl) => ( + renderTimeRangeTags = (value, title, filterEl) => ( - {value.from_date && ( + {value.last_change_from && ( - From {value.from_date} + {title} from {value.last_change_from}