Consistent default active tab on the CSP settings form

Created on 1 February 2024, 5 months ago
Updated 15 June 2024, 2 days ago

Problem/Motivation

My team lead that knows a lot more about CSP than I do raised this in a work chat channel and it sounded like a legit quality of life fix that could be a quick win.

Steps to reproduce

Use the CSP settings form at any time.

Proposed resolution

Swap the default tab that is selected.

User interface changes

Default selected tab when you first hit the form.

API changes

None

Data model changes

None

πŸ“Œ Task
Status

Fixed

Version

2.0

Component

Code

Created by

πŸ‡³πŸ‡ΏNew Zealand Gold 20 minutes in the future

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @Gold
  • Merge request !30Swap policy type order in CspSettingsForm β†’ (Closed) created by Gold
  • Pipeline finished with Success
    5 months ago
    Total: 153s
    #86340
  • πŸ‡¨πŸ‡¦Canada gapple

    I think I agree with that change - IIRC, my thought was that viewing that there is an enforced policy and its values would be important.
    But if editing is the priority then having the report-only policy default makes sense. There's also the tab summary which indicates that a policy is enabled (and how many directives), and ✨ Copy configuration between report-only and enforced Active would help with suggested workflow of tweaking the report-only policy, then copying it to enforced after testing.

    I would not switch the order of the form tabs though. There is a following line that causes the switch to have the enforced policy tab as default if it is enabled:

          if ($config->get($policyTypeKey . '.enable')) {
            $form['policies']['#default_tab'] = 'edit-' . $policyTypeKey;
          }
    
  • πŸ‡³πŸ‡ΏNew Zealand Gold 20 minutes in the future

    @grapple, I did look at that snippet and tracked back to where the config for that value was being set. It started getting a bit convoluted though and I had a bit of time pressure.

    This value seems to be being set in 1 place when the form is first submitted in CspSettingsForm.php:631.

    I tried flipping the order that $policyTypeKey was processing at L626 but that didn't make any difference either.

    I think the issue is tying the $form['policies']['#default_tab'] to the value in that config var.

    An alternative could be to add #weight to the $form[$policyTypeKey] array.

    I'll push an update for that in a moment. Let me know what you think.

  • Pipeline finished with Success
    4 months ago
    Total: 151s
    #87524
    • gapple β†’ committed b34ab2fd on 2.x
      Issue #3418744: Always set report-only options as default active tab
      
    • gapple β†’ committed b9cffa1e on 8.x-1.x
      Issue #3418744: Always set report-only options as default active tab
      
  • Status changed to Fixed 4 months ago
  • πŸ‡¨πŸ‡¦Canada gapple

    I've just set the report-only options to always be default - I don't think having it switch to enforced if that's the only enabled policy provides much benefit, and having it always show the first possible tab is clear and consistent behaviour (that also reduces the likelyhood of making inadvertent changes to the enforced policy).

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024