Skip to content

Commit

Permalink
Added date range to client count csv filename (hashicorp#12960)
Browse files Browse the repository at this point in the history
  • Loading branch information
arnav28 authored and Artem Alexandrov committed Feb 4, 2022
1 parent 2f33eca commit 8ab1d2d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions ui/app/components/clients/history.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Component from '@glimmer/component';
import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';
import { format } from 'date-fns';

export default class HistoryComponent extends Component {
max_namespaces = 10;
Expand Down Expand Up @@ -77,6 +78,19 @@ export default class HistoryComponent extends Component {
return results;
}

// Return csv filename with start and end dates
get getCsvFileName() {
let defaultFileName = `clients-by-namespace`,
startDate =
this.args.model.queryStart || `${format(new Date(this.args.model.activity.startTime), 'MM-yyyy')}`,
endDate =
this.args.model.queryEnd || `${format(new Date(this.args.model.activity.endTime), 'MM-yyyy')}`;
if (startDate && endDate) {
defaultFileName += `-${startDate}-${endDate}`;
}
return defaultFileName;
}

// Get the namespace by matching the path from the namespace list
getNamespace(path) {
return this.args.model.activity.byNamespace.find(ns => {
Expand Down
2 changes: 1 addition & 1 deletion ui/app/templates/components/clients/history.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
(hash key='distinct_entities' label='Unique entities')
}}
>
<DownloadCsv @label={{'Export all namespace data'}} @csvData={{this.getCsvData}} @fileName={{'client-count-by-namespaces.csv'}} />
<DownloadCsv @label={{'Export all namespace data'}} @csvData={{this.getCsvData}} @fileName={{this.getCsvFileName}} />
</BarChart>
</div>
<div class="column">
Expand Down

0 comments on commit 8ab1d2d

Please sign in to comment.