From 68bbba296c6f99b81d2882e1fef6f37cf4a6bb51 Mon Sep 17 00:00:00 2001 From: Yoshie Muranaka Date: Mon, 18 May 2020 09:49:37 -0700 Subject: Add date filter on Event logs page Created global TableDateFilter component that uses the BootstrapVue Datepicker with a native text input. This will allow users to manually enter a date in ISO format or use the Bootstrap calendar dropdown. Storing language preference from Login to use locale prop on BootstrapVue Datepicker component. Signed-off-by: Yoshie Muranaka Change-Id: I66de9fb04451572c9a90f90d8522934b6204aed2 --- src/components/Mixins/TableFilterMixin.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/components/Mixins') diff --git a/src/components/Mixins/TableFilterMixin.js b/src/components/Mixins/TableFilterMixin.js index 25c7497a..58e70c57 100644 --- a/src/components/Mixins/TableFilterMixin.js +++ b/src/components/Mixins/TableFilterMixin.js @@ -16,6 +16,25 @@ const TableFilterMixin = { } return returnRow; }); + }, + getFilteredTableDataByDate( + tableData = [], + startDate, + endDate, + propertyKey = 'date' + ) { + if (!startDate && !endDate) return tableData; + const startDateInMs = startDate ? startDate.getTime() : 0; + const endDateInMs = endDate + ? endDate.getTime() + : Number.POSITIVE_INFINITY; + return tableData.filter(row => { + const date = row[propertyKey]; + if (!(date instanceof Date)) return; + + const dateInMs = date.getTime(); + if (dateInMs >= startDateInMs && dateInMs <= endDateInMs) return row; + }); } } }; -- cgit v1.2.3