Skip to content

Commit 73db064

Browse files
committed
chore: 🤖 use statically referenced components for host form
1 parent 2bf0901 commit 73db064

File tree

2 files changed

+47
-15
lines changed

2 files changed

+47
-15
lines changed

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

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,17 @@
44
}}
55

66
{{#if @model.compositeType}}
7-
{{component
8-
(concat 'form/host/' @model.compositeType)
9-
model=@model
10-
submit=@submit
11-
cancel=@cancel
12-
}}
7+
<this.hostFormComponent
8+
@model={{@model}}
9+
@submit={{@submit}}
10+
@cancel={{@cancel}}
11+
/>
1312
{{else}}
14-
{{! create-and-add-host cancel route doesn't
15-
have a model and this else part is required to prevent
16-
erroring out here. This has been noted in the tech debt doc to further investigate }}
17-
{{component
18-
(concat 'form/host/' 'static')
19-
model=@model
20-
submit=@submit
21-
cancel=@cancel
22-
}}
13+
{{! create-and-add-host cancel route doesn't have a model and this else part is required
14+
to prevent erroring out here. This has been noted in the tech debt doc to further investigate }}
15+
<Form::Host::Static
16+
@model={{@model}}
17+
@submit={{@submit}}
18+
@cancel={{@cancel}}
19+
/>
2320
{{/if}}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import Component from '@glimmer/component';
2+
import { assert } from '@ember/debug';
3+
import {
4+
TYPE_HOST_CATALOG_PLUGIN_AWS,
5+
TYPE_HOST_CATALOG_PLUGIN_AZURE,
6+
TYPE_HOST_CATALOG_PLUGIN_GCP,
7+
TYPE_HOST_CATALOG_STATIC,
8+
} from 'api/models/host-catalog';
9+
import awsHostFormComponent from './aws';
10+
import azureHostFormComponent from './azure';
11+
import gcpHostFormComponent from './gcp';
12+
import staticHostFormComponent from './static';
13+
14+
const modelCompositeTypeToComponent = {
15+
[TYPE_HOST_CATALOG_PLUGIN_AWS]: awsHostFormComponent,
16+
[TYPE_HOST_CATALOG_PLUGIN_AZURE]: azureHostFormComponent,
17+
[TYPE_HOST_CATALOG_PLUGIN_GCP]: gcpHostFormComponent,
18+
[TYPE_HOST_CATALOG_STATIC]: staticHostFormComponent,
19+
};
20+
21+
export default class FormHostIndex extends Component {
22+
/**
23+
* Returns the host form component associated with the model's composite type
24+
* @type {Component}
25+
*/
26+
get hostFormComponent() {
27+
const component =
28+
modelCompositeTypeToComponent[this.args.model.compositeType];
29+
assert(
30+
`Mapped component must exist for host composite type: ${this.args.model.compositeType}`,
31+
component,
32+
);
33+
return component;
34+
}
35+
}

0 commit comments

Comments
 (0)