Skip to content

Commit 91a6023

Browse files
authored
Refactor key value list component (#1949)
* refactor: 💡 update keyvalue list component to allow only rows
1 parent 7b96dd1 commit 91a6023

File tree

2 files changed

+41
-19
lines changed

2 files changed

+41
-19
lines changed

ui/admin/app/components/form/field/key-value-list/index.hbs

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
<:head as |H|>
1919
<H.Tr>
2020
<H.Th id={{keyHeaderID}}>{{t 'form.key.label'}}</H.Th>
21-
<H.Th id={{valueHeaderID}}>{{t 'form.value.label'}}</H.Th>
21+
{{#unless @hasNoValue}}
22+
<H.Th id={{valueHeaderID}}>{{t 'form.value.label'}}</H.Th>
23+
{{/unless}}
2224
<H.Th>
2325
{{#if @removeOptionByIndex}}
2426
{{t 'titles.actions'}}
@@ -39,15 +41,18 @@
3941
{{on 'input' (set-from-event option 'key')}}
4042
/>
4143
</B.Td>
42-
<B.Td>
43-
<Hds::Form::TextInput::Field
44-
@value={{option.value}}
45-
@type='text'
46-
disabled={{@disabled}}
47-
aria-labelledby={{valueHeaderID}}
48-
{{on 'input' (set-from-event option 'value')}}
49-
/>
50-
</B.Td>
44+
{{#unless @hasNoValue}}
45+
<B.Td>
46+
<Hds::Form::TextInput::Field
47+
@value={{option.value}}
48+
@type='text'
49+
disabled={{@disabled}}
50+
aria-labelledby={{valueHeaderID}}
51+
{{on 'input' (set-from-event option 'value')}}
52+
/>
53+
</B.Td>
54+
{{/unless}}
55+
5156
<B.Td>
5257
{{#if @removeOptionByIndex}}
5358
<Hds::Button
@@ -73,15 +78,17 @@
7378
{{on 'input' (set-from-event this 'newOptionKey')}}
7479
/>
7580
</B.Td>
76-
<B.Td>
77-
<Hds::Form::TextInput::Field
78-
@value={{this.newOptionValue}}
79-
@type='text'
80-
disabled={{@disabled}}
81-
aria-labelledby={{valueHeaderID}}
82-
{{on 'input' (set-from-event this 'newOptionValue')}}
83-
/>
84-
</B.Td>
81+
{{#unless @hasNoValue}}
82+
<B.Td>
83+
<Hds::Form::TextInput::Field
84+
@value={{this.newOptionValue}}
85+
@type='text'
86+
disabled={{@disabled}}
87+
aria-labelledby={{valueHeaderID}}
88+
{{on 'input' (set-from-event this 'newOptionValue')}}
89+
/>
90+
</B.Td>
91+
{{/unless}}
8592
<B.Td>
8693
<Hds::Button
8794
@text={{t 'actions.add'}}

ui/admin/tests/integration/components/form/field/key-value-list-test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,19 @@ module('Integration | Component | key-value-list', function (hooks) {
4646

4747
assert.dom('tbody tr').exists({ count: 3 });
4848
});
49+
50+
test('it renders multiple options with only keys', async function (assert) {
51+
this.options = [{ key: 'one' }, { key: 'three' }];
52+
53+
// Template block usage:
54+
await render(hbs`
55+
<Form::Field::KeyValueList
56+
@options={{this.options}}
57+
@hasNoValue={{true}}
58+
/>
59+
`);
60+
61+
assert.dom('tbody tr:first-child td').exists({ count: 2 });
62+
assert.dom('tbody tr').exists({ count: 3 });
63+
});
4964
});

0 commit comments

Comments
 (0)