{% endif %}
- {% include 'common/tag_badges.html' with tags=instance.tags.all %}
+ {% with tags=instance.tags.all %}{% include 'common/tag_badges.html' with tags=tags|slice:":3" more=tags|slice:"3:" %}{% endwith %}
diff --git a/instances/tests/js/table_filter.test.js b/instances/tests/js/table_filter.test.js
index 8f35a376..2acda370 100644
--- a/instances/tests/js/table_filter.test.js
+++ b/instances/tests/js/table_filter.test.js
@@ -163,6 +163,10 @@ assert.deepStrictEqual(visible(turkish), ["Şişli"]);
const ellipsis = {hidden: false, nextElementSibling: others};
listeners.click({target: {closest: (s) => (s === "[data-show-tags]" ? ellipsis : null)}});
assert.deepStrictEqual([others.hidden, ellipsis.hidden, focused], [false, true, "d4"]);
+ // tags that are not buttons (no tag list on the page): the tags shown take it
+ const plain = {hidden: true, querySelector: () => null, focus: () => { focused = "plain"; }};
+ listeners.click({target: {closest: (s) => (s === "[data-show-tags]" ? {hidden: false, nextElementSibling: plain} : null)}});
+ assert.strictEqual(focused, "plain");
}
// a kept tag the list no longer has is forgotten: made again later, it is not chosen by itself
diff --git a/instances/tests/test_tags.py b/instances/tests/test_tags.py
index 311e3606..b2f907d6 100644
--- a/instances/tests/test_tags.py
+++ b/instances/tests/test_tags.py
@@ -92,6 +92,18 @@ class VmTagsTests(TestCase):
self.assertContains(self.client.get(reverse("instances", args=[self.vm.compute_id])), "prod")
self.assertContains(self.client.get(reverse("accounts:account", args=[self.owner.id])), "prod")
+ def test_the_host_s_vm_list_shows_three_and_the_others_behind_an_ellipsis(self):
+ self.vm.tags.add(*(Tag.objects.create(name=name) for name in ("a1", "b2", "c3", "d4")))
+ self.client.force_login(self.admin)
+ with patch("computes.views.utils.refresh_instance_database"), patch("computes.views.vm_states", return_value={}), \
+ patch("computes.views.read_list_rows"):
+ page = lxml_html.fromstring(self.client.get(reverse("instances", args=[self.vm.compute_id])).content)
+ self.assertEqual(page.xpath("//td//span[contains(@class,'tag-badge')][not(ancestor::*[@hidden])]/text()[last()]"),
+ [" a1", " b2", " c3"])
+ self.assertEqual(page.xpath("//button[@data-show-tags]/@title"), ["d4"])
+ # the tags "…" shows take the focus from it (table_filter.js), not buttons here
+ self.assertEqual(page.xpath("//button[@data-show-tags]/following-sibling::span[1]/@tabindex"), ["-1"])
+
def test_the_vm_list_shows_them(self):
self.vm.tags.add(Tag.objects.create(name="prod"))
html = render_to_string("instance_name_cell.html", {"instance": self.vm})
diff --git a/static/js/table_filter.js b/static/js/table_filter.js
index 8690368a..64e8f1e7 100644
--- a/static/js/table_filter.js
+++ b/static/js/table_filter.js
@@ -137,10 +137,11 @@ if (typeof module !== "undefined") {
document.addEventListener("click", function (event) {
var more = event.target.closest("[data-show-tags]");
if (more) {
+ var others = more.nextElementSibling;
more.hidden = true;
- more.nextElementSibling.hidden = false;
- // the focus is not lost with the button: the first tag shown takes it
- more.nextElementSibling.querySelector("button, [tabindex]")?.focus();
+ others.hidden = false;
+ // the focus is not lost with the button: the first tag shown takes it, or the tags if they are not buttons
+ (others.querySelector("button") || others).focus();
return;
}
var badge = event.target.closest("[data-tag-filter]");
diff --git a/templates/common/tag_badges.html b/templates/common/tag_badges.html
index 7c84c91b..29b26f50 100644
--- a/templates/common/tag_badges.html
+++ b/templates/common/tag_badges.html
@@ -4,5 +4,5 @@
{% for tag in tags %}{% include 'common/tag_badge.html' %} {% endfor %}
{% if more %}
-{% for tag in more %}{% include 'common/tag_badge.html' %} {% endfor %}
+{% for tag in more %}{% include 'common/tag_badge.html' %} {% endfor %}
{% endif %}