From 1e58488dcdd30a713ec0befc1a4ffc98625bbdb2 Mon Sep 17 00:00:00 2001 From: Arnav Palnitkar Date: Tue, 24 Aug 2021 12:13:53 -0700 Subject: [PATCH 1/6] Client count config view - Switched to toggle button from checkbox and updated the design - Switched to ember octane - Update ember concurrency dependency --- ui/app/components/pricing-metrics-config.js | 66 +++++++++++-------- .../components/pricing-metrics-config.hbs | 60 ++++++++++++----- ui/package.json | 2 +- ui/yarn.lock | 17 ++++- 4 files changed, 97 insertions(+), 48 deletions(-) diff --git a/ui/app/components/pricing-metrics-config.js b/ui/app/components/pricing-metrics-config.js index 50ad103545b72..898307b86ce22 100644 --- a/ui/app/components/pricing-metrics-config.js +++ b/ui/app/components/pricing-metrics-config.js @@ -10,19 +10,20 @@ * @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 { computed } from '@ember/object'; -import Component from '@ember/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 Component.extend({ - router: service(), - mode: 'show', - model: null, +export default class PricingMetricsConfigComponent extends Component { + @service router; + @tracked mode = 'show'; + @tracked modalOpen = false; + error = null; - error: null, - modalOpen: false, - infoRows: computed(function() { + get infoRows() { return [ { label: 'Usage data collection', @@ -40,35 +41,42 @@ export default Component.extend({ valueKey: 'defaultReportMonths', }, ]; - }), - modalTitle: computed('model.enabled', function() { + } + + @computed('args.model.enabled') + get modalTitle() { let content = 'Turn usage tracking off?'; - if (this.model.enabled === 'On') { + if (this.args.model && this.args.model.enabled === 'On') { content = 'Turn usage tracking on?'; } return content; - }), + } - save: task(function*() { - let model = this.model; + @(task(function*() { try { - yield model.save(); + yield this.args.model.save(); } catch (err) { - this.set('error', err.message); + this.error = err.message; return; } this.router.transitionTo('vault.cluster.metrics.config'); - }).drop(), + }).drop()) + save; + + @action + updateBooleanValue(attr, value) { + let valueToSet = value === true ? attr.options.trueValue : attr.options.falseValue; + this.args.model[attr.name] = valueToSet; + } - actions: { - onSaveChanges: function(evt) { - evt.preventDefault(); - const changed = this.model.changedAttributes(); - if (!changed.enabled) { - this.save.perform(); - return; - } - this.set('modalOpen', true); - }, - }, -}); + @action + onSaveChanges(evt) { + evt.preventDefault(); + const changed = this.args.model.changedAttributes(); + if (!changed.enabled) { + this.save.perform(); + return; + } + this.modalOpen = true; + } +} diff --git a/ui/app/templates/components/pricing-metrics-config.hbs b/ui/app/templates/components/pricing-metrics-config.hbs index 4581569bbf8d8..088e43c7f0089 100644 --- a/ui/app/templates/components/pricing-metrics-config.hbs +++ b/ui/app/templates/components/pricing-metrics-config.hbs @@ -1,13 +1,43 @@ -{{#if (eq mode "edit")}} +{{#if (eq @mode "edit")}}
- - {{#each model.configAttrs as |attr|}} - + + {{#each @model.configAttrs as |attr|}} + {{#if (and (eq attr.type "string") (eq attr.options.editType "boolean"))}} + + {{#if attr.options.helpText}} +

{{attr.options.helpText}} {{#if attr.options.docLink}}See our documentation for help.{{/if}}

+ {{/if}} +
+ + +
+ {{else if (eq attr.type "number")}} +
+ + {{#if attr.options.subText}} +

{{attr.options.subText}} {{#if attr.options.docLink}}See our documentation for help.{{/if}}

+ {{/if}} +
+ +
+
+ {{/if}} {{/each}}
@@ -29,14 +59,14 @@