Files
threshold-ui/ui/admin/app/components/form/role/grants/index.js
T
Lauren dd8e1864db [Replace] Rose::Form::Label and <input.field> elements (#2783)
* replace with hds::form::label

* test Hds::Form::TextInput::Field

* add event handler

* add hds text componenet to grant.value fields

* fix test failures

* replace with set-from-event

* address feedback

* add title html element to hds component
2025-05-02 11:12:30 -04:00

62 lines
1.4 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
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 = '';
/**
* Returns grants currently on model, in addition to
* grants added (or deleted) interactively by user -
* before form submission
* @return {[string]}
*/
@computed('args.model.grant_strings.[]')
get grants() {
return this.args.model.grant_strings.map((value) => ({ value }));
}
/**
* Returns grants after form submission
* @return {[object]}
*/
@computed('grants.@each.value')
get grantStrings() {
return this.grants.map((obj) => obj.value);
}
/**
* 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 = '';
}
}