2022-01-27 18:59:08 +00:00
|
|
|
import Component from '@glimmer/component';
|
2022-02-02 19:46:59 +00:00
|
|
|
import { tracked } from '@glimmer/tracking';
|
2022-02-08 18:12:23 +00:00
|
|
|
import { isAfter, startOfMonth } from 'date-fns';
|
2022-02-04 18:44:13 +00:00
|
|
|
import { action } from '@ember/object';
|
2022-01-27 18:59:08 +00:00
|
|
|
export default class Current extends Component {
|
|
|
|
chartLegend = [
|
|
|
|
{ key: 'entity_clients', label: 'entity clients' },
|
|
|
|
{ key: 'non_entity_clients', label: 'non-entity clients' },
|
|
|
|
];
|
2022-02-08 21:07:04 +00:00
|
|
|
@tracked selectedNamespace = null;
|
|
|
|
@tracked namespaceArray = this.byNamespaceCurrent.map((namespace) => {
|
2022-02-04 18:44:13 +00:00
|
|
|
return { name: namespace['label'], id: namespace['label'] };
|
|
|
|
});
|
2022-02-08 21:07:04 +00:00
|
|
|
@tracked firstUpgradeVersion = this.args.model.versionHistory[0].id || null; // return 1.9.0 or earliest upgrade post 1.9.0
|
|
|
|
@tracked upgradeDate = this.args.model.versionHistory[0].timestampInstalled || null; // returns RFC3339 timestamp
|
|
|
|
|
|
|
|
// API client count data by namespace for current/partial month
|
|
|
|
get byNamespaceCurrent() {
|
|
|
|
return this.args.model.monthly?.byNamespace || [];
|
|
|
|
}
|
2022-02-02 19:46:59 +00:00
|
|
|
|
2022-02-08 18:12:23 +00:00
|
|
|
get countsIncludeOlderData() {
|
|
|
|
let firstUpgrade = this.args.model.versionHistory[0];
|
|
|
|
if (!firstUpgrade) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
let versionDate = new Date(firstUpgrade.timestampInstalled);
|
|
|
|
// compare against this month and this year to show message or not.
|
|
|
|
return isAfter(versionDate, startOfMonth(new Date())) ? versionDate : false;
|
2022-02-02 19:46:59 +00:00
|
|
|
}
|
|
|
|
|
2022-02-02 21:24:24 +00:00
|
|
|
// top level TOTAL client counts for current/partial month
|
|
|
|
get totalUsageCounts() {
|
|
|
|
return this.selectedNamespace
|
|
|
|
? this.filterByNamespace(this.selectedNamespace)
|
|
|
|
: this.args.model.monthly?.total;
|
|
|
|
}
|
|
|
|
|
|
|
|
// total client data for horizontal bar chart in attribution component
|
|
|
|
get totalClientsData() {
|
2022-02-02 19:46:59 +00:00
|
|
|
if (this.selectedNamespace) {
|
|
|
|
let filteredNamespace = this.filterByNamespace(this.selectedNamespace);
|
2022-02-02 21:24:24 +00:00
|
|
|
return filteredNamespace.mounts ? this.filterByNamespace(this.selectedNamespace).mounts : null;
|
2022-02-02 19:46:59 +00:00
|
|
|
} else {
|
|
|
|
return this.byNamespaceCurrent;
|
|
|
|
}
|
2022-01-27 18:59:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get responseTimestamp() {
|
|
|
|
return this.args.model.monthly?.responseTimestamp;
|
|
|
|
}
|
2022-02-02 19:46:59 +00:00
|
|
|
|
|
|
|
// HELPERS
|
|
|
|
filterByNamespace(namespace) {
|
|
|
|
return this.byNamespaceCurrent.find((ns) => ns.label === namespace);
|
|
|
|
}
|
2022-02-04 18:44:13 +00:00
|
|
|
|
|
|
|
// ACTIONS
|
|
|
|
@action
|
|
|
|
selectNamespace([value]) {
|
|
|
|
// value comes in as [namespace0]
|
|
|
|
this.selectedNamespace = value;
|
|
|
|
}
|
2022-01-27 18:59:08 +00:00
|
|
|
}
|