feat: 🎸 finish up grants UI

This commit is contained in:
Randall Morey committed 2020-08-10 16:40:03 -04:00
1 parent f539224afe
commit 674882d7bd
6 files changed
+123 -1

No files matched your search

@@ -1,3 +1,39 @@
<Rose::Form
@onSubmit={{fn this.createGrant @addGrant}}
@cancel={{@cancel}}
@disabled={{@model.isSaving}}
as |form|
>
<Rose::List::KeyValue as |list|>
{{!-- Add grant field (only one per form) --}}
<list.item as |item|>
<form.input
@contextual={{true}}
@name="grant"
@type="text"
@value={{this.newGrantString}}
as |input|>
<item.key>
<input.label>{{t "titles.new-grant"}}</input.label>
</item.key>
<item.cell>
<input.field />
</item.cell>
<item.cell>
<Rose::Button
@submit={{true}}
@disabled={{this.cannotSave}}
@style="secondary"
title={{t "actions.add"}}
>
{{t "actions.add"}}
</Rose::Button>
</item.cell>
</form.input>
</list.item>
</Rose::List::KeyValue>
</Rose::Form>
<Rose::Form
@onSubmit={{@submit}}
@cancel={{@cancel}}
@@ -33,6 +69,16 @@
<input.field />
</item.cell>
</form.input>
<item.cell>
<Rose::Button
@style="secondary"
@iconOnly="trash"
title={{t "actions.remove"}}
{{on "click" (fn @removeGrant grant)}}
>
{{t "actions.remove"}}
</Rose::Button>
</item.cell>
</list.item>
{{/each}}
</Rose::List::KeyValue>
@@ -0,0 +1,37 @@
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { computed, action } from '@ember/object';
export default class FormRoleGrantsComponent extends Component {
// =attributes
/**
* @type {string}
*/
@tracked newGrantString = '';
/**
* True if the grant string field is empty, false otherwise. This is used
* to disable the submit button.
* @return {boolean}
*/
@computed('newGrantString')
get cannotSave() {
return !this.newGrantString;
}
// =actions
/**
* Calls the passed function with the grant string as an argument and then
* clears the value of the grant string field.
* `@addGrant` should be passed by the context calling this component.
* @param {Function} addGrantFn
*/
@action
createGrant(addGrantFn) {
addGrantFn(this.newGrantString);
this.newGrantString = '';
}
}