|
4 | 4 | */
|
5 | 5 |
|
6 | 6 | import Component from '@glimmer/component';
|
7 |
| -import getStorage from 'vault/lib/token-storage'; |
8 | 7 | import timestamp from 'core/utils/timestamp';
|
9 | 8 | import { task } from 'ember-concurrency';
|
10 | 9 | import { waitFor } from '@ember/test-waiters';
|
11 | 10 | import { tracked } from '@glimmer/tracking';
|
12 | 11 | import { service } from '@ember/service';
|
| 12 | +import { setStartTimeQuery } from 'core/utils/client-count-utils'; |
| 13 | +import { dateFormat } from 'core/helpers/date-format'; |
13 | 14 |
|
14 | 15 | /**
|
15 | 16 | * @module DashboardClientCountCard
|
16 | 17 | * DashboardClientCountCard component are used to display total and new client count information
|
17 | 18 | *
|
18 | 19 | * @example
|
19 |
| - * ```js |
20 |
| - * <Dashboard::ClientCountCard @license={{@model.license}} /> |
21 |
| - * ``` |
22 |
| - * @param {object} license - license object passed from the parent |
| 20 | + * |
| 21 | + * <Dashboard::ClientCountCard @isEnterprise={{@version.isEnterprise}} /> |
| 22 | + * |
| 23 | + * @param {boolean} isEnterprise - used for setting the start time for the activity log query |
23 | 24 | */
|
24 | 25 |
|
25 | 26 | export default class DashboardClientCountCard extends Component {
|
26 | 27 | @service store;
|
27 | 28 |
|
| 29 | + clientConfig = null; |
| 30 | + licenseStartTime = null; |
28 | 31 | @tracked activityData = null;
|
29 |
| - @tracked clientConfig = null; |
30 | 32 | @tracked updatedAt = timestamp.now().toISOString();
|
31 | 33 |
|
32 | 34 | constructor() {
|
33 | 35 | super(...arguments);
|
34 | 36 | this.fetchClientActivity.perform();
|
35 |
| - this.clientConfig = this.store.queryRecord('clients/config', {}).catch(() => {}); |
36 | 37 | }
|
37 | 38 |
|
38 | 39 | get currentMonthActivityTotalCount() {
|
39 | 40 | return this.activityData?.byMonth?.lastObject?.new_clients.clients;
|
40 | 41 | }
|
41 | 42 |
|
42 |
| - get licenseStartTime() { |
43 |
| - return this.args.license.startTime || getStorage().getItem('vault:ui-inputted-start-date') || null; |
| 43 | + get statSubText() { |
| 44 | + const format = (date) => dateFormat([date, 'MMM yyyy'], {}); |
| 45 | + return this.licenseStartTime |
| 46 | + ? { |
| 47 | + total: `The number of clients in this billing period (${format(this.licenseStartTime)} - ${format( |
| 48 | + this.updatedAt |
| 49 | + )}).`, |
| 50 | + new: 'The number of clients new to Vault in the current month.', |
| 51 | + } |
| 52 | + : { total: 'No total client data available.', new: 'No new client data available.' }; |
44 | 53 | }
|
45 | 54 |
|
46 | 55 | @task
|
47 | 56 | @waitFor
|
48 | 57 | *fetchClientActivity(e) {
|
49 | 58 | if (e) e.preventDefault();
|
50 | 59 | this.updatedAt = timestamp.now().toISOString();
|
| 60 | + |
| 61 | + if (!this.clientConfig) { |
| 62 | + // set config and license start time when component initializes |
| 63 | + this.clientConfig = yield this.store.queryRecord('clients/config', {}).catch(() => {}); |
| 64 | + this.licenseStartTime = setStartTimeQuery(this.args.isEnterprise, this.clientConfig); |
| 65 | + } |
| 66 | + |
51 | 67 | // only make the network request if we have a start_time
|
52 | 68 | if (!this.licenseStartTime) return {};
|
53 | 69 | try {
|
|
0 commit comments