Skip to content

Commit

Permalink
feat(incidentscsv): fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
reidmeyer committed Aug 18, 2020
1 parent 30b266d commit a5f60b2
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 20 deletions.
59 changes: 39 additions & 20 deletions src/incidents/list/ViewIncidentsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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 (
<>
<Dropdown
direction="down"
variant="secondary"
text={t('incidents.reports.download')}
style={dropStyle}
items={dropdownItems}
/>
<Table
getID={(row) => row.id}
data={data}
Expand Down Expand Up @@ -115,7 +135,6 @@ function ViewIncidentsTable(props: Props) {
},
]}
/>
<Dropdown direction="down" variant="secondary" text="DOWNLOAD" items={dropdownItems} />
</>
)
}
Expand Down
1 change: 1 addition & 0 deletions src/shared/locales/enUs/translations/incidents/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit a5f60b2

Please sign in to comment.