Skip to content

Commit 2accf06

Browse files
committed
chore: 🤖 use statically referenced components for host catalog
1 parent 2bf0901 commit 2accf06

File tree

2 files changed

+40
-12
lines changed

2 files changed

+40
-12
lines changed

‎ui/admin/app/components/form/host-catalog/index.hbs‎

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
SPDX-License-Identifier: BUSL-1.1
44
}}
55

6-
{{component
7-
(concat 'form/host-catalog/' @model.compositeType)
8-
model=@model
9-
submit=@submit
10-
cancel=@cancel
11-
changeType=@changeType
12-
changeCredentialType=@changeCredentialType
13-
mapResourceTypeWithIcon=this.mapResourceTypeWithIcon
14-
hostCatalogTypes=this.hostCatalogTypes
15-
toggleDisableCredentialRotation=this.toggleDisableCredentialRotation
16-
}}
6+
<this.hostCatalogFormComponent
7+
@model={{@model}}
8+
@submit={{@submit}}
9+
@cancel={{@cancel}}
10+
@changeType={{@changeType}}
11+
@changeCredentialType={{@changeCredentialType}}
12+
@mapResourceTypeWithIcon={{this.mapResourceTypeWithIcon}}
13+
@hostCatalogTypes={{this.hostCatalogTypes}}
14+
@toggleDisableCredentialRotation={{this.toggleDisableCredentialRotation}}
15+
/>

‎ui/admin/app/components/form/host-catalog/index.js‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,26 @@
55

66
import Component from '@glimmer/component';
77
import { action } from '@ember/object';
8-
8+
import { assert } from '@ember/debug';
99
import {
1010
TYPES_HOST_CATALOG,
1111
TYPES_HOST_CATALOG_PLUGIN,
12+
TYPE_HOST_CATALOG_PLUGIN_AWS,
13+
TYPE_HOST_CATALOG_PLUGIN_AZURE,
14+
TYPE_HOST_CATALOG_PLUGIN_GCP,
15+
TYPE_HOST_CATALOG_STATIC,
1216
} from 'api/models/host-catalog';
17+
import awsHostCatalogFormComponent from './aws';
18+
import azureHostCatalogFormComponent from './azure';
19+
import gcpHostCatalogFormComponent from './gcp';
20+
import staticHostCatalogFormComponent from './static';
21+
22+
const modelCompositeTypeToComponent = {
23+
[TYPE_HOST_CATALOG_PLUGIN_AWS]: awsHostCatalogFormComponent,
24+
[TYPE_HOST_CATALOG_PLUGIN_AZURE]: azureHostCatalogFormComponent,
25+
[TYPE_HOST_CATALOG_PLUGIN_GCP]: gcpHostCatalogFormComponent,
26+
[TYPE_HOST_CATALOG_STATIC]: staticHostCatalogFormComponent,
27+
};
1328

1429
const icons = ['aws-color', 'azure-color', 'gcp-color'];
1530

@@ -27,6 +42,20 @@ export default class FormHostCatalogIndexComponent extends Component {
2742
);
2843
}
2944

45+
/**
46+
* Returns the host catalog form component associated with the model's composite type
47+
* @type {Component}
48+
*/
49+
get hostCatalogFormComponent() {
50+
const component =
51+
modelCompositeTypeToComponent[this.args.model.compositeType];
52+
assert(
53+
`Mapped component must exist for host catalog composite type: ${this.args.model.compositeType}`,
54+
component,
55+
);
56+
return component;
57+
}
58+
3059
// =actions
3160

3261
@action

0 commit comments

Comments
 (0)