vault/ui/app/components/dashboard/client-count-card.js
claire bontempo 1e8eefade1
UI: wrap client count card in permission conditional (#26848)
* consistent timestamp format

* wrap client count card in permissions

* add test

* add changelog

* move tests into module, add more!

* final test cleanup, stub permissions manually without helper

* use current_billing_period for dashboard, add tests

* update mirage to handle new client param

* Update ui/app/components/dashboard/client-count-card.js
2024-05-07 17:45:42 +00:00

65 lines
1.8 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import Component from '@glimmer/component';
import timestamp from 'core/utils/timestamp';
import { task } from 'ember-concurrency';
import { waitFor } from '@ember/test-waiters';
import { tracked } from '@glimmer/tracking';
import { service } from '@ember/service';
import { parseAPITimestamp } from 'core/utils/date-formatters';
/**
* @module DashboardClientCountCard
* DashboardClientCountCard component are used to display total and new client count information
*
* @example
* <Dashboard::ClientCountCard />
*/
export default class DashboardClientCountCard extends Component {
@service store;
@tracked activityData = null;
@tracked hasActivity = false;
@tracked updatedAt = null;
constructor() {
super(...arguments);
this.fetchClientActivity.perform();
}
get currentMonthActivityTotalCount() {
return this.activityData?.byMonth?.lastObject?.new_clients.clients;
}
get statSubText() {
const format = (date) => parseAPITimestamp(date, 'MMM yyyy');
const { startTime, endTime } = this.activityData;
return startTime && endTime
? {
total: `The number of clients in this billing period (${format(startTime)} - ${format(endTime)}).`,
new: 'The number of clients new to Vault in the current month.',
}
: { total: 'No total client data available.', new: 'No new client data available.' };
}
@task
@waitFor
*fetchClientActivity(e) {
if (e) e.preventDefault();
this.updatedAt = timestamp.now().toISOString();
try {
this.activityData = yield this.store.queryRecord('clients/activity', {
current_billing_period: true,
});
this.hasActivity = this.activityData.id === 'no-data' ? false : true;
} catch (error) {
this.error = error;
}
}
}