Files
threshold-ui/ui/admin/app/components/form/target/add-host-sets/index.js
T
Zhihe Li 999c21c66a Upgrade eslint (#3175)
* chore: 🤖 Upgrade eslint config for admin ui

* chore: 🤖 Fix eslint issues for admin

* chore: 🤖 Upgrade eslint config for desktop

* chore: 🤖 Fix linting errors in desktop

* chore: 🤖 Upgrade eslint for api addon

* chore: 🤖 Fix eslint issues in api addon

* chore: 🤖 Upgrade eslint for auth addon

* chore: 🤖 Fix eslint issues in auth addon

* chore: 🤖 Upgrade core eslint config

* chore: 🤖 Fix eslint issue for core addon

* chore: 🤖 Upgrade eslint config for rose addon

* chore: 🤖 Fix eslint issue for rose addon

* chore: 🤖 Upgrade e2e eslint config

* chore: 🤖 Fix eslint issues in e2e

* chore: 🤖 Fix CI linting issues

* chore: 🤖 Add back linting server files for the future

* chore: 🤖 Update qunit rules to use extends
2026-02-27 13:32:27 -05:00

96 lines
2.3 KiB
JavaScript

/**
* Copyright IBM Corp. 2021, 2026
* SPDX-License-Identifier: BUSL-1.1
*/
import Component from '@glimmer/component';
import { action } from '@ember/object';
import { A } from '@ember/array';
import { service } from '@ember/service';
import { loading } from 'ember-loading';
import { notifyError } from 'core/decorators/notify';
export default class FormTargetAddHostSetsComponent extends Component {
// =services
@service confirm;
@service intl;
// =properties
/**
* Array of selected host set IDs.
* @type {EmberArray}
*/
selectedHostSetIDs = A();
/**
* Checks for unassigned host-sets.
* @param {[HostSetModel]} filteredHostSets
* @type {boolean}
*/
get hasAvailableHostSets() {
return this.filteredHostSets.length > 0;
}
/**
* Host sets not already added to the target.
* @type {[HostSetModel]}
*/
get filteredHostSets() {
// Get IDs for host sets already added to the current target
const alreadyAddedHostSetIDs = this.args.model.host_sources.map(
({ host_source_id }) => host_source_id,
);
const notAddedHostSets = this.args.hostSets.filter(
({ id }) => !alreadyAddedHostSetIDs.includes(id),
);
return notAddedHostSets;
}
// =actions
/**
* Add/Remove host set to current selection
* @param {string} hostSetId
*/
@action
toggleHostSet(hostSetId) {
if (!this.selectedHostSetIDs.includes(hostSetId)) {
this.selectedHostSetIDs.addObject(hostSetId);
} else {
this.selectedHostSetIDs.removeObject(hostSetId);
}
}
@action
@loading
@notifyError(({ message }) => message)
async submit() {
const target = this.args.model;
if (target.address && this.selectedHostSetIDs.length) {
try {
await this.confirm.confirm(
this.intl.t(
'resources.target.host-source.questions.delete-address.message',
),
{
title:
'resources.target.host-source.questions.delete-address.title',
confirm: 'resources.target.actions.remove-address',
},
);
} catch {
// if the user denies, do nothing and return
return;
}
target.address = null;
await target.save();
}
await this.args.submit(this.selectedHostSetIDs);
}
}