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

Ticket #2484: Dynamic portfolio fields #2548

Merged
merged 16 commits into from
Aug 14, 2024

Conversation

zandercymatics
Copy link
Contributor

@zandercymatics zandercymatics commented Aug 7, 2024

Ticket

Resolves #2484

Changes

  • Selecting federal agency dynamically changes organization type to federal.
  • The Federal Agency dynamically changes the SO to be the SO for that Agency, if it exists in the table.
    • You either must run the load_senior_official_table script for this to work, as no data exists otherwise - or create dummy federal agencies
  • The urbanization field on dynamically shows if the user selects PR, otherwise it does not show.
  • Adds some error handling in the action needed dropdown javascript function (was causing issues on this page)

Context for reviewers

This PR attaches some javascript logic to the Portfolio page.

It does the following:

  • The urbanization field is hidden when not Puerto Rico, and shown otherwise
  • When a federal_agency is selected, the organization_type will switch to "federal" if it is not empty or "Non-Federal Agency". Otherwise, if "Non-Federal Agency" is selected, type federal will be deselected.
  • When a federal_agency is selected, the senior official on the underlying federal_agency will auto-populate
    • This will only work if you run the load_senior_officials script

Note:
As noted, this ticket automatically populates the senior_official and organization_type fields based off of the current federal_agency selection.

Due to the nature of the data, senior_official required an admin-only API that returns the field id based off of the federal agency name. This is accessible to analysts and superusers, though do note that the portfolio page isn't yet visible to analysts yet (as that comes down the road).

Setup

  1. Run the load_senior_officials_table script. Instructions here.
  2. Add a portfolio in /admin and modify the state field, and the federal_agency field.

Code Review Verification Steps

As the original developer, I have

Satisfied acceptance criteria and met development standards

  • Met the acceptance criteria, or will meet them in a subsequent PR
  • Created/modified automated tests
  • Added at least 2 developers as PR reviewers (only 1 will need to approve)
  • Messaged on Slack or in standup to notify the team that a PR is ready for review
  • Changes to “how we do things” are documented in READMEs and or onboarding guide
  • If any model was updated to modify/add/delete columns, makemigrations was ran and the associated migrations file has been commited.

Ensured code standards are met (Original Developer)

  • All new functions and methods are commented using plain language
  • Did dependency updates in Pipfile also get changed in requirements.txt?
  • Interactions with external systems are wrapped in try/except
  • Error handling exists for unusual or missing values

Validated user-facing changes (if applicable)

  • New pages have been added to .pa11yci file so that they will be tested with our automated accessibility testing
  • Checked keyboard navigability
  • Tested general usability, landmarks, page header structure, and links with a screen reader (such as Voiceover or ANDI)
  • Add at least 1 designer as PR reviewer

As a code reviewer, I have

Reviewed, tested, and left feedback about the changes

  • Pulled this branch locally and tested it
  • Reviewed this code and left comments
  • Checked that all code is adequately covered by tests
  • Made it clear which comments need to be addressed before this work is merged
  • If any model was updated to modify/add/delete columns, makemigrations was ran and the associated migrations file has been commited.

Ensured code standards are met (Code reviewer)

  • All new functions and methods are commented using plain language
  • Interactions with external systems are wrapped in try/except
  • Error handling exists for unusual or missing values
  • (Rarely needed) Did dependency updates in Pipfile also get changed in requirements.txt?

Validated user-facing changes as a developer

  • New pages have been added to .pa11yci file so that they will be tested with our automated accessibility testing

  • Checked keyboard navigability

  • Meets all designs and user flows provided by design/product

  • Tested general usability, landmarks, page header structure, and links with a screen reader (such as Voiceover or ANDI)

  • Tested with multiple browsers, the suggestion is to use ones that the developer didn't (check off which ones were used)

    • Chrome
    • Microsoft Edge
    • FireFox
    • Safari
  • (Rarely needed) Tested as both an analyst and applicant user

Note: Multiple code reviewers can share the checklists above, a second reviewers should not make a duplicate checklist

As a designer reviewer, I have

Verified that the changes match the design intention

  • Checked that the design translated visually
  • Checked behavior
  • Checked different states (empty, one, some, error)
  • Checked for landmarks, page heading structure, and links
  • Tried to break the intended flow

Validated user-facing changes as a designer

  • Checked keyboard navigability

  • Tested general usability, landmarks, page header structure, and links with a screen reader (such as Voiceover or ANDI)

  • Tested with multiple browsers (check off which ones were used)

    • Chrome
    • Microsoft Edge
    • FireFox
    • Safari
  • (Rarely needed) Tested as both an analyst and applicant user

Screenshots

@zandercymatics zandercymatics changed the title (Draft) Ticket #2484: Dynamic portfolio fields (Draft) (on-getgov-meoward) Ticket #2484: Dynamic portfolio fields Aug 7, 2024
Copy link

github-actions bot commented Aug 7, 2024

🥳 Successfully deployed to developer sandbox meoward.

Copy link

github-actions bot commented Aug 7, 2024

🥳 Successfully deployed to developer sandbox meoward.

Copy link

github-actions bot commented Aug 8, 2024

🥳 Successfully deployed to developer sandbox meoward.

Copy link

github-actions bot commented Aug 8, 2024

🥳 Successfully deployed to developer sandbox meoward.

Copy link

github-actions bot commented Aug 8, 2024

🥳 Successfully deployed to developer sandbox meoward.

Copy link

github-actions bot commented Aug 8, 2024

🥳 Successfully deployed to developer sandbox meoward.

Copy link

github-actions bot commented Aug 8, 2024

🥳 Successfully deployed to developer sandbox meoward.

@zandercymatics zandercymatics changed the title (Draft) (on-getgov-meoward) Ticket #2484: Dynamic portfolio fields (on-getgov-meoward) Ticket #2484: Dynamic portfolio fields Aug 8, 2024
@Matt-Spence Matt-Spence self-assigned this Aug 9, 2024
Copy link

🥳 Successfully deployed to developer sandbox meoward.

Copy link

🥳 Successfully deployed to developer sandbox meoward.

@zandercymatics zandercymatics changed the title (on-getgov-meoward) Ticket #2484: Dynamic portfolio fields (on getgov-litterbox) Ticket #2484: Dynamic portfolio fields Aug 12, 2024
Copy link

🥳 Successfully deployed to developer sandbox meoward.

@zandercymatics
Copy link
Contributor Author

@Matt-Spence Those changes are ready!

Copy link
Contributor

@Matt-Spence Matt-Spence left a comment

Choose a reason for hiding this comment

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

Nice changes

@rachidatecs rachidatecs self-assigned this Aug 14, 2024
Copy link
Contributor

@rachidatecs rachidatecs left a comment

Choose a reason for hiding this comment

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

Will run code and finalize review next.



@login_required
@staff_member_required
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems redundant with the superuser and analyst checks you're doing below. That's not a bad thing, but I'm wondering why you bothered with the decorator?

Copy link
Contributor Author

@zandercymatics zandercymatics Aug 14, 2024

Choose a reason for hiding this comment

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

This decorator redirects you to the admin login page and basically does the default django checks for admin perms. Tiny QOL thing, otherwise you do get blocked but you can technically still """access""" the endpoint

"""Save override for custom properties"""

# The urbanization field is only intended for the state_territory puerto rico
if self.state_territory != self.StateTerritoryChoices.PUERTO_RICO and self.urbanization:
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs a unit test


let emailWasSent = document.getElementById("action-needed-email-sent");
if (!emailWasSent) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Line 534 should be handling this and !actionNeededEmail || !actionNeededReasonDropdown cases

Copy link
Contributor Author

@zandercymatics zandercymatics Aug 14, 2024

Choose a reason for hiding this comment

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

I added these because this script was failing on the portfolio page, causing script execution to stop (on textContent because the query returned none). That said I can simplify these checks to just check on if action-needed-emails-data exists or not before trying to do .textContent

src/registrar/assets/js/get-gov-admin.js Show resolved Hide resolved
src/registrar/assets/js/get-gov-admin.js Outdated Show resolved Hide resolved
}

// $ symbolically denotes that this is using jQuery
let $federalAgency = django.jQuery("#id_federal_agency");
Copy link
Contributor

Choose a reason for hiding this comment

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

Q: Why use django.JQuery instead of getElement or querySelector?

Copy link
Contributor Author

@zandercymatics zandercymatics Aug 14, 2024

Choose a reason for hiding this comment

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

Ah, its because everywhere else in the app federal agency is a select2 (autocomplete field). The portfolio page is still undergoing some work - so its likely that this will be added to that as well. Doing it this way gives us out of the box support so we don't have to alter this script when we do.

For context: you can't do .value on Select2 objects. You can only manipulate them through jQuery, its a quirk of that particular library. Went down that rabbit hole a few tickets ago

src/registrar/assets/js/get-gov-admin.js Outdated Show resolved Hide resolved
src/registrar/assets/js/get-gov-admin.js Outdated Show resolved Hide resolved
Copy link

🥳 Successfully deployed to developer sandbox meoward.

Copy link

🥳 Successfully deployed to developer sandbox meoward.

@zandercymatics
Copy link
Contributor Author

@rachidatecs Got your changes in. Pushing them up to litterbox now

Copy link

🥳 Successfully deployed to developer sandbox meoward.

@rachidatecs
Copy link
Contributor

What does that mean?

"Otherwise, if "Non-Federal Agency" is selected, type federal will be deselected."

@zandercymatics
Copy link
Contributor Author

@rachidatecs Basically, the organization_type field will be set to federal automatically UNLESS its Non-Federal Agency. If it is, it'll set the field to None (assuming it isn't another value like County or something)

@zandercymatics zandercymatics changed the title (on getgov-litterbox) Ticket #2484: Dynamic portfolio fields Ticket #2484: Dynamic portfolio fields Aug 14, 2024
Copy link

🥳 Successfully deployed to developer sandbox meoward.

@zandercymatics zandercymatics merged commit 9a55ade into main Aug 14, 2024
10 checks passed
@zandercymatics zandercymatics deleted the meoward/2484-dynamic-portfolio-fields branch August 14, 2024 18:53
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.

Analyst: On portfolio add/update pages show fields dynamically
4 participants