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-10 20:51:50 +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
|
|
|
|
|
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
|
|
|
|
2022-02-17 20:17:59 +00:00
|
|
|
@tracked selectedAuthMethod = null;
|
|
|
|
@tracked authMethodOptions = [];
|
|
|
|
|
2022-02-10 20:51:50 +00:00
|
|
|
// Response client count data by namespace for current/partial month
|
2022-02-08 21:07:04 +00:00
|
|
|
get byNamespaceCurrent() {
|
|
|
|
return this.args.model.monthly?.byNamespace || [];
|
|
|
|
}
|
2022-02-02 19:46:59 +00:00
|
|
|
|
2022-02-10 20:51:50 +00:00
|
|
|
get isGatheringData() {
|
|
|
|
// return true if tracking IS enabled but no data collected yet
|
|
|
|
return this.args.model.config?.enabled === 'On' && this.byNamespaceCurrent.length === 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
get hasAttributionData() {
|
2022-02-24 20:04:40 +00:00
|
|
|
if (this.selectedAuthMethod) return false;
|
|
|
|
if (this.selectedNamespace) {
|
|
|
|
return this.authMethodOptions.length > 0;
|
|
|
|
}
|
|
|
|
return this.totalUsageCounts.clients !== 0 && !!this.totalClientsData;
|
2022-02-17 20:17:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get filteredActivity() {
|
|
|
|
const namespace = this.selectedNamespace;
|
|
|
|
const auth = this.selectedAuthMethod;
|
|
|
|
if (!namespace && !auth) {
|
|
|
|
return this.getActivityResponse;
|
|
|
|
}
|
|
|
|
if (!auth) {
|
|
|
|
return this.byNamespaceCurrent.find((ns) => ns.label === namespace);
|
|
|
|
}
|
|
|
|
return this.byNamespaceCurrent
|
|
|
|
.find((ns) => ns.label === namespace)
|
|
|
|
.mounts?.find((mount) => mount.label === auth);
|
2022-02-16 19:03:34 +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() {
|
2022-02-17 20:17:59 +00:00
|
|
|
return this.selectedNamespace ? this.filteredActivity : this.args.model.monthly?.total;
|
2022-02-02 21:24:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// total client data for horizontal bar chart in attribution component
|
|
|
|
get totalClientsData() {
|
2022-02-02 19:46:59 +00:00
|
|
|
if (this.selectedNamespace) {
|
2022-02-17 20:17:59 +00:00
|
|
|
return this.filteredActivity?.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
|
|
|
|
2022-02-04 18:44:13 +00:00
|
|
|
// ACTIONS
|
|
|
|
@action
|
|
|
|
selectNamespace([value]) {
|
|
|
|
// value comes in as [namespace0]
|
|
|
|
this.selectedNamespace = value;
|
2022-02-17 20:17:59 +00:00
|
|
|
if (!value) {
|
2022-02-25 18:21:15 +00:00
|
|
|
this.authMethodOptions = [];
|
2022-02-17 20:17:59 +00:00
|
|
|
// on clear, also make sure auth method is cleared
|
|
|
|
this.selectedAuthMethod = null;
|
|
|
|
} else {
|
|
|
|
// Side effect: set auth namespaces
|
|
|
|
const mounts = this.filteredActivity.mounts?.map((mount) => ({
|
|
|
|
id: mount.label,
|
|
|
|
name: mount.label,
|
|
|
|
}));
|
|
|
|
this.authMethodOptions = mounts;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
setAuthMethod([authMount]) {
|
|
|
|
this.selectedAuthMethod = authMount;
|
2022-02-04 18:44:13 +00:00
|
|
|
}
|
2022-01-27 18:59:08 +00:00
|
|
|
}
|