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

On ws notifications, update name, details, and state in flow sidebar #1353

Merged
merged 5 commits into from
Nov 26, 2024

Conversation

nmajor25
Copy link
Contributor

@nmajor25 nmajor25 commented Nov 22, 2024

Shortcut Story ID: [sc-56894]

Summary by CodeRabbit

  • New Features

    • Enhanced sidebar to dynamically display patient name and details using new data attributes.
    • Introduced NameView and DetailsView for improved rendering of patient information in the sidebar.
  • Bug Fixes

    • Improved integration tests to ensure real-time updates are accurately reflected in the sidebar.
  • Documentation

    • Updated test suite to verify websocket notifications and UI updates.

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

coderabbitai bot commented Nov 22, 2024

Walkthrough

The changes in this pull request involve modifications to the flow-sidebar.hbs file and the associated SidebarView in flow-sidebar_views.js. The flow-sidebar.hbs file has been updated to replace static content with new data attributes for dynamic rendering. Correspondingly, the SidebarView has been enhanced with new views for displaying patient name and details, along with updated event listeners and rendering methods. Additionally, the integration tests for the patient flow have been improved to ensure that real-time updates via WebSocket notifications are accurately reflected in the sidebar.

Changes

File Path Change Summary
src/js/views/patients/sidebar/flow/flow-sidebar.hbs Replaced static divs for patient name and details with new data-name-region and data-details-region attributes.
src/js/views/patients/sidebar/flow/flow-sidebar_views.js Added NameView and DetailsView, updated SidebarView to include new regions and methods for rendering patient data.
test/integration/patients/patient/patient-flow.js Enhanced tests to verify sidebar updates for flow name, details, and ownership based on WebSocket notifications.

Possibly related PRs

Suggested reviewers

  • paulfalgout

🐇 In the sidebar where details now play,
New data regions brighten the day.
With names and flows in a dynamic dance,
The updates come swift, give change a chance!
So hop along, let the views take flight,
Real-time magic makes everything 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.

@@ -107,7 +107,7 @@ const SidebarView = View.extend({
modelEvents: {
'change:name': 'showName',
'change:details': 'showDetails',
'change:_state': 'showOwner',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure why this was showOwner? May be missing something, but I think showFlow is what this should be.

Copy link
Member

Choose a reason for hiding this comment

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

canEdit is only affected by the owner. I think this should just be 'change:_state': 'showState'

Copy link
Contributor Author

@nmajor25 nmajor25 Nov 25, 2024

Choose a reason for hiding this comment

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

So this was originally showOwner because of this: https://github.com/RoundingWell/care-ops-frontend/blob/develop/src/js/views/patients/sidebar/flow/flow-sidebar_views.js#L133.

If the flow state is set to Done, the owner component becomes disabled.

So I have it set to 'change:_state': 'showActions'. Since the change:_state model events listener needs to now update the state component and potentially the owner component if state is set to done.

But in this scenario this.canEdit = this.model.canEdit(); and this.showPermission() would be ran for no purpose.

Copy link

cypress bot commented Nov 22, 2024

RoundingWell Care Ops Frontend    Run #6988

Run Properties:  status check passed Passed #6988  •  git commit 8df0bf6f26: Refactor flow sidebar views
Project RoundingWell Care Ops Frontend
Branch Review ws-flow-sidebar
Run status status check passed Passed #6988
Run duration 02m 41s
Commit git commit 8df0bf6f26: Refactor flow sidebar views
Committer Nick Major
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
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 ↗︎

@coveralls
Copy link

coveralls commented Nov 22, 2024

Pull Request Test Coverage Report for Build 8cd4d3ae-f18a-41aa-8d22-5eb729e044a8

Details

  • 9 of 9 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 99.936%

Totals Coverage Status
Change from base Build a649abc4-d399-480d-850f-88bbadbf1513: 0.0%
Covered Lines: 6040
Relevant Lines: 6040

💛 - Coveralls

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: 2

🧹 Outside diff range and nitpick comments (4)
src/js/views/patients/sidebar/flow/flow-sidebar_views.js (2)

63-66: Add fallback for undefined name

The template should handle cases where the name is undefined or empty.

Consider updating the template:

-  template: hbs`{{ name }}`,
+  template: hbs`
+    {{#if name}}
+      {{ name }}
+    {{else}}
+      <span class="sidebar--no-results">{{ @intl.patients.sidebar.flow.flowSidebarTemplate.noName }}</span>
+    {{/if}}
+  `,

108-110: Consider debouncing change handlers

Multiple rapid changes to name or details could trigger unnecessary re-renders. Consider debouncing these handlers for better performance.

Example implementation:

+import { debounce } from 'underscore';
+
 modelEvents: {
-  'change:name': 'showName',
-  'change:details': 'showDetails',
+  'change:name': 'debouncedShowName',
+  'change:details': 'debouncedShowDetails',
   'change:_state': 'showFlow',
   'change:_owner': 'showFlow',
 },
+initialize() {
+  this.debouncedShowName = debounce(this.showName, 250);
+  this.debouncedShowDetails = debounce(this.showDetails, 250);
+},
test/integration/patients/patient/patient-flow.js (2)

2561-2565: Consider consolidating owner update assertions.

The owner update assertions are split between header and sidebar. Consider consolidating these assertions into a single chain for better readability and maintenance.

-    cy
-      .get('[data-header-region]')
-      .find('[data-owner-region]')
-      .should('contain', 'CO');
-
-    cy
-      .get('@flowSidebar')
-      .find('[data-owner-region]')
-      .should('contain', 'Coordinator');
+    cy.then(() => {
+      cy
+        .get('[data-header-region]')
+        .find('[data-owner-region]')
+        .should('contain', 'CO');
+
+      cy
+        .get('@flowSidebar')
+        .find('[data-owner-region]')
+        .should('contain', 'Coordinator');
+    });

Also applies to: 2566-2570


2617-2617: Consider consolidating state update assertions.

Similar to the owner updates, the state update assertions are split. Consider consolidating these assertions for better test organization.

-    cy
-      .get('[data-header-region]')
-      .find('[data-state-region] .fa-circle-check');
-
-    cy
-      .get('@flowSidebar')
-      .find('[data-state-region]')
-      .should('contain', 'Done');
+    cy.then(() => {
+      cy
+        .get('[data-header-region]')
+        .find('[data-state-region] .fa-circle-check');
+
+      cy
+        .get('@flowSidebar')
+        .find('[data-state-region]')
+        .should('contain', 'Done');
+    });

Also applies to: 2620-2622

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 3ad47ed and af91a01.

📒 Files selected for processing (3)
  • src/js/views/patients/sidebar/flow/flow-sidebar.hbs (1 hunks)
  • src/js/views/patients/sidebar/flow/flow-sidebar_views.js (4 hunks)
  • test/integration/patients/patient/patient-flow.js (4 hunks)
🔇 Additional comments (7)
src/js/views/patients/sidebar/flow/flow-sidebar.hbs (1)

2-3: Ensure preservation of styling classes in views.

The original template had specific styling classes (patient-flow-sidebar__name and sidebar__details) that need to be preserved in the new views to maintain consistent styling.

Let's verify the styling classes in the view implementations:

✅ Verification successful

The styling classes are correctly preserved in the view implementations

The verification shows that both styling classes are properly maintained:

  • patient-flow-sidebar__name is defined in flow-sidebar.scss and used in flow-sidebar_views.js
  • sidebar__details is defined in sidebar.scss and used in flow-sidebar_views.js

The classes are being assigned through the view's JavaScript implementation rather than directly in the template, which is a valid approach for maintaining the styling.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if the styling classes are preserved in the new views

# Search for the original class names in view files
rg 'patient-flow-sidebar__name|sidebar__details'

# Look for className or class assignments in the new views
ast-grep --pattern 'className = $_' 

Length of output: 1041

src/js/views/patients/sidebar/flow/flow-sidebar_views.js (3)

68-76: LGTM!

Good implementation with proper empty state handling.


91-92: LGTM!

Region definitions follow Marionette best practices and maintain consistency with existing patterns.


120-121: LGTM!

The changes to showFlow maintain a logical flow and properly integrate the new view methods.

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

2424-2429: LGTM: Good test coverage for flow name updates in sidebar.

The test effectively verifies that WebSocket notifications update the flow name in the sidebar, maintaining UI consistency.


2455-2459: LGTM: Good test coverage for flow details updates in sidebar.

The test properly verifies that WebSocket notifications update the flow details in the sidebar, ensuring synchronized UI updates.


Line range hint 2424-2622: Verify WebSocket notification error handling.

The test suite thoroughly covers successful WebSocket notifications but lacks coverage for error scenarios.

Consider adding test cases for:

  1. Connection failures
  2. Malformed WebSocket messages
  3. Out-of-order notifications
  4. Reconnection scenarios

Comment on lines +2 to +3
<div data-name-region></div>
<div data-details-region></div>
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Accessibility attributes need to be added to the new regions

The verification reveals that the new name and details regions lack proper accessibility attributes, while other regions in the codebase consistently use semantic HTML with proper labeling. To maintain accessibility:

  • Add aria-label or associate the regions with their respective heading labels using aria-labelledby
  • Ensure the dynamic content maintains a proper heading structure
  • Consider adding appropriate ARIA roles based on the content type

Example locations needing attention:

  • src/js/views/patients/sidebar/flow/flow-sidebar.hbs: Add accessibility attributes to data-name-region and data-details-region
  • Corresponding view files: Ensure rendered content follows accessibility patterns seen in other sidebar regions
🔗 Analysis chain

LGTM! Verify accessibility attributes.

The shift to region-based rendering is a good architectural choice that enables real-time updates and better separation of concerns. However, ensure that the new views maintain proper accessibility.

Let's verify the accessibility attributes in the corresponding view files:


Let me gather more information about the views to better understand the accessibility implementation.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if the new views implement proper accessibility attributes

# Search for aria attributes in the related view files
rg -A 5 'NameView|DetailsView' | rg -i 'aria-|role'

# Check for any existing accessibility patterns in other sidebar regions
rg -A 5 'data-\w+-region' | rg -i 'aria-|role'

Length of output: 1545


Script:

#!/bin/bash
# Search for the NameView and DetailsView implementations
ast-grep --pattern 'class $NAME extends $_ {
  $$$
}'

# Search for any accessibility-related patterns in the flow sidebar views
rg -l "flow.*sidebar" | xargs rg -i "aria-|role|tabindex|label|description"

# Check template files for existing accessibility patterns
fd "\.hbs$" | xargs rg -i "aria-|role|tabindex|label|description"

Length of output: 17738

@@ -98,13 +117,23 @@ const SidebarView = View.extend({
showFlow() {
this.canEdit = this.model.canEdit();

this.showName();
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 name or details need to be in this function.. they can just be in onRender.. this function appears to be needed if something changes that affects canEdit

Copy link
Member

Choose a reason for hiding this comment

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

really I think this method did more a bit ago and it likely doesn't make any sense now.. this.canEdit = this.model.canEdit(); should move into showActions and changing the owner should do that.

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 moved showName() and showDetails() up to the render function. And moved the this.canEdit = ... to showActions().

@@ -107,7 +107,7 @@ const SidebarView = View.extend({
modelEvents: {
'change:name': 'showName',
'change:details': 'showDetails',
'change:_state': 'showOwner',
Copy link
Member

Choose a reason for hiding this comment

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

canEdit is only affected by the owner. I think this should just be 'change:_state': 'showState'

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 (2)
src/js/views/patients/sidebar/flow/flow-sidebar_views.js (2)

63-76: Add defensive checks for name and details properties

The view templates should handle potential undefined or null values gracefully.

Consider this implementation:

 const NameView = View.extend({
   className: 'patient-flow-sidebar__name',
-  template: hbs`{{ name }}`,
+  template: hbs`{{#if name}}{{ name }}{{else}}-{{/if}}`,
 });

 const DetailsView = View.extend({
   className: 'sidebar__details',
   template: hbs`
-    {{ details }}
+    {{#if details}}{{ details }}{{/if}}
     {{#unless details}}
       <span class="sidebar--no-results">{{ @intl.patients.sidebar.flow.flowSidebarTemplate.noDetails }}</span>
     {{/unless}}
   `,
 });

119-125: Simplify showActions method

The method is handling multiple responsibilities. Consider moving the canEdit check to where it's actually needed.

Consider this implementation:

 showActions() {
-  this.canEdit = this.model.canEdit();
-
   this.showState();
   this.showOwner();
   this.showPermission();
 },
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between af91a01 and 8df0bf6.

📒 Files selected for processing (1)
  • src/js/views/patients/sidebar/flow/flow-sidebar_views.js (3 hunks)
🔇 Additional comments (4)
src/js/views/patients/sidebar/flow/flow-sidebar_views.js (4)

91-92: LGTM!

The new regions are properly defined and follow the existing pattern.


126-133: Add error handling and view cleanup

The view methods should handle potential errors and ensure proper cleanup of previous views, as suggested in the previous review.


114-116: LGTM!

The onRender method properly initializes all necessary views.


63-76: Verify template compatibility with new views

Let's ensure the template has the necessary regions for these new views.

✅ Verification successful

Template regions are properly configured for the new views

The template file flow-sidebar.hbs contains both required regions:

  • <div data-name-region></div> for the NameView
  • <div data-details-region></div> for the DetailsView

The integration tests also confirm these regions are actively used across the application, showing proper integration with the UI components.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if flow-sidebar.hbs has the required data attributes for new regions

# Search for data-name-region and data-details-region in the template
rg -l 'data-(name|details)-region' src/js/views/patients/sidebar/flow/flow-sidebar.hbs

# Check for any other uses of these regions in tests
rg 'data-(name|details)-region' test/

Length of output: 5316


Script:

#!/bin/bash
# Let's check the actual content of flow-sidebar.hbs to verify the template structure

cat src/js/views/patients/sidebar/flow/flow-sidebar.hbs

Length of output: 790

Comment on lines +108 to +111
'change:name': 'showName',
'change:details': 'showDetails',
'change:_state': 'showActions',
'change:_owner': 'showActions',
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider separating state and owner change handlers

Based on the previous review discussion, change:_state should only trigger showState since canEdit is only affected by the owner.

Consider this implementation:

 modelEvents: {
   'change:name': 'showName',
   'change:details': 'showDetails',
-  'change:_state': 'showActions',
-  'change:_owner': 'showActions',
+  'change:_state': 'showState',
+  'change:_owner': function() {
+    this.canEdit = this.model.canEdit();
+    this.showOwner();
+    this.showPermission();
+  },
 },

Committable suggestion skipped: line range outside the PR's diff.

@nmajor25 nmajor25 requested a review from paulfalgout November 26, 2024 17:12
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