Files
threshold-ui/ui/admin/app/components/form/host-set/add-hosts/index.js
T
Zhihe Li bcf004b8a4 Reformat codebase with trailing commas in functions (#2006)
* style: 💄 Update trailing commas in API

* style: 💄 Update trailing commas in core

* style: 💄 Update trailing commas in rose

* style: 💄 Update trailing commas in admin

* style: 💄 Update trailing commas in desktop
2023-11-22 14:07:41 -05:00

64 lines
1.3 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import Component from '@glimmer/component';
import { action, computed } from '@ember/object';
import { A } from '@ember/array';
export default class FormHostSetAddHostsIndexComponent extends Component {
// =properties
/**
* Array of selected host IDs.
* @type {EmberArray}
*/
selectedHostIDs = A();
/**
* Checks for unassigned hosts.
* @param {[HostModel]} filteredHosts
* @type {boolean}
*/
@computed('filteredHosts.length')
get hasAvailableHosts() {
return this.filteredHosts.length > 0;
}
/**
* Hosts currently not assigned to current host set.
* @type {[HostModel]}
*/
@computed('args.{model,model.host_ids,hosts}')
get filteredHosts() {
return this.args.hosts.filter(
({ id }) => !this.args.model.host_ids.includes(id),
);
}
// =actions
/**
* Toggle host selection
* @param {string} hostId
*/
@action
toggleHost(hostId) {
if (!this.selectedHostIDs.includes(hostId)) {
this.selectedHostIDs.addObject(hostId);
} else {
this.selectedHostIDs.removeObject(hostId);
}
}
/**
* Callback submit with selected host ids
* @param {requestCallback} fn
*/
@action
submit(fn) {
fn(this.selectedHostIDs);
}
}