mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-02 08:56:07 +00:00
fix(tags): three tags and "…" on the host's VM list too
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.
This commit is contained in:
parent
65b8110464
commit
6680e14ce4
5 changed files with 22 additions and 5 deletions
|
|
@ -65,7 +65,7 @@
|
|||
<a class="link-primary" href="{% url 'instances:instance' instance.id %}">{{ instance.name }}</a>
|
||||
<br>
|
||||
{% if instance.info %}<p class="m-0 small fst-italic">{{ instance.title }}</p>{% 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 %}
|
||||
</td>
|
||||
<td>
|
||||
<em>
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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})
|
||||
|
|
|
|||
|
|
@ -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]");
|
||||
|
|
|
|||
|
|
@ -4,5 +4,5 @@
|
|||
{% for tag in tags %}{% include 'common/tag_badge.html' %} {% endfor %}
|
||||
{% if more %}
|
||||
<button type="button" class="badge tag-badge text-bg-light border" data-show-tags title="{{ more|join:", " }}">…<span class="visually-hidden"> {% trans "more tags" %}</span></button>
|
||||
<span hidden>{% for tag in more %}{% include 'common/tag_badge.html' %} {% endfor %}</span>
|
||||
<span hidden tabindex="-1">{% for tag in more %}{% include 'common/tag_badge.html' %} {% endfor %}</span>
|
||||
{% endif %}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue