chore: 🤖 use statically referenced credential form components (#3069)

* chore: 🤖 use statically referenced credential form components

* chore: 🤖 add entry for password credential form
This commit is contained in:
hashicc authored and GitHub committed 2025-11-25 13:32:58 -05:00
1 parent 30c2cab0b7
commit 183bde311c
2 files changed
+43 -9

No files matched your search

@@ -4,12 +4,11 @@
}}
{{#if @model.type}}
{{component
(concat 'form/credential/' @model.type)
model=@model
types=this.credentialTypes
submit=@submit
cancel=@cancel
changeType=@changeType
}}
<this.credentialFormComponent
@model={{@model}}
@types={{this.credentialTypes}}
@submit={{@submit}}
@cancel={{@cancel}}
@changeType={{@changeType}}
/>
{{/if}}
@@ -4,7 +4,29 @@
*/
import Component from '@glimmer/component';
import { TYPES_CREDENTIAL } from 'api/models/credential';
import { assert } from '@ember/debug';
import {
TYPES_CREDENTIAL,
TYPE_CREDENTIAL_USERNAME_PASSWORD,
TYPE_CREDENTIAL_SSH_PRIVATE_KEY,
TYPE_CREDENTIAL_JSON,
TYPE_CREDENTIAL_USERNAME_PASSWORD_DOMAIN,
TYPE_CREDENTIAL_PASSWORD,
} from 'api/models/credential';
import usernamePasswordFormComponent from './username_password';
import sshPrivateKeyFormComponent from './ssh_private_key';
import jsonFormComponent from './json';
import usernamePasswordDomainFormComponent from './username_password_domain';
import passwordFormComponent from './password';
const modelTypeToComponent = {
[TYPE_CREDENTIAL_USERNAME_PASSWORD]: usernamePasswordFormComponent,
[TYPE_CREDENTIAL_SSH_PRIVATE_KEY]: sshPrivateKeyFormComponent,
[TYPE_CREDENTIAL_JSON]: jsonFormComponent,
[TYPE_CREDENTIAL_USERNAME_PASSWORD_DOMAIN]:
usernamePasswordDomainFormComponent,
[TYPE_CREDENTIAL_PASSWORD]: passwordFormComponent,
};
export default class FormCredentialComponent extends Component {
// =attributes
@@ -16,4 +38,17 @@ export default class FormCredentialComponent extends Component {
get credentialTypes() {
return TYPES_CREDENTIAL;
}
/**
* Returns the form component for the credential model type
* @type {Component}
*/
get credentialFormComponent() {
const component = modelTypeToComponent[this.args.model.type];
assert(
`Mapped component must exist for credential type: ${this.args.model.type}`,
component,
);
return component;
}
}