-
Notifications
You must be signed in to change notification settings - Fork 4.1k
/
pricing-metrics-config.js
80 lines (73 loc) · 2.19 KB
/
pricing-metrics-config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/**
* @module PricingMetricsConfig
* PricingMetricsConfig components are used to show and edit the pricing metrics config information.
*
* @example
* ```js
* <PricingMetricsConfig @model={{model}} @mode="edit" />
* ```
* @param {object} model - model is the DS metrics/config model which should be passed in
* @param {string} [mode=show] - mode is either show or edit. Show results in a table with the config, show has a form.
*/
import Component from '@glimmer/component';
import { action } from '@ember/object';
import { inject as service } from '@ember/service';
import { tracked } from '@glimmer/tracking';
import { task } from 'ember-concurrency';
export default class PricingMetricsConfigComponent extends Component {
@service router;
@tracked mode = 'show';
@tracked modalOpen = false;
error = null;
get infoRows() {
return [
{
label: 'Usage data collection',
helperText: 'Enable or disable collecting data to track clients.',
valueKey: 'enabled',
},
{
label: 'Retention period',
helperText: 'The number of months of activity logs to maintain for client tracking.',
valueKey: 'retentionMonths',
},
{
label: 'Default display',
helperText: 'The number of months we’ll display in the Vault usage dashboard by default.',
valueKey: 'defaultReportMonths',
},
];
}
get modalTitle() {
let content = 'Turn usage tracking off?';
if (this.args.model && this.args.model.enabled === 'On') {
content = 'Turn usage tracking on?';
}
return content;
}
@(task(function*() {
try {
yield this.args.model.save();
} catch (err) {
this.error = err.message;
return;
}
this.router.transitionTo('vault.cluster.metrics.config');
}).drop())
save;
@action
updateBooleanValue(attr, value) {
let valueToSet = value === true ? attr.options.trueValue : attr.options.falseValue;
this.args.model[attr.name] = valueToSet;
}
@action
onSaveChanges(evt) {
evt.preventDefault();
const changed = this.args.model.changedAttributes();
if (!changed.enabled) {
this.save.perform();
return;
}
this.modalOpen = true;
}
}