Icu 5253 add query to include credentials (#1227)

* refactor: 💡 add-credential-sources to include credentials

* refactor: 💡 update add-credential-sources template

Update to how AddCredentialSources form is rendered in the template

✅ Closes: ICU-5253

* refactor: 💡 Update add-credential-sources method signatures

* refactor: 💡 change how add-credential-source form is rendered

* refactor: 💡 Remove duplicate add-credential-sources message

Remove the duplicate No Credential Credential Sources message from
add-credential-sources form

* refactor: 💡 Move filter logic to controller

Move credential source filter logic from route to controller for
add-credential-sources

* test: 💍 Verify all available credential sources are listed
This commit is contained in:
Cameron Perera authored and GitHub committed 2022-08-02 11:55:26 -05:00
1 parent c8a76078ec
commit 9f09f01f36
9 files changed
+199 -143

No files matched your search

@@ -1,63 +0,0 @@
{{#if this.hasAvailableCredentialLibraries}}
<Rose::Form
class='full-width'
@onSubmit={{fn this.submit @submit}}
@cancel={{@cancel}}
@disabled={{@model.isSaving}}
@error={{@model.errors.base}}
as |form|
>
<form.actions
@submitText={{t 'resources.target.actions.add-credential-sources'}}
@cancelText={{t 'actions.cancel'}}
/>
<Rose::Table as |table|>
<table.header as |header|>
<header.row as |row|>
<row.headerCell>{{t 'form.id.label'}}</row.headerCell>
<row.headerCell>{{t 'form.name.label'}}</row.headerCell>
<row.headerCell>{{t 'form.type.label'}}</row.headerCell>
</header.row>
</table.header>
<table.body as |body|>
{{#each this.filteredCredentialLibraries as |credentialLibrary|}}
<body.row as |row|>
<row.headerCell>
<form.checkbox
@label={{credentialLibrary.id}}
@description={{credentialLibrary.description}}
@onChange={{fn this.toggleCredentialLibrary credentialLibrary}}
/>
</row.headerCell>
<row.cell>{{credentialLibrary.name}}</row.cell>
<row.cell>
<Rose::Badge>{{t
(concat
'resources.credential-library.types.' credentialLibrary.type
)
}}</Rose::Badge>
</row.cell>
</body.row>
{{/each}}
</table.body>
</Rose::Table>
</Rose::Form>
{{/if}}
{{#unless this.hasAvailableCredentialLibraries}}
<Rose::Layout::Centered>
<Rose::Message
@title={{t 'resources.target.credential-source.messages.none.title'}}
as |message|
>
<message.description>
{{t 'resources.target.credential-source.messages.none.description'}}
</message.description>
<message.link @route='scopes.scope.targets.target.credential-sources'>
<Rose::Icon @name='flight-icons/svg/chevron-left-16' />
{{t 'actions.back'}}
</message.link>
</Rose::Message>
</Rose::Layout::Centered>
{{/unless}}
@@ -1,65 +0,0 @@
import Component from '@glimmer/component';
import { computed, action } from '@ember/object';
import { A } from '@ember/array';
export default class FormTargetAddCredentialLibrariesIndexComponent extends Component {
// =properties
/**
* Array of selected credential library IDs.
* @type {EmberArray}
*/
selectedCredentialLibraryIDs = A();
/**
* Checks for unassigned credential libraries.
* @param {[CredentialLibraryModel]} filteredCredentialLibraries
* @type {boolean}
*/
@computed('filteredCredentialLibraries.length')
get hasAvailableCredentialLibraries() {
return this.filteredCredentialLibraries.length > 0;
}
/**
* Filter out credential libraries not already added to the target.
* @type {[CredentialLibraryModel]}
*/
@computed(
'args.{credentialLibraries.[],model.application_credential_source_ids.[]}'
)
get filteredCredentialLibraries() {
// Get IDs for credential libraries already added to the current target
const currentCredentialLibraryIDs =
this.args.model.application_credential_source_ids.map(
(source) => source.value
);
const notAddedCredentialLibraries = this.args.credentialLibraries.filter(
({ id }) => !currentCredentialLibraryIDs.includes(id)
);
return notAddedCredentialLibraries;
}
// =actions
/**
* Add/Remove credential library to current selection
* @param CredentialLibraryModel
*/
@action
toggleCredentialLibrary(credentialLibrary) {
if (!this.selectedCredentialLibraryIDs.includes(credentialLibrary.id)) {
this.selectedCredentialLibraryIDs.addObject(credentialLibrary.id);
} else {
this.selectedCredentialLibraryIDs.removeObject(credentialLibrary.id);
}
}
/**
* Submit selected credential library ids
*/
@action
submit(fn) {
fn(this.selectedCredentialLibraryIDs);
}
}
@@ -0,0 +1,45 @@
<Rose::Form
class='full-width'
@onSubmit={{fn this.submit @submit}}
@cancel={{@cancel}}
@disabled={{@model.isSaving}}
@error={{@model.errors.base}}
as |form|
>
<form.actions
@submitText={{t 'resources.target.actions.add-credential-sources'}}
@cancelText={{t 'actions.cancel'}}
/>
<Rose::Table as |table|>
<table.header as |header|>
<header.row as |row|>
<row.headerCell>{{t 'form.id.label'}}</row.headerCell>
<row.headerCell>{{t 'form.name.label'}}</row.headerCell>
<row.headerCell>{{t 'form.type.label'}}</row.headerCell>
</header.row>
</table.header>
<table.body as |body|>
{{#each @filteredCredentialSources as |credentialSource|}}
<body.row as |row|>
<row.headerCell>
<form.checkbox
@label={{credentialSource.id}}
@description={{credentialSource.description}}
@onChange={{fn this.toggleCredentialSource credentialSource}}
/>
</row.headerCell>
<row.cell>{{credentialSource.name}}</row.cell>
<row.cell>
<Rose::Badge>{{t
(concat
'resources.target.credential-source.types.'
credentialSource.type
)
}}</Rose::Badge>
</row.cell>
</body.row>
{{/each}}
</table.body>
</Rose::Table>
</Rose::Form>
@@ -0,0 +1,36 @@
import Component from '@glimmer/component';
import { action } from '@ember/object';
import { A } from '@ember/array';
export default class FormTargetAddCredentialSourcesIndexComponent extends Component {
// =properties
/**
* Array of selected credential source IDs.
* @type {EmberArray}
*/
selectedCredentialSourceIDs = A();
// =actions
/**
* Add/Remove credential source to current selection
* @param {CredentialLibraryModel, CredentialModel} credentialSource
*/
@action
toggleCredentialSource(credentialSource) {
if (!this.selectedCredentialSourceIDs.includes(credentialSource.id)) {
this.selectedCredentialSourceIDs.addObject(credentialSource.id);
} else {
this.selectedCredentialSourceIDs.removeObject(credentialSource.id);
}
}
/**
* Submit selected credential source ids
*/
@action
submit(fn) {
fn(this.selectedCredentialSourceIDs);
}
}