From a5f60b228ceccc7030b36c4498ec1c227897092a Mon Sep 17 00:00:00 2001 From: reidmeyer Date: Tue, 18 Aug 2020 20:55:03 +0800 Subject: [PATCH] feat(incidentscsv): fixes re #2292 --- src/incidents/list/ViewIncidentsTable.tsx | 59 ++++++++++++------- .../enUs/translations/incidents/index.ts | 1 + 2 files changed, 40 insertions(+), 20 deletions(-) diff --git a/src/incidents/list/ViewIncidentsTable.tsx b/src/incidents/list/ViewIncidentsTable.tsx index c52f3f1de0..eecad38e6e 100644 --- a/src/incidents/list/ViewIncidentsTable.tsx +++ b/src/incidents/list/ViewIncidentsTable.tsx @@ -25,34 +25,42 @@ function ViewIncidentsTable(props: Props) { // filter data const exportData = [{}] - let first = true - if (data != null) { - data.forEach((elm) => { - const entry = { - code: elm.code, - date: format(new Date(elm.date), 'yyyy-MM-dd hh:mm a'), - reportedBy: elm.reportedBy, - reportedOn: format(new Date(elm.reportedOn), 'yyyy-MM-dd hh:mm a'), - status: elm.status, - } - if (first) { - exportData[0] = entry - first = false - } else { - exportData.push(entry) - } - }) + + function populateExportData() { + let first = true + if (data != null) { + data.forEach((elm) => { + const entry = { + code: elm.code, + date: format(new Date(elm.date), 'yyyy-MM-dd hh:mm a'), + reportedBy: elm.reportedBy, + reportedOn: format(new Date(elm.reportedOn), 'yyyy-MM-dd hh:mm a'), + status: elm.status, + } + if (first) { + exportData[0] = entry + first = false + } else { + exportData.push(entry) + } + }) + } } function downloadCSV() { + populateExportData() + const fields = Object.keys(exportData[0]) const opts = { fields } const parser = new Parser(opts) const csv = parser.parse(exportData) - console.log(csv) const incidentsText = t('incidents.label') - const filename = incidentsText.concat('.csv') + + const filename = incidentsText + .concat('-') + .concat(format(new Date(Date.now()), 'yyyy-MM-dd--hh-mma')) + .concat('.csv') const text = csv const element = document.createElement('a') @@ -76,8 +84,20 @@ function ViewIncidentsTable(props: Props) { }, ] + const dropStyle = { + marginLeft: 'auto', // note the capital 'W' here + marginBottom: '4px', // 'ms' is the only lowercase vendor prefix + } + return ( <> + row.id} data={data} @@ -115,7 +135,6 @@ function ViewIncidentsTable(props: Props) { }, ]} /> - ) } diff --git a/src/shared/locales/enUs/translations/incidents/index.ts b/src/shared/locales/enUs/translations/incidents/index.ts index 6223bafb29..f39d87cb59 100644 --- a/src/shared/locales/enUs/translations/incidents/index.ts +++ b/src/shared/locales/enUs/translations/incidents/index.ts @@ -17,6 +17,7 @@ export default { resolve: 'Resolve Incident', dateOfIncident: 'Date of Incident', department: 'Department', + download: 'Download', category: 'Category', categoryItem: 'Category Item', description: 'Description of Incident',