-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UI: Update dashboard client count query to use billing_start_timestamp
#26729
Changes from all commits
2b55627
fbf7706
80dd3ed
5353fe4
6542107
0d645e0
6797d3b
3041dea
2364f05
a5753a4
6697ea2
22f2ed8
f1162ee
d3fefc4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:improvement | ||
ui (enterprise): Update dashboard to make activity log query using the same start time as the metrics overview | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,50 +4,66 @@ | |
*/ | ||
|
||
import Component from '@glimmer/component'; | ||
import getStorage from 'vault/lib/token-storage'; | ||
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 { setStartTimeQuery } from 'core/utils/client-count-utils'; | ||
import { dateFormat } from 'core/helpers/date-format'; | ||
|
||
/** | ||
* @module DashboardClientCountCard | ||
* DashboardClientCountCard component are used to display total and new client count information | ||
* | ||
* @example | ||
* ```js | ||
* <Dashboard::ClientCountCard @license={{@model.license}} /> | ||
* ``` | ||
* @param {object} license - license object passed from the parent | ||
* | ||
* <Dashboard::ClientCountCard @isEnterprise={{@version.isEnterprise}} /> | ||
* | ||
* @param {boolean} isEnterprise - used for setting the start time for the activity log query | ||
*/ | ||
|
||
export default class DashboardClientCountCard extends Component { | ||
@service store; | ||
|
||
clientConfig = null; | ||
licenseStartTime = null; | ||
@tracked activityData = null; | ||
@tracked clientConfig = null; | ||
@tracked updatedAt = timestamp.now().toISOString(); | ||
|
||
constructor() { | ||
super(...arguments); | ||
this.fetchClientActivity.perform(); | ||
this.clientConfig = this.store.queryRecord('clients/config', {}).catch(() => {}); | ||
} | ||
|
||
get currentMonthActivityTotalCount() { | ||
return this.activityData?.byMonth?.lastObject?.new_clients.clients; | ||
} | ||
|
||
get licenseStartTime() { | ||
return this.args.license.startTime || getStorage().getItem('vault:ui-inputted-start-date') || null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we no longer saved the inputted user start date in local storage |
||
get statSubText() { | ||
const format = (date) => dateFormat([date, 'MMM yyyy'], {}); | ||
return this.licenseStartTime | ||
? { | ||
total: `The number of clients in this billing period (${format(this.licenseStartTime)} - ${format( | ||
this.updatedAt | ||
)}).`, | ||
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(); | ||
|
||
if (!this.clientConfig) { | ||
// set config and license start time when component initializes | ||
this.clientConfig = yield this.store.queryRecord('clients/config', {}).catch(() => {}); | ||
this.licenseStartTime = setStartTimeQuery(this.args.isEnterprise, this.clientConfig); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. technically I could just pass |
||
} | ||
|
||
// only make the network request if we have a start_time | ||
if (!this.licenseStartTime) return {}; | ||
try { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,9 +14,10 @@ import type VersionService from 'vault/services/version'; | |
|
||
import type { ModelFrom } from 'vault/vault/route'; | ||
import type ClientsRoute from '../clients'; | ||
import type ClientsConfigModel from 'vault/models/clients/config'; | ||
import type ClientsActivityModel from 'vault/models/clients/activity'; | ||
import type ClientsCountsController from 'vault/controllers/vault/cluster/clients/counts'; | ||
import { setStartTimeQuery } from 'core/utils/client-count-utils'; | ||
|
||
export interface ClientsCountsRouteParams { | ||
start_time?: string | number | undefined; | ||
end_time?: string | number | undefined; | ||
|
@@ -86,10 +87,7 @@ export default class ClientsCountsRoute extends Route { | |
async model(params: ClientsCountsRouteParams) { | ||
const { config, versionHistory } = this.modelFor('vault.cluster.clients') as ModelFrom<ClientsRoute>; | ||
// only enterprise versions will have a relevant billing start date, if null users must select initial start time | ||
let startTime = null; | ||
if (this.version.isEnterprise && this._hasConfig(config)) { | ||
startTime = getUnixTime(config.billingStartTimestamp); | ||
} | ||
const startTime = setStartTimeQuery(this.version.isEnterprise, config); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Although this logic is fairly simple and only used in two places, I wanted to consolidate it so that setting the start time was handled the same in both places the |
||
|
||
const startTimestamp = Number(params.start_time) || startTime; | ||
const endTimestamp = Number(params.end_time) || getUnixTime(timestamp.now()); | ||
|
@@ -118,8 +116,4 @@ export default class ClientsCountsRoute extends Route { | |
}); | ||
} | ||
} | ||
|
||
_hasConfig(model: ClientsConfigModel | object): model is ClientsConfigModel { | ||
return 'billingStartTimestamp' in model; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This format is consistent with the format we show response timestamps elsewhere in the app