Include stat graphs JavaScript in all admin stats actions

Since the main stats index loads this JavaScript using
`"data-turbolinks-track" => "reload"`, going from the stats index to a
section that doesn't include this JavaScript did the strange effect
Turbolinks does in these situations: it first loaded the page using an
AJAX request and, after getting the contents of the page, it reloaded it
in order to apply the changes in the included JavaScript.

This behavior was a bit confusing, particularly when browsing to a
section of the admin stats, clicking the browser's back button to go
back to the stats index, the going to another section, ...

One of the admin stats tests was failing sometimes with this message:

```
  1) Stats Budget investments Supporting phase Number of users and
     supports in investment projects
     Failure/Error: raise ex, cause: cause

     Selenium::WebDriver::Error::UnknownError:
       unknown error: unhandled inspector error:
         {"code":-32000,"message":"Node with given id does not belong to the document"}
         (Session info: chrome=129.0.6668.89)
```

This was probably caused by the mentioned Turbolinks behavior that loads
the page twice. It's possible that Selenium was somehow checking the
node related to the first request when the second request had finished.

Avoiding that double request solves the issue.
This commit is contained in:
Javi Martín
2024-11-08 15:43:20 +01:00
parent 9a4aea9381
commit 02825c22fe
7 changed files with 13 additions and 0 deletions

View File

@@ -1,3 +1,5 @@
<% include_stat_graphs_javascript %>
<%= back_link_to budgets_admin_stats_path %>
<h2><%= budget.name %> - <%= t("admin.stats.budget_balloting.title") %></h2>

View File

@@ -1,5 +1,6 @@
class Admin::Stats::BudgetBallotingComponent < ApplicationComponent
attr_reader :budget
use_helpers :include_stat_graphs_javascript
def initialize(budget)
@budget = budget

View File

@@ -1,3 +1,5 @@
<% include_stat_graphs_javascript %>
<%= back_link_to admin_stats_path %>
<h2><%= t("admin.stats.budgets.title") %></h2>

View File

@@ -1,3 +1,5 @@
<% include_stat_graphs_javascript %>
<%= back_link_to admin_stats_path %>
<h2><%= t("admin.stats.direct_messages.title") %></h2>

View File

@@ -1,3 +1,5 @@
<% include_stat_graphs_javascript %>
<%= back_link_to admin_stats_path %>
<h2 id="top"><%= t("admin.stats.polls.title") %></h2>

View File

@@ -1,3 +1,5 @@
<% include_stat_graphs_javascript %>
<%= back_link_to admin_stats_path %>
<h2><%= t("admin.stats.proposal_notifications.title") %></h2>

View File

@@ -1 +1,3 @@
<% include_stat_graphs_javascript %>
<%= render Admin::Stats::SDGComponent.new(@goals) %>