Commit Graph

18014 Commits

Author SHA1 Message Date
Javi Martín
229fe8086a Use a Font Awesome icon in locale switcher
We've deprecated the "icons" font since we started using Font Awesome
two years ago.
2021-07-05 22:27:39 +02:00
Javi Martín
0750166d77 Extract methods in locale switcher 2021-07-05 22:27:39 +02:00
Javi Martín
ff0f2215ea Extract component for locale switcher
Note that in order to simplify the component tests (which for some
reason seem to be whitespace-sensitive), we have to omit whitespace
characters inside the `<option>` tags.

Also note we're simplifying the test with a missing language name; since
a component test doesn't involve a whole request, we don't need a
complex setup (I'm not sure we even need it in system tests).
2021-07-05 22:27:39 +02:00
Javi Martín
7abca09e03 Extract methods in link list component
Since we're simplifying the main method, we can use a view file instead
of the `call` method. This way we make the code more consistent with the
rest of our components, since we always use a separate file.

Doing so generates an extra newline at the end of the generated HTML, so
we need to change a couple of tests a little bit.
2021-07-05 22:27:39 +02:00
Javi Martín
d0243764a2 Extract component to render a list of links
This way it's easier to refactor it and/or change it.

Back in commit c156621a4 I wrote:

> Generally speaking, I'm not a big fan of helpers, but there are
> methods which IMHO qualify as helpers when (...) many Rails helpers,
> like `tag`, follow these principles.

It's time to modify these criteria a little bit. In some situations,
it's great to have a helper method so it can be easily used in view
(like `link_to`). However, from the maintenance point of view, helper
methods are usually messy because extracting methods requires making
sure there isn't another helper method with that name.

So we can use the best part of these worlds and provide a helper so it
can be easily called from the view, but internally make that helper
render a component and enjoy the advantages associated with using an
isolated Ruby class.
2021-07-05 22:27:39 +02:00
Javi Martín
1a477eb511 Remove unneeded optgroup in locale switcher
The `<optgroup>` doesn't make much sense if all options are inside one
group. And the information provided was redundant: when using a select
field having "Language" as a label, it's obvious that the options are
the available languages.

Now that, since now the `<select>` field is smaller, we need to add an
extra padding so the icon doesn't overlap the text.
2021-07-05 22:27:39 +02:00
Javi Martín
93c521bd29 Use labels in language selector tests
This way the test verifies there's a label associated to that form
field.
2021-07-05 22:27:39 +02:00
Javi Martín
554bc926c7 Get current locale from the lang HTML attribute
The language attribute is present in all layouts since commit 025923ac4,
so there's no need to use the language selector locale. Besides, it
wouldn't work if there's only one locale and the language selector isn't
shown.
2021-07-05 22:27:39 +02:00
Javi Martín
3b71974920 Merge pull request #4527 from consul/asset_data_url
Load SVG icons using asset-data-url
2021-07-05 15:27:22 +02:00
Javi Martín
1214e6dd29 Load SVG icons using asset-data-url
Back in commit 925f04e3f3 from pull request #4206 we wrote about our way
to load SVG icons:

> Using this technique will result in one HTTP request per icon, which
> might affect performance

We considered using CSS with Data URIs, and wrote:

> This method does not generate any extra HTTP requests and only
> downloads the icons we need. However, maintaining it is really hard,
> since we need to manually copy all the <svg> code for every icon we
> use, and do it again every time we upgrade Font Awesome.

Back when I wrote that, I didn't know Sass had a function named
`asset-data-url` which generated Data URIs automatically given a
filename. I searched for it, but somehow I only found Compass helpers
doing a similar thing.

Note we're using CSS variables to reduce the size of the generated CSS.
If we used `mask-image: asset-data-url(...)`, the generated CSS would
include the value returned by `asset-data-url` twice: once for the
`mask-image` property and once for the `-webkit-image` property.

The percentage of browsers supporting `mask-image` and not supporting
CSS variables is really small (less than 1%), so in that regard things
remain more or less the same and unsupported browsers will render the
icons using the `font-family: "Font Awesome 5 Free` property.

After these changes, the size of the generated CSS increases from 475KB
to 533KB. If we didn't use CSS variables, the generated CSS would use
591KB.

We believe this is acceptable because the SVG icons we use are very
small files (about 1-1.5KB big) and, downloaded separately, they also
amount to about 45KB, which is similar to the CSS file increase we get.
Using `asset-data-url` we download them in one request instead of having
one request per file (about 35 extra requests).
2021-07-05 13:46:11 +02:00
Javi Martín
9f0858ac40 Merge pull request #4578 from consul/fix_font_icon_content
Fix content and line-height in SVG font icons
2021-07-02 19:16:43 +02:00
Javi Martín
53d49c223e Fix font icon line-height
We forgot to include this property when replacing our use of `%fa-icon`,
and it was causing the admin menu to have a blank space at the bottom.

So we're including it again to make sure nothing else breaks because of
this omition.
2021-07-02 18:33:16 +02:00
Sebastia
171190d170 Merge pull request #4579 from consul/update_core
Update core members
2021-07-02 17:23:36 +02:00
Javi Martín
2ea098cdd9 Update core members 2021-07-02 16:48:28 +02:00
Javi Martín
d8e9dcb92d Fix content property in SVG font icons
In commit 4d49ec8ef we replaced an `@extend .fa-` clause with a
`content: fa-content()` clause.

With the `@extend` clause, the `content:` property appeared wherever the
`.fa-` selector was defined, so we later overwrote it in our `%svg-icon`
selector, which was defined later in the generated CSS.

Defining the property with `content: fa-content()`, on the other hand,
caused the `content:` property to appear wherever we used the mixin with
`@include has-fa-icon`. That meant our `%svg-icon` selector would appear
before it, and would not overwrite it.

We could modify a few things and make the code more complicate in order
to avoid that. In this case, however, it's easier to add an `!important`
flag; after all, it is indeed important that SVG icons have no content
so screen readers don't try to announce illegible characters.
2021-07-02 15:59:15 +02:00
Javi Martín
a2ec33eddc Merge pull request #4577 from consul/admin_polls_sdg
Hide SDG columns on admin polls if SDG feature is disabled
2021-07-02 15:19:18 +02:00
decabeza
3762421247 Do not show SDG columns if disabled 2021-07-02 14:59:31 +02:00
Javi Martín
0a5dd094b3 Merge pull request #4561 from consul/ie_flex
Fix footer overlap on Internet Explorer 11
2021-07-02 13:50:06 +02:00
Javi Martín
0262104cd7 Merge pull request #4516 from consul/reduce_font_awesome
Limit Font Awesome imports to reduce CSS size
2021-07-02 13:49:31 +02:00
Javi Martín
42a7db87cc Merge pull request #4530 from consul/body_background
Reduce duplication in background color definitions
2021-06-30 19:28:54 +02:00
Javi Martín
be109caa59 Merge pull request #4569 from consul/poll_questions_filter
Use a submit button in admin poll question filters
2021-06-30 18:16:59 +02:00
Javi Martín
e4f8f702c7 Use a submit button in admin poll question filters
As mentioned in commit 5214d89c8, using a `<select>` tag which
automatically submits a form on change has a few accessibility issues,
particularly for keyboard users who might accidentally submit the form
while browsing the options.

So we're adding a submit button and removing the "submit on change"
behavior.

Note that, while `<select>` tags have their own usability issues,
alternatives in this case are not obvious because the number of existing
polls could be very low (zero, for instance) or very high (dozens, if
the application has been used for years).

I thought of using a `<datalist>` tag with a regular text input. The
problem here is we don't want to send the name of the poll to the server
(as we would with a `<datalist>` tag); we want to send the ID of the
poll.

Maybe we could add an automplete field instead, providing a similar
funcionality. However, for now we're keeping it simple. This poll
questions page isn't even accessible through the admin menu since commit
83e8d603, so right now anything we change here will be pretty much
useless.
2021-06-30 17:56:47 +02:00
Javi Martín
b7f6c4c43e Fix footer on Internet Explorer 11
There are two bugs in Internet Explorer which caused our footer to be
rendered incorrectly.

First, the `flex: 1` property doesn't work so well when `flex-direction`
is set to `column`. We're replacing it with `flex-grow: 1`. No need to
set other `flex-basis` nor `flex-shrink` in this case since in this case
the default values will work just fine.

Second, it didn't handle the body height being set to `100%` so well,
and the footer was rendered after that 100% point, even if the content
still continued.

So we're using `min-height` instead, which is actually a bit more
accurate (since the body is usually taller than the document root
element). This causes a different issue since on IE the `flex-grow: 1`
property becomes useless. This will only affect IE users with very large
screens, though, and it's way better than rendering the footer
overlapping the main content, so we can live with that. The page won't
look as great as in other browser, but it will still be usable.
2021-06-30 16:43:03 +02:00
Javi Martín
366fd630dc Use $table-background to set table colors
This way it's possible to customize these colors by just changing a
variable.

The code is now quite a bit hacky; since I'm not an expert in color
design, I didn't want to change the colors we were using in case it made
the application have less appeal.

If slightly changing these colors isn't a problem, we could use
Foundation's defaults to simplify the code, maybe just changing the
`$table-color-scale` variable.
2021-06-30 16:42:54 +02:00
Javi Martín
73fe89829d Use $body-background to remove color duplication
We're using `background: #fff` and `background: $white` in many places.
Sometimes we mean "use the same background as the body", which means if
we change the body background so it's, let's say, dark, we'll also have
to change all these places.

So now we're using `$body-background` in more places, so changing the
general background color is easier.

There are still some places where we use `#fff` or `$white`. Sometimes
it's hard to tell whether the intention is "use a white background here"
or "use the same background as the body here". When in doubt, I've left
it the way it was.

Just for testing purposes, I've tested locally how things would look
like if we added this code to `_consul_custom_overrides.scss`:

```
$body-background: #fea;
$card-background: $body-background;
$tab-background: $body-background;
$tab-content-background: $body-background;
$table-background: $body-background;
```

Or:

```
$body-background: #333;
$text: #fcfcfc;
$body-font-color: $text;
$card-background: $body-background;
$tab-background: $body-background;
$tab-content-background: $body-background;
$table-background: $body-background;
```

Testing shows we've still got a long way to go to make it easy to add
custom color themes, since there are many custom colors in the code.
Hopefully these changes bring us one step closer.
2021-06-30 16:42:53 +02:00
Javi Martín
c3a329a6f6 Remove unnecessary background color definitions
These elements already inherit these background colors form their parent
elements. Defining them explicitly makes it harder to change them and it
also makes it harder to customize the styles in other CONSUL
installations.
2021-06-30 16:42:53 +02:00
Javi Martín
ae66211c34 Simplify colors in dashboard icons
We can just inherit the colors; no need to define them explicitly.
2021-06-30 16:42:53 +02:00
Javi Martín
422404085f Extract poll questions filter to a component 2021-06-30 16:42:23 +02:00
Javi Martín
ccbc708b5b Simplify poll select options helper
The `include_all` parameter was always used, and the option was
redundant because we already had a prompt offering the same
functionality.

I guess one possible reason was users would want to filter by all polls,
and having to click on "select a poll" to do so wasn't that intuitive.
So we're using "All" as the prompt instead.
2021-06-30 16:42:23 +02:00
Javi Martín
4d49ec8efe Limit Font Awesome imports to reduce CSS size
We were using Font Awesome fonts and selectors to support the browsers
which don't support mask images (at the time of writing, about 5% of the
browsers). However, we were only importing the selectors in order to
extend them. This resulted in our compiled CSS including styles for
every Font Awesome icon (currenty, more than a thousand), even if we
only use a few of them.

So we're using Font Awesome variables instead of using the selectors it
provides. Since variables are only compiled in the CSS if they're
actually used, this reduces the size of our compiled CSS considerably.
In production environments, the size is reduced from 539KB to 475KB,
meaning we reduce its size in about 12%.

The downside here is we can't easily use Font Awesome variables in our
Sass mixins because we can't use interpolation in variable names (that
is, we can't use `$fa-var-#{icon}`). So we're using a map containing all
Font Awesome variables in order to access it in the mixin.

Note installations using `.fa-*` selectors will now have to add extra
`@import` clauses.
2021-06-30 16:41:39 +02:00
Javi Martín
6b7792937f Merge pull request #4572 from consul/add_missing_expectation
Add missing expectation to related content test
2021-06-30 16:32:19 +02:00
Javi Martín
58d123ad51 Merge pull request #4552 from consul/table_icons_with_text
Use icons with text in admin table actions
2021-06-30 16:31:18 +02:00
Javi Martín
db4a262a0d Merge pull request #4571 from consul/campaigns_specs
Make campaign specs more robust
2021-06-30 16:16:28 +02:00
Javi Martín
bf5afd8e7c Add missing expectation to related content test
It looks like we accidentally missed it while rebasing commit
48dc72cea9.
2021-06-30 16:13:37 +02:00
Javi Martín
2eb02d555a Merge pull request #4568 from consul/executions_filters
Use a submit button in budget executions filters
2021-06-30 16:06:18 +02:00
Javi Martín
28e720a1ec Make sure we use non-existent IDs in campaign test
Previously, depending on the database status, it could be possible that
the ID of the campaign2 record was exactly 999 and this test could fail.
2021-06-30 16:00:07 +02:00
Javi Martín
855f47f386 Create campaings before running campaigns tests
We were defining campaigns with `let`. That meant they weren't created
until these methods were used in the tests.

For the test "Do not track erroneous track_ids", that meant the line
`expect(page).not_to have_content campaign2.name.to_s` wasn't really
testing anything, since before this line is executed, the campaign2
wasn't in the database at all, and so obviously its name wouldn't be on
the stats page.

For the test "Track email templates", it meant we were creating the
campaign2 record after visiting the campaign1 page with the browser.
Creating records in the tests after starting the browser might be the
reason why this test has recenty failed in our CI [1]:

 1) Email campaigns Track email templates
     Failure/Error: ds.add params[:event].titleize, Ahoy::Event.where(
                    name: params[:event]).group_by_day(:time).count
     ActiveRecord::StatementInvalid:
       PG::ProtocolViolation: ERROR:  bind message supplies 0
       parameters, but prepared statement "" requires 1
     # ./app/controllers/admin/api/stats_controller.rb:13:in `show'

Using `let!` to create the campaings before the browser starts improves
the situation.

[1] https://github.com/consul/consul/runs/2952333023
2021-06-30 16:00:00 +02:00
Javi Martín
450d954526 Don't add default margin to font awesome icons
We were removing the margin half of the time, and sometimes removing it
made us use `!important` rules.
2021-06-30 15:01:47 +02:00
Javi Martín
5531a0b2bc Simplify action links in budgets table
The word "budget" in the "Preview budget" link is redundant.

On the other hand, the words "Manage", Edit" and "Admin" are not
really necessary in my humble opinion. Just like in the admin
navigation menu we use "Participatory budgets" instead of "Manage
Participatory budgets", the fact that we're going to manage or
admin or edit something can be deduced from the fact that we're in
the admin section.

Besides, it isn't clear to me why we use "Manage" for projects,
"Edit" for heading groups and "Admin" for ballots. The differences
between these three concepts might be too subtle for me.

The previous paragraphs haven't been corroborated with real users,
though, so I might be mistaken and we might need to revisit these
links in the future.

These actions still take quite a lot of space. Maybe in the future we
could remove the "delete" icon, at least on budgets which cannot be
deleted.
2021-06-30 14:33:37 +02:00
Javi Martín
6f04c8f057 Use conventions in page actions texts
We use the words "Manage" and "View" in other places; we don't use the
word "See" as often.
2021-06-30 14:33:37 +02:00
Javi Martín
7d590031f5 Remove redundant words in edit and destroy links
When we see a list of, let's say, banners, and each one has a link to
edit them, the word "banner" in the text "edit banner" is redundant and
adds noise; even for users with cognitive disabilities, it's obvious
that the "edit" link refers to the banner.
2021-06-30 14:33:37 +02:00
Javi Martín
25e9065913 Use icons with text in admin table actions
In commit 9794ffbbf, we replaced "buttons" with icons in order to make
the admin interface consistent with the planned budget investments
redesign.

However, using icons has some issues. For once, icons like a trash for
the "delete" action might be obvious, but other icons like "confirm
moderation" or "send pending" might be a bit confusing.

It's true that we were adding tooltips on hover. We tried two
approaches: using Foundation's tooltips and using CSS tooltips.

Foundation tooltips are not activated on focus (only on hover), while
CSS tooltips always appear below the icon, which might be a problem when
the icons are at the bottom of the screen (one of our milestone tests
was failing because of that and we can now run it with JavaScript
enabled).

Both Foundation and CSS tooltips have other issues:

* They force users to make an extra step and move the mouse over the
  link just to know what the link is about
* They aren't available on touch screens, so these users will have to
  memorize what each icon does
* They are not hoverable, and making them hoverable would cause a
  different issue because the tooltip might cover links below it, making
  it impossible to click these links without moving the mouse away
  first
* They are not dismissable, which is considered an accessibility issue
  and a requirement in the Web Content Accessibility Guidelines [1]

For all these reasons, we're using both texts and icons. As Thomas
Byttebier said "The best icon is a text label [2]". Heydon Pickering
also makes a point towards providing text alongside icons in his book
"Inclusive Components" [3].

Note that, since we're now adding text and some of the colors we use for
actions are hard to read against a white/gray background, we're making a
few colors darker.

With these changes, actions take more space in the admin table compared
to the space they took in version 1.3, but they are more usable and
accessible while they still take less space than they did in version
1.2.

[1] https://www.w3.org/WAI/WCAG21/Understanding/content-on-hover-or-focus
[2] https://thomasbyttebier.be/blog/the-best-icon-is-a-text-label
[3] https://inclusive-components.design/tooltips-toggletips/
2021-06-30 14:33:37 +02:00
Javi Martín
db55a744ec Include disabled state in base button mixin
So all disabled buttons have the same styles.
2021-06-30 14:14:43 +02:00
Javi Martín
614e6da92b Use a submit button in budget executions filters
As mentioned in commit 5214d89c8, there are several issues with
submitting a form when a `<select>` tag changes. In particular, keyboard
users might accidentally fire the event while browsing the options, and
screen reader users will find a form with no obvious way to submit it.

In this case, there's an extra problem: in commit be8a0dbe8 we added a
second `<select>` field to this form, which also submitted on change.
Sometimes users changed one of the values and wanted to change the other
value as well before submitting the form. However, it wasn't possible,
because we would submit it before they had a chance to change the second
value.

So now we don't submit the form on change and add a submit button. This
is similar to what we do in the "Advanced filters" we use in several
places.
2021-06-30 14:14:43 +02:00
Javi Martín
d4bebc810a Merge pull request #4520 from consul/border_color
Simplify using current color on borders
2021-06-30 13:54:55 +02:00
Javi Martín
ee4ef8d3a5 Use labels to select filters in executions tests
This way we check there's a label associated to these fields.
2021-06-29 20:07:55 +02:00
Javi Martín
d8d5b7f60a Extract budget executions filters to a component 2021-06-29 20:07:55 +02:00
Javi Martín
b2a05322fd Simplify using current color on borders
Using `currentcolor` is IMHO more expressive, since it shows the
intention of styling the border with the same color as the text.

This is particularly useful for CONSUL installations using custom
styles. Consider the following code:

```
.is-active {
  border: 1px solid $brand;
  color: $brand;
}
```

If we'd like to customize the way active items look, we'd have to
override two colors:

```
.is-active {
  border: 1px solid $brand-secondary;
  color: $brand-secondary;
}
```

Consider the scenario where we use `currentcolor` (which is the default
border color):

```
.is-active {
  border: 1px solid;
  color: $brand;
}
```

Now we only need to override one color to change the styles:

```
.is-active {
  color: $brand-secondary;
}
```
2021-06-29 20:03:36 +02:00
Javi Martín
7053b17e64 Simplify setting border on active menu elements
Since we are using the same color as the text color in both the public
and admin areas, we can omit the border color completely. Since now
admin elements get the exact same border, we can remove this border so
they'll inherit the same border as used in the public area.
2021-06-29 20:03:36 +02:00
Javi Martín
2efc307e59 Simplify changing "delete/remove" links styles
Since we're only changing the style of the border in one case and the
color in the other case, we don't have to duplicate the code for every
property.

This makes it easier for other CONSUL installations to customize these
borders.
2021-06-29 20:03:36 +02:00