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;
|
2022-04-15 19:06:10 +00:00
|
|
|
@tracked namespaceArray = this.byNamespaceTotalClients.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-04-15 19:06:10 +00:00
|
|
|
// Response total client count data by namespace for current/partial month
|
|
|
|
get byNamespaceTotalClients() {
|
|
|
|
return this.args.model.monthly?.byNamespaceTotalClients || [];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Response new client count data by namespace for current/partial month
|
|
|
|
get byNamespaceNewClients() {
|
|
|
|
return this.args.model.monthly?.byNamespaceNewClients || [];
|
2022-02-08 21:07:04 +00:00
|
|
|
}
|
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
|
2022-04-15 19:06:10 +00:00
|
|
|
return (
|
|
|
|
this.args.model.config?.enabled === 'On' &&
|
|
|
|
this.byNamespaceTotalClients.length === 0 &&
|
|
|
|
this.byNamespaceNewClients.length === 0
|
|
|
|
);
|
2022-02-10 20:51:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-04-15 19:06:10 +00:00
|
|
|
get filteredTotalData() {
|
2022-02-17 20:17:59 +00:00
|
|
|
const namespace = this.selectedNamespace;
|
|
|
|
const auth = this.selectedAuthMethod;
|
|
|
|
if (!namespace && !auth) {
|
2022-04-15 19:06:10 +00:00
|
|
|
return this.byNamespaceTotalClients;
|
2022-02-17 20:17:59 +00:00
|
|
|
}
|
|
|
|
if (!auth) {
|
2022-04-15 19:06:10 +00:00
|
|
|
return this.byNamespaceTotalClients.find((ns) => ns.label === namespace);
|
2022-02-17 20:17:59 +00:00
|
|
|
}
|
2022-04-15 19:06:10 +00:00
|
|
|
return this.byNamespaceTotalClients
|
|
|
|
.find((ns) => ns.label === namespace)
|
|
|
|
.mounts?.find((mount) => mount.label === auth);
|
|
|
|
}
|
|
|
|
|
|
|
|
get filteredNewData() {
|
|
|
|
const namespace = this.selectedNamespace;
|
|
|
|
const auth = this.selectedAuthMethod;
|
|
|
|
if (!namespace && !auth) {
|
|
|
|
return this.byNamespaceNewClients;
|
|
|
|
}
|
|
|
|
if (!auth) {
|
|
|
|
return this.byNamespaceNewClients.find((ns) => ns.label === namespace);
|
|
|
|
}
|
|
|
|
return this.byNamespaceNewClients
|
2022-02-17 20:17:59 +00:00
|
|
|
.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-04-15 19:06:10 +00:00
|
|
|
return this.selectedNamespace ? this.filteredTotalData : this.args.model.monthly?.total;
|
|
|
|
}
|
|
|
|
|
|
|
|
get newUsageCounts() {
|
|
|
|
return this.selectedNamespace ? this.filteredNewData : this.args.model.monthly?.new;
|
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-04-15 19:06:10 +00:00
|
|
|
return this.filteredTotalData?.mounts || null;
|
|
|
|
} else {
|
|
|
|
return this.byNamespaceTotalClients;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// new client data for horizontal bar chart in attribution component
|
|
|
|
get newClientsData() {
|
|
|
|
if (this.selectedNamespace) {
|
|
|
|
return this.filteredNewData?.mounts || null;
|
2022-02-02 19:46:59 +00:00
|
|
|
} else {
|
2022-04-15 19:06:10 +00:00
|
|
|
return this.byNamespaceNewClients;
|
2022-02-02 19:46:59 +00:00
|
|
|
}
|
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
|
2022-04-15 19:06:10 +00:00
|
|
|
const mounts = this.filteredTotalData.mounts?.map((mount) => ({
|
2022-02-17 20:17:59 +00:00
|
|
|
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
|
|
|
}
|