claire bontempo 009702cae0
UI: Convert client count utils to typescript (#26262)
* cleanup namespaceArrayToObject method

* WIP typescript conversion

* WIP typescripted destructured block

* slowly making progress....

* WIP move all types to util type file, separate returns in formatByMonths

* namespaceArrayToObject is working?!?

* fix mirage handler not generating months when queries are after upgrade

* wow, the types are actually working omg

* add comments and update client-count-utils test

* delete old js file

* remove types from activity model

* remove comment

* reuse totalclients type to minimize places we add types

* commit file with type changes for git diff

* delete util file again

* address PR feedback and move type declarations to util file

* remove unused types

* update tests, use client helper in dashboard clients test

* remove typo

* make modifications with updated combined activity response from the backend
2024-04-09 20:53:16 +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 tokenUsageCounts() {
if (this.totalUsageCounts) {
const { entity_clients, non_entity_clients } = this.totalUsageCounts;
return {
clients: entity_clients + non_entity_clients,
entity_clients,
non_entity_clients,
};
}
return null;
}
}