chore: 🤖 migrate host catalog and host set list wrapper fields to key value (#3276)

This commit is contained in:
Dharini committed 2026-06-03 16:36:29 -07:00
1 parent 4e2b779d96
commit 0e223ded8f
26 files changed
+512 -388

No files matched your search

@@ -11,8 +11,5 @@
@removeItemByIndex={{@removeItemByIndex}}
@addStringItem={{@addStringItem}}
@addAccountMapItem={{@addAccountMapItem}}
@addRow={{this.addRow}}
@removeRow={{this.removeRow}}
@updateRow={{this.updateRow}}
/>
{{/if}}
@@ -5,7 +5,6 @@
import Component from '@glimmer/component';
import { assert } from '@ember/debug';
import { action } from '@ember/object';
import oidc from './oidc';
import ldap from './ldap';
import password from './password';
@@ -25,47 +24,4 @@ export default class FormAuthMethodIndex extends Component {
);
return component;
}
/**
* Adds a new empty row to the specified field
* @param {string} field - The field name to add a row to
* @param {Array<string>} properties - Array of property names for the empty row (e.g., ['value'] or ['key', 'value'])
*/
@action
addRow(field, properties) {
const emptyRow = Object.fromEntries(properties.map((prop) => [prop, '']));
this.args.model[field] = [...this.args.model[field], emptyRow];
}
/**
* Removes a row from the specified field
* @param {string} field - The field name to remove a row from
* @param {object} rowData - The row data to remove
*/
@action
removeRow(field, rowData) {
let rows = this.args.model[field].filter((item) => item !== rowData);
// Ensure at least one empty row exists for editing
if (rows.length === 0) {
const emptyRow = Object.fromEntries(
Object.keys(rowData).map((key) => [key, '']),
);
rows = [emptyRow];
}
this.args.model[field] = rows;
}
/**
* Updates a specific property in a row
* @param {string} field - The field name containing the row
* @param {object} rowData - The row object to update
* @param {string} property - The property name to update
* @param {object} event - The DOM event containing the new value
*/
@action
updateRow(field, rowData, property, { target: { value } }) {
rowData[property] = value;
this.args.model[field] = [...this.args.model[field]];
}
}
@@ -84,10 +84,9 @@
<Form::Field::KeyValue
@name='certificates'
@model={{@model}}
@properties={{array 'value'}}
@data={{@model.certificates}}
@onAdd={{fn @addRow 'certificates' (array 'value')}}
@onRemove={{fn @removeRow 'certificates'}}
@onUpdate={{fn @updateRow 'certificates'}}
@legend={{t 'resources.auth-method.form.certificates.label'}}
@helperText={{t 'resources.auth-method.form.certificates.help'}}
@errors={{@model.errors.certificates}}
@@ -402,10 +401,9 @@
<Form::field::KeyValue
@name='account_attribute_maps'
@model={{@model}}
@properties={{array 'key' 'value'}}
@data={{@model.account_attribute_maps}}
@onAdd={{fn @addRow 'account_attribute_maps' (array 'key' 'value')}}
@onRemove={{fn @removeRow 'account_attribute_maps'}}
@onUpdate={{fn @updateRow 'account_attribute_maps'}}
@legend={{t 'resources.auth-method.form.account_attribute_maps.label'}}
@helperText={{t 'resources.auth-method.form.account_attribute_maps.help'}}
@errors={{@model.errors.account_attribute_maps}}
@@ -149,10 +149,9 @@
{{! Signing algorithms }}
<Form::Field::KeyValue
@name='signing_algorithms'
@model={{@model}}
@properties={{array 'value'}}
@data={{@model.signing_algorithms}}
@onAdd={{fn @addRow 'signing_algorithms' (array 'value')}}
@onRemove={{fn @removeRow 'signing_algorithms'}}
@onUpdate={{fn @updateRow 'signing_algorithms'}}
@legend={{t 'form.signing_algorithms.label'}}
@helperText={{t 'form.signing_algorithms.help'}}
@errors={{@model.errors.signing_algorithms}}
@@ -187,10 +186,9 @@
{{! Allowed audiences }}
<Form::Field::KeyValue
@name='allowed_audiences'
@model={{@model}}
@properties={{array 'value'}}
@data={{@model.allowed_audiences}}
@onAdd={{fn @addRow 'allowed_audiences' (array 'value')}}
@onRemove={{fn @removeRow 'allowed_audiences'}}
@onUpdate={{fn @updateRow 'allowed_audiences'}}
@legend={{t 'form.allowed_audiences.label'}}
@helperText={{t 'form.allowed_audiences.help'}}
@errors={{@model.errors.allowed_audiences}}
@@ -214,10 +212,9 @@
{{! Claims Scopes }}
<Form::Field::KeyValue
@name='claims_scopes'
@model={{@model}}
@properties={{array 'value'}}
@data={{@model.claims_scopes}}
@onAdd={{fn @addRow 'claims_scopes' (array 'value')}}
@onRemove={{fn @removeRow 'claims_scopes'}}
@onUpdate={{fn @updateRow 'claims_scopes'}}
@legend={{t 'form.claims_scopes.label'}}
@helperText={{t 'form.claims_scopes.help'}}
@errors={{@model.errors.claims_scopes}}
@@ -241,10 +238,9 @@
{{! Account Claim Maps }}
<Form::Field::KeyValue
@name='account_claim_maps'
@model={{@model}}
@properties={{array 'key' 'value'}}
@data={{@model.account_claim_maps}}
@onAdd={{fn @addRow 'account_claim_maps' (array 'key' 'value')}}
@onRemove={{fn @removeRow 'account_claim_maps'}}
@onUpdate={{fn @updateRow 'account_claim_maps'}}
@legend={{t 'form.account_claim_maps.label'}}
@helperText={{t 'form.account_claim_maps.help'}}
@errors={{@model.errors.account_claim_maps}}
@@ -287,10 +283,9 @@
{{! Certificates }}
<Form::Field::KeyValue
@name='idp_ca_certs'
@model={{@model}}
@properties={{array 'value'}}
@data={{@model.idp_ca_certs}}
@onAdd={{fn @addRow 'idp_ca_certs' (array 'value')}}
@onRemove={{fn @removeRow 'idp_ca_certs'}}
@onUpdate={{fn @updateRow 'idp_ca_certs'}}
@legend={{t 'form.idp_ca_certs.label'}}
@helperText={{t 'form.idp_ca_certs.help'}}
@errors={{@model.errors.idp_ca_certs}}
@@ -227,10 +227,9 @@
<Form::Field::KeyValue
@name='critical_options'
@model={{@model}}
@properties={{array 'key' 'value'}}
@data={{@model.critical_options}}
@onAdd={{this.addCriticalOption}}
@onRemove={{this.removeCriticalOption}}
@onUpdate={{this.updateCriticalOptions}}
@legend={{t 'resources.credential-library.form.critical_options.label'}}
@helperText={{t 'resources.credential-library.form.critical_options.help'}}
@errors={{@model.errors.critical_options}}
@@ -4,8 +4,6 @@
*/
import Component from '@glimmer/component';
import { action } from '@ember/object';
import { options } from 'api/models/credential-library';
export default class FormCredentialLibraryVaultSshCertComponent extends Component {
@@ -24,41 +22,4 @@ export default class FormCredentialLibraryVaultSshCertComponent extends Componen
const keyType = this.args.model.key_type;
return keyType === 'rsa' || keyType === 'ecdsa';
}
/**
* Adds a new empty row to critical options
*/
@action
addCriticalOption() {
this.args.model.critical_options = [
...this.args.model.critical_options,
{ key: '', value: '' },
];
}
/**
* Updates critical options data
*/
@action
updateCriticalOptions(rowData, property, { target: { value } }) {
rowData[property] = value;
this.args.model.critical_options = [...this.args.model.critical_options];
}
/**
* Removes a row from critical options
* @param {Object} rowData - The row to remove
*/
@action
removeCriticalOption(rowData) {
let rows = this.args.model.critical_options.filter(
(item) => item !== rowData,
);
// Ensure at least one empty row exists for editing
if (rows.length === 0) {
rows = [{ key: '', value: '' }];
}
this.args.model.critical_options = rows;
}
}
@@ -21,8 +21,8 @@
Field=R.Field
DeleteRowButton=R.DeleteRowButton
rowData=R.rowData
removeRow=(fn @onRemove R.rowData)
updateRow=(fn @onUpdate R.rowData)
removeRow=(fn this.handleRemove R.rowData)
updateRow=(fn this.handleUpdate R.rowData)
canDelete=this.canDelete
)
to='row'
@@ -32,7 +32,7 @@
<F.AddRowButton
@text={{t 'actions.add'}}
data-test-add-button
@onClick={{@onAdd}}
@onClick={{this.handleAdd}}
/>
{{#if @errors}}
<F.Error as |E|>
@@ -4,6 +4,8 @@
*/
import Component from '@glimmer/component';
import { action } from '@ember/object';
import { assert } from '@ember/debug';
export default class FormFieldKeyValueComponent extends Component {
/**
@@ -25,4 +27,78 @@ export default class FormFieldKeyValueComponent extends Component {
// Return false if there are no rows
return false;
}
/**
* Default handler for adding a row.
* Uses @model, @name, and @properties if provided, otherwise calls @onAdd.
*/
@action
handleAdd() {
// If an onAdd handler is provided, use it
if (this.args.onAdd) {
return this.args.onAdd();
}
const { model, name, properties } = this.args;
assert(
'FormFieldKeyValueComponent: model, name, and properties are required if no custom onAdd handler is provided.',
model && name && properties,
);
const emptyRow = Object.fromEntries(properties.map((prop) => [prop, '']));
model[name] = [...(model[name] ?? []), emptyRow];
}
/**
* Default handler for removing a row.
* Uses @model and @name if provided, otherwise calls @onRemove.
*/
@action
handleRemove(rowData) {
// If an onRemove handler is provided, use it
if (this.args.onRemove) {
return this.args.onRemove(rowData);
}
const { model, name, properties } = this.args;
assert(
'FormFieldKeyValueComponent: model, name, and properties are required if no custom onRemove handler is provided.',
model && name && properties,
);
const rows = (model[name] ?? []).filter((item) => item !== rowData);
// If removing the last row, add an empty row back
if (rows.length === 0) {
const emptyRow = Object.fromEntries(properties.map((prop) => [prop, '']));
model[name] = [emptyRow];
} else {
model[name] = rows;
}
}
/**
* Default handler for updating a row.
* Uses @model and @name if provided, otherwise calls @onUpdate.
*/
@action
handleUpdate(rowData, property, event) {
// If an onUpdate handler is provided, use it
if (this.args.onUpdate) {
return this.args.onUpdate(rowData, property, event);
}
const { model, name } = this.args;
assert(
'FormFieldKeyValueComponent: model and name are required if no custom onUpdate handler is provided.',
model && name,
);
const value = event?.target?.value ?? event;
rowData[property] = value;
model[name] = [...(model[name] ?? [])];
}
}
@@ -4,6 +4,7 @@
}}
<Rose::Form
@edit={{@edit}}
@onSubmit={{@submit}}
@cancel={{@cancel}}
@disabled={{@model.isSaving}}
@@ -271,44 +272,37 @@
</Hds::Form::TextInput::Field>
{{! role_tags }}
<Form::Field::ListWrapper
@layout='horizontal'
@isOptional={{true}}
<Form::Field::KeyValue
@name='role_tags'
@model={{@model}}
@properties={{array 'key' 'value'}}
@data={{@model.role_tags}}
@legend={{t 'resources.storage-bucket.form.role_tags.label'}}
@helperText={{t 'resources.storage-bucket.form.role_tags.help'}}
@errors={{@model.errors.role_tags}}
@disabled={{form.disabled}}
@isOptional={{true}}
>
<:fieldset as |F|>
<F.Legend>
{{t 'resources.storage-bucket.form.role_tags.label'}}
</F.Legend>
<F.HelperText>
{{t 'resources.storage-bucket.form.role_tags.help'}}
</F.HelperText>
{{#if @model.errors.role_tags}}
<F.Error as |E|>
{{#each @model.errors.role_tags as |error|}}
<E.Message>
{{error.message}}
</E.Message>
{{/each}}
</F.Error>
<:row as |R|>
<R.Field as |F|>
<F.TextInput
data-test-key-input
@value={{R.rowData.key}}
{{on 'input' (fn R.updateRow 'key')}}
/>
</R.Field>
<R.Field as |F|>
<F.TextInput
data-test-value-input
@value={{R.rowData.value}}
{{on 'input' (fn R.updateRow 'value')}}
/>
</R.Field>
{{#if R.canDelete}}
<R.DeleteRowButton data-test-delete-button @onClick={{R.removeRow}} />
{{/if}}
</:fieldset>
<:field as |F|>
<F.KeyValue
@name='role_tags'
@options={{@model.role_tags}}
@model={{@model}}
>
<:key as |K|>
<K.text />
</:key>
<:value as |V|>
<V.text />
</:value>
</F.KeyValue>
</:field>
</Form::Field::ListWrapper>
</:row>
</Form::Field::KeyValue>
{{else}}
<Hds::Form::TextInput::Field
@@ -4,6 +4,7 @@
}}
<Rose::Form
@edit={{@edit}}
@onSubmit={{@submit}}
@cancel={{@cancel}}
@disabled={{@model.isSaving}}
@@ -4,6 +4,7 @@
}}
<Rose::Form
@edit={{@edit}}
@onSubmit={{@submit}}
@cancel={{@cancel}}
@disabled={{@model.isSaving}}
@@ -5,6 +5,7 @@
<this.hostCatalogFormComponent
@model={{@model}}
@edit={{@edit}}
@submit={{@submit}}
@cancel={{@cancel}}
@changeType={{@changeType}}
@@ -4,6 +4,7 @@
}}
<Rose::Form
@edit={{@edit}}
@onSubmit={{@submit}}
@cancel={{@cancel}}
@disabled={{@model.isSaving}}
@@ -62,65 +62,55 @@
</F.HelperText>
</InfoField>
<Form::Field::ListWrapper
@layout='horizontal'
@isOptional={{true}}
<Form::Field::KeyValue
@name='preferred_endpoints'
@model={{@model}}
@properties={{array 'value'}}
@data={{@model.preferred_endpoints}}
@legend={{t 'resources.host-set.form.preferred_endpoints.label'}}
@helperText={{t 'resources.host-set.form.preferred_endpoints.help'}}
@errors={{@model.errors.preferred_endpoints}}
@disabled={{form.disabled}}
>
<:fieldset as |F|>
<F.Legend>
{{t 'resources.host-set.form.preferred_endpoints.label'}}
</F.Legend>
<F.HelperText>
{{t 'resources.host-set.form.preferred_endpoints.help'}}
</F.HelperText>
{{#if @model.errors.preferred_endpoints}}
<F.Error as |E|>
{{#each @model.errors.preferred_endpoints as |error|}}
<E.Message>{{error.message}}</E.Message>
{{/each}}
</F.Error>
{{/if}}
</:fieldset>
<:field as |F|>
<F.TextInput
@name='preferred_endpoints'
@options={{@model.preferred_endpoints}}
@model={{@model}}
/>
</:field>
</Form::Field::ListWrapper>
<Form::Field::ListWrapper
@layout='horizontal'
@isOptional={{true}}
@disabled={{form.disabled}}
>
<:fieldset as |F|>
<F.Legend>
{{t 'resources.host-set.form.filter.label'}}
</F.Legend>
<F.HelperText>
{{t 'resources.host-set.form.filter.aws.help'}}
</F.HelperText>
{{#if @model.errors.filters}}
<F.Error as |E|>
{{#each @model.errors.filters as |error|}}
<E.Message>{{error.message}}</E.Message>
{{/each}}
</F.Error>
<:row as |R|>
<R.Field as |F|>
<F.TextInput
data-test-value-input
@value={{R.rowData.value}}
{{on 'input' (fn R.updateRow 'value')}}
/>
</R.Field>
{{#if R.canDelete}}
<R.DeleteRowButton data-test-delete-button @onClick={{R.removeRow}} />
{{/if}}
</:fieldset>
<:field as |F|>
<F.TextInput
@name='filters'
@options={{@model.filters}}
@model={{@model}}
/>
</:field>
</Form::Field::ListWrapper>
</:row>
</Form::Field::KeyValue>
<Form::Field::KeyValue
@name='filters'
@model={{@model}}
@properties={{array 'value'}}
@data={{@model.filters}}
@legend={{t 'resources.host-set.form.filter.label'}}
@helperText={{t 'resources.host-set.form.filter.aws.help'}}
@errors={{@model.errors.filters}}
@disabled={{form.disabled}}
@isOptional={{true}}
>
<:row as |R|>
<R.Field as |F|>
<F.TextInput
data-test-value-input
@value={{R.rowData.value}}
{{on 'input' (fn R.updateRow 'value')}}
/>
</R.Field>
{{#if R.canDelete}}
<R.DeleteRowButton data-test-delete-button @onClick={{R.removeRow}} />
{{/if}}
</:row>
</Form::Field::KeyValue>
<Hds::Form::TextInput::Field
name='sync_interval_seconds'
@@ -62,36 +62,30 @@
</F.HelperText>
</InfoField>
<Form::Field::ListWrapper
@layout='horizontal'
@isOptional={{true}}
<Form::Field::KeyValue
@name='preferred_endpoints'
@model={{@model}}
@properties={{array 'value'}}
@data={{@model.preferred_endpoints}}
@legend={{t 'resources.host-set.form.preferred_endpoints.label'}}
@helperText={{t 'resources.host-set.form.preferred_endpoints.help'}}
@errors={{@model.errors.preferred_endpoints}}
@disabled={{form.disabled}}
@isOptional={{true}}
>
<:fieldset as |F|>
<F.Legend>
{{t 'resources.host-set.form.preferred_endpoints.label'}}
</F.Legend>
<F.HelperText>
{{t 'resources.host-set.form.preferred_endpoints.help'}}
</F.HelperText>
{{#if @model.errors.preferred_endpoints}}
<F.Error as |E|>
{{#each @model.errors.preferred_endpoints as |error|}}
<E.Message>{{error.message}}</E.Message>
{{/each}}
</F.Error>
<:row as |R|>
<R.Field as |F|>
<F.TextInput
data-test-value-input
@value={{R.rowData.value}}
{{on 'input' (fn R.updateRow 'value')}}
/>
</R.Field>
{{#if R.canDelete}}
<R.DeleteRowButton data-test-delete-button @onClick={{R.removeRow}} />
{{/if}}
</:fieldset>
<:field as |F|>
<F.TextInput
@name='preferred_endpoints'
@options={{@model.preferred_endpoints}}
@model={{@model}}
/>
</:field>
</Form::Field::ListWrapper>
</:row>
</Form::Field::KeyValue>
<Hds::Form::Textarea::Field
name='filter'
@@ -61,65 +61,55 @@
</F.HelperText>
</InfoField>
<Form::Field::ListWrapper
@layout='horizontal'
@isOptional={{true}}
<Form::Field::KeyValue
@name='preferred_endpoints'
@model={{@model}}
@properties={{array 'value'}}
@data={{@model.preferred_endpoints}}
@legend={{t 'resources.host-set.form.preferred_endpoints.label'}}
@helperText={{t 'resources.host-set.form.preferred_endpoints.help'}}
@errors={{@model.errors.preferred_endpoints}}
@disabled={{form.disabled}}
>
<:fieldset as |F|>
<F.Legend>
{{t 'resources.host-set.form.preferred_endpoints.label'}}
</F.Legend>
<F.HelperText>
{{t 'resources.host-set.form.preferred_endpoints.help'}}
</F.HelperText>
{{#if @model.errors.preferred_endpoints}}
<F.Error as |E|>
{{#each @model.errors.preferred_endpoints as |error|}}
<E.Message>{{error.message}}</E.Message>
{{/each}}
</F.Error>
{{/if}}
</:fieldset>
<:field as |F|>
<F.TextInput
@name='preferred_endpoints'
@options={{@model.preferred_endpoints}}
@model={{@model}}
/>
</:field>
</Form::Field::ListWrapper>
<Form::Field::ListWrapper
@layout='horizontal'
@isOptional={{true}}
@disabled={{form.disabled}}
>
<:fieldset as |F|>
<F.Legend>
{{t 'resources.host-set.form.filter.label'}}
</F.Legend>
<F.HelperText>
{{t 'resources.host-set.form.filter.gcp.help'}}
</F.HelperText>
{{#if @model.errors.filters}}
<F.Error as |E|>
{{#each @model.errors.filters as |error|}}
<E.Message>{{error.message}}</E.Message>
{{/each}}
</F.Error>
<:row as |R|>
<R.Field as |F|>
<F.TextInput
data-test-value-input
@value={{R.rowData.value}}
{{on 'input' (fn R.updateRow 'value')}}
/>
</R.Field>
{{#if R.canDelete}}
<R.DeleteRowButton data-test-delete-button @onClick={{R.removeRow}} />
{{/if}}
</:fieldset>
<:field as |F|>
<F.TextInput
@name='filters'
@options={{@model.filters}}
@model={{@model}}
/>
</:field>
</Form::Field::ListWrapper>
</:row>
</Form::Field::KeyValue>
<Form::Field::KeyValue
@name='filters'
@model={{@model}}
@properties={{array 'value'}}
@data={{@model.filters}}
@legend={{t 'resources.host-set.form.filter.label'}}
@helperText={{t 'resources.host-set.form.filter.gcp.help'}}
@errors={{@model.errors.filters}}
@disabled={{form.disabled}}
@isOptional={{true}}
>
<:row as |R|>
<R.Field as |F|>
<F.TextInput
data-test-value-input
@value={{R.rowData.value}}
{{on 'input' (fn R.updateRow 'value')}}
/>
</R.Field>
{{#if R.canDelete}}
<R.DeleteRowButton data-test-delete-button @onClick={{R.removeRow}} />
{{/if}}
</:row>
</Form::Field::KeyValue>
<Hds::Form::TextInput::Field
name='sync_interval_seconds'