Skip to content

Frontend/compact states from server#716

Merged
isabeleliassen merged 6 commits intocsg-org:developmentfrom
InspiringApps:frontend/compact-states-from-server
Apr 11, 2025
Merged

Frontend/compact states from server#716
isabeleliassen merged 6 commits intocsg-org:developmentfrom
InspiringApps:frontend/compact-states-from-server

Conversation

@jsandoval81
Copy link
Copy Markdown
Collaborator

@jsandoval81 jsandoval81 commented Apr 7, 2025

Requirements List

  • yarn install --ignore-engines

Description List

  • Added endpoint calls to new server endpoints for fetching compact states
  • Added store actions to invoke new endpoint calls, including a new loading state
  • Updated setCurrentCompact action to fetch compact states as needed
  • Updated setCurrentCompact call sites to ensure async compatibility
  • Minor update in edit-user state list for consistency
  • Updated browserlist build dependency

Draft Todo

Testing List

  • yarn test:unit:all should run without errors or warnings
  • yarn serve should run without errors or warnings
  • yarn build should run without errors or warnings
  • Code review
  • Test all state-select lists in app UI to make sure they are populated correctly
    • Logged-out public search UI
    • Logged-in Staff license search UI
    • Logged-in Staff user edit & invite UI
    • Compact-switching (for users with multiple compacts)
    • etc.

Closes #663

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced API endpoints to fetch and deliver compact state data for both authenticated and public users.
    • Added a new constant for compact states with U.S. postal abbreviations.
    • Added a computed property to dynamically retrieve and update state options based on the current compact.
  • Refactor

    • Simplified compact configuration by streamlining member state details.
    • Enhanced conditional state updates in compact selection and improved asynchronous operations for smoother UI transitions.
  • Tests

    • Expanded test coverage to validate compact state fetching and ensure reliable user interactions.
    • Updated tests to utilize enumerated types for improved type safety.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 7, 2025

Walkthrough

This pull request introduces a new dependency and refines the handling of compact state data throughout the application. It removes detailed member state arrays from configuration files, updates component and test logic to properly await asynchronous operations, and adds new API methods and corresponding store actions/mutations for fetching compact states. The changes also update model and test validations to reflect the simplified member state structure, enhancing overall state management.

Changes

File(s) Change Summary
webroot/package.json Added dependency "caniuse-lite": "^1.0.30001709".
webroot/src/app.config.ts Removed member state arrays in compacts object and replaced them with empty objects.
webroot/src/components/CompactSelector/CompactSelector.ts, webroot/src/router/index.ts, webroot/src/components/Licensee/LicenseeList/LicenseeList.ts, webroot/src/components/StateUpload/StateUpload.spec.ts Updated dispatch logic for setCurrentCompact and modified methods to properly await asynchronous store dispatches.
webroot/src/components/Page/PageContainer/PageContainer.ts Extended isLoading computed property to include isLoadingCompactStates.
webroot/src/models/Compact/Compact.model.spec.ts, webroot/src/models/Compact/Compact.model.ts, webroot/src/models/StaffUser/StaffUser.model.spec.ts Updated Compact and StaffUser model tests by removing the compactConfigs import/mapping and adjusting test expectations for member states.
webroot/src/network/data.api.ts, webroot/src/network/mocks/mock.data.api.ts, webroot/src/network/userApi/data.api.ts Added new methods getCompactStates and getCompactStatesPublic to fetch compact state data from corresponding endpoints, plus necessary import and mapping updates in mocks.
webroot/src/network/mocks/mock.data.ts Added new constant compactStates with an array of state data objects (compact and postal abbreviations).
webroot/src/store/user/user.actions.ts, webroot/src/store/user/user.mutations.ts, webroot/src/store/user/user.spec.ts, webroot/src/store/user/user.state.ts Introduced new actions, mutations, and a state property (isLoadingCompactStates) to manage the fetching process and loading state for compact states.

Sequence Diagram(s)

sequenceDiagram
    participant UI as User Interface
    participant Store as User Store
    participant API as Data API
    participant Backend as Server API

    UI->>Store: setCurrentCompact(compact)
    Store->>Store: Dispatch getCompactStatesRequest
    Store->>API: getCompactStates(compact)
    API->>Backend: GET /v1/compacts/{compact}/jurisdictions
    Backend-->>API: Return compact states data
    API-->>Store: Resolve Promise with states
    Store->>Store: Commit GET_COMPACT_STATES_SUCCESS mutation
    Store->>UI: Update UI with compact states
Loading

Assessment against linked issues

Objective Addressed Explanation
Pull list of configured states from backend to populate list of possible staff user state invites (#663)

Suggested reviewers

  • carlsims
  • ChiefStief
  • jlkravitz
  • isabeleliassen

Poem

I'm a hopping rabbit in the code forest,
Leaping through API calls and async quests.
Compact states fetched with a gentle hop,
Await and commit until the data stops.
In every change I find a burrow of cheer –
CodeRabbit's magic is thriving right here!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Free

📥 Commits

Reviewing files that changed from the base of the PR and between d7d2a74 and aa6d0b6.

📒 Files selected for processing (3)
  • webroot/src/models/Compact/Compact.model.ts (1 hunks)
  • webroot/src/network/mocks/mock.data.ts (1 hunks)
  • webroot/src/store/user/user.spec.ts (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • webroot/src/models/Compact/Compact.model.ts
  • webroot/src/network/mocks/mock.data.ts
  • webroot/src/store/user/user.spec.ts

Note

🎁 Summarized by CodeRabbit Free

Your organization has reached its limit of developer seats under the Pro Plan. For new users, CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please add seats to your subscription by visiting https://app.coderabbit.ai/login.If you believe this is a mistake and have available seats, please assign one to the pull request author through the subscription management page using the link above.

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@jsandoval81
Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 7, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 008e478 and 2450e9f.

⛔ Files ignored due to path filters (1)
  • webroot/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (18)
  • webroot/package.json (1 hunks)
  • webroot/src/app.config.ts (1 hunks)
  • webroot/src/components/CompactSelector/CompactSelector.ts (1 hunks)
  • webroot/src/components/Licensee/LicenseeList/LicenseeList.ts (1 hunks)
  • webroot/src/components/Page/PageContainer/PageContainer.ts (1 hunks)
  • webroot/src/components/StateUpload/StateUpload.spec.ts (1 hunks)
  • webroot/src/models/Compact/Compact.model.spec.ts (2 hunks)
  • webroot/src/models/Compact/Compact.model.ts (1 hunks)
  • webroot/src/models/StaffUser/StaffUser.model.spec.ts (1 hunks)
  • webroot/src/network/data.api.ts (1 hunks)
  • webroot/src/network/mocks/mock.data.api.ts (3 hunks)
  • webroot/src/network/mocks/mock.data.ts (1 hunks)
  • webroot/src/network/userApi/data.api.ts (2 hunks)
  • webroot/src/router/index.ts (1 hunks)
  • webroot/src/store/user/user.actions.ts (1 hunks)
  • webroot/src/store/user/user.mutations.ts (2 hunks)
  • webroot/src/store/user/user.spec.ts (6 hunks)
  • webroot/src/store/user/user.state.ts (2 hunks)
🧰 Additional context used
🧬 Code Definitions (7)
webroot/src/network/mocks/mock.data.api.ts (2)
webroot/src/network/mocks/mock.data.ts (1)
  • compactStates (1055-1076)
webroot/src/models/State/State.model.ts (1)
  • StateSerializer (54-70)
webroot/src/components/CompactSelector/CompactSelector.ts (1)
webroot/src/models/Compact/Compact.model.ts (1)
  • CompactSerializer (80-90)
webroot/src/network/data.api.ts (3)
webroot/src/pages/PublicLicensingDetail/PublicLicensingDetail.ts (1)
  • compact (48-52)
webroot/src/pages/LicensingDetail/LicensingDetail.ts (1)
  • compact (59-63)
webroot/src/network/userApi/data.api.ts (1)
  • userDataApi (358-358)
webroot/src/router/index.ts (1)
webroot/src/models/Compact/Compact.model.ts (1)
  • CompactSerializer (80-90)
webroot/src/models/Compact/Compact.model.spec.ts (5)
webroot/src/store/user/user.state.ts (1)
  • State (19-31)
webroot/src/models/State/State.model.ts (1)
  • State (21-49)
webroot/src/store/pagination/pagination.state.ts (1)
  • State (11-16)
webroot/src/models/Compact/Compact.model.ts (2)
  • CompactSerializer (80-90)
  • Compact (39-75)
backend/compact-connect/lambdas/nodejs/lib/models/compact.ts (1)
  • Compact (6-17)
webroot/src/store/user/user.actions.ts (3)
webroot/src/store/user/user.state.ts (1)
  • state (33-45)
webroot/src/network/data.api.ts (1)
  • dataApi (330-330)
webroot/src/network/mocks/mock.data.api.ts (1)
  • dataApi (324-324)
webroot/src/store/user/user.mutations.ts (2)
webroot/src/store/user/user.state.ts (1)
  • state (33-45)
webroot/src/network/mocks/mock.data.ts (1)
  • compactStates (1055-1076)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: CheckWebroot
🔇 Additional comments (28)
webroot/package.json (1)

19-19: LGTM: Added caniuse-lite dependency

This addition supports the browserlist build dependency update mentioned in the PR objectives.

webroot/src/app.config.ts (1)

217-219: LGTM: Removed hardcoded member states

The member states have been removed from the compact configurations, which aligns with the PR objective to fetch compact states from the server instead of using static configuration.

webroot/src/components/StateUpload/StateUpload.spec.ts (1)

30-30:

Details

✅ Verification successful

Good improvement: Added await to setCurrentCompact dispatch

Added await to properly handle the now-asynchronous setCurrentCompact action, preventing potential race conditions in tests.


🏁 Script executed:

#!/bin/bash
# Check for any other tests that might need the same await pattern for setCurrentCompact
rg "dispatch\('user/setCurrentCompact" -A 1 -B 1 --glob "*.spec.ts" | grep -v "await.*dispatch\('user/setCurrentCompact"

Length of output: 152


Action Required: Verify Await Usage in Other Tests

The asynchronous dispatch fix for setCurrentCompact in webroot/src/components/StateUpload/StateUpload.spec.ts (line 30) is a good improvement. However, the original verification script failed due to regex-escaping issues. Please manually verify that all test files calling
dispatch('user/setCurrentCompact', …) have the correct await pattern.

As a next step, consider running a revised command like:

Manually inspect the output to ensure no instances are missing the await keyword.


🏁 Script executed:

#!/bin/bash
# Verify that all occurrences of dispatch('user/setCurrentCompact') in *.spec.ts files include "await"
rg "dispatch\\('user/setCurrentCompact" --glob "*.spec.ts" -A 1 -B 1 | grep -v "await"

Length of output: 658


Await Fix Verified for setCurrentCompact Dispatch

The asynchronous dispatch fix in webroot/src/components/StateUpload/StateUpload.spec.ts has been correctly applied (line 30). Our verification—despite the extraneous context from other test files—shows no unawaited calls to dispatch('user/setCurrentCompact') in the relevant test files.

  • Confirmed in StateUpload.spec.ts:
    • Correct usage:
      await component.$store.dispatch('user/setCurrentCompact', new Compact({ type: CompactType.ASLP }));
  • No evidence of other tests missing the await pattern for this specific action.

Please manually review the output of the revised grep command to ensure no instances were overlooked.

webroot/src/store/user/user.state.ts (1)

25-25: LGTM: Added loading state for compact states

Added a new state property to track loading state specifically for compact states, which corresponds to the PR's implementation of a new loading state. This allows the UI to provide appropriate feedback during asynchronous operations.

Also applies to: 39-39

webroot/src/components/Page/PageContainer/PageContainer.ts (1)

70-72: LGTM: Loading state correctly extended to include compact states loading

The addition of isLoadingCompactStates to the isLoading computed property makes sense as it ensures the loading mask is displayed when compact states are being fetched.

webroot/src/components/CompactSelector/CompactSelector.ts (1)

146-149: Improved conditional dispatch logic

The refactored code now only calls setCurrentCompact when not redirecting to a different route. This avoids an unnecessary store update since the router's beforeEach guard will handle setting the compact after redirection.

webroot/src/router/index.ts (1)

41-43: Correctly awaiting async action

Good addition of the await keyword to ensure navigation continues only after the compact states have been fully loaded. This is essential as setCurrentCompact is now an asynchronous action that may trigger network requests.

webroot/src/network/mocks/mock.data.api.ts (2)

15-15: LGTM: Import statements properly updated

The new imports for StateSerializer and adding compactStates to the mock data imports are appropriate for the new functionality.

Also applies to: 25-25


230-241: Mock API methods for compact states properly implemented

The new methods getCompactStates and getCompactStatesPublic follow the established patterns in the codebase:

  1. They use the wait function to simulate network latency
  2. They transform the mock data using the appropriate serializer
  3. They have both authenticated and public versions of the API endpoints

This implementation will allow for proper testing of the compact states functionality without requiring a backend.

webroot/src/models/StaffUser/StaffUser.model.spec.ts (1)

7-7: Import removed for compacts configuration.

The compacts as compactConfigs import has been removed, which aligns with the PR objective of moving from hardcoded compact states to dynamically fetched ones from server endpoints.

webroot/src/models/Compact/Compact.model.ts (1)

85-85: Simplified memberStates assignment.

This change simplifies how memberStates are populated, now directly using server data instead of processing it through configuration. This is in line with the PR objective of fetching compact states from server endpoints rather than static configuration.

webroot/src/network/data.api.ts (2)

230-237: Added new method to fetch compact states.

This method provides the interface to retrieve compact states from the server through the userDataApi, which is a key component of the PR objective to integrate new server endpoints.


239-246: Added public endpoint for compact states.

A corresponding public method has been added to fetch compact states without authentication requirements, enabling both authenticated and unauthenticated access paths to state data.

webroot/src/components/Licensee/LicenseeList/LicenseeList.ts (1)

202-207: Great update to handle asynchronous operation.

The method signature change to async and the addition of await before the store dispatch is a necessary improvement that ensures proper control flow when resetting the search. This change properly aligns with the updated asynchronous behavior of the setCurrentCompact action in the user store.

webroot/src/models/Compact/Compact.model.spec.ts (2)

8-8: Import simplification aligns with compact states refactoring.

Removing the import for compacts as compactConfigs reflects the architectural change to fetch compact states from the server rather than storing them in config files. This is a good cleanup.


76-76: Test updated to match new compact states implementation.

The test has been correctly modified to align with the new implementation where member states are fetched from the server instead of being defined in configuration. The test now properly verifies a simpler structure with just one state in the test data.

Also applies to: 84-84

webroot/src/store/user/user.spec.ts (5)

16-16: Good use of CompactType enum import.

Adding the CompactType import ensures type safety and consistency when handling compact types throughout the tests. This is a good practice that improves code maintainability.


146-179: Comprehensive test coverage for compact states mutations.

The new tests thoroughly verify that the mutations for compact states correctly handle request, success, and failure states. They check both the loading state and error handling, as well as the case where member states are updated.


630-631: Use of CompactType enum instead of string literals.

Replacing string literals with the CompactType enum improves type safety and makes the code more maintainable. This change ensures consistent usage of compact types throughout the application.

Also applies to: 634-635, 645-646


784-847: Thorough testing of new compact states actions.

The new tests comprehensively verify that the actions for fetching compact states work correctly for both staff and non-staff users, and that the setCurrentCompact action properly handles null values and dispatches the fetch action when needed.


857-858: Updated getter test for consistency with CompactType.

The test for the current compact getter has been updated to use CompactType instead of string literals, maintaining consistency throughout the codebase.

Also applies to: 860-860

webroot/src/store/user/user.actions.ts (2)

118-136: Well-implemented compact states fetch action.

The new getCompactStatesRequest action intelligently selects the appropriate API method based on the user's login status, which is a good design choice for handling both authenticated and public access scenarios. The proper handling of success and failure cases is also implemented correctly.


138-144: Good enhancement to setCurrentCompact action.

Making setCurrentCompact async and adding conditional fetching of compact states is a sensible approach. This ensures that when a compact is selected, its member states are automatically fetched when needed, providing a better user experience without additional code at call sites.

webroot/src/network/userApi/data.api.ts (3)

19-19: Import addition looks good.

The added import for StateSerializer is correctly placed with other model imports and will be used by the new methods for handling compact states.


256-267: Well-implemented API method for fetching compact states.

The implementation follows the established pattern in the codebase for API methods:

  • Clear JSDoc comments with parameter and return type documentation
  • Proper async/await usage
  • Appropriate serialization of the server response

The transformation of postalAbbreviation to abbrev handles the data mapping correctly between server and client models.


269-280: Public endpoint implementation matches the authenticated version.

The public endpoint implementation correctly mirrors the authenticated version but uses the appropriate public API path. Both methods share the same transformation logic, which is good for consistency.

webroot/src/store/user/user.mutations.ts (2)

27-29: Mutation types follow naming convention.

The new mutation types follow the established naming pattern with descriptive names that clearly indicate their purpose in the request-failure-success cycle.


109-124: Mutation handlers properly manage state transitions.

The implementation correctly:

  • Sets and clears loading flags appropriately across the request lifecycle
  • Handles error states consistently with other mutations
  • Updates the compact states only when a current compact exists
  • Follows the pattern established by other request-failure-success mutations

One thing to note is the conditional check before updating memberStates, which is a good defensive programming practice.

@jsandoval81 jsandoval81 requested a review from ChiefStief April 7, 2025 15:29
@jsandoval81 jsandoval81 marked this pull request as ready for review April 8, 2025 21:52
@ChiefStief
Copy link
Copy Markdown
Collaborator

ChiefStief commented Apr 8, 2025

Some of the time Im logging in as a staff user and then being redirected to this page, the state list does not seem to populate.
Seems like there may be a race condition here. Edit: I was able to reproduce once or twice and it seemed like the jurisdiction call came back after the page had loaded.
Screenshot 2025-04-08 at 4 43 06 PM

@jsandoval81
Copy link
Copy Markdown
Collaborator Author

@jlkravitz This is ready for your review.

Copy link
Copy Markdown
Collaborator

@jlkravitz jlkravitz left a comment

Choose a reason for hiding this comment

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

Looks good! @isabeleliassen Good to merge.

@isabeleliassen isabeleliassen merged commit 847e3c9 into csg-org:development Apr 11, 2025
2 checks passed
@jsandoval81 jsandoval81 deleted the frontend/compact-states-from-server branch September 15, 2025 15:53
@coderabbitai coderabbitai bot mentioned this pull request Apr 7, 2026
2 tasks
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.

Pull list of configured states from backend from backend to populate list of possible staff user state invites

4 participants