Skip to content

Commit 183bde3

Browse files
authored
chore: πŸ€– use statically referenced credential form components (#3069)
* chore: πŸ€– use statically referenced credential form components * chore: πŸ€– add entry for password credential form
1 parent 30c2cab commit 183bde3

File tree

2 files changed

+43
-9
lines changed

2 files changed

+43
-9
lines changed

β€Žui/admin/app/components/form/credential/index.hbsβ€Ž

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
}}
55

66
{{#if @model.type}}
7-
{{component
8-
(concat 'form/credential/' @model.type)
9-
model=@model
10-
types=this.credentialTypes
11-
submit=@submit
12-
cancel=@cancel
13-
changeType=@changeType
14-
}}
7+
<this.credentialFormComponent
8+
@model={{@model}}
9+
@types={{this.credentialTypes}}
10+
@submit={{@submit}}
11+
@cancel={{@cancel}}
12+
@changeType={{@changeType}}
13+
/>
1514
{{/if}}

β€Žui/admin/app/components/form/credential/index.jsβ€Ž

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,29 @@
44
*/
55

66
import 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

931
export 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

Comments
Β (0)