Commit Graph

17301 Commits

Author SHA1 Message Date
Javi Martín
f638e50174 Wait for suggestions to finish loading in tests
Sometimes tests were hanging indefinitely. Debugging shows that in some
cases it's due to submitting a form before the AJAX request to get
proposals, debates or investments suggestions is finished, since having
an AJAX and a non-AJAX request at the same time when running the test
sometimes leads to unexpected results.

In our case, we were having many timeouts in Github Actions in the
branches where we use both ActiveStorage and Paperclip to store files
(based on pull request 4598). I can reproduce it in those branches
running the following test ("Should show new image after successful
creation with one uploaded file"), although only when my laptop isn't
plugged (!!):

```
rspec './spec/system/proposals_spec.rb[1:33:1:14]'
```

Since we didn't have a proper way to know the AJAX request had finished,
we're adding a `suggest-success` class to the element showing the
suggestions when that happens. Then in the tests we can look for that
class after filling in the title of a proposal, debate or investments.
Just for clarity's sake, we're also adding the `suggest-loading` class
when the suggestions are loading.

In order not to have expectations everywhere about the suggestions,
we're extracting methods to fill in those titles in the tests. Note we
aren't using these methods in the "edit" actions (suggestions are not
showing when editing) or in tests with the `no_js` tag (since
suggestions only work with JavaScript).
2021-09-22 18:29:23 +02:00
Senén Rodero
c61c62e5ac Merge pull request #4701 from consul/absolute_image_url
Fix social share image URL with external storage
2021-09-21 17:19:38 +02:00
Senén Rodero Rodríguez
c115165ef1 Fix social share image URL with external storage
Co-Authored-By: Pierre Mesure <pierre@mesu.re>
2021-09-21 15:09:45 +02:00
Javi Martín
62d98694db Merge pull request #4665 from consul/admin_actions_accessibility
Improve accessibility in admin table actions
2021-09-21 14:14:19 +02:00
Javi Martín
2c5f151d0e Remove no longer needed table action style
It isn't used since commit 25e906591.
2021-09-20 20:27:37 +02:00
Javi Martín
66320c3eca Fix clickable blank space in admin table actions
There were times when some actions had text expanding over two lines
while other actions had text on just one line.

Since all the items in a row had the same height, the elements with just
one line added a blank second line. This was obvious when hovering with
the mouse or focusing on the element with the keyboard. It looked weird
when the element received focused, and it could also lead to
unintentional clicks when clicking on the blank space below the element.
2021-09-20 20:27:37 +02:00
Javi Martín
475b18d171 Adjust hover styles in table actions
The underline text decoration looked a bit strange with the icon on top
of it, and we had an inconsistency since links had a text decoration but
buttons didn't. I think we can remove it since both the color of the
icon and the cursor change on hover and that's enough feedback.

And we were accidentally overwriting the color of the investments link
on hover and focus.
2021-09-20 20:27:37 +02:00
Javi Martín
aaa5f6c285 Disable buttons in table actions when pressed
By default, Rails disables submit inputs (<input type="submit">) when
they're pressed so we avoid a double-submission when users click the
button twice.

However, Rails does not disable submit buttons (<button type="submit">)
when they're pressed. This means there's a chance users might press the
button several times. Even if most our table actions are idempotent, it
might cause certain issues. For instance, pressing the "Delete" button
twice means the second request might raise an
`ActiveRecord::RecordNotFound` exception.

Disabling the button also gives feedback to users, letting them know
they've correctly clicked the button.
2021-09-20 20:27:37 +02:00
Javi Martín
5311daadfe Use a button for non-GET table actions
Links acting like buttons have a few disadvantages.

First, screen readers will announce them as "links". Screen reader users
usually associate links with "things that get you somewhere" and buttons
with "things that perform an action". So when something like "Delete,
link" is announced, they'll probably think this is a link which will
take them to another page where they can delete a record.

Furthermore, the URL of the link for the "destroy" action might be the
same as the URL for the "show" action (only one is accessed with a
DELETE request and the other one with a GET request). That means screen
readers could announce the link like "Delete, visited link", which is
very confusing.

They also won't work when opening links in a new tab, since opening
links in a new tab always results in a GET request to the URL the link
points to.

Finally, submit buttons work without JavaScript enabled, so they'll work
even if the JavaScript in the page hasn't loaded (for whatever reason).

For all these reasons (and probably many more), using a button to send
forms is IMHO superior to using links.

There's one disadvantage, though. Using `button_to` we create a <form>
tag, which means we'll generate invalid HTML if the table is inside
another form. If we run into this issue, we need to use `button_tag`
with a `form` attribute and then generate a form somewhere else inside
the HTML (with `content_for`).

Note we're using `button_to` with a block so it generates a <button>
tag. Using it in a different way the text would result in an <input />
tag, and input elements can't have pseudocontent added via CSS.

The following code could be a starting point to use the `button_tag`
with a `form` attribute. One advantage of this approach is screen
readers wouldn't announce "leaving form" while navigating through these
buttons. However, it doesn't work in Internet Explorer.

```
ERB:

<% content_for(:hidden_content, form_tag(path, form_options) {}) %>
<%= button_tag text, button_options %>

Ruby:

def form_id
  path.gsub("/", "_")
end

def form_options
  { id: form_id, method: options[:method] }
end

def button_options
  html_options.except(:method).merge(form: form_id)
end

Layout:

<%= content_for :hidden_content %> # Right before the `</body>`
```
2021-09-20 20:27:37 +02:00
Javi Martín
6510cb9615 Add a more detailed confirmation message
The message "Are you sure?" is usually followed by blindly clicking
"Yes" without really thinking about what one is doing. So we're
including a bit more information about what's about to happen. That way
it's more likely users will notice it when they accidentally click the
wrong button.

Ideally we would offer the option to undo every common action and then
we wouldn't have to ask for confirmation. But since that isn't the case,
for now we're adding a better confirmation message.

Note we're removing the `resource_name` parameter from the translation
to confirm the action of deleting a record. The reason is, in many
languages it only makes sense to add the model name when it's got an
associated article, and, unlike in English (where "the" is used for
every word), that article is different depending on the noun it's
related to. So we'd have to provide a translation like "name with
article, when singular" for every model.

The complexity of these translations could scalate quickly. And, given
the context, IMHO it isn't essential to add the resouce name. When we're
in the proposals index and there's a proposal named "Improve XYZ", and
we click on "Delete" and see a message saying "This action will delete
XYZ", it is implied that XYZ is a proposal.

So instead we're changing the message so it works for every record with
no need of noun-dependent articles.
2021-09-20 20:27:37 +02:00
Javi Martín
2b4b2f3442 Use aria-label in admin table actions
This way screen reader users will know which record they're going to
access when focusing on a link to a certain action. Otherwise they'd
hear something like "Edit, link", and they wouldn't know which record
they'll end up editing if they follow the link.
2021-09-20 20:27:37 +02:00
Javi Martín
6a2c01b119 Extract method to render an admin table action
This way it will be easier to change the behavior of all table actions,
like adding ARIA attributes. In the past, when we changed the behavior
of the `link_to` method, we had to change all table action classes.
2021-09-20 20:27:37 +02:00
Javi Martín
d7015792ea Merge pull request #4698 from consul/attachments_cache
Expire cache when adding documents and images
2021-09-20 14:27:57 +02:00
Javi Martín
dd15cb01eb Merge pull request #4660 from consul/bug_investments_advanced_search_with_filters
Avoid error when combining investments advanced search with filters
2021-09-15 22:40:16 +02:00
Julian Herrero
541a5fa89f Avoid error when combining investments advanced search with filters 2021-09-15 22:05:18 +02:00
Javi Martín
7254ca333e Merge pull request #4680 from consul/small_menu_links
Increase login links touch area on small screens
2021-09-15 17:30:33 +02:00
Javi Martín
56c2243d1a Merge pull request #4679 from consul/focus_styles
Add default focus outline to buttons
2021-09-15 13:55:45 +02:00
Javi Martín
bd135966ca Use :focus-visible to define styles on focus
Styles on keyboard focus are essential for keyboard navigation; without
them, keyboard users wouldn't see which element they're currently
interacting with. That's why we use an `outline` on elements having the
current keyboard focus.

However, this is sometimes annoying for mouse/touchscreen users, since
clicking/touching an element also gives it keyboard focus.

When clicking on a button performing some kind of action through
JavaScript, keeping the outline on the button after clicking it is
distracting.

Even after clicking a link, for some users having the outline present
while they wait for the next page to load is annoying.

That's why modern browsers (at the time of writing, 74%) implement the
`:focus-visible` pseudoclass, which selects elements which have received
focus using the keyboard, but not elements which have been
clicked/tapped on. We can use it to provide focus styles for keyboard
users without getting in the way of mouse/touchscreen users.

Usually we wouldn't use a feature which isn't supported in more than 96%
of the browsers out there. However, in this case we've got a solid
fallback: we just use the `:focus` pseudoclass. Since the `@support` CSS
condition doesn't accept pseudoclasses as parameters, we're disabling
`:focus` styles only on browsers supporting the `:focus-visible`
pseudoclass using the `:focus:not(:focus-visible)` selector, which will
be ignored by browsers without support for `:focus-visible`.

Since now users receive less feedback when clicking/touching a link or a
button, we're adding styles for the `:active` pseudoclass. This way
users will know which item they're clicking/tapping on. I'm not sure the
outline is a good option for this case, though; I think for touchscreen
users a better solution would be to apply the styles we apply on hover.
We might change it in the future.

Note grouping styles together like this would *not* work:

```
&:focus,
&:focus-visible {
  // Styles here
}
```

Browsers not supporting the `:focus-visible` pseudoclass would ignore
this statement completely, meaning they wouldn't apply the styles on
`:focus` either.
2021-09-15 13:38:36 +02:00
Javi Martín
cd45607ce2 Fix focus styles in admin form controls
We lost focus styles on certain controls in commit 4dad04ae3, since we
were applying a border with a rule which had more precedence than the
rule of border on focus.
2021-09-15 13:38:36 +02:00
Javi Martín
35a45837ff Add default focus outline to buttons
We were using a focus outline on links, but weren't doing the same for
buttons. Since sometimes browsers use a default outline which is barely
visible, this was very disorienting when browsing using the keyboard; we
were navigating through links that clearly indicated where the keyboard
focus was, and when reaching a button suddenly we had this almost
imperceptible feedback. Even if I'm used to it, my first reaction is
always "where did the focus go?" until I realize it's now on a button.

This is even more confusing because we've got buttons looking like links
and links looking like buttons.

Note that in the rules for the `:focus` styles we're including buttons
and the `[type="button"]` attribute. This seems redundant since those
styles are already covered by the `button` selector. However, Foundation
adds styles to buttons with the `[type]` attribute. Since the attribute
selector has precedence over the tag selector, we need to use the
attribute selector as well in order to override Foundation's styles.
2021-09-15 13:38:36 +02:00
Javi Martín
b24994abf7 Fix styles in draft version body
There were no elements matching this selector since commit d679c1eb7 and
these styles were completely ignored. I'm re-adding the ones with make
sense in my humble opinion. I'm not adding top and bottom paddings since
they affect the way the height of the element is calculated, and am not
sure about the intention behind setting the height property.
2021-09-15 13:38:34 +02:00
Javi Martín
f7b83319c6 Expire cache when adding documents and images
Proposals and budget investments were not correctly updated when adding,
removing or modifying their documents and images.
2021-09-14 18:34:31 +02:00
Javi Martín
288ae13958 Merge pull request #4687 from consul/phases_image_button
Fix "Add image" button styles in budget phases
2021-09-14 13:19:30 +02:00
Javi Martín
7df175d7fa Merge pull request #4668 from consul/official_level_search
Remove official level filter from advanced search
2021-09-14 13:18:55 +02:00
Javi Martín
622b7d2a27 Merge pull request #4661 from consul/remove_devise_async
Remove devise-async dependency
2021-09-13 14:32:40 +02:00
Javi Martín
74013e8a2f Merge pull request #4595 from consul/attachable
Reduce duplication in attachments code
2021-09-13 11:32:43 +02:00
Javi Martín
e2d680947a Add separator in small screen navigation
The "Sign in" or "My account" links and the main navigation are
different elements, and they're in different places on medium and large
screens. Now we're also separating them on small screens.

Since the `.vertical` class in the menu added quite a few styles and it
was difficult to overwrite them, we're simply removing this class from
this element. This way we're also removing the huge space between the
menu button and the first element of the navigation.
2021-09-12 14:20:53 +02:00
Javi Martín
00565bba6a Increase login links touch area on small screens
On small screens, the "Sign in", "Register", "My content", "My account"
and "Sign out" links didn't have much padding nor space between them,
and it was easy to accidentally click the wrong link.

This change also positively affects the menu on medium and large
screens. When one of the options (like "SDG content") had a text
spanning over two lines (like it happens in Swedish), there was barely
any space between those two lines. So we're using `line-height: inherit`
instead and adjusting the padding accordingly.
2021-09-12 14:00:42 +02:00
Javi Martín
4fbe2d99d5 Simplify small screen styles in admin submenu
Some of these styles were redundant and so we can remove them.
2021-09-12 14:00:42 +02:00
Javi Martín
877eb44bd4 Simplify logo layout in admin header
Having the logo inside a list of one item wasn't needed and its classes
conflicted with other elements with the `.menu` class.
2021-09-12 14:00:40 +02:00
Javi Martín
59da7d0af4 Fix "Add image" button styles in budget phases
It was broken since we fixed issues with other image fields in commit
394a94cbf, because there we added a fieldset for the image fields, and
so they inherited the styles in budget phases fields (these styles were
added before it was possible to attach an image to a phase).
2021-09-12 13:47:15 +02:00
Javi Martín
d6fe49ff4f Unify Foundation classes in header menus
In commit 55c3c7987 we updated the admin layout header to use
`class="dropdown menu" data-dropdown-menu` instead of `class="menu"
data-responsive-menu="medium-dropdown"`.

Then, in commit dcec003d0, we updated the public layout header to use
`class="menu" data-responsive-menu="medium-dropdown"` instead of
`class="dropdown menu" data-dropdown-menu`.

Now we're applying the same classes to both, hoping we can get some
consistent styles.

I'm choosing to keep the ones in the public layout because using it I
had less problems when trying to improve the styles of this navigation.
2021-09-12 01:25:10 +02:00
Javi Martín
4ea30da299 Fix line height in subnavigation items
When, on small screens, a navigation element had a very long text
causing it to span over multiple lines, the space between each line was
the same as the space between elements. This made it hard to see where
elements started and ended.

Using a padding to separate the contents of one element and the contents
of the next one solves the issue.
2021-09-12 01:25:10 +02:00
Javi Martín
3347157b43 Remove placeholder in advanced search
When users see a label saying "With the text" and an input field, they
don't usually need a placeholder saying "Write the text". On the
contrary, this text adds noise and is hard to read due to the low
contrast between the color of the placeholder and the color of the
field, making the text an unnecessary distraction.
2021-09-11 17:28:38 +02:00
Javi Martín
9f1f912d84 Remove official level filter from advanced search
User testing has shown this filter isn't really useful and sometimes
makes users wonder what it's about. This is particularly true in CONSUL
installations which don't change the default values (most of them),
since users will see a filter with options like "Official position 1".
2021-09-11 17:28:38 +02:00
Javi Martín
1c973289a8 Remove devise-async dependency
We don't use it since commit 84338592d.
2021-09-11 17:28:19 +02:00
Javi Martín
7bbaad9a19 Extract method for link to remove association text
We had an ultra-long line which was hard to read.
2021-09-11 17:15:47 +02:00
Javi Martín
507fa7c5f5 Remove duplication in attachable fields components
These classes were almost identical.
2021-09-11 17:05:00 +02:00
Javi Martín
e01940c166 Move image/document attachments code to a concern
This way we reduce some of the duplication in these classes.
2021-09-11 17:05:00 +02:00
Javi Martín
b52ceb2c78 Move attachable methods from helpers to models
We were using helper methods inside the model; we might as well include
them in the model and use them from anywhere else.

Note we're using a different logic for images and documents methods.
That's because for images the logic was defined in the helper methods,
but for documents the logic is defined in the Documentable concern. In
the past, different documentable classes allowed different content
types, while imageable classes have always allowed the same content
types.

I'm not sure which method is better; for now, I'm leaving it the way it
was (except for the fact that we're removing the helper methods).
2021-09-11 17:05:00 +02:00
Javi Martín
4d8842c0d4 Remove unneeded helpers inclusion
We aren't using any methods from these helpers in these models.
2021-09-11 17:05:00 +02:00
Javi Martín
d14f6691dc Return document max file size in megabytes
The same way it's done for images.

We were converting the number of megabytes to bytes and then converting
it to megabytes again. Instead, we can leave it as it is and only
convert it to bytes when necessary (only one place).
2021-09-11 17:05:00 +02:00
Javi Martín
30bbd844b5 Merge pull request #4690 from consul/simplify_component_specs
Simplify type and current user in component tests
2021-09-08 17:05:48 +02:00
Javi Martín
53f4770544 Merge pull request #4667 from consul/published_proposals_feed
Do not show unpublished proposals on the homepage
2021-09-08 17:00:01 +02:00
Javi Martín
0a7c50fad8 Merge pull request #4603 from consul/fix_updating_original_translation
Fix updating a translation to its original value
2021-09-08 16:56:24 +02:00
Javi Martín
ce621677a4 Merge pull request #4695 from consul-ml/consul_ml
Machine learning scripts for Related content clustering, Tags generation, and Comments summarisation
2021-09-08 13:10:34 +02:00
Javi Martín
81c836fb9f Remove unneeded sign in tag list component
We don't need to sign in as administrator in order to see the tags;
anyone can see them.
2021-09-08 12:39:36 +02:00
Javi Martín
9247a31e85 Stub current_user in all component tests
The `sign_in(nil)` method was a bit hard to understand IMHO. After all,
in controller and system tests we don't have to specify no user is
signed in; that's the default behavior.

So we're making it the default behavior for component tests as well.
2021-09-08 12:39:36 +02:00
Javi Martín
e97c375063 Add method to stub current_user in component tests
We're choosing `sign_in` instead of `login_as` because IMHO component
tests are more similar to controller tests than they are to system
tests.
2021-09-08 12:39:36 +02:00
Javi Martín
4cbf945228 Infer type for component specs automatically 2021-09-08 12:39:36 +02:00