|
| 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