Skip to content

Commit 0bd152e

Browse files
authored
Migrate away from component helper in credential library form component (#3013)
* refactor: 💡 migrate away from component helper for cred library form * Add missing copyright headers
1 parent 928ca54 commit 0bd152e

File tree

2 files changed

+40
-8
lines changed

2 files changed

+40
-8
lines changed

ui/admin/app/components/form/credential-library/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-library/' @model.type)
9-
model=@model
10-
submit=@submit
11-
cancel=@cancel
12-
changeType=@changeType
13-
edit=@edit
14-
}}
7+
<this.credentialLibraryFormComponent
8+
@model={{@model}}
9+
@submit={{@submit}}
10+
@cancel={{@cancel}}
11+
@changeType={{@changeType}}
12+
@edit={{@edit}}
13+
/>
1514
{{/if}}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* Copyright (c) HashiCorp, Inc.
3+
* SPDX-License-Identifier: BUSL-1.1
4+
*/
5+
6+
import Component from '@glimmer/component';
7+
import { assert } from '@ember/debug';
8+
import {
9+
TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC,
10+
TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE,
11+
TYPE_CREDENTIAL_LIBRARY_VAULT_LDAP,
12+
} from 'api/models/credential-library';
13+
import VaultGenericFormComponent from './vault-generic';
14+
import VaultSshCertificateFormComponent from './vault-ssh-certificate';
15+
import VaultLdapFormComponent from './vault-ldap';
16+
17+
const modelTypeToComponent = {
18+
[TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC]: VaultGenericFormComponent,
19+
[TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE]:
20+
VaultSshCertificateFormComponent,
21+
[TYPE_CREDENTIAL_LIBRARY_VAULT_LDAP]: VaultLdapFormComponent,
22+
};
23+
24+
export default class FormCredentialLibraryIndex extends Component {
25+
get credentialLibraryFormComponent() {
26+
const component = modelTypeToComponent[this.args.model.type];
27+
assert(
28+
`Mapped component must exist for credential library type: ${this.args.model.type}`,
29+
component,
30+
);
31+
return component;
32+
}
33+
}

0 commit comments

Comments
 (0)