summaryrefslogtreecommitdiff
path: root/src/components/Mixins
diff options
context:
space:
mode:
authorYoshie Muranaka <yoshiemuranaka@gmail.com>2020-05-18 19:49:37 +0300
committerDerick Montague <derick.montague@ibm.com>2020-06-13 07:49:18 +0300
commit68bbba296c6f99b81d2882e1fef6f37cf4a6bb51 (patch)
treef07d9fef5079ef7e9728bcbfc71a4dd3e5cc5aa3 /src/components/Mixins
parent71724befc716d373e2fd6396fcd6934277f38f66 (diff)
downloadwebui-vue-68bbba296c6f99b81d2882e1fef6f37cf4a6bb51.tar.xz
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 <yoshiemuranaka@gmail.com> Change-Id: I66de9fb04451572c9a90f90d8522934b6204aed2
Diffstat (limited to 'src/components/Mixins')
-rw-r--r--src/components/Mixins/TableFilterMixin.js19
1 files changed, 19 insertions, 0 deletions
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;
+ });
}
}
};