Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ui: [BUGFIX] De-duplicate Tag rendering #10186

Merged
merged 5 commits into from
May 7, 2021
Merged
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
3 changes: 3 additions & 0 deletions .changelog/10186.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
ui: De-duplicate tags in rendered tag listings
```
75 changes: 75 additions & 0 deletions ui/packages/consul-ui/app/components/tag-list/README.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# TagList

Template only component for rendering a list of tags. You can pass either/or/and `@tags=tags` and/or `@item=item` (`item` must have a `Tags` property) for ease. If you pass both they are merged and de-duped.

Tags are de-duplicated when rendered.

```hbs preview-template
<TagList
@item={{hash
Tags=(array 'tag' 'tag' 'another-tag')
}}
/>

<hr />

<TagList
@tags={{array 'another-tag' 'tag' 'tag'}}
/>
```

`TagList` is also a recursive component, which can currently be used for when you need to wrap the `TagList` component in more DOM, but you only want that DOM to appear if your array of tags is non-empty.


```hbs preview-template
<figure>
<figcaption>
This list has tags therefore the red border div will also be rendered.
</figcaption>

<TagList
@item={{hash
Tags=(array 'tag' 'tag' 'another-tag')
}}
as |Tags|>
<div style="border: 1px solid red;">
<Tags />
</div>
</TagList>

</figure>

<hr />

<figure>
<figcaption>
This list has no tags therefore the tags _and_ red border div will **not** be rendered.
</figcaption>

<TagList
@item={{hash
Tags=(array)
}}
as |Tags|>
<div style="border: 1px solid red;">
<Tags />
</div>
</TagList>

</figure>
```

## Arguments

| Argument | Type | Default | Description |
| --- | --- | --- | --- |
| `item` | `Object` | | Object with a `Tags` property equalling an array of string tags |
| `tags` | `Array` | | An array of string tags |

## Yields

When used as a block level component the `TagList` yields itself, see above example for usage.

| Property | Type | Description |
| --- | --- | --- |
| `Tags` | `Array` | The resulting collection of data after searching/sorting/filtering |
45 changes: 27 additions & 18 deletions ui/packages/consul-ui/app/components/tag-list/index.hbs
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
{{#if (gt item.Tags.length 0)}}
{{#if (has-block)}}
{{yield
(component 'tag-list' item=item)
{{#let (union (or @item.Tags (array)) (or @tags (array))) as |tags|}}
{{#if (gt tags.length 0)}}
{{#if (has-block)}}
{{yield
(component 'tag-list' item=@item)
}}
{{else}}
<dl
class="tag-list"
...attributes
>
<dt
{{tooltip}}
>
{{t "components.tag-list.title"
default=(array
"common.consul.tags"
)
}}
{{else}}
<dl class="tag-list">
<dt>
<Tooltip>
Tags
</Tooltip>
</dt>
<dd data-test-tags>
{{#each item.Tags as |item|}}
<span>{{item}}</span>
{{/each}}
</dd>
</dl>
</dt>
<dd data-test-tags>
{{#each tags as |item|}}
<span>{{item}}</span>
{{/each}}
</dd>
</dl>
{{/if}}
{{/if}}
{{/if}}
{{/let}}
5 changes: 0 additions & 5 deletions ui/packages/consul-ui/app/components/tag-list/index.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
@setupApplicationTest
Feature: dc / services / show / tags
Background:
Given 1 datacenter model with the value "dc1"
And 1 node models
Scenario: A service with multiple tags
Given 1 service model from yaml
---
- Service:
Name: service
Kind: ~
Tags:
- tag
- tag1
- tag2
---
When I visit the service page for yaml
---
dc: dc1
service: service
---
And I see tags on the tabs
When I click tags on the tabs
And I see tagsIsSelected on the tabs
And I see 3 tag models on the tabs.tagsTab component
Scenario: A service with multiple duplicated tags
Given 1 service model from yaml
---
- Service:
Name: service
Kind: ~
Tags:
- tag1
- tag2
- tag
- tag
- tag1
- tag2
---
When I visit the service page for yaml
---
dc: dc1
service: service
---
And I see tags on the tabs
When I click tags on the tabs
And I see tagsIsSelected on the tabs
And I see 3 tag models on the tabs.tagsTab component
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import steps from '../../../steps';

// step definitions that are shared between features should be moved to the
// tests/acceptance/steps/steps.js file

export default function(assert) {
return steps(assert).then('I should find a file', function() {
assert.ok(true, this.step);
});
}
5 changes: 5 additions & 0 deletions ui/packages/consul-ui/tests/pages/dc/services/show.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,10 @@ export default function(visitable, clickable, attribute, collection, text, inten
name: text('[data-test-service-name]'),
}),
};
page.tabs.tagsTab = {
tags: collection('.tag-list dd > span', {
name: text(),
}),
};
return page;
}