From 6680e14ce48d98f2bbd6dfe3e03be02e31814f70 Mon Sep 17 00:00:00 2001 From: catborise Date: Thu, 19 Nov 2026 08:29:40 +0300 Subject: [PATCH] =?UTF-8?q?fix(tags):=20three=20tags=20and=20"=E2=80=A6"?= =?UTF-8?q?=20on=20the=20host's=20VM=20list=20too?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The host's VM list showed every tag of a VM, widening its Name column as the VM list did before; it now shows three and the others behind "…". There its tags are not buttons: the tags "…" shows take the focus, so a keyboard user is not sent back to the top of the page. --- computes/templates/computes/instances.html | 2 +- instances/tests/js/table_filter.test.js | 4 ++++ instances/tests/test_tags.py | 12 ++++++++++++ static/js/table_filter.js | 7 ++++--- templates/common/tag_badges.html | 2 +- 5 files changed, 22 insertions(+), 5 deletions(-) diff --git a/computes/templates/computes/instances.html b/computes/templates/computes/instances.html index 38cffa54..79b2edc6 100644 --- a/computes/templates/computes/instances.html +++ b/computes/templates/computes/instances.html @@ -65,7 +65,7 @@ {{ instance.name }}
{% if instance.info %}

{{ instance.title }}

{% 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 %} - + {% endif %}