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

Support SharingUpdated web socket notification on patient flow page #1351

Merged
merged 2 commits into from
Nov 13, 2024

Conversation

nmajor25
Copy link
Contributor

@nmajor25 nmajor25 commented Nov 11, 2024

Shortcut Story ID: [sc-56333]

Summary by CodeRabbit

  • New Features

    • Introduced a new message handler for sharing attributes in the model.
  • Improvements

    • Streamlined message handlers to accept a single attributes parameter, simplifying state updates.
    • Updated styling for the sharing form to enhance user interface consistency.
  • Tests

    • Enhanced integration tests for patient flow, including new attributes for actions and improved websocket handling.

@nmajor25 nmajor25 requested a review from paulfalgout November 11, 2024 22:09
Copy link

coderabbitai bot commented Nov 11, 2024

Walkthrough

The changes in this pull request modify the _Model class by refactoring several message handlers to accept only an attributes parameter, simplifying the code. A new handler, SharingUpdated, is introduced to manage sharing attributes. Additionally, updates to the FormSharingView and FormLayoutView classes adjust CSS class names for styling. The test suite for the patient flow is enhanced with workspace relationships and refined action attributes, improving the accuracy of sidebar functionality tests. Existing functionalities remain unchanged.

Changes

File Path Change Summary
src/js/entities-service/entities/actions.js Refactored message handlers ActionDueChanged, ActionDurationChanged, NameChanged, and DetailsChanged to accept only attributes. Added new handler SharingUpdated({ attributes }).
src/js/entities-service/entities/flows.js Refactored message handlers NameChanged and DetailsChanged to accept only attributes.
src/js/views/patients/sidebar/action/action-sidebar-forms_views.js Updated className in FormSharingView and modified template structure in FormLayoutView.
test/integration/patients/patient/patient-flow.js Updated testPatient to include workspaceOne relationship and added outreach and sharing attributes to testFlowAction.

Possibly related PRs

Suggested reviewers

  • paulfalgout

Poem

🐰 In the meadow where rabbits play,
New handlers hop in, brightening the day.
With sharing and outreach, they dance and twirl,
Enhancing our model, giving it a whirl!
CSS changes, a stylish delight,
Testing with workspaces, everything feels right! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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 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.

@@ -58,7 +58,7 @@ function getSharingOpts(sharing) {
}

const FormSharingView = View.extend({
className: 'sidebar__dialog',
className: 'sidebar__dialog u-margin--t-24',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

So that the element has the correct top margin when being shown/hidden on the fly via a web socket notification.

Copy link

cypress bot commented Nov 11, 2024

RoundingWell Care Ops Frontend    Run #6947

Run Properties:  status check passed Passed #6947  •  git commit f7973404b5: Update how ws notification payload data is handled
Project RoundingWell Care Ops Frontend
Branch Review ws-sharing
Run status status check passed Passed #6947
Run duration 02m 55s
Commit git commit f7973404b5: Update how ws notification payload data is handled
Committer Nick Major
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 1
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 312
View all changes introduced in this branch ↗︎

Copy link

@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: 0

🧹 Outside diff range and nitpick comments (4)
src/js/views/patients/sidebar/action/action-sidebar-forms_views.js (1)

105-107: LGTM: Improved margin handling

Good refactor moving the margin responsibility to the child view (FormSharingView) instead of handling it conditionally in the parent template. This makes the spacing logic more maintainable and centralized.

Consider documenting this layout dependency in a comment to make it clear that FormSharingView handles its own spacing:

 <div class="flex">
+  {/* Spacing handled by FormSharingView's margin classes */}
   <div class="flex-grow" data-form-sharing-region></div>
 </div>
src/js/entities-service/entities/actions.js (1)

42-44: Consider adding JSDoc comments for the new message handler.

To improve maintainability and make the websocket notification handling more discoverable, consider adding documentation that describes:

  • The purpose of the SharingUpdated message
  • The expected format of the message payload
  • Example usage in the context of websocket notifications

Here's a suggested documentation format:

+    /**
+     * Handles the 'sharing:updated' websocket notification
+     * @param {Object} options
+     * @param {string} options.sharing - The new sharing status
+     * @param {string} options.outreach - The new outreach status
+     * @param {Object} [options.attributes] - Additional attributes to update
+     */
     SharingUpdated({ sharing, outreach, attributes = {} }) {
       this.set({ sharing, outreach, ...attributes });
     },
test/integration/patients/patient/patient-flow.js (2)

250-290: Consider adding negative test cases for sharing states

While the current test cases cover the positive flow of sharing state transitions (disabled → waiting → responded), consider adding test cases for:

  1. Invalid state transitions
  2. Error scenarios
  3. Edge cases like cancellation of sharing

2453-2474: Enhance icon verification in sharing tests

The test verifies icon changes from file-lines to share-from-square, but consider:

  1. Adding assertions for icon accessibility attributes
  2. Verifying icon color/styling classes
  3. Testing icon behavior when sharing is disabled

Example enhancement:

 cy
   .get('.patient-flow__list')
   .find('.table-list__item .patient__action-icon')
-  .find('.fa-share-from-square');
+  .find('.fa-share-from-square')
+  .should('have.attr', 'aria-label', 'Sharing Enabled')
+  .should('have.class', 'is-success');
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between fc3a684 and 2203f0b.

📒 Files selected for processing (3)
  • src/js/entities-service/entities/actions.js (1 hunks)
  • src/js/views/patients/sidebar/action/action-sidebar-forms_views.js (2 hunks)
  • test/integration/patients/patient/patient-flow.js (6 hunks)
🔇 Additional comments (7)
src/js/views/patients/sidebar/action/action-sidebar-forms_views.js (1)

61-61: LGTM: Consistent class naming convention

The addition of the top margin utility class follows the project's naming conventions and improves the visual spacing.

src/js/entities-service/entities/actions.js (2)

42-44: Verify permission handling for sharing updates.

While the implementation looks correct, it's important to ensure that sharing updates respect the model's permission system.

Let's verify the permission checks:

#!/bin/bash
# Description: Verify permission handling for sharing updates

# Check for permission checks in sharing-related code
rg -B 5 -A 5 "sharing.*canEdit|canEdit.*sharing" --type js

# Look for websocket authorization checks
ast-grep --pattern 'socket.on("sharing:updated", function($params) {
  $$$
  can($$$)
  $$$
})'

42-44: LGTM! The message handler follows established patterns.

The new SharingUpdated message handler is well-implemented and consistent with other handlers in the class. It properly updates both sharing and outreach attributes while supporting additional attributes through the spread operator.

Let's verify the integration points with this handler:

✅ Verification successful

The SharingUpdated message handler is correctly implemented and well-integrated

The verification confirms that the handler is properly integrated with the codebase:

  • The hasSharing() and hasOutreach() methods are used extensively across multiple views for UI rendering
  • ACTION_SHARING and ACTION_OUTREACH constants are properly imported and used throughout the codebase
  • The sharing/outreach states are used in various contexts including form sharing, UI icons, and state management
  • Integration tests verify the correct handling of sharing states ('pending', 'canceled', etc.)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the integration of sharing and outreach functionality

# Check for consistent usage of sharing/outreach constants
rg "ACTION_SHARING\." --type js
rg "ACTION_OUTREACH\." --type js

# Check for related websocket handling
ast-grep --pattern 'socket.on("sharing:updated", $_)'

# Verify the model's sharing-related method implementations
ast-grep --pattern 'hasOutreach() {
  $$$
}'

ast-grep --pattern 'hasSharing() {
  $$$
}'

Length of output: 364


Script:

#!/bin/bash
# Let's try a different approach to verify the integration

# Check for sharing/outreach related methods and their usage
rg "hasSharing|hasOutreach" --type js -A 2 -B 2

# Look for sharing/outreach attribute usage
rg "\.sharing|\.outreach" --type js -A 2 -B 2

# Check for websocket event handlers related to sharing
rg "sharing:updated" --type js -A 2 -B 2

# Look for imports of ACTION_SHARING and ACTION_OUTREACH
rg "import.*ACTION_(SHARING|OUTREACH)" --type js

Length of output: 13416

test/integration/patients/patient/patient-flow.js (4)

108-116: LGTM: Workspace relationship addition

The addition of workspace relationships to the test patient data is well-structured and aligns with the PR objectives for supporting sharing functionality.


122-123: LGTM: Form and sharing attributes

The addition of outreach and sharing attributes set to 'disabled' along with the form relationship provides good test coverage for the initial state of actions.

Also applies to: 129-130


155-159: LGTM: Patient routing setup

The patient routing setup is properly implemented with appropriate test data handling.


2347-2348: LGTM: Socket test initial state

The socket test setup correctly initializes the action with disabled sharing state and form relationship.

Also applies to: 2354-2354

@coveralls
Copy link

coveralls commented Nov 11, 2024

Pull Request Test Coverage Report for Build d558e510-661e-4a3b-8848-8ccb361d24ce

Details

  • 7 of 7 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 99.987%

Totals Coverage Status
Change from base Build 4374e046-ef53-4e31-abb8-a8ef3b8d7c6e: 0.0%
Covered Lines: 5957
Relevant Lines: 5957

💛 - Coveralls

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is a simple implementation, unless I'm missing something.

In the action sidebar tests, I did:

  1. Start out action as having sharing: 'disabled'. i.e. sharing section is hidden in UI.
  2. Socket notification comes in that sets sharing: 'enabled'. Verify UI elements are now shown.
  3. Socket notification comes in tha sets sharing: 'responded'. Verify UI elements are updated.

In the action list, I did:

  1. Start out action as having outreach: 'disabled'. i.e. icon for the action list item is the default version.
  2. Socket notification comes in that sets outreach: 'patient'. Verify icon for action list item changes. (I'm not sure there's anything else that changes based on that outreach attribute).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The notification from the BE contains data for the recipient: https://github.com/RoundingWell/care-ops-backend/blob/develop/tests/Notifications/Data/Messages/sharing-updated-message-structure.json.

Can we assume the recipient will always be the patient the action/flow belongs to? And therefore we don't need to do anything on the FE with that recipient data?

Copy link
Member

Choose a reason for hiding this comment

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

I don't think FE needs to know the recipient. FE needs to know all of the data such that if the user hard refreshed they'd see the same thing.

@@ -39,6 +39,9 @@ const _Model = BaseModel.extend({
DetailsChanged({ details, attributes = {} }) {
this.set({ details, ...attributes });
},
SharingUpdated({ sharing, outreach, attributes = {} }) {
Copy link
Member

Choose a reason for hiding this comment

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

so a bunch of these are wrong.. the only thing doing any work here is attributes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These have been updated 👍

@@ -102,7 +102,7 @@ const FormLayoutView = View.extend({
{{#if hasForm}}<h4 class="sidebar__label u-margin--t-8">{{ @intl.patients.sidebar.action.actionSidebarFormsViews.formLayoutView.formLabel }}</h4>{{/if}}
<div class="flex-grow" data-form-region></div>
</div>
<div class="flex{{#if hasSharing}} u-margin--t-24{{/if}}">
<div class="flex">
Copy link
Member

Choose a reason for hiding this comment

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

is the templateContext still in use?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The hasSharing value can be removed. But hasForm is still in use in that templateContext().

Copy link
Member

Choose a reason for hiding this comment

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

I don't think FE needs to know the recipient. FE needs to know all of the data such that if the user hard refreshed they'd see the same thing.

And update the tests to replicate what actual data structure will look like in prod
Copy link

@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

🧹 Outside diff range and nitpick comments (1)
test/integration/patients/patient/patient-flow.js (1)

2473-2496: Consider adding comments to explain icon meanings

While the test correctly verifies icon changes from fa-file-lines to fa-share-from-square, it would be helpful to add comments explaining what each icon represents in terms of the sharing state.

 cy
   .get('.patient-flow__list')
   .find('.table-list__item .patient__action-icon')
+  // Verify default form icon when sharing is disabled
   .find('.fa-file-lines');

 cy.sendWs({
   category: 'SharingUpdated',
   resource: {
     type: 'patient-actions',
     id: testSocketAction.id,
   },
   payload: {
     attributes: {
       sharing: 'pending',
       outreach: 'patient',
     },
   },
 });

 cy
   .get('.patient-flow__list')
   .find('.table-list__item .patient__action-icon')
+  // Verify sharing icon when sharing is pending
   .find('.fa-share-from-square');
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 2203f0b and f797340.

📒 Files selected for processing (4)
  • src/js/entities-service/entities/actions.js (1 hunks)
  • src/js/entities-service/entities/flows.js (1 hunks)
  • src/js/views/patients/sidebar/action/action-sidebar-forms_views.js (2 hunks)
  • test/integration/patients/patient/patient-flow.js (13 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/js/entities-service/entities/actions.js
  • src/js/views/patients/sidebar/action/action-sidebar-forms_views.js
🔇 Additional comments (5)
src/js/entities-service/entities/flows.js (2)

25-26: LGTM! Clean refactoring of the NameChanged handler.

The simplified message handler that only accepts attributes improves code maintainability and follows a consistent pattern across the codebase.


28-29: LGTM! Clean refactoring of the DetailsChanged handler.

The simplified message handler that only accepts attributes improves code maintainability and follows a consistent pattern across the codebase.

test/integration/patients/patient/patient-flow.js (3)

108-116: LGTM: Good addition of workspace relationship

The addition of the workspace relationship to the test patient makes the test data more realistic and complete.


122-123: LGTM: Proper initialization of sharing-related attributes

The addition of outreach and sharing attributes with 'disabled' default state, along with the form relationship, provides the necessary setup for testing sharing functionality.

Also applies to: 129-130, 2359-2360, 2366-2366


259-302: LGTM: Comprehensive sharing state UI tests

The test cases effectively verify the sharing functionality through different states:

  1. Initial empty state
  2. Enabled state with "Waiting for Response"
  3. Responded state with "Response Saved"

The assertions properly verify the UI elements for each state.

Comment on lines 24 to 30
},
NameChanged({ name, attributes = {} }) {
this.set({ name, ...attributes });
NameChanged({ attributes }) {
this.set(attributes);
},
DetailsChanged({ details, attributes = {} }) {
this.set({ details, ...attributes });
DetailsChanged({ attributes }) {
this.set(attributes);
},
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

⚠️ Potential issue

Implement SharingUpdated Message Handler

The SharingUpdated handler is not implemented in the messages object. Please add the SharingUpdated handler to support websocket notifications.

🔗 Analysis chain

Missing SharingUpdated message handler implementation.

The PR objectives mention supporting SharingUpdated websocket notifications, but I don't see the handler implemented in the messages object. Please add the SharingUpdated handler to support this functionality.

Let's verify if this handler exists elsewhere:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any existing SharingUpdated handler implementations
rg -l "SharingUpdated"

# Search for websocket notification handlers pattern
ast-grep --pattern 'messages: {
  $$$
  SharingUpdated($$$) {
    $$$
  }
  $$$
}'

Length of output: 323

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.

3 participants