Skip to content

Commit

Permalink
unset model on controller after unloading it because controllers are …
Browse files Browse the repository at this point in the history
…singletons
  • Loading branch information
meirish committed Jun 20, 2019
1 parent 4dbfa60 commit 86d9050
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 45 deletions.
5 changes: 2 additions & 3 deletions ui/app/components/role-edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ export default Component.extend(FocusOnInsertMixin, {

willDestroyElement() {
this._super(...arguments);
const model = this.get('model');
if (get(model, 'isError')) {
model.rollbackAttributes();
if (this.model && this.model.isError) {
this.model.rollbackAttributes();
}
},

Expand Down
9 changes: 6 additions & 3 deletions ui/app/components/secret-edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export default Component.extend(FocusOnInsertMixin, WithNavToNearestAncestor, {
updatePath: maybeQueryRecord(
'capabilities',
context => {
if (context.mode === 'create') {
if (!context.model || context.mode === 'create') {
return;
}
let backend = context.isV2 ? context.get('model.engine.id') : context.model.backend;
Expand All @@ -116,7 +116,7 @@ export default Component.extend(FocusOnInsertMixin, WithNavToNearestAncestor, {
v2UpdatePath: maybeQueryRecord(
'capabilities',
context => {
if (context.mode === 'create' || context.isV2 === false) {
if (!context.model || context.mode === 'create' || context.isV2 === false) {
return;
}
let backend = context.get('model.engine.id');
Expand All @@ -137,7 +137,9 @@ export default Component.extend(FocusOnInsertMixin, WithNavToNearestAncestor, {
buttonDisabled: or('requestInFlight', 'model.isFolder', 'model.flagsIsInvalid', 'hasLintError', 'error'),

modelForData: computed('isV2', 'model', function() {
return this.isV2 ? this.model.belongsTo('selectedVersion').value() : this.model;
let { model } = this;
if (!model) return null;
return this.isV2 ? model.belongsTo('selectedVersion').value() : model;
}),

basicModeDisabled: computed('secretDataIsAdvanced', 'showAdvancedMode', function() {
Expand All @@ -160,6 +162,7 @@ export default Component.extend(FocusOnInsertMixin, WithNavToNearestAncestor, {
'model.{failedServerRead,selectedVersion.failedServerRead}',
'isV2',
function() {
if (!this.model) return;
// if the version couldn't be read from the server
if (this.isV2 && this.model.selectedVersion.failedServerRead) {
return true;
Expand Down
5 changes: 2 additions & 3 deletions ui/app/components/transit-edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ export default Component.extend(FocusOnInsertMixin, {

willDestroyElement() {
this._super(...arguments);
const key = this.get('key');
if (get(key, 'isError')) {
key.rollbackAttributes();
if (this.key && this.key.isError) {
this.key.rollbackAttributes();
}
},

Expand Down
5 changes: 4 additions & 1 deletion ui/app/mixins/unload-model-route.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ import Mixin from '@ember/object/mixin';
export default Mixin.create({
modelPath: 'model',
unloadModel() {
const model = this.controller.get(this.get('modelPath'));
let { modelPath } = this;
let model = this.controller.get(modelPath);
if (!model || !model.unloadRecord) {
return;
}
this.store.unloadRecord(model);
model.destroy();
// it's important to unset the model on the controller since controllers are singletons
this.controller.set(modelPath, null);
},

actions: {
Expand Down
42 changes: 22 additions & 20 deletions ui/app/templates/partials/role-ssh/form.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,29 @@
<div class="box is-sideless is-fullwidth is-marginless">
{{message-error model=model}}
<NamespaceReminder @mode={{mode}} @noun="SSH role" />
{{#with (if (eq model.keyType 'otp') 3 4) as |numRequired|}}
{{#each (take numRequired model.attrsForKeyType) as |attr|}}
{{#unless (and (eq mode 'edit') (eq attr.name 'name'))}}
{{partial "partials/form-field-from-model"}}
{{/unless}}
{{/each}}
{{toggle-button
toggleAttr="showOptions"
toggleTarget=this
openLabel="Hide options"
closedLabel="More options"
data-test-toggle-more="true"
}}
{{#if showOptions}}
<div class="box is-marginless">
{{#each (drop numRequired model.attrsForKeyType) as |attr|}}
{{#if model.attrsForKeyType}}
{{#with (if (eq model.keyType 'otp') 3 4) as |numRequired|}}
{{#each (take numRequired model.attrsForKeyType) as |attr|}}
{{#unless (and (eq mode 'edit') (eq attr.name 'name'))}}
{{partial "partials/form-field-from-model"}}
{{/each}}
</div>
{{/if}}
{{/with}}
{{/unless}}
{{/each}}
{{toggle-button
toggleAttr="showOptions"
toggleTarget=this
openLabel="Hide options"
closedLabel="More options"
data-test-toggle-more="true"
}}
{{#if showOptions}}
<div class="box is-marginless">
{{#each (drop numRequired model.attrsForKeyType) as |attr|}}
{{partial "partials/form-field-from-model"}}
{{/each}}
</div>
{{/if}}
{{/with}}
{{/if}}
</div>
<div class="field is-grouped-split box is-fullwidth is-bottomless">
<div class="control">
Expand Down
32 changes: 17 additions & 15 deletions ui/app/templates/vault/cluster/secrets/backend/sign.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,23 @@
<div class="box is-sideless is-fullwidth is-marginless">
{{message-error model=model}}
<NamespaceReminder @mode="sign" @noun="SSH key" />
{{#each (take 1 model.attrs) as |attr|}}
{{partial "partials/form-field-from-model"}}
{{/each}}
{{toggle-button
toggleAttr="showOptions"
toggleTarget=this
openLabel="Hide options"
closedLabel="More options"
}}
{{#if showOptions}}
<div class="box is-marginless">
{{#each (drop 1 model.attrs) as |attr|}}
{{partial "partials/form-field-from-model"}}
{{/each}}
</div>
{{#if model.attrs}}
{{#each (take 1 model.attrs) as |attr|}}
{{partial "partials/form-field-from-model"}}
{{/each}}
{{toggle-button
toggleAttr="showOptions"
toggleTarget=this
openLabel="Hide options"
closedLabel="More options"
}}
{{#if showOptions}}
<div class="box is-marginless">
{{#each (drop 1 model.attrs) as |attr|}}
{{partial "partials/form-field-from-model"}}
{{/each}}
</div>
{{/if}}
{{/if}}
</div>
<div class="field is-grouped box is-fullwidth is-bottomless">
Expand Down

0 comments on commit 86d9050

Please sign in to comment.