44 */
55
66import Component from '@glimmer/component' ;
7- import { TYPES_CREDENTIAL } from 'api/models/credential' ;
7+ import { assert } from '@ember/debug' ;
8+ import {
9+ TYPES_CREDENTIAL ,
10+ TYPE_CREDENTIAL_USERNAME_PASSWORD ,
11+ TYPE_CREDENTIAL_SSH_PRIVATE_KEY ,
12+ TYPE_CREDENTIAL_JSON ,
13+ TYPE_CREDENTIAL_USERNAME_PASSWORD_DOMAIN ,
14+ TYPE_CREDENTIAL_PASSWORD ,
15+ } from 'api/models/credential' ;
16+ import usernamePasswordFormComponent from './username_password' ;
17+ import sshPrivateKeyFormComponent from './ssh_private_key' ;
18+ import jsonFormComponent from './json' ;
19+ import usernamePasswordDomainFormComponent from './username_password_domain' ;
20+ import passwordFormComponent from './password' ;
21+
22+ const modelTypeToComponent = {
23+ [ TYPE_CREDENTIAL_USERNAME_PASSWORD ] : usernamePasswordFormComponent ,
24+ [ TYPE_CREDENTIAL_SSH_PRIVATE_KEY ] : sshPrivateKeyFormComponent ,
25+ [ TYPE_CREDENTIAL_JSON ] : jsonFormComponent ,
26+ [ TYPE_CREDENTIAL_USERNAME_PASSWORD_DOMAIN ] :
27+ usernamePasswordDomainFormComponent ,
28+ [ TYPE_CREDENTIAL_PASSWORD ] : passwordFormComponent ,
29+ } ;
830
931export default class FormCredentialComponent extends Component {
1032 // =attributes
@@ -16,4 +38,17 @@ export default class FormCredentialComponent extends Component {
1638 get credentialTypes ( ) {
1739 return TYPES_CREDENTIAL ;
1840 }
41+
42+ /**
43+ * Returns the form component for the credential model type
44+ * @type {Component }
45+ */
46+ get credentialFormComponent ( ) {
47+ const component = modelTypeToComponent [ this . args . model . type ] ;
48+ assert (
49+ `Mapped component must exist for credential type: ${ this . args . model . type } ` ,
50+ component ,
51+ ) ;
52+ return component ;
53+ }
1954}
0 commit comments