feat(ui) - audit - date

This commit is contained in:
Shekar Siri 2022-05-09 19:34:59 +02:00
parent 5b627c17ec
commit eae31eac37
2 changed files with 8 additions and 12 deletions

View file

@ -4,6 +4,8 @@ import Audit from './types/audit'
import Period, { LAST_7_DAYS } from 'Types/app/period';
import { toast } from 'react-toastify';
import { exportCSVFile } from 'App/utils';
import { formatDateTimeDefault } from 'App/date';
import { DateTime, Duration } from 'luxon'; // TODO
export default class AuditStore {
list: any[] = [];
@ -60,11 +62,13 @@ export default class AuditStore {
{ label: 'Method', key: 'method' },
{ label: 'Action', key: 'action' },
{ label: 'Endpoint', key: 'endpoint' },
// { label: 'Status', key: 'status' },
{ label: 'Created At', key: 'createdAt' },
]
// console.log('data', data)
exportCSVFile(headers, data.sessions, `audit-${new Date().toLocaleDateString()}.csv`);
data = data.sessions.map(item => ({
...item,
createdAt: DateTime.fromMillis(item.createdAt).toFormat('LLL dd yyyy hh:mm a')
}))
exportCSVFile(headers, data, `audit-${new Date().toLocaleDateString()}`);
resolve(data)
}).catch(error => {
reject(error)

View file

@ -279,10 +279,7 @@ export const convertToCSV = (headers, objArray) => {
acc[curr.key] = curr;
return acc;
}, {});
console.log('headersMap', headersMap)
// csv header line
// comma seprated header line from array
str += headers.map(h => h.label).join(',') + '\r\n';
for (var i = 0; i < array.length; i++) {
@ -299,10 +296,6 @@ export const convertToCSV = (headers, objArray) => {
}
export const exportCSVFile = (headers, items, fileTitle) => {
// if (headers) {
// items.unshift(headers);
// }
var jsonObject = JSON.stringify(items);
var csv = convertToCSV(headers, jsonObject);
var exportedFilenmae = fileTitle + '.csv' || 'export.csv';
@ -312,8 +305,7 @@ export const exportCSVFile = (headers, items, fileTitle) => {
navigator.msSaveBlob(blob, exportedFilenmae);
} else {
var link = document.createElement("a");
if (link.download !== undefined) { // feature detection
// Browsers that support HTML5 download attribute
if (link.download !== undefined) {
var url = URL.createObjectURL(blob);
link.setAttribute("href", url);
link.setAttribute("download", exportedFilenmae);