-
Notifications
You must be signed in to change notification settings - Fork 4
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
Conversation
WalkthroughThe changes in this pull request involve modifications to the Changes
Possibly related PRs
Suggested reviewers
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
@@ -107,7 +107,7 @@ const SidebarView = View.extend({ | |||
modelEvents: { | |||
'change:name': 'showName', | |||
'change:details': 'showDetails', | |||
'change:_state': 'showOwner', |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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'
There was a problem hiding this comment.
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.
RoundingWell Care Ops Frontend Run #6988
Run Properties:
|
Project |
RoundingWell Care Ops Frontend
|
Branch Review |
ws-flow-sidebar
|
Run status |
Passed #6988
|
Run duration | 02m 41s |
Commit |
8df0bf6f26: Refactor flow sidebar views
|
Committer | Nick Major |
View all properties for this run ↗︎ |
Test results | |
---|---|
Failures |
0
|
Flaky |
0
|
Pending |
0
|
Skipped |
0
|
Passing |
312
|
View all changes introduced in this branch ↗︎ |
Pull Request Test Coverage Report for Build 8cd4d3ae-f18a-41aa-8d22-5eb729e044a8Details
💛 - Coveralls |
There was a problem hiding this 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 nameThe 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 handlersMultiple 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
📒 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 inflow-sidebar.scss
and used inflow-sidebar_views.js
sidebar__details
is defined insidebar.scss
and used inflow-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:
- Connection failures
- Malformed WebSocket messages
- Out-of-order notifications
- Reconnection scenarios
<div data-name-region></div> | ||
<div data-details-region></div> |
There was a problem hiding this comment.
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 usingaria-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 todata-name-region
anddata-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(); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
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'
There was a problem hiding this 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 propertiesThe 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 methodThe 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
📒 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 theNameView
<div data-details-region></div>
for theDetailsView
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
'change:name': 'showName', | ||
'change:details': 'showDetails', | ||
'change:_state': 'showActions', | ||
'change:_owner': 'showActions', |
There was a problem hiding this comment.
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.
Shortcut Story ID: [sc-56894]
Summary by CodeRabbit
New Features
NameView
andDetailsView
for improved rendering of patient information in the sidebar.Bug Fixes
Documentation