From a1034981fa9beb96fe11c77c9e400a0ca9b2e7d8 Mon Sep 17 00:00:00 2001 From: Angel Garbarino Date: Tue, 5 Apr 2022 15:47:50 -0600 Subject: [PATCH 01/11] inital glimmerize --- ui/app/components/secret-delete-menu.js | 2 + ui/app/components/secret-edit.js | 263 +++++++++++++----------- 2 files changed, 143 insertions(+), 122 deletions(-) diff --git a/ui/app/components/secret-delete-menu.js b/ui/app/components/secret-delete-menu.js index cc9ae6bf9fd1..f4137273c165 100644 --- a/ui/app/components/secret-delete-menu.js +++ b/ui/app/components/secret-delete-menu.js @@ -7,6 +7,8 @@ import { action } from '@ember/object'; import { alias } from '@ember/object/computed'; import { maybeQueryRecord } from 'vault/macros/maybe-query-record'; +// ARG TODO documentation + const getErrorMessage = (errors) => { let errorMessage = errors?.join('. ') || 'Something went wrong. Check the Vault logs for more information.'; return errorMessage; diff --git a/ui/app/components/secret-edit.js b/ui/app/components/secret-edit.js index 5e968a71586c..5ab86f02390c 100644 --- a/ui/app/components/secret-edit.js +++ b/ui/app/components/secret-edit.js @@ -7,161 +7,180 @@ * * ``` / - * @param {object} model - Model returned from route secret-v2 + * @param {object} model - Model returned from secret-v2 which is generated in the secret-edit route */ import { inject as service } from '@ember/service'; -import Component from '@ember/component'; -import { computed } from '@ember/object'; -import { alias, or } from '@ember/object/computed'; -import FocusOnInsertMixin from 'vault/mixins/focus-on-insert'; -import WithNavToNearestAncestor from 'vault/mixins/with-nav-to-nearest-ancestor'; +import Component from '@glimmer/component'; +import { action } from '@ember/object'; +import { tracked } from '@glimmer/tracking'; +// ARGTODO work on +// import FocusOnInsertMixin from 'vault/mixins/focus-on-insert'; +// import WithNavToNearestAncestor from 'vault/mixins/with-nav-to-nearest-ancestor'; import KVObject from 'vault/lib/kv-object'; import { maybeQueryRecord } from 'vault/macros/maybe-query-record'; - -export default Component.extend(FocusOnInsertMixin, WithNavToNearestAncestor, { - wizard: service(), - store: service(), +// https://stackoverflow.com/questions/60843983/does-ember-octane-route-class-support-using-mixins +export default class SecretEdit extends Component { + // export default Component.extend(FocusOnInsertMixin, WithNavToNearestAncestor, { + @service wizard; + @service store; // a key model - key: null, - model: null, + @tracked key = null; + // @tracked model = null; // a value to pre-fill the key input - this is populated by the corresponding // 'initialKey' queryParam - initialKey: null, + @tracked initialKey = null; // set in the route's setupController hook - mode: null, + @tracked mode = null; - secretData: null, + @tracked secretData = null; // called with a bool indicating if there's been a change in the secretData and customMetadata - onDataChange() {}, - onRefresh() {}, - onToggleAdvancedEdit() {}, + onDataChange() {} + onRefresh() {} + onToggleAdvancedEdit() {} // did user request advanced mode - preferAdvancedEdit: false, + preferAdvancedEdit = false; // use a named action here so we don't have to pass one in // this will bubble to the route - toggleAdvancedEdit: 'toggleAdvancedEdit', + toggleAdvancedEdit = 'toggleAdvancedEdit'; - codemirrorString: null, + codemirrorString = null; - isV2: false, + @tracked isV2 = false; - init() { - this._super(...arguments); - let secrets = this.model.secretData; - if (!secrets && this.model.selectedVersion) { - this.set('isV2', true); - secrets = this.model.belongsTo('selectedVersion').value().secretData; + constructor() { + super(...arguments); + let secrets = this.args.model.secretData; + if (!secrets && this.args.model.selectedVersion) { + this.args.isV2 = true; + secrets = this.args.model.belongsTo('selectedVersion').value().secretData; } const data = KVObject.create({ content: [] }).fromJSON(secrets); - this.set('secretData', data); - this.set('codemirrorString', data.toJSONString()); + this.secretData = data; + this.codemirrorString = data.toJSONString(); if (data.isAdvanced()) { - this.set('preferAdvancedEdit', true); + this.preferAdvancedEdit = true; } - if (this.wizard.featureState === 'details' && this.mode === 'create') { - let engine = this.model.backend.includes('kv') ? 'kv' : this.model.backend; - this.wizard.transitionFeatureMachine('details', 'CONTINUE', engine); + // ARG unsure about this.args.wizard + if (this.args.wizard.featureState === 'details' && this.args.mode === 'create') { + let engine = this.args.model.backend.includes('kv') ? 'kv' : this.args.model.backend; + this.args.wizard.transitionFeatureMachine('details', 'CONTINUE', engine); } - }, - - checkSecretCapabilities: maybeQueryRecord( - 'capabilities', - (context) => { - if (!context.model || context.mode === 'create') { - return; - } - let backend = context.isV2 ? context.get('model.engine.id') : context.model.backend; - let id = context.model.id; - let path = context.isV2 ? `${backend}/data/${id}` : `${backend}/${id}`; - return { - id: path, - }; - }, - 'isV2', - 'model', - 'model.id', - 'mode' - ), - canUpdateSecretData: alias('checkSecretCapabilities.canUpdate'), - canReadSecretData: alias('checkSecretCapabilities.canRead'), - - checkMetadataCapabilities: maybeQueryRecord( - 'capabilities', - (context) => { - if (!context.model || !context.isV2) { - return; - } - let backend = context.model.backend; - let path = `${backend}/metadata/`; - return { - id: path, - }; - }, - 'isV2', - 'model', - 'model.id', - 'mode' - ), - canDeleteSecretMetadata: alias('checkMetadataCapabilities.canDelete'), - canUpdateSecretMetadata: alias('checkMetadataCapabilities.canUpdate'), - canReadSecretMetadata: alias('checkMetadataCapabilities.canRead'), - - requestInFlight: or('model.isLoading', 'model.isReloading', 'model.isSaving'), - - buttonDisabled: or('requestInFlight', 'model.isFolder', 'model.flagsIsInvalid'), - - modelForData: computed('isV2', 'model', function () { - let { model } = this; + } + + checkSecretCapabilities() { + return maybeQueryRecord( + 'capabilities', + (context) => { + // ARG TODO check context works here + if (!context.model || context.mode === 'create') { + return; + } + let backend = context.isV2 ? context.get('model.engine.id') : context.model.backend; + let id = context.model.id; + let path = context.isV2 ? `${backend}/data/${id}` : `${backend}/${id}`; + return { + id: path, + }; + }, + 'isV2', + 'model', + 'model.id', + 'mode' + ); + } + // these where alias + @tracked + canUpdateSecretData = this.checkSecretCapabilities.canUpdate; + @tracked + canReadSecretData = this.checkSecretCapabilities.canRead; + + checkMetadataCapabilities() { + return maybeQueryRecord( + 'capabilities', + (context) => { + // ARG TODO check context work here + if (!context.model || !context.isV2) { + return; + } + let backend = context.model.backend; + let path = `${backend}/metadata/`; + return { + id: path, + }; + }, + 'isV2', + 'model', + 'model.id', + 'mode' + ); + } + @tracked + canDeleteSecretMetadata = this.checkMetadataCapabilities.canDelete; + @tracked + canUpdateSecretMetadata = this.checkMetadataCapabilities.canUpdate; + @tracked + canReadSecretMetadata = this.checkMetadataCapabilities.canRead; + // this was an or + get requestInFlight() { + return this.args.model.isLoading || this.args.model.isReloading || this.args.model.isSaving; + } + // this was an or + get buttonDisabled() { + return this.requestInFlight || this.args.model.isFolder || this.args.model.flagsIsInvalid; + } + + get modelForData() { + let { model } = this.args; if (!model) return null; - return this.isV2 ? model.belongsTo('selectedVersion').value() : model; - }), + return this.args.isV2 ? model.belongsTo('selectedVersion').value() : model; + } - basicModeDisabled: computed('secretDataIsAdvanced', 'showAdvancedMode', function () { + get basicModeDisabled() { return this.secretDataIsAdvanced || this.showAdvancedMode === false; - }), + } - secretDataAsJSON: computed('secretData', 'secretData.[]', function () { + get secretDataAsJSON() { return this.secretData.toJSON(); - }), + } - secretDataIsAdvanced: computed('secretData', 'secretData.[]', function () { + get secretDataIsAdvanced() { return this.secretData.isAdvanced(); - }), - - showAdvancedMode: or('secretDataIsAdvanced', 'preferAdvancedEdit'), - - isWriteWithoutRead: computed( - 'model.failedServerRead', - 'modelForData.failedServerRead', - 'isV2', - function () { - if (!this.model) return; - // if the version couldn't be read from the server - if (this.isV2 && this.modelForData.failedServerRead) { - return true; - } - // if the model couldn't be read from the server - if (!this.isV2 && this.model.failedServerRead) { - return true; - } - return false; + } + + get showAdvancedMode() { + return this.secretDataIsAdvanced || this.preferAdvancedEdit; + } + + get isWriteWithoutRead() { + if (!this.args.model) { + return null; + // ARG TODO was a return instead of null??? + } + // if the version couldn't be read from the server + if (this.args.isV2 && this.modelForData.failedServerRead) { + return true; + } + // if the model couldn't be read from the server + if (!this.args.isV2 && this.args.model.failedServerRead) { + return true; } - ), - - actions: { - refresh() { - this.onRefresh(); - }, - - toggleAdvanced(bool) { - this.onToggleAdvancedEdit(bool); - }, - }, -}); + return false; + } + + @action + refresh() { + this.onRefresh(); + } + + @action + toggleAdvanced(bool) { + this.onToggleAdvancedEdit(bool); + } +} From b7cd9b740f749179c82b8c52eaa15c886ba19f49 Mon Sep 17 00:00:00 2001 From: Angel Garbarino Date: Wed, 6 Apr 2022 10:46:05 -0600 Subject: [PATCH 02/11] wip --- ui/app/components/secret-edit.js | 15 ++++---- .../components/secret-edit-toolbar.hbs | 1 + ui/app/templates/components/secret-edit.hbs | 36 +++++++++---------- .../components/secret-edit-test.js | 1 - 4 files changed, 28 insertions(+), 25 deletions(-) diff --git a/ui/app/components/secret-edit.js b/ui/app/components/secret-edit.js index 5ab86f02390c..6044246c919c 100644 --- a/ui/app/components/secret-edit.js +++ b/ui/app/components/secret-edit.js @@ -4,10 +4,14 @@ * * @example * ```js - * + * * ``` / * @param {object} model - Model returned from secret-v2 which is generated in the secret-edit route + * @param {string} mode - Edit, create, etc. + * @param {boolean} isV2 - Whether it's kv version two or version 1. + * @param {string} basekey - For navigation. + This component is initialized from the secret-edit-layout.hbs file */ import { inject as service } from '@ember/service'; @@ -44,6 +48,7 @@ export default class SecretEdit extends Component { onToggleAdvancedEdit() {} // did user request advanced mode + @tracked preferAdvancedEdit = false; // use a named action here so we don't have to pass one in @@ -52,8 +57,6 @@ export default class SecretEdit extends Component { codemirrorString = null; - @tracked isV2 = false; - constructor() { super(...arguments); let secrets = this.args.model.secretData; @@ -65,12 +68,12 @@ export default class SecretEdit extends Component { this.secretData = data; this.codemirrorString = data.toJSONString(); if (data.isAdvanced()) { + console.log('here'); this.preferAdvancedEdit = true; } - // ARG unsure about this.args.wizard - if (this.args.wizard.featureState === 'details' && this.args.mode === 'create') { + if (this.wizard.featureState === 'details' && this.args.mode === 'create') { let engine = this.args.model.backend.includes('kv') ? 'kv' : this.args.model.backend; - this.args.wizard.transitionFeatureMachine('details', 'CONTINUE', engine); + this.wizard.transitionFeatureMachine('details', 'CONTINUE', engine); } } diff --git a/ui/app/templates/components/secret-edit-toolbar.hbs b/ui/app/templates/components/secret-edit-toolbar.hbs index 59a1ba780fe8..029ef0a3dc33 100644 --- a/ui/app/templates/components/secret-edit-toolbar.hbs +++ b/ui/app/templates/components/secret-edit-toolbar.hbs @@ -16,6 +16,7 @@ {{/unless}} {{#if (eq @mode "show")}} + here

- {{#if (eq this.mode "create")}} + {{#if (eq @mode "create")}} Create secret - {{else if (and this.isV2 (eq this.mode "edit"))}} + {{else if (and @isV2 (eq @mode "edit"))}} Create new version - {{else if (eq this.mode "edit")}} + {{else if (eq @mode "edit")}} Edit secret {{else}} - {{this.key.id}} + {{@key.id}} {{/if}}

{{! tabs for show only }} -{{#if (eq this.mode "show")}} +{{#if (eq @mode "show")}}
{{/if}} - {{#if (or (eq @mode "create") (eq @mode "edit"))}} @@ -63,16 +62,16 @@ @showAdvancedMode={{this.showAdvancedMode}} @modelForData={{this.modelForData}} @error={{this.error}} - @isV2={{@isV2}} + @isV2={{this.isV2}} @secretData={{this.secretData}} @buttonDisabled={{this.buttonDisabled}} @canUpdateSecretMetadata={{this.canUpdateSecretMetadata}} @canReadSecretData={{this.canReadSecretData}} @canReadSecretMetadata={{this.canReadSecretMetadata}} /> -{{else if (eq this.mode "show")}} +{{else if (eq @mode "show")}} Date: Wed, 6 Apr 2022 11:43:27 -0600 Subject: [PATCH 04/11] wip --- ui/app/components/secret-edit.js | 19 ++++--------------- ui/app/templates/components/secret-edit.hbs | 2 +- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/ui/app/components/secret-edit.js b/ui/app/components/secret-edit.js index e7f44bdf40f2..f09e01bae328 100644 --- a/ui/app/components/secret-edit.js +++ b/ui/app/components/secret-edit.js @@ -4,7 +4,7 @@ * * @example * ```js - * + * * ``` / * @param {object} model - Model returned from secret-v2 which is generated in the secret-edit route @@ -14,7 +14,7 @@ * @param {string} initalKey - ARG TODO * @param {function} onRefresh - ARG TODO * @param {function} onToggleAdvancedEdit - ARG TODO - * @param {boolean} preferAdvancedEdit - ARG TODO + * @param {boolean} preferAdvancedEdit - property set from the controller of show/edit/create route passed in through secret-edit-layout This component is initialized from the secret-edit-layout.hbs file */ @@ -34,19 +34,8 @@ export default class SecretEdit extends Component { @service store; @tracked secretData = null; - - // called with a bool indicating if there's been a change in the secretData and customMetadata - onDataChange() {} - onRefresh() {} - onToggleAdvancedEdit() {} - @tracked isV2 = false; - - // use a named action here so we don't have to pass one in - // this will bubble to the route - // toggleAdvancedEdit = 'toggleAdvancedEdit'; - @tracked codemirrorString = null; @@ -151,7 +140,7 @@ export default class SecretEdit extends Component { } get showAdvancedMode() { - return this.secretDataIsAdvanced || this.preferAdvancedEdit; + return this.secretDataIsAdvanced || this.args.preferAdvancedEdit; } get isWriteWithoutRead() { @@ -172,7 +161,7 @@ export default class SecretEdit extends Component { @action refresh() { - this.args.nRefresh(); + this.args.onRefresh(); } @action diff --git a/ui/app/templates/components/secret-edit.hbs b/ui/app/templates/components/secret-edit.hbs index d9905d5ed6d2..2f88bd6d34d1 100644 --- a/ui/app/templates/components/secret-edit.hbs +++ b/ui/app/templates/components/secret-edit.hbs @@ -52,7 +52,7 @@ @canUpdateSecretData={{this.canUpdateSecretData}} @canReadSecretMetadata={{this.canReadSecretMetadata}} @codemirrorString={{this.codemirrorString}} - @editActions={{hash toggleAdvanced=this.toggleAdvanced refresh=this.refresh}} + @editActions={{hash toggleAdvanced=(action "toggleAdvanced") refresh=(action "refresh")}} /> {{#if (or (eq @mode "create") (eq @mode "edit"))}} From 0a6f65a18a8cfb5c3818c6779c9cf0341bd9b7a9 Mon Sep 17 00:00:00 2001 From: Angel Garbarino Date: Wed, 6 Apr 2022 13:03:33 -0600 Subject: [PATCH 05/11] fix maybeQueryRecord --- ui/app/components/secret-edit.js | 111 ++++++++++++++----------------- 1 file changed, 49 insertions(+), 62 deletions(-) diff --git a/ui/app/components/secret-edit.js b/ui/app/components/secret-edit.js index f09e01bae328..3136901d76a6 100644 --- a/ui/app/components/secret-edit.js +++ b/ui/app/components/secret-edit.js @@ -1,3 +1,4 @@ +/* eslint ember/no-computed-properties-in-native-classes: 'warn' */ /** * @module SecretEdit * SecretEdit component manages the secret and model data, and displays either the create, update, empty state or show view of a KV secret. @@ -27,6 +28,7 @@ import { tracked } from '@glimmer/tracking'; // import WithNavToNearestAncestor from 'vault/mixins/with-nav-to-nearest-ancestor'; import KVObject from 'vault/lib/kv-object'; import { maybeQueryRecord } from 'vault/macros/maybe-query-record'; +import { alias } from '@ember/object/computed'; // https://stackoverflow.com/questions/60843983/does-ember-octane-route-class-support-using-mixins export default class SecretEdit extends Component { // export default Component.extend(FocusOnInsertMixin, WithNavToNearestAncestor, { @@ -34,10 +36,8 @@ export default class SecretEdit extends Component { @service store; @tracked secretData = null; - @tracked - isV2 = false; - @tracked - codemirrorString = null; + @tracked isV2 = false; + @tracked codemirrorString = null; constructor() { super(...arguments); @@ -49,74 +49,61 @@ export default class SecretEdit extends Component { const data = KVObject.create({ content: [] }).fromJSON(secrets); this.secretData = data; this.codemirrorString = data.toJSONString(); - // if (data.isAdvanced()) { - // // ARG TODO cannot set an args?? - // this.args.preferAdvancedEdit = true; - // } if (this.wizard.featureState === 'details' && this.args.mode === 'create') { let engine = this.args.model.backend.includes('kv') ? 'kv' : this.args.model.backend; this.wizard.transitionFeatureMachine('details', 'CONTINUE', engine); } } - checkSecretCapabilities() { - return maybeQueryRecord( - 'capabilities', - (context) => { - // ARG TODO check context works here - if (!context.model || context.mode === 'create') { - return; - } - let backend = context.isV2 ? context.get('model.engine.id') : context.model.backend; - let id = context.model.id; - let path = context.isV2 ? `${backend}/data/${id}` : `${backend}/${id}`; - return { - id: path, - }; - }, - 'isV2', - 'model', - 'model.id', - 'mode' - ); - } - // these where alias - @tracked - canUpdateSecretData = this.checkSecretCapabilities.canUpdate; - @tracked - canReadSecretData = this.checkSecretCapabilities.canRead; + @maybeQueryRecord( + 'capabilities', + (context) => { + // ARG TODO check context works here + if (!context.args.model || context.args.mode === 'create') { + return; + } + let backend = context.isV2 ? context.get('model.engine.id') : context.args.model.backend; + let id = context.args.model.id; + let path = context.isV2 ? `${backend}/data/${id}` : `${backend}/${id}`; + return { + id: path, + }; + }, + 'isV2', + 'model', + 'model.id', + 'mode' + ) + checkSecretCapabilities; + @alias('checkSecretCapabilities.canUpdate') canUpdateSecretData; + @alias('checkSecretCapabilities.canRead') canReadSecretData; + + @maybeQueryRecord( + 'capabilities', + (context) => { + if (!context.args.model || !context.isV2) { + return; + } + let backend = context.args.model.backend; + let path = `${backend}/metadata/`; + return { + id: path, + }; + }, + 'isV2', + 'model', + 'model.id', + 'mode' + ) + checkMetadataCapabilities; + @alias('checkMetadataCapabilities.canDelete') canDeleteSecretMetadata; + @alias('checkMetadataCapabilities.canUpdate') canUpdateSecretMetadata; + @alias('checkMetadataCapabilities.canRead') canReadSecretMetadata; - checkMetadataCapabilities() { - return maybeQueryRecord( - 'capabilities', - (context) => { - // ARG TODO check context work here - if (!context.model || !context.isV2) { - return; - } - let backend = context.model.backend; - let path = `${backend}/metadata/`; - return { - id: path, - }; - }, - 'isV2', - 'model', - 'model.id', - 'mode' - ); - } - @tracked - canDeleteSecretMetadata = this.checkMetadataCapabilities.canDelete; - @tracked - canUpdateSecretMetadata = this.checkMetadataCapabilities.canUpdate; - @tracked - canReadSecretMetadata = this.checkMetadataCapabilities.canRead; - // this was an or get requestInFlight() { return this.args.model.isLoading || this.args.model.isReloading || this.args.model.isSaving; } - // this was an or + get buttonDisabled() { return this.requestInFlight || this.args.model.isFolder || this.args.model.flagsIsInvalid; } From bc720736b7af552125c9f8d6c88fba07625a4131 Mon Sep 17 00:00:00 2001 From: Angel Garbarino Date: Wed, 6 Apr 2022 13:29:47 -0600 Subject: [PATCH 06/11] fix --- ui/app/components/secret-edit.js | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/ui/app/components/secret-edit.js b/ui/app/components/secret-edit.js index 3136901d76a6..d84c8e64e96a 100644 --- a/ui/app/components/secret-edit.js +++ b/ui/app/components/secret-edit.js @@ -28,7 +28,7 @@ import { tracked } from '@glimmer/tracking'; // import WithNavToNearestAncestor from 'vault/mixins/with-nav-to-nearest-ancestor'; import KVObject from 'vault/lib/kv-object'; import { maybeQueryRecord } from 'vault/macros/maybe-query-record'; -import { alias } from '@ember/object/computed'; +import { alias, or } from '@ember/object/computed'; // https://stackoverflow.com/questions/60843983/does-ember-octane-route-class-support-using-mixins export default class SecretEdit extends Component { // export default Component.extend(FocusOnInsertMixin, WithNavToNearestAncestor, { @@ -58,11 +58,10 @@ export default class SecretEdit extends Component { @maybeQueryRecord( 'capabilities', (context) => { - // ARG TODO check context works here if (!context.args.model || context.args.mode === 'create') { return; } - let backend = context.isV2 ? context.get('model.engine.id') : context.args.model.backend; + let backend = context.isV2 ? context.args.model.engine.id : context.args.model.backend; let id = context.args.model.id; let path = context.isV2 ? `${backend}/data/${id}` : `${backend}/${id}`; return { @@ -100,13 +99,8 @@ export default class SecretEdit extends Component { @alias('checkMetadataCapabilities.canUpdate') canUpdateSecretMetadata; @alias('checkMetadataCapabilities.canRead') canReadSecretMetadata; - get requestInFlight() { - return this.args.model.isLoading || this.args.model.isReloading || this.args.model.isSaving; - } - - get buttonDisabled() { - return this.requestInFlight || this.args.model.isFolder || this.args.model.flagsIsInvalid; - } + @or('model.isLoading', 'model.isReloading', 'model.isSaving') requestInFlight; + @or('requestInFlight', 'model.isFolder', 'model.flagsIsInvalid') buttonDisabled; get modelForData() { let { model } = this.args; @@ -126,9 +120,7 @@ export default class SecretEdit extends Component { return this.secretData.isAdvanced(); } - get showAdvancedMode() { - return this.secretDataIsAdvanced || this.args.preferAdvancedEdit; - } + @or('secretDataIsAdvanced', 'preferAdvancedEdit') showAdvancedMode; get isWriteWithoutRead() { if (!this.args.model) { From 4e53ad84dbe138a44131f31278eaa18ba1a04538 Mon Sep 17 00:00:00 2001 From: Angel Garbarino Date: Wed, 6 Apr 2022 14:03:18 -0600 Subject: [PATCH 07/11] fix --- ui/app/components/secret-edit.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ui/app/components/secret-edit.js b/ui/app/components/secret-edit.js index d84c8e64e96a..812b9c295b3a 100644 --- a/ui/app/components/secret-edit.js +++ b/ui/app/components/secret-edit.js @@ -120,7 +120,9 @@ export default class SecretEdit extends Component { return this.secretData.isAdvanced(); } - @or('secretDataIsAdvanced', 'preferAdvancedEdit') showAdvancedMode; + get showAdvancedMode() { + return this.secretDataIsAdvanced || this.args.preferAdvancedEdit; + } get isWriteWithoutRead() { if (!this.args.model) { From 423c5ca53714e1546c035392ecc2da1072cf693b Mon Sep 17 00:00:00 2001 From: Angel Garbarino Date: Wed, 6 Apr 2022 14:09:58 -0600 Subject: [PATCH 08/11] fix test --- ui/app/components/secret-edit.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ui/app/components/secret-edit.js b/ui/app/components/secret-edit.js index 812b9c295b3a..064d23491231 100644 --- a/ui/app/components/secret-edit.js +++ b/ui/app/components/secret-edit.js @@ -126,15 +126,15 @@ export default class SecretEdit extends Component { get isWriteWithoutRead() { if (!this.args.model) { - return null; + return false; // ARG TODO was a return instead of null??? } // if the version couldn't be read from the server - if (this.args.isV2 && this.modelForData.failedServerRead) { + if (this.isV2 && this.modelForData.failedServerRead) { return true; } // if the model couldn't be read from the server - if (!this.args.isV2 && this.args.model.failedServerRead) { + if (!this.isV2 && this.args.model.failedServerRead) { return true; } return false; From c862feedbae7d30612c837e05e8d9929bc95ffc3 Mon Sep 17 00:00:00 2001 From: Angel Garbarino Date: Wed, 6 Apr 2022 15:50:47 -0600 Subject: [PATCH 09/11] cleanup --- ui/app/components/secret-delete-menu.js | 2 -- ui/app/components/secret-edit-toolbar.js | 2 -- ui/app/components/secret-edit.js | 21 +++++++------------ .../components/secret-edit-toolbar.hbs | 1 - ui/app/templates/components/secret-edit.hbs | 1 - 5 files changed, 7 insertions(+), 20 deletions(-) diff --git a/ui/app/components/secret-delete-menu.js b/ui/app/components/secret-delete-menu.js index f4137273c165..cc9ae6bf9fd1 100644 --- a/ui/app/components/secret-delete-menu.js +++ b/ui/app/components/secret-delete-menu.js @@ -7,8 +7,6 @@ import { action } from '@ember/object'; import { alias } from '@ember/object/computed'; import { maybeQueryRecord } from 'vault/macros/maybe-query-record'; -// ARG TODO documentation - const getErrorMessage = (errors) => { let errorMessage = errors?.join('. ') || 'Something went wrong. Check the Vault logs for more information.'; return errorMessage; diff --git a/ui/app/components/secret-edit-toolbar.js b/ui/app/components/secret-edit-toolbar.js index f2bfb44c54db..b953c2545155 100644 --- a/ui/app/components/secret-edit-toolbar.js +++ b/ui/app/components/secret-edit-toolbar.js @@ -12,7 +12,6 @@ * @secretDataIsAdvanced={{secretDataIsAdvanced}} * @showAdvancedMode={{showAdvancedMode}} * @modelForData={{this.modelForData}} - * @navToNearestAncestor={{this.navToNearestAncestor}} * @canUpdateSecretData={{canUpdateSecretData}} * @codemirrorString={{codemirrorString}} * @wrappedData={{wrappedData}} @@ -30,7 +29,6 @@ * @param {boolean} secretDataIsAdvanced - used to determine if show JSON toggle * @param {boolean} showAdvacnedMode - used for JSON toggle * @param {object} modelForData - a modified version of the model with secret data - * @param {string} navToNearestAncestor - route to nav to if press cancel * @param {boolean} canUpdateSecretData - permissions that show the create new version button or not. * @param {string} codemirrorString - used to copy the JSON * @param {object} wrappedData - when copy the data it's the token of the secret returned. diff --git a/ui/app/components/secret-edit.js b/ui/app/components/secret-edit.js index 064d23491231..a0a2f51d7e63 100644 --- a/ui/app/components/secret-edit.js +++ b/ui/app/components/secret-edit.js @@ -5,33 +5,27 @@ * * @example * ```js - * + * * ``` -/ +/This component is initialized from the secret-edit-layout.hbs file * @param {object} model - Model returned from secret-v2 which is generated in the secret-edit route * @param {string} mode - Edit, create, etc. - * @param {string} basekey - For navigation. - * @param {string} key - ARG TODO - * @param {string} initalKey - ARG TODO - * @param {function} onRefresh - ARG TODO - * @param {function} onToggleAdvancedEdit - ARG TODO + * @param {string} baseKey - Provided for navigation. + * @param {object} key - Passed through, copy of the model. + * @param {string} initialKey - model's name. + * @param {function} onRefresh - action that refreshes the model + * @param {function} onToggleAdvancedEdit - changes the preferAdvancedEdit to true or false * @param {boolean} preferAdvancedEdit - property set from the controller of show/edit/create route passed in through secret-edit-layout - This component is initialized from the secret-edit-layout.hbs file */ import { inject as service } from '@ember/service'; import Component from '@glimmer/component'; import { action } from '@ember/object'; import { tracked } from '@glimmer/tracking'; -// ARGTODO work on -// import FocusOnInsertMixin from 'vault/mixins/focus-on-insert'; -// import WithNavToNearestAncestor from 'vault/mixins/with-nav-to-nearest-ancestor'; import KVObject from 'vault/lib/kv-object'; import { maybeQueryRecord } from 'vault/macros/maybe-query-record'; import { alias, or } from '@ember/object/computed'; -// https://stackoverflow.com/questions/60843983/does-ember-octane-route-class-support-using-mixins export default class SecretEdit extends Component { - // export default Component.extend(FocusOnInsertMixin, WithNavToNearestAncestor, { @service wizard; @service store; @@ -127,7 +121,6 @@ export default class SecretEdit extends Component { get isWriteWithoutRead() { if (!this.args.model) { return false; - // ARG TODO was a return instead of null??? } // if the version couldn't be read from the server if (this.isV2 && this.modelForData.failedServerRead) { diff --git a/ui/app/templates/components/secret-edit-toolbar.hbs b/ui/app/templates/components/secret-edit-toolbar.hbs index d0b864079ee1..70a4d3a6a5d0 100644 --- a/ui/app/templates/components/secret-edit-toolbar.hbs +++ b/ui/app/templates/components/secret-edit-toolbar.hbs @@ -19,7 +19,6 @@ Date: Wed, 6 Apr 2022 15:55:01 -0600 Subject: [PATCH 10/11] add changelog --- changelog/14941.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelog/14941.txt diff --git a/changelog/14941.txt b/changelog/14941.txt new file mode 100644 index 000000000000..f82b63366854 --- /dev/null +++ b/changelog/14941.txt @@ -0,0 +1,3 @@ +```release-note:bug +ui: Fix issue with KV not recomputing model when you changed versions. +``` From 831fa45cfeefd188df342e48f93a6e3efc299dad Mon Sep 17 00:00:00 2001 From: Angel Garbarino Date: Wed, 6 Apr 2022 15:59:28 -0600 Subject: [PATCH 11/11] clean up --- ui/app/components/secret-edit.js | 1 + ui/app/templates/components/secret-edit.hbs | 1 + ui/tests/integration/components/secret-edit-test.js | 1 + 3 files changed, 3 insertions(+) diff --git a/ui/app/components/secret-edit.js b/ui/app/components/secret-edit.js index a0a2f51d7e63..9b413d74691e 100644 --- a/ui/app/components/secret-edit.js +++ b/ui/app/components/secret-edit.js @@ -25,6 +25,7 @@ import { tracked } from '@glimmer/tracking'; import KVObject from 'vault/lib/kv-object'; import { maybeQueryRecord } from 'vault/macros/maybe-query-record'; import { alias, or } from '@ember/object/computed'; + export default class SecretEdit extends Component { @service wizard; @service store; diff --git a/ui/app/templates/components/secret-edit.hbs b/ui/app/templates/components/secret-edit.hbs index 651138f55188..e55d46fb2eb4 100644 --- a/ui/app/templates/components/secret-edit.hbs +++ b/ui/app/templates/components/secret-edit.hbs @@ -40,6 +40,7 @@ {{/if}} +