Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 12 additions & 15 deletions ui/admin/app/components/form/host/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,17 @@
}}

{{#if @model.compositeType}}
{{component
(concat 'form/host/' @model.compositeType)
model=@model
submit=@submit
cancel=@cancel
}}
<this.hostFormComponent
@model={{@model}}
@submit={{@submit}}
@cancel={{@cancel}}
/>
{{else}}
{{! create-and-add-host cancel route doesn't
have a model and this else part is required to prevent
erroring out here. This has been noted in the tech debt doc to further investigate }}
{{component
(concat 'form/host/' 'static')
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This didn't have to use the dynamic component helper before since the concat is only using known strings

model=@model
submit=@submit
cancel=@cancel
}}
{{! create-and-add-host cancel route doesn't have a model and this else part is required
to prevent erroring out here. This has been noted in the tech debt doc to further investigate }}
<Form::Host::Static
@model={{@model}}
@submit={{@submit}}
@cancel={{@cancel}}
/>
{{/if}}
40 changes: 40 additions & 0 deletions ui/admin/app/components/form/host/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/

import Component from '@glimmer/component';
import { assert } from '@ember/debug';
import {
TYPE_HOST_CATALOG_PLUGIN_AWS,
TYPE_HOST_CATALOG_PLUGIN_AZURE,
TYPE_HOST_CATALOG_PLUGIN_GCP,
TYPE_HOST_CATALOG_STATIC,
} from 'api/models/host-catalog';
Comment on lines +8 to +13
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are being imported from host-catalog but since the host's composite type is derived from these it seems alright to use these constants

import awsHostFormComponent from './aws';
import azureHostFormComponent from './azure';
import gcpHostFormComponent from './gcp';
import staticHostFormComponent from './static';

const modelCompositeTypeToComponent = {
[TYPE_HOST_CATALOG_PLUGIN_AWS]: awsHostFormComponent,
[TYPE_HOST_CATALOG_PLUGIN_AZURE]: azureHostFormComponent,
[TYPE_HOST_CATALOG_PLUGIN_GCP]: gcpHostFormComponent,
[TYPE_HOST_CATALOG_STATIC]: staticHostFormComponent,
};

export default class FormHostIndex extends Component {
/**
* Returns the host form component associated with the model's composite type
* @type {Component}
*/
get hostFormComponent() {
const component =
modelCompositeTypeToComponent[this.args.model.compositeType];
assert(
`Mapped component must exist for host composite type: ${this.args.model.compositeType}`,
component,
);
return component;
}
}