Commit bd8fcca2 authored by Loic Huder's avatar Loic Huder
Browse files

Merge branch 'filter-end-date' into 'master'

Investigations now match when the selected date for filtering is between the start and the end

See merge request !433
parents 0a562b87 a8e04ed2
Pipeline #32450 passed with stages
in 7 minutes and 36 seconds
......@@ -13,11 +13,14 @@ function InvestigationDateFilter(props) {
<DayPickerInput
inputProps={{ className: styles.dateFilterInput }}
value={value}
placeholder="Filter by start date"
placeholder="Filter by date"
format={INVESTIGATION_DATE_FORMAT}
formatDate={formatDate}
parseDate={parseDate}
onDayChange={onDayChange}
dayPickerProps={{
todayButton: 'Today',
}}
/>
<Button
disabled={!value}
......
......@@ -231,7 +231,7 @@ function getColumns(props) {
function InvestigationTable(props) {
const { expanded, user, investigations } = props;
const [dateFilter, setDateFilter] = useState();
const [selectedDate, setSelectedDate] = useState();
const expandRow = {
showExpandColumn: true,
......@@ -265,20 +265,29 @@ function InvestigationTable(props) {
),
};
function dateFilter(investigation) {
return investigation.endDate
? selectedDate.isBetween(
investigation.startDate,
investigation.endDate,
'day',
'[]'
)
: selectedDate.isSame(investigation.startDate, 'day');
}
return (
<>
<div className={styles.wrapper}>
<InvestigationDateFilter
rootClassName={styles.filter}
value={dateFilter && dateFilter.toDate()}
onDayChange={(date) => setDateFilter(moment(date))}
onClear={() => setDateFilter(undefined)}
value={selectedDate && selectedDate.toDate()}
onDayChange={(date) => setSelectedDate(moment(date))}
onClear={() => setSelectedDate(undefined)}
/>
</div>
<ResponsiveTable
data={investigations.filter(
(inv) => !dateFilter || dateFilter.isSame(inv.startDate, 'day')
)}
data={selectedDate ? investigations.filter(dateFilter) : investigations}
columns={getColumns(props)}
expandRow={expandRow}
/>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment