@fleetbase/iam-engine
Version:
Fleetbase IAM extension provides identity and access management module for managing users, permissions and policies.
42 lines (34 loc) • 1.05 kB
JavaScript
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
import { isArray } from '@ember/array';
const toArray = function (value = []) {
if (value && typeof value.toArray === 'function') {
return value.toArray();
}
if (isArray(value)) {
return value;
}
return [];
};
export default class PolicyAttacherComponent extends Component {
selected = [];
lastSelected = null;
constructor(owner, { value }) {
super(...arguments);
this.selected = toArray(value);
}
selectPolicy(policy) {
this.lastSelected = null;
this.selected.pushObject(policy);
if (typeof this.args.onChange === 'function') {
this.args.onChange(this.selected);
}
}
removePolicy(policy) {
this.selected.removeObject(policy);
if (typeof this.args.onChange === 'function') {
this.args.onChange(this.selected);
}
}
}