fix report crash when some values are null

This commit is contained in:
Kukks 2023-11-10 12:30:12 +01:00
parent 2326894a2b
commit f2b1e5f93e
No known key found for this signature in database
GPG key ID: 8E5530D9D1C93097
2 changed files with 6 additions and 3 deletions

View file

@ -133,7 +133,7 @@
<template v-else-if="srv.result.fields[columnIndex].type === 'tx_id'">
<vc:truncate-center text="value" is-vue="true" padding="15" classes="truncate-center-id" link="getExplorerUrl(value, row[columnIndex-1])" />
</template>
<template v-else-if="['Address', 'PaymentId'].includes(srv.result.fields[columnIndex].name)">
<template v-else-if="value && ['Address', 'PaymentId'].includes(srv.result.fields[columnIndex].name)" >
<vc:truncate-center text="value" is-vue="true" padding="15" classes="truncate-center-id" />
</template>
<template v-else-if="srv.result.fields[columnIndex].type === 'datetime'">{{ displayDate(value) }}</template>

View file

@ -149,6 +149,9 @@ document.addEventListener("DOMContentLoaded", () => {
const dtFormatter = new Intl.DateTimeFormat('default', { dateStyle: 'short', timeStyle: 'short' });
function displayDate(val) {
if(!val){
return val;
}
const date = new Date(val);
return dtFormatter.format(date);
}
@ -182,7 +185,7 @@ function downloadCSV() {
// Convert ISO8601 dates to YYYY-MM-DD HH:mm:ss so the CSV easily integrate with Excel
modifyFields(srv.result.fields, data, 'amount', displayValue)
modifyFields(srv.result.fields, data, 'datetime', v => moment(v).format('YYYY-MM-DD hh:mm:ss'));
modifyFields(srv.result.fields, data, 'datetime', v => v? moment(v).format('YYYY-MM-DD hh:mm:ss'): v);
const csv = Papa.unparse({ fields: srv.result.fields.map(f => f.name), data });
const blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' });
saveAs(blob, "export.csv");
@ -202,7 +205,7 @@ async function fetchStoreReports() {
srv.dataUpdated();
// Dates from API are UTC, convert them to local time
modifyFields(srv.result.fields, srv.result.data, 'datetime', a => moment(a).format());
modifyFields(srv.result.fields, srv.result.data, 'datetime', a => a? moment(a).format(): a);
var urlParams = new URLSearchParams(new URL(window.location).search);
urlParams.set("viewName", srv.request.viewName);
urlParams.set("from", srv.request.timePeriod.from);