Skip to content

Commit

Permalink
fix: Min/max date always less than / greater than other
Browse files Browse the repository at this point in the history
Avoid having invalid date ranges where min date is after max date. This will change the min/max to be the same day as the min/max
  • Loading branch information
gmaclennan committed Oct 6, 2019
1 parent dd52013 commit 1cc7a27
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
19 changes: 17 additions & 2 deletions src/FilterPanel/DateFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,25 @@ const DateFilter = ({
(filterMax != null && filterMax < max)

const handleChange = (minOrMax: 'min' | 'max') => value => {
const filterValue = createFilterValue(value, minOrMax)
const newFilter =
minOrMax === 'min'
? compileFilter(fieldKey, createFilterValue(value, 'min'), filterMax)
: compileFilter(fieldKey, filterMin, createFilterValue(value, 'max'))
? compileFilter(
fieldKey,
filterValue,
filterMax &&
(filterMax < filterValue
? createFilterValue(value, 'max')
: filterMax)
)
: compileFilter(
fieldKey,
filterMin &&
(filterMin > filterValue
? createFilterValue(value, 'min')
: filterMin),
filterValue
)
onChangeFilter(newFilter)
}

Expand Down
4 changes: 2 additions & 2 deletions src/FilterPanel/DateFilter.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ export const defaultStory = () => {
label="Select Date"
fieldKey={['foo']}
filter={filter}
min="2018-01-01"
max="2019-09-28"
min="2019-01-01T18:40:48.749Z"
max="2019-09-28T08:40:48.749Z"
onChangeFilter={setFilter}
/>
)
Expand Down

0 comments on commit 1cc7a27

Please sign in to comment.