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
1 change: 1 addition & 0 deletions addons/rose/addon/styles/hds/overrides.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
form {
[class*='hds-form-field--layout'],
[class*='hds-form-group--layout'],
[class='hds-form-key-value-inputs'],
.rose-form-actions.hds-button-set {
margin-bottom: 1.5rem;
}
Expand Down
2 changes: 1 addition & 1 deletion addons/rose/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
},
"dependencies": {
"@babel/core": "^7.26.10",
"@hashicorp/design-system-components": "^4.20.2",
"@hashicorp/design-system-components": "^4.24.0",
"@hashicorp/design-system-tokens": "^2.3.0",
"@hashicorp/flight-icons": "^3.10.0",
"@nullvoxpopuli/ember-composable-helpers": "^5.2.10",
Expand Down
155 changes: 82 additions & 73 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

52 changes: 14 additions & 38 deletions ui/admin/app/components/form/auth-method/oidc/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -247,45 +247,21 @@
</Form::Field::ListWrapper>

{{! Account Claim Maps }}
<Form::Field::ListWrapper
@layout='horizontal'
@isOptional={{true}}
<Form::Field::KeyValue
@name='account_claim_maps'
@data={{@model.account_claim_maps}}
@onChange={{this.updateAccountClaimMaps}}
@legend={{t 'form.account_claim_maps.label'}}
@helperText={{t 'form.account_claim_maps.help'}}
@errors={{@model.errors.account_claim_maps}}
@disabled={{form.disabled}}
>
<:fieldset as |F|>
<F.Legend>
{{t 'form.account_claim_maps.label'}}
</F.Legend>
<F.HelperText>
{{t 'form.account_claim_maps.help'}}
</F.HelperText>

{{#if @model.errors.account_claim_maps}}
<F.Error as |E|>
{{#each @model.errors.account_claim_maps as |error|}}
<E.Message>{{error.message}}</E.Message>
{{/each}}
</F.Error>
{{/if}}
</:fieldset>
<:field as |F|>
<F.KeyValue
@name='account_claim_maps'
@options={{@model.account_claim_maps}}
@model={{@model}}
@keyLabel={{t 'form.from_claim.label'}}
@valueLabel={{t 'form.to_claim.label'}}
@width='100%'
>
<:key as |K|>
<K.text />
</:key>
<:value as |V|>
<V.select @selectOptions={{this.toClaims}} />
</:value>
</F.KeyValue>
</:field>
</Form::Field::ListWrapper>
@isOptional={{true}}
@keyFieldType='text'
@valueFieldType='select'
@valueFieldOptions={{this.toClaims}}
@keyLabel={{t 'form.from_claim.label'}}
@valueLabel={{t 'form.to_claim.label'}}
/>

{{! Certificates }}
<Form::Field::ListWrapper
Expand Down
8 changes: 8 additions & 0 deletions ui/admin/app/components/form/auth-method/oidc/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ export default class FormAuthMethodOidcComponent extends Component {

//actions

/**
* Updates the account claim maps on the model with new data
* @param {Array} newData - Array of account claim map objects
*/
@action
updateAccountClaimMaps(newData) {
this.args.model.account_claim_maps = newData;
}
/**
* @param {string} value
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,45 +225,18 @@
{{/if}}
</Hds::Form::TextInput::Field>

<Form::Field::ListWrapper
@layout='horizontal'
@isOptional={{true}}
<Form::Field::KeyValue
@name='critical_options'
@data={{@model.critical_options}}
@onChange={{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}}
@disabled={{form.disabled}}
>
<:fieldset as |F|>
<F.Legend>
{{t 'resources.credential-library.form.critical_options.label'}}
</F.Legend>
<F.HelperText>
{{t 'resources.credential-library.form.critical_options.help'}}
</F.HelperText>

{{#if @model.errors.critical_options}}
<F.Error as |E|>
{{#each @model.errors.critical_options as |error|}}
<E.Message>{{error.message}}</E.Message>
{{/each}}
</F.Error>
{{/if}}
</:fieldset>

<:field as |F|>
<F.KeyValue
@name='critical_options'
@options={{@model.critical_options}}
@model={{@model}}
@disabled={{form.disabled}}
>
<:key as |K|>
<K.text />
</:key>
<:value as |K|>
<K.text />
</:value>
</F.KeyValue>
</:field>

</Form::Field::ListWrapper>
@isOptional={{true}}
@keyFieldType='text'
@valueFieldType='text'
/>

<Form::Field::ListWrapper
@layout='horizontal'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import Component from '@glimmer/component';

import { action } from '@ember/object';
import { options } from 'api/models/credential-library';

export default class FormCredentialLibraryVaultSshCertComponent extends Component {
Expand All @@ -23,4 +24,13 @@ export default class FormCredentialLibraryVaultSshCertComponent extends Componen
const keyType = this.args.model.key_type;
return keyType === 'rsa' || keyType === 'ecdsa';
}

/**
* Updates the critical options on the credential library model with new data
* @param {Array} newData - Array of critical option objects
*/
@action
updateCriticalOptions(newData) {
this.args.model.critical_options = newData;
}
}
130 changes: 130 additions & 0 deletions ui/admin/app/components/form/field/key-value/index.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
{{!
Copyright (c) HashiCorp, Inc.
SPDX-License-Identifier: BUSL-1.1
}}
<Hds::Form::KeyValueInputs
@data={{this.data}}
@isRequired={{@isRequired}}
@isOptional={{@isOptional}}
disabled={{@disabled}}
>
<:header as |H|>
{{#if @legend}}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this be optional? It seems we should always have a legend to be accessible

Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we have a use cases for not having a legend? I also lean towards this not being optional.

<H.Legend data-test-legend>{{@legend}}</H.Legend>
{{/if}}
{{#if @helperText}}
<H.HelperText data-test-helper-text>{{@helperText}}</H.HelperText>
{{/if}}
</:header>
<:row as |R|>
<R.Field as |F|>
<F.Label>{{or @keyLabel (t 'form.key.label')}}</F.Label>
{{#if (eq @keyFieldType 'select')}}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm wondering if this component is trying too hard to simplify the HDS component without adding enough convenience for the limitations it now builds in.

It seems the hideValueField is only necessary because we need to handle the option of one field or two fields but we actually should be able to handle any number of fields as HDS also supports generic fields and not just inputs which we now limit.

Would it make more sense to cut down and remove the baked in fields (as well as the switches for keyFieldType) and just let the consumer handle adding in the fields? We could just yield back the <:row as |R|> to the consumer to handle this. I also notice all the keys/values also share the same name/errors which doesn't seem right.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Looking over this and Zed's comment, I think I would lean towards allowing the consumer to handle this by yielding back. That should give us the flexibility without this complexity I think.

<F.Select
name={{@name}}
disabled={{@disabled}}
data-test-key-input
@isInvalid={{@errors}}
{{on 'change' (fn this.updateKey R.rowData)}}
>
<option disabled hidden selected value=''>
{{t 'titles.choose-an-option'}}
</option>
{{#each @keyFieldOptions as |selectOption|}}
<option
value={{selectOption}}
selected={{eq R.rowData.key selectOption}}
>
{{selectOption}}
</option>
{{/each}}
</F.Select>
{{else if (eq @keyFieldType 'textarea')}}
<F.Textarea
name={{@name}}
@value={{R.rowData.key}}
disabled={{@disabled}}
data-test-key-input
@isInvalid={{@errors}}
{{on 'input' (fn this.updateKey R.rowData)}}
/>
{{else}}
{{! Default to text input }}
<F.TextInput
name={{@name}}
@value={{R.rowData.key}}
disabled={{@disabled}}
data-test-key-input
@isInvalid={{@errors}}
{{on 'input' (fn this.updateKey R.rowData)}}
/>
{{/if}}
</R.Field>

{{#unless this.hideValueField}}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't this be hiding the key field instead of the value field if we just want one field? Though should this even be necessary?

<R.Field as |F|>
<F.Label>{{or @valueLabel (t 'form.value.label')}}</F.Label>
{{#if (eq @valueFieldType 'select')}}
<F.Select
name={{@name}}
disabled={{@disabled}}
data-test-value-input
@isInvalid={{@errors}}
{{on 'change' (fn this.updateValue R.rowData)}}
>
<option disabled hidden selected value=''>
{{t 'titles.choose-an-option'}}
</option>
{{#each @valueFieldOptions as |selectOption|}}
<option
value={{selectOption}}
selected={{eq R.rowData.value selectOption}}
>
{{selectOption}}
</option>
{{/each}}
</F.Select>
{{else if (eq @valueFieldType 'textarea')}}
<F.Textarea
name={{@name}}
@value={{R.rowData.value}}
disabled={{@disabled}}
data-test-value-input
@isInvalid={{@errors}}
{{on 'input' (fn this.updateValue R.rowData)}}
/>
{{else}}
{{! Default to text input }}
<F.TextInput
name={{@name}}
@value={{R.rowData.value}}
disabled={{@disabled}}
data-test-value-input
@isInvalid={{@errors}}
{{on 'input' (fn this.updateValue R.rowData)}}
/>
{{/if}}
</R.Field>
{{/unless}}

<R.DeleteRowButton
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like we need to hide this if there's no input yet according to HDS suggestions.

data-test-delete-button
onclick={{fn this.removeRow R.rowData}}
/>
</:row>
<:footer as |F|>

{{#if @errors}}
<F.Error as |E|>
{{#each @errors as |error|}}
<E.Message data-test-error-message>{{error.message}}</E.Message>
{{/each}}
</F.Error>
{{/if}}
<F.AddRowButton
@text={{t 'actions.add'}}
data-test-add-button
onclick={{this.addNewRow}}
/>
</:footer>
</Hds::Form::KeyValueInputs>
95 changes: 95 additions & 0 deletions ui/admin/app/components/form/field/key-value/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/

import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';

export default class FormFieldKeyValueComponent extends Component {
// =properties

@tracked data = this.args.data?.length
? [...this.args.data]
: [this.createEmptyRow()];

/**
* Determine if the value field should be shown
* Defaults to false (show the value field by default)
* @type {boolean}
*/
get hideValueField() {
return this.args.hideValueField ?? false;
}

createEmptyRow() {
const row = { key: '' };
if (!this.hideValueField) {
row.value = '';
}
return row;
}

// =actions

/**
* Updates the key value for a specific row and triggers change notification
* @param {Object} rowData
* @param {Event} event
*/
@action
updateKey(rowData, { target: { value } }) {
this.updateRowProperty(rowData, 'key', value);
}

/**
* Updates the value field for a specific row and triggers change notification
* @param {Object} rowData
* @param {Event} event
*/
@action
updateValue(rowData, { target: { value } }) {
this.updateRowProperty(rowData, 'value', value);
}

@action
addNewRow() {
this.data = [...this.data, this.createEmptyRow()];
this.notifyChange();
}

@action
removeRow(rowData) {
this.data = this.data.filter((item) => item !== rowData);

// Ensure at least one row exists
if (this.data.length === 0) {
this.data = [this.createEmptyRow()];
}
this.notifyChange();
}

/**
* Helper method to update a property on a row
* @param {Object} rowData - The row object to update
* @param {string} property - The property name to update
* @param {string} value - The new value
*/
updateRowProperty(rowData, property, value) {
rowData[property] = value;
this.data = [...this.data];
this.notifyChange();
}

/**
* Notifies parent component of data changes with filtered results
*/
notifyChange() {
if (this.args.onChange) {
// Filter out entries with empty/whitespace keys
const filteredData = this.data.filter((item) => item.key?.trim());
this.args.onChange(filteredData);
}
}
}
Loading