Skip to content

Commit

Permalink
fix(analytics): detect type of fields for XLSX export (#2729)
Browse files Browse the repository at this point in the history
  • Loading branch information
open-dynaMIX authored Jul 4, 2024
1 parent 86eb035 commit 6ea49aa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/analytics/addon/components/ca-report-preview.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
{{#each this.data.value.fields as |row|}}
<tr>
{{#each row as |entry|}}
<td>
<td data-t={{this.getXLSXType entry.value}}>
{{entry.value}}
</td>
{{/each}}
Expand All @@ -39,7 +39,7 @@
{{#if this.data.value.summary}}
<tr class="uk-text-bold">
{{#each this.data.value.summary as |summary|}}
<td>
<td data-t={{this.getXLSXType summary.value}}>
{{summary.value}}
</td>
{{/each}}
Expand Down
15 changes: 15 additions & 0 deletions packages/analytics/addon/components/ca-report-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,19 @@ export default class CaReportPreviewComponent extends Component {
);
});
}

getXLSXType(input) {
// Check if it's a number
if (!isNaN(input) && input.trim() !== "") {
return "n";
}

// Check if it looks like a date and can be parsed as a date
if (/^\d{4}-\d{2}-\d{2}$/.test(input) && !isNaN(Date.parse(input))) {
return "d";
}

// Default to string
return "s";
}
}

0 comments on commit 6ea49aa

Please sign in to comment.