claire bontempo 6d0e4f654e
UI: Update dashboard client count query to use billing_start_timestamp (#26729)
* remvoe request tolicense in dashboard client count card

* cleanup jsdoc

* add changelog

* use helper to set start time

* update component tests

* update overview test

* update util tests

* throw error instead, add comment to util file

* fix accidentally removed type from import

* remove typo arg from test component

* rename token stat getter to avoid future typos
2024-05-02 17:45:33 +00:00

52 lines
1.3 KiB
TypeScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import ActivityComponent from '../activity';
import type {
ByMonthNewClients,
MountNewClients,
NamespaceByKey,
NamespaceNewClients,
} from 'core/utils/client-count-utils';
export default class ClientsTokenPageComponent extends ActivityComponent {
legend = [
{ key: 'entity_clients', label: 'entity clients' },
{ key: 'non_entity_clients', label: 'non-entity clients' },
];
calculateClientAverages(
dataset:
| (NamespaceByKey | undefined)[]
| (ByMonthNewClients | NamespaceNewClients | MountNewClients | undefined)[]
) {
return ['entity_clients', 'non_entity_clients'].reduce((count, key) => {
const average = this.average(dataset, key);
return (count += average || 0);
}, 0);
}
get averageTotalClients() {
return this.calculateClientAverages(this.byMonthActivityData);
}
get averageNewClients() {
return this.calculateClientAverages(this.byMonthNewClients);
}
get tokenStats() {
if (this.totalUsageCounts) {
const { entity_clients, non_entity_clients } = this.totalUsageCounts;
return {
total: entity_clients + non_entity_clients,
entity_clients,
non_entity_clients,
};
}
return null;
}
}