Skip to content

Commit

Permalink
Refactor key value list component (#1949)
Browse files Browse the repository at this point in the history
* refactor: 💡 update keyvalue list component to allow only rows
  • Loading branch information
DhariniJeeva committed Oct 12, 2023
1 parent 7b96dd1 commit 91a6023
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 19 deletions.
45 changes: 26 additions & 19 deletions ui/admin/app/components/form/field/key-value-list/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
<:head as |H|>
<H.Tr>
<H.Th id={{keyHeaderID}}>{{t 'form.key.label'}}</H.Th>
<H.Th id={{valueHeaderID}}>{{t 'form.value.label'}}</H.Th>
{{#unless @hasNoValue}}
<H.Th id={{valueHeaderID}}>{{t 'form.value.label'}}</H.Th>
{{/unless}}
<H.Th>
{{#if @removeOptionByIndex}}
{{t 'titles.actions'}}
Expand All @@ -39,15 +41,18 @@
{{on 'input' (set-from-event option 'key')}}
/>
</B.Td>
<B.Td>
<Hds::Form::TextInput::Field
@value={{option.value}}
@type='text'
disabled={{@disabled}}
aria-labelledby={{valueHeaderID}}
{{on 'input' (set-from-event option 'value')}}
/>
</B.Td>
{{#unless @hasNoValue}}
<B.Td>
<Hds::Form::TextInput::Field
@value={{option.value}}
@type='text'
disabled={{@disabled}}
aria-labelledby={{valueHeaderID}}
{{on 'input' (set-from-event option 'value')}}
/>
</B.Td>
{{/unless}}

<B.Td>
{{#if @removeOptionByIndex}}
<Hds::Button
Expand All @@ -73,15 +78,17 @@
{{on 'input' (set-from-event this 'newOptionKey')}}
/>
</B.Td>
<B.Td>
<Hds::Form::TextInput::Field
@value={{this.newOptionValue}}
@type='text'
disabled={{@disabled}}
aria-labelledby={{valueHeaderID}}
{{on 'input' (set-from-event this 'newOptionValue')}}
/>
</B.Td>
{{#unless @hasNoValue}}
<B.Td>
<Hds::Form::TextInput::Field
@value={{this.newOptionValue}}
@type='text'
disabled={{@disabled}}
aria-labelledby={{valueHeaderID}}
{{on 'input' (set-from-event this 'newOptionValue')}}
/>
</B.Td>
{{/unless}}
<B.Td>
<Hds::Button
@text={{t 'actions.add'}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,19 @@ module('Integration | Component | key-value-list', function (hooks) {

assert.dom('tbody tr').exists({ count: 3 });
});

test('it renders multiple options with only keys', async function (assert) {
this.options = [{ key: 'one' }, { key: 'three' }];

// Template block usage:
await render(hbs`
<Form::Field::KeyValueList
@options={{this.options}}
@hasNoValue={{true}}
/>
`);

assert.dom('tbody tr:first-child td').exists({ count: 2 });
assert.dom('tbody tr').exists({ count: 3 });
});
});

2 comments on commit 91a6023

@vercel
Copy link

@vercel vercel bot commented on 91a6023 Oct 12, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

boundary-ui-desktop – ./ui/desktop

boundary-ui-desktop.vercel.app
boundary-ui-desktop-git-main-hashicorp.vercel.app
boundary-ui-desktop-hashicorp.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 91a6023 Oct 12, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

boundary-ui – ./ui/admin

boundary-ui-hashicorp.vercel.app
boundary-ui-git-main-hashicorp.vercel.app
boundary-ui.vercel.app

Please sign in to comment.