Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use option-select vs checkboxes for granting permissions #2424

Merged

Conversation

floehopper
Copy link
Contributor

@floehopper floehopper commented Oct 10, 2023

Trello: https://trello.com/c/SfIc6Q2q

The main motivation for these changes is the Licensing app which has a large number of permissions. The recent changes which moved the UI for granting permissions to the GOV.UK Design System have made managing the permissions for the Licensing app unmanageable.

This PR replaces the accordion component where each item of the accordion was a checkboxes component (i.e. a set of checkboxes) with a list of option-select components (each of which has a set of checkboxes within it). We've made this change to both the new invitation ("Create new user") page and the new batch invitation permissions page.

The option-select component gives us something similar to the show/hide toggle which was previously provided by the accordion which is why it no longer makes sense to use the accordion. Also it makes the permissions section more compact which is no bad thing given how long it is! Most importantly the option-select component provides a search filter for the permissions for a given app - this is enabled for apps which have more than 4 permissions which is roughly the point that a scrollbar appears. This addresses the primary motivation which is improving the managability of the Licensing app permissions.

We've also set each option-select component to open on load if any of its permissions are selected and moved any checked permission checkboxes to the top of the list. At the moment this is only relevant to the new invitation page when validation errors have occurred and the form has been re-rendered. This behaviour is very similar to what we did on the users index page.

The use of the option-select component isn't really what it was intended for in that it doesn't control a list of things. However, I don't think it's too far away and it gives us a much better UI.

In making this change I've worked out we don't really need to set the id attribute for each checkbox in UsersHelper#options_for_permission_option_select - the checkboxes component within the option-select component will generate unique id values automatically and we don't need to reference them anywhere. Also we can set the checkbox name at the option-select component level (via its key attribute) rather than having to set it for each of its options in UsersHelper#options_for_permission_option_select. This simplifies the code somewhat.

New invitation page

Screenshot 2023-10-11 at 15 36 48

New batch invitation permissions page

Screenshot 2023-10-11 at 15 36 48

@floehopper floehopper force-pushed the use-option-select-vs-checkboxes-for-granting-permissions branch 3 times, most recently from c776419 to a12bc15 Compare October 11, 2023 13:57
@floehopper floehopper changed the title Spike: Use option-select vs checkboxes for granting permissions Use option-select vs checkboxes for granting permissions Oct 11, 2023
This should have been changed in this earlier commit [1].

[1]: 735fd59
Trello: https://trello.com/c/SfIc6Q2q

The main motivation for these changes is the Licensing app which has a
large number of permissions. The recent changes [1,2] which moved the UI
for granting permissions to the GOV.UK Design System have made managing
the permissions for the Licensing unmanageable.

This replaces the accordion component [3] where each item of the
accordion was a checkboxes component [4] (i.e. a set of checkboxes) with
a list of option-select components [5] (each of which has a set of
checkboxes within it). We've made this change to *both* the new
invitation ("Create new user") page and the new batch invitation
permissions page.

The option-select component gives us something similar to the show/hide
toggle which was previously provided by the accordion which is why it no
longer makes sense to use the accordion. Also it makes the permissions
section more compact which is no bad thing given how long it is! Most
importantly the option-select component gives us the option to enable a
search filter for the permissions for a given app. I plan to make use of
this in a subsequent commit. This will address the primary motivation
which is the unmanagability of the Licensing app permissions.

Note that I've set the `key` attribute of the option-select components
to "not-used" for now, because it's a required attribute but the name of
the checkboxes is being derived from each individual option hash. I plan
to address this in a subsequent commit.

The use of the option-select component isn't really what it was intended
for in that it doesn't *control* a list of things. However, I don't
think it's too far away and it gives us a much better UI.

[1]: #2361
[2]: #2412
[3]: https://components.publishing.service.gov.uk/component-guide/accordion
[4]: https://components.publishing.service.gov.uk/component-guide/checkboxes
[5]: https://components.publishing.service.gov.uk/component-guide/option_select
We don't really need to set the `id` attribute for each checkbox in
`UsersHelper#options_for_permission_option_select` - the checkboxes
component within the option-select component will generate unique `id`
values automatically and we don't need to reference them anywhere. This
simplifies the code somewhat.
Set the name of the permission checkboxes at the option-select component
level (via its `key` attribute) rather than having to set it for each of
its options in `UsersHelper#options_for_permission_option_select`. This
simplifies the code somewhat.
Enable the search filter for the option-select component for
applications which have more than 4 permissions which is roughly the
point that a scrollbar appears. This addresses the primary motivation of
this PR which is to improve the managability of the Licensing app
permissions.
Set each option-select component to open on load only if any of its
permissions are selected. At the moment this is only relevant to the new
invitation page when validation errors have occurred and the form has
been re-rendered. The new batch invitation permissions page currently
never has any validation errors, so we can just hard-code the value of
`closed_on_load` to `true`. This behaviour is very similar to what we
did on the users index page.

Since this behaviour is implemented in JS, it's not possible to test it
in the controller test and it doesn't seem important enough to add an
integration test for it.
I want to be able to use this in the new invitation page and the new
batch invitation permissions page. Moving it to a more generic namespace
will make that easier.
This change ensures any checked permission checkboxes are displayed at
the top of the list of checkboxes for a given application option-select.

At the moment this is only relevant to the new invitation page when
validation errors have occurred and the form has been re-rendered.
Currently the new batch invitation permissions page can never have any
validation errors.

This behaviour is very similar to what we did on the users index page.
@floehopper floehopper force-pushed the use-option-select-vs-checkboxes-for-granting-permissions branch from a12bc15 to 7eb14ee Compare October 11, 2023 14:35
@floehopper floehopper marked this pull request as ready for review October 11, 2023 14:38
Copy link
Contributor

@chrislo chrislo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all looks good to me 👍

@floehopper floehopper merged commit 4bf9257 into main Oct 11, 2023
6 checks passed
@floehopper floehopper deleted the use-option-select-vs-checkboxes-for-granting-permissions branch October 11, 2023 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants