Files
threshold-ui/ui/admin/app/controllers/scopes/scope/targets/target/add-injected-application-credential-sources.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

41 lines
1.2 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import Controller from '@ember/controller';
export default class ScopesScopeTargetsTargetAddInjectedApplicationCredentialSourcesController extends Controller {
// =services
// =attributes
/**
* Checks for unassigned credential sources.
* @type {boolean}
*/
get hasAvailableInjectedApplicationCredentialSources() {
return this.filteredCredentialSources.length > 0;
}
/**
* Filter out credential sources not already added to the target.
* @type {[CredentialLibraryModel, CredentialModel]}
*/
get filteredCredentialSources() {
// Get IDs for credential sources already added to the current target
const currentCredentialSourceIDs = new Set(
this.model.target.injected_application_credential_source_ids.map(
(source) => source.value,
),
);
const notAddedCredentialLibraries = this.model.credentialLibraries.filter(
({ id }) => !currentCredentialSourceIDs.has(id),
);
const notAddedCredentials = this.model.credentials.filter(
({ id, type }) => !currentCredentialSourceIDs.has(id) && type !== 'json',
);
return [...notAddedCredentialLibraries, ...notAddedCredentials];
}
}