Files
threshold-ui/ui/admin/app/components/form/user/add-accounts/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.5 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import Component from '@glimmer/component';
import { action } from '@ember/object';
import { A } from '@ember/array';
import { inject as service } from '@ember/service';
export default class FormUserAddAccountsComponent extends Component {
// =properties
@service can;
/**
* Array of selected account IDs.
* @type {EmberArray}
*/
selectedAccountIDs = A();
/**
* Checks for unassigned accounts.
* @param {[AccountModel]} filteredAccounts
* @type {boolean}
*/
get hasAvailableAccounts() {
return this.filteredAccounts.length > 0;
}
/**
* Accounts not already added to the user.
* @type {[AccountModel]}
*/
get filteredAccounts() {
// Get IDs for accounts already added to the current user
const alreadyAddedAccountIDs = this.args.model.account_ids;
const notAddedAccounts = this.args.accounts.filter(
(account) =>
!alreadyAddedAccountIDs.includes(account.id) &&
this.can.can('addAccount user', this.args.model, { account }),
);
return notAddedAccounts;
}
// =actions
/**
* Toggle account selection
* @param {string} accountId
*/
@action
toggleAccount(accountId) {
if (!this.selectedAccountIDs.includes(accountId)) {
this.selectedAccountIDs.addObject(accountId);
} else {
this.selectedAccountIDs.removeObject(accountId);
}
}
@action
submit(fn) {
fn(this.selectedAccountIDs);
}
}