Skip to content

Commit 6fcc743

Browse files
authored
chore: 🤖 use statically referenced components for host form (#3072)
* chore: 🤖 use statically referenced components for host form * Add missing copyright headers
1 parent 719bab7 commit 6fcc743

File tree

2 files changed

+52
-15
lines changed

2 files changed

+52
-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: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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_HOST_CATALOG_PLUGIN_AWS,
10+
TYPE_HOST_CATALOG_PLUGIN_AZURE,
11+
TYPE_HOST_CATALOG_PLUGIN_GCP,
12+
TYPE_HOST_CATALOG_STATIC,
13+
} from 'api/models/host-catalog';
14+
import awsHostFormComponent from './aws';
15+
import azureHostFormComponent from './azure';
16+
import gcpHostFormComponent from './gcp';
17+
import staticHostFormComponent from './static';
18+
19+
const modelCompositeTypeToComponent = {
20+
[TYPE_HOST_CATALOG_PLUGIN_AWS]: awsHostFormComponent,
21+
[TYPE_HOST_CATALOG_PLUGIN_AZURE]: azureHostFormComponent,
22+
[TYPE_HOST_CATALOG_PLUGIN_GCP]: gcpHostFormComponent,
23+
[TYPE_HOST_CATALOG_STATIC]: staticHostFormComponent,
24+
};
25+
26+
export default class FormHostIndex extends Component {
27+
/**
28+
* Returns the host form component associated with the model's composite type
29+
* @type {Component}
30+
*/
31+
get hostFormComponent() {
32+
const component =
33+
modelCompositeTypeToComponent[this.args.model.compositeType];
34+
assert(
35+
`Mapped component must exist for host composite type: ${this.args.model.compositeType}`,
36+
component,
37+
);
38+
return component;
39+
}
40+
}

0 commit comments

Comments
 (0)