mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-01 19:17:58 +00:00
add in secret metadata form for create
This commit is contained in:
@@ -8,7 +8,7 @@ import { task, waitForEvent } from 'ember-concurrency';
|
||||
import FocusOnInsertMixin from 'vault/mixins/focus-on-insert';
|
||||
import keys from 'vault/lib/keycodes';
|
||||
import KVObject from 'vault/lib/kv-object';
|
||||
import { queryRecord } from 'ember-computed-query';
|
||||
import { maybeQueryRecord } from 'vault/macros/maybe-query-record';
|
||||
|
||||
const LIST_ROUTE = 'vault.cluster.secrets.backend.list';
|
||||
const LIST_ROOT_ROUTE = 'vault.cluster.secrets.backend.list-root';
|
||||
@@ -87,11 +87,11 @@ export default Component.extend(FocusOnInsertMixin, {
|
||||
return `partials/secret-form-${this.mode}`;
|
||||
}),
|
||||
|
||||
updatePath: queryRecord(
|
||||
updatePath: maybeQueryRecord(
|
||||
'capabilities',
|
||||
context => {
|
||||
if (context.mode === 'create') {
|
||||
return {};
|
||||
return;
|
||||
}
|
||||
let backend = context.isV2 ? context.model.belongsTo('engine').id : context.model.backend;
|
||||
let id = context.model.id;
|
||||
@@ -108,11 +108,11 @@ export default Component.extend(FocusOnInsertMixin, {
|
||||
canDelete: alias('updatePath.canDelete'),
|
||||
canEdit: alias('updatePath.canUpdate'),
|
||||
|
||||
v2UpdatePath: queryRecord(
|
||||
v2UpdatePath: maybeQueryRecord(
|
||||
'capabilities',
|
||||
context => {
|
||||
if (context.mode === 'create' || context.isV2 === false) {
|
||||
return {};
|
||||
return;
|
||||
}
|
||||
let backend = context.model.belongsTo('engine').id;
|
||||
let id = context.model.id;
|
||||
@@ -125,7 +125,7 @@ export default Component.extend(FocusOnInsertMixin, {
|
||||
'model.id',
|
||||
'mode'
|
||||
),
|
||||
canEditV2Secret: alias('updatePath.canUpdate'),
|
||||
canEditV2Secret: alias('v2UpdatePath.canUpdate'),
|
||||
|
||||
requestInFlight: or('model.isLoading', 'model.isReloading', 'model.isSaving'),
|
||||
|
||||
@@ -237,6 +237,7 @@ export default Component.extend(FocusOnInsertMixin, {
|
||||
|
||||
createOrUpdateKey(type, event) {
|
||||
event.preventDefault();
|
||||
let model = this.modelForData;
|
||||
// prevent from submitting if there's no key
|
||||
// maybe do something fancier later
|
||||
if (type === 'create' && isBlank(model.get('path') || model.id)) {
|
||||
|
||||
17
ui/app/macros/maybe-query-record.js
Normal file
17
ui/app/macros/maybe-query-record.js
Normal file
@@ -0,0 +1,17 @@
|
||||
import { computed } from '@ember/object';
|
||||
import ObjectProxy from '@ember/object/proxy';
|
||||
import PromiseProxyMixin from '@ember/object/promise-proxy-mixin';
|
||||
import { resolve } from 'rsvp';
|
||||
|
||||
export function maybeQueryRecord(modelName, options = {}, ...keys) {
|
||||
return computed(...keys, {
|
||||
get() {
|
||||
const query = typeof options === 'function' ? options(this) : options;
|
||||
const PromiseObject = ObjectProxy.extend(PromiseProxyMixin);
|
||||
|
||||
return PromiseObject.create({
|
||||
promise: query ? this.get('store').queryRecord(modelName, query) : resolve({}),
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import Secret from './secret';
|
||||
import DS from 'ember-data';
|
||||
import { alias, bool } from '@ember/object/computed';
|
||||
import { bool } from '@ember/object/computed';
|
||||
|
||||
const { attr, belongsTo } = DS;
|
||||
|
||||
|
||||
@@ -140,8 +140,11 @@ export default Route.extend(UnloadModelRoute, {
|
||||
willTransition(transition) {
|
||||
let model = this.controller.model;
|
||||
let version = model.get('selectedVersion');
|
||||
debugger; //eslint-disable-line
|
||||
// if (model.isNew || (version && version.isNew)) {
|
||||
// return this._super(...arguments);
|
||||
// }
|
||||
if (model.hasDirtyAttributes || (version && version.hasDirtyAttributes)) {
|
||||
console.log(model.changedAttributes(), version.changedAttributes());
|
||||
if (
|
||||
window.confirm(
|
||||
'You have unsaved changes. Navigating away will discard these changes. Are you sure you want to discard your changes?'
|
||||
|
||||
@@ -1,3 +1,14 @@
|
||||
{{#if (and (or @model.isNew @canEditV2Secret) @isV2)}}
|
||||
<div class="form-section box is-shadowless is-fullwidth">
|
||||
<label class="title is-5">
|
||||
Secret Metadata
|
||||
</label>
|
||||
{{#each @model.fields as |attr|}}
|
||||
<FormField data-test-field @attr={{attr}} @model={{this.model}} />
|
||||
{{/each}}
|
||||
</div>
|
||||
{{/if}}
|
||||
|
||||
{{#if @showAdvancedMode}}
|
||||
<JsonEditor
|
||||
@value={{@codemirrorString}}
|
||||
|
||||
@@ -16,6 +16,9 @@
|
||||
@showAdvancedMode={{showAdvancedMode}}
|
||||
@codemirrorString={{codemirrorString}}
|
||||
@secretData={{secretData}}
|
||||
@isV2={{isV2}}
|
||||
@model={{model}}
|
||||
@canEditV2Secret={{canEditV2Secret}}
|
||||
@editActions={{hash
|
||||
codemirrorUpdated=(action "codemirrorUpdated")
|
||||
formatJSON=(action "formatJSON")
|
||||
|
||||
@@ -2,21 +2,13 @@
|
||||
<div class="box is-sideless is-fullwidth is-marginless is-paddingless">
|
||||
<MessageError @model={{model}} @errorMessage={{error}} />
|
||||
<NamespaceReminder @mode="edit" @noun="secret" />
|
||||
{{#if (and this.canEditV2Secret this.isV2)}}
|
||||
<div class="form-section box is-shadowless is-fullwidth">
|
||||
<label class="title is-5">
|
||||
Secret Metadata
|
||||
</label>
|
||||
{{#each this.model.fields as |attr|}}
|
||||
<FormField data-test-field @attr={{attr}} @model={{this.model}} />
|
||||
{{/each}}
|
||||
</div>
|
||||
{{/if}}
|
||||
<SecretEditDisplay
|
||||
@showAdvancedMode={{showAdvancedMode}}
|
||||
@codemirrorString={{codemirrorString}}
|
||||
@secretData={{secretData}}
|
||||
@isV2={{isV2}}
|
||||
@canEditV2Secret={{canEditV2Secret}}
|
||||
@model={{model}}
|
||||
@editActions={{hash
|
||||
codemirrorUpdated=(action "codemirrorUpdated")
|
||||
formatJSON=(action "formatJSON")
|
||||
|
||||
Reference in New Issue
Block a user