2022-01-25 22:06:56 +00:00
|
|
|
import Component from '@glimmer/component';
|
2022-06-03 22:47:19 +00:00
|
|
|
import { calculateAverage } from 'vault/utils/chart-helpers';
|
2022-01-25 22:06:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @module RunningTotal
|
2022-05-10 22:32:36 +00:00
|
|
|
* RunningTotal components display total and new client counts in a given date range by month.
|
2022-01-25 22:06:56 +00:00
|
|
|
* A line chart shows total monthly clients and below a stacked, vertical bar chart shows new clients per month.
|
2022-05-10 22:32:36 +00:00
|
|
|
*
|
2022-01-25 22:06:56 +00:00
|
|
|
*
|
|
|
|
* @example
|
|
|
|
* ```js
|
|
|
|
<Clients::RunningTotal
|
|
|
|
@chartLegend={{this.chartLegend}}
|
2022-05-09 19:16:32 +00:00
|
|
|
@selectedNamespace={{this.selectedNamespace}}
|
2022-01-25 22:06:56 +00:00
|
|
|
@barChartData={{this.byMonthNewClients}}
|
|
|
|
@lineChartData={{this.byMonth}}
|
|
|
|
@runningTotals={{this.runningTotals}}
|
2022-04-20 15:35:57 +00:00
|
|
|
@upgradeData={{if this.countsIncludeOlderData this.latestUpgradeData}}
|
2022-01-25 22:06:56 +00:00
|
|
|
/>
|
|
|
|
* ```
|
|
|
|
|
2022-05-09 19:16:32 +00:00
|
|
|
* @param {array} chartLegend - array of objects with key names 'key' and 'label' so data can be stacked
|
|
|
|
* @param {string} selectedAuthMethod - string of auth method label for empty state message in bar chart
|
|
|
|
* @param {array} barChartData - array of objects from /activity response, from the 'months' key
|
2022-01-25 22:06:56 +00:00
|
|
|
object example: {
|
|
|
|
month: '1/22',
|
|
|
|
entity_clients: 23,
|
|
|
|
non_entity_clients: 45,
|
|
|
|
total: 68,
|
|
|
|
namespaces: [],
|
|
|
|
new_clients: {
|
|
|
|
entity_clients: 11,
|
|
|
|
non_entity_clients: 36,
|
|
|
|
total: 47,
|
|
|
|
namespaces: [],
|
|
|
|
},
|
|
|
|
};
|
2022-05-09 19:16:32 +00:00
|
|
|
* @param {array} lineChartData - array of objects from /activity response, from the 'months' key
|
2022-01-25 22:06:56 +00:00
|
|
|
* @param {object} runningTotals - top level totals from /activity response { clients: 3517, entity_clients: 1593, non_entity_clients: 1924 }
|
2022-04-20 15:35:57 +00:00
|
|
|
* @param {object} upgradeData - object containing version upgrade data e.g.: {id: '1.9.0', previousVersion: null, timestampInstalled: '2021-11-03T10:23:16Z'}
|
2022-05-09 19:16:32 +00:00
|
|
|
* @param {string} timestamp - ISO timestamp created in serializer to timestamp the response
|
2022-05-10 22:32:36 +00:00
|
|
|
*
|
2022-01-25 22:06:56 +00:00
|
|
|
*/
|
|
|
|
export default class RunningTotal extends Component {
|
2022-04-12 22:49:35 +00:00
|
|
|
get entityClientData() {
|
|
|
|
return {
|
|
|
|
runningTotal: this.args.runningTotals.entity_clients,
|
2022-06-03 22:47:19 +00:00
|
|
|
averageNewClients: calculateAverage(this.args.barChartData, 'entity_clients') || '0',
|
2022-04-12 22:49:35 +00:00
|
|
|
};
|
2022-01-25 22:06:56 +00:00
|
|
|
}
|
|
|
|
|
2022-04-12 22:49:35 +00:00
|
|
|
get nonEntityClientData() {
|
|
|
|
return {
|
|
|
|
runningTotal: this.args.runningTotals.non_entity_clients,
|
2022-06-03 22:47:19 +00:00
|
|
|
averageNewClients: calculateAverage(this.args.barChartData, 'non_entity_clients') || '0',
|
2022-04-12 22:49:35 +00:00
|
|
|
};
|
2022-01-25 22:06:56 +00:00
|
|
|
}
|
2022-05-09 19:16:32 +00:00
|
|
|
|
|
|
|
get hasRunningTotalClients() {
|
|
|
|
return (
|
|
|
|
typeof this.entityClientData.runningTotal === 'number' ||
|
|
|
|
typeof this.nonEntityClientData.runningTotal === 'number'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
get hasAverageNewClients() {
|
|
|
|
return (
|
|
|
|
typeof this.entityClientData.averageNewClients === 'number' ||
|
|
|
|
typeof this.nonEntityClientData.averageNewClients === 'number'
|
|
|
|
);
|
|
|
|
}
|
2022-05-10 22:32:36 +00:00
|
|
|
|
|
|
|
get showSingleMonth() {
|
2022-06-03 22:47:19 +00:00
|
|
|
if (this.args.lineChartData?.length === 1) {
|
|
|
|
const monthData = this.args?.lineChartData[0];
|
2022-05-10 22:32:36 +00:00
|
|
|
return {
|
|
|
|
total: {
|
|
|
|
total: monthData.clients,
|
|
|
|
entityClients: monthData.entity_clients,
|
|
|
|
nonEntityClients: monthData.non_entity_clients,
|
|
|
|
},
|
|
|
|
new: {
|
|
|
|
total: monthData.new_clients.clients,
|
|
|
|
entityClients: monthData.new_clients.entity_clients,
|
|
|
|
nonEntityClients: monthData.new_clients.non_entity_clients,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2022-01-25 22:06:56 +00:00
|
|
|
}
|