From 16ea9709600137697f6671798369c9d3b372eabd Mon Sep 17 00:00:00 2001 From: Harenome Ranaivoarivony-Razanajato Date: Thu, 19 Nov 2026 13:22:13 +0100 Subject: [PATCH 1/2] perf(runs): render the Launches page's add-to-workspace dialog once Every row carried a hidden copy of the Add dialog with a select of every workspace the launch was not in: with 200 launches and 100 workspaces, about 20,000 options and two thirds of the page's bytes. The page now draws the dialog once; a row's button carries its add URL and title, and opening it drops the workspaces the row already lists (data-f-ws). --- app/templates/runs/_launch_ask.html | 4 ++-- app/templates/runs/launches.html | 31 +++++++++++++++++++---------- app/ui_tests/test_run_routes.py | 16 ++++++++++++--- 3 files changed, 35 insertions(+), 16 deletions(-) diff --git a/app/templates/runs/_launch_ask.html b/app/templates/runs/_launch_ask.html index cb6abae7..ca2a3a58 100644 --- a/app/templates/runs/_launch_ask.html +++ b/app/templates/runs/_launch_ask.html @@ -21,7 +21,7 @@ {% endif %} {%- endmacro %} -{#- One dialog for every launch: a button fills it from its launch's template (`asks`: button class -> template class), +{#- One dialog for every launch: a button fills it from its launch's template, else the page's (`asks`: button class -> template class), or from the server (the button's data-ask); ?delete= opens the Delete question on load. #} {% macro dialogs(asks={'launch-delete-btn': 'launch-ask'}) %} @@ -40,7 +40,7 @@ const r = await nulliusFetch(b.dataset.ask); if (!r.ok) { b.title = await r.text(); return; } d.innerHTML = await r.text(); - } else d.replaceChildren(l.querySelector('template.' + asks[cls]).content.cloneNode(true)); + } else d.replaceChildren((l.querySelector('template.' + asks[cls]) || document.querySelector('template.' + asks[cls])).content.cloneNode(true)); // the row's own, or the page's one d.showModal(); }; const sel = Object.keys(asks).map(c => '.' + c).join(','); diff --git a/app/templates/runs/launches.html b/app/templates/runs/launches.html index ae5ff156..474c7911 100644 --- a/app/templates/runs/launches.html +++ b/app/templates/runs/launches.html @@ -49,28 +49,37 @@ {%- elif c.key == 'size' %}{% call cell(c, sort=r.bytes, class='nowrap') %}{{ r.bytes|filesizeformat }}{% endcall %} {%- elif c.key == 'ws' %}{% call cell(c, sort=wss|map(attribute='label')|sort|join(' ')) %}{% for w in wss %}{{ open_at(w, L, w.label) }}{% if not loop.last %}
{% endif %}{% else %}none{% endfor %}{% endcall %} {%- elif c.key == 'actions' %}{% call cell(c, class='acts-col') %} - {% set others = workspaces|rejectattr('name', 'in', wss|map(attribute='name')|list)|list %} - - + {% if not r.why %}{{ delete_ask(L, none, 'launches', icon=true) }} {%- else %}{{ greyed('Delete launch ' ~ L.title, 'Delete launch', r.why, 'why-' ~ L.key) }}{% endif %} {% endcall %} {%- endif %} {% endcall %} +{#- Add, once for the page: its button fills in the launch, and drops the workspaces its row already lists. #} + {{ dialogs({'launch-delete-btn': 'launch-ask', 'launch-add-btn': 'launch-add'}) }} {% else %} diff --git a/app/ui_tests/test_run_routes.py b/app/ui_tests/test_run_routes.py index ef385a4c..70843462 100644 --- a/app/ui_tests/test_run_routes.py +++ b/app/ui_tests/test_run_routes.py @@ -893,18 +893,28 @@ def test_add_to_a_new_workspace(self): def test_a_blank_name_is_a_new_random_workspace_though_one_holds_the_launch(self): before = {w.name for w in workspace.list_all(self.home)} row = self.rows()[f"run:{self.ex.id}"] # every workspace holds it - self.assertIn('class="icon-btn launch-add-btn" aria-haspopup="dialog" aria-label="Add launch r1-* to a workspace" title="Add to workspace">', row) - self.assertIn('', row) + self.assertIn(f'class="icon-btn launch-add-btn" aria-haspopup="dialog" aria-label="Add launch r1-* to a workspace" title="Add to workspace" data-add="/launch/run:{self.ex.id}/add" data-title="r1-*">', row) self.post(f"/launch/run:{self.ex.id}/add", workspace="", label=" ") (new,) = [w for w in workspace.list_all(self.home) if w.name not in before] self.assertEqual((new.label, new.roots), (new.name, [self.ex.jobs])) self.assertRegex(new.name, r"^[a-z]+-[a-z]+$") + def test_the_add_dialog_is_drawn_once_for_the_page(self): + orphan = self.record("r3") + html, rows = self.get("/launches").get_data(as_text=True), self.rows() + wss = workspace.list_all(self.home) + self.assertEqual((html.count('

Roots of {{ ws.label }}

+ Add a root
+ diff --git a/app/templates/workspaces/workspaces.html b/app/templates/workspaces/workspaces.html index 2c273c37..b95e9c63 100644 --- a/app/templates/workspaces/workspaces.html +++ b/app/templates/workspaces/workspaces.html @@ -8,7 +8,7 @@ {% endblock %} {#- A workspace's row: the open one marked, what its search reads. #} -{% macro ws_tr(ws) %} class="{{ 'ws-current' if workspace and ws.name == workspace.name }}" data-ws="{{ ws.name }}" data-search="{{ ws.label }} {{ ws.name }}" data-holder{% endmacro %} +{% macro ws_tr(ws) %} class="{{ 'ws-current' if workspace and ws.name == workspace.name }}" data-ws="{{ ws.name }}" data-search="{{ ws.label }} {{ ws.name }}"{% endmacro %} {% block body %} {% set actions %}New workspace{% endset %} @@ -20,7 +20,7 @@ dict(key='checks', label='Checks', type='num'), dict(key='opened', label='Last opened', type='num', align='left'), dict(key='launches', label='Launches', type='num', align='right'), dict(key='roots', label='Roots', type='num', align='right'), dict(key='actions', label='Actions', blank=true)] %} {% call(ws, c) table('workspaces', cols, workspaces, ws_tr, class='ws-table', search='Search by name', noun='workspaces') %} - {%- set current = workspace and ws.name == workspace.name %}{% set rs = roots[ws.name] %}{% set clash = labels.count(ws.label) > 1 %} + {%- set current = workspace and ws.name == workspace.name %}{% set clash = labels.count(ws.label) > 1 %} {%- if c.key == 'open' %}{% call cell(c) %}{% if current %}●{% endif %}{% endcall %} {%- elif c.key == 'name' %}{% call cell(c, sort=ws.label, class='ws-name') %} @@ -39,54 +39,40 @@ {%- elif c.key == 'opened' %}{% call cell(c, sort=ws.opened[:19]|replace('-', '')|replace(':', '')|replace('T', '') or 0, class='mono faint nowrap') %}{{ ws.opened[:16]|replace('T', ' ') }}{% endcall %} {%- elif c.key == 'launches' %}{% call cell(c) %}{% set n = n_launches[ws.name] %}{% if n %}{{ n }} {%- else %}{{ greyed('Launches of ' ~ ws.label ~ ': 0', '', 'No launches in ' ~ ws.label, 'none-' ~ ws.name, icon='launches', class='btn ghost sm count-btn', text='0') }}{% endif %}{% endcall %} - {%- elif c.key == 'roots' %}{% call cell(c, sort=rs|length) %} - - + {%- elif c.key == 'roots' %}{% call cell(c, sort=ws.roots|length) %} + {% endcall %} {%- elif c.key == 'actions' %}{% call cell(c, class='acts-col') %} - - + {% endcall %} {%- endif %} {% endcall %} +{#- every row's Delete, filled from its button #} +