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

Fixed Multi-selection functionality. #9345

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

Jeffrin2005
Copy link

@Jeffrin2005 Jeffrin2005 commented Dec 10, 2024

Proposed Changes

multiselection1.mp4

@ohcnetwork/care-fe-code-reviewers

Merge Checklist

  • Add specs that demonstrate bug / test a new feature.
  • Update product documentation.
  • Ensure that UI text is kept in I18n files.
  • Prep screenshot or demo video for changelog entry, and attach it to issue.
  • Request for Peer Reviews
  • Completion of QA

Summary by CodeRabbit

  • New Features

    • Introduced a button to clear selected investigations, enhancing user control.
    • Added error notifications for unavailable reports when no investigation parameters are provided.
  • Improvements

    • Enhanced layout for better alignment of report generation and clearing buttons.
    • Updated the optionValue prop for better reference in the investigations selection.

@Jeffrin2005 Jeffrin2005 requested a review from a team as a code owner December 10, 2024 05:11
Copy link
Contributor

coderabbitai bot commented Dec 10, 2024

Walkthrough

The changes in this pull request focus on enhancing the InvestigationReports component by adding a new function to clear selected investigations, improving error handling for fetching investigation data, and refining the processing logic using lodash. Additionally, the component's user interface is updated with a new button for clearing selections and adjustments to the layout for better alignment. The reducer function is also simplified for improved readability.

Changes

File Path Change Summary
src/components/Facility/Investigations/Reports/index.tsx - Added clearSelectedInvestigations function to reset state.
- Updated fetchInvestigationsData to handle empty params with an error notification.
- Corrected optionValue prop in AutocompleteMultiSelectFormField.
- Introduced a button for clearing selections, conditionally disabled.
- Modified button layout to use a flex container.
package.json - Removed and re-added @radix-ui/react-icons version ^1.3.2 in dependencies.
- Added @tanstack/react-query version ^5.62.3 and @tanstack/react-query-devtools version ^5.62.7 to dependencies.

Assessment against linked issues

Objective Addressed Explanation
Multi selection of investigations not working in Patient log lab results (#9144)

Possibly related PRs

  • partially revert c9343d5 to fix investigation issues #9026: This PR modifies the same InvestigationReports component in src/components/Facility/Investigations/Reports/index.tsx, specifically changing how lodash's chain function is accessed, which is relevant to the overall functionality of the component.
  • Fix : Advanced Filters Autofilling on Revisit to Patient Tab #9251: This PR updates the ManagePatients.tsx component, which is related to the patient management functionality that may interact with the InvestigationReports component in terms of user interface and state management.
  • Reorder Patient Search buttons #9319: This PR also modifies the ManagePatients.tsx component, focusing on enhancing the search functionality, which could be relevant to the overall patient management experience that includes investigations.

Suggested labels

needs testing, needs review

Suggested reviewers

  • rithviknishad
  • Jacobjeevan

Poem

In the land of hops and playful cheer,
A button appears, oh so near!
Clear those choices, one by one,
Investigations, now more fun!
With a flick of the paw, all's set right,
Let's log those results, with delight! 🐇✨


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between db2fb4c and 2098454.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (2)
  • package.json (2 hunks)
  • src/components/Facility/Investigations/Reports/index.tsx (7 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • package.json
  • src/components/Facility/Investigations/Reports/index.tsx

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 generate docstrings to generate docstrings for this PR. (Experiment)
  • @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.

Copy link

netlify bot commented Dec 10, 2024

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 2098454
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/675c6d811a33c200087635ca
😎 Deploy Preview https://deploy-preview-9345--care-ohc.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@Jeffrin2005 Jeffrin2005 changed the title "Fixed Multi-selection functionality. Fixed Multi-selection functionality. Dec 10, 2024
Copy link
Member

@rithviknishad rithviknishad left a comment

Choose a reason for hiding this comment

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

lgtm, but do revert changes made to unrelated files

.gitattributes Outdated
Copy link
Member

Choose a reason for hiding this comment

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

revert unrelated changes

Copy link
Member

Choose a reason for hiding this comment

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

revert unrelated changes

Copy link
Author

Choose a reason for hiding this comment

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

@rithviknishad I added " * text=auto " to the .gitattributes file. Should I remove it? do I need to update any packages in the package-lock.json file?

Copy link
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

🧹 Outside diff range and nitpick comments (3)
src/components/Facility/Investigations/Reports/index.tsx (3)

111-113: Consider adding a confirmation dialog for clearing selections.

The clear functionality works correctly, but since it's a bulk operation that clears all selections, consider adding a confirmation dialog to prevent accidental clearing of multiple selections.

 const clearSelectedInvestigations = () => {
+  if (window.confirm(t("clear_selections_confirmation"))) {
     dispatch({ type: "set_selected_investigations", payload: [] });
+  }
 };

352-372: Consider adding ARIA labels for accessibility.

The button layout improvements look good, but consider adding ARIA labels to improve accessibility.

 <ButtonV2
   onClick={clearSelectedInvestigations}
   disabled={!selectedInvestigations.length}
   variant="secondary"
   className="my-2.5"
+  aria-label={t("clear_selected_investigations")}
 >
   {t("clear")}
 </ButtonV2>

Line range hint 111-372: Add tests for the new multi-selection functionality.

While the implementation looks good, please ensure adequate test coverage for:

  • Multi-selection behavior
  • Clear functionality
  • Edge cases with empty/invalid selections

Would you like me to help generate test cases for these scenarios?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between d520018 and 72c25c7.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (2)
  • .gitattributes (1 hunks)
  • src/components/Facility/Investigations/Reports/index.tsx (4 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .gitattributes
🔇 Additional comments (2)
src/components/Facility/Investigations/Reports/index.tsx (2)

57-82: LGTM! Clean reducer case formatting.

The reducer cases have been reformatted for better readability while maintaining the same functionality.


346-349: Verify the multi-selection fix.

The changes correctly implement multi-selection by using external_id as the unique identifier and enabling the selectAll functionality.

✅ Verification successful

Multi-selection implementation verified successfully

The verification confirms that:

  • The external_id is consistently used for investigation identification across API endpoints
  • The AutocompleteMultiSelect component is properly implemented in the Investigations module
  • The selection logic is correctly implemented with appropriate IDs and naming conventions
  • The translation key "select_investigation" indicates proper UI messaging for the multi-select functionality
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that external_id is consistently used across the codebase for investigation identification

# Search for investigation identification patterns
rg -A 2 "external_id.*investigation" --type typescript

# Search for potential places where the old selection logic might still be used
rg "investigation.*select" --type typescript

Length of output: 173


Script:

#!/bin/bash
# Let's try without typescript file type specification
# Search for external_id usage patterns in investigation context
rg -A 2 "external_id.*investigation"

# Search for investigation selection patterns
rg "investigation.*select"

# Also search for AutocompleteMultiSelect component usage
rg -A 3 "AutocompleteMultiSelect"

Length of output: 8612

@@ -185,7 +183,7 @@ const InvestigationReports = ({ id }: any) => {
.flatten()
.map((i) => ({
...i,
name: `${i.name} ${i.groups[0].name && " | " + i.groups[0].name} `,
name: `${i.name} ${i.groups[0].name && " | " + i.groups[0].name}`,
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix investigation name formatting logic.

The current implementation has a logical error in the string concatenation that could lead to incorrect formatting.

-        name: `${i.name} ${i.groups[0].name && " | " + i.groups[0].name}`,
+        name: `${i.name}${i.groups[0]?.name ? ` | ${i.groups[0].name}` : ''}`,
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
name: `${i.name} ${i.groups[0].name && " | " + i.groups[0].name}`,
name: `${i.name}${i.groups[0]?.name ? ` | ${i.groups[0].name}` : ''}`,

Copy link
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

🧹 Outside diff range and nitpick comments (2)
src/components/Facility/Investigations/Reports/index.tsx (2)

Line range hint 130-143: Improve error message clarity

The current error message "No more reports to load" might be confusing when no investigations are selected. Consider providing more specific messages for different scenarios:

  • When no investigations are selected
  • When selected investigations have no reports
  • When all reports have been loaded
   if (investigationsParams.length === 0) {
     Notification.Error({
-      msg: "No more reports to load",
+      msg: selectedInvestigations.length === 0
+        ? "Please select at least one investigation"
+        : "No more reports to load",
     });

349-349: Consider using the prop value directly

The selectAll prop is hardcoded as a boolean literal. Consider using just selectAll instead of selectAll={true} for better readability.

-                  selectAll={true}
+                  selectAll
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between d520018 and 72c25c7.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (2)
  • .gitattributes (1 hunks)
  • src/components/Facility/Investigations/Reports/index.tsx (4 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .gitattributes
🔇 Additional comments (5)
src/components/Facility/Investigations/Reports/index.tsx (5)

57-82: LGTM! Clean reducer implementation.

The simplified reducer cases improve readability while maintaining the same functionality.


111-113: LGTM! Clear function implementation.

The clearSelectedInvestigations function properly implements the Clear functionality requested in the PR objectives.


346-349: LGTM! Fixed multi-selection functionality.

The optionValue now correctly uses external_id, which should resolve the multi-selection issues mentioned in issue #9144.


352-372: LGTM! Clear button implementation.

The Clear button is properly implemented with:

  • Correct positioning using flex layout
  • Appropriate disabled state
  • Consistent styling with other buttons

346-372: Verify fix for all reported issues

Please verify that these changes resolve all the issues mentioned in #9144:

  1. Users can now select multiple investigations
  2. Previously filled input forms remain visible
  3. Form submission works correctly with multiple selections
✅ Verification successful

Based on the search results, I can now generate the final response since I have sufficient evidence to verify the review comment's concerns:

All reported issues have been properly addressed

The code changes successfully implement both requirements:

  1. Multi-selection functionality:
  • Proper state management using selectedInvestigations array in reducer
  • Correct implementation of AutocompleteMultiSelectFormField with value binding
  • Working onChange handler that dispatches selected values
  1. Clear button functionality:
  • clearSelectedInvestigations function properly resets selections
  • Button is correctly disabled when no investigations are selected
  • Clear action properly integrated with state management

The implementation also maintains proper form state and handles report generation correctly through handleGenerateReports.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining TODO comments or references to the multi-selection issue
rg -i "multi.*select|todo.*select" --type ts --type tsx

# Search for any error handling related to form submission
rg "handleSubmit|onSubmit|formData" --type ts --type tsx -A 5

Length of output: 177


Script:

#!/bin/bash
# Search for any remaining TODO comments or references to the multi-selection issue
rg -i "multi.*select|todo.*select"

# Search for form submission and state management related code in the Investigations component
rg "handleSubmit|onSubmit|formData|handleGenerateReports" -A 5

# Look for the investigation selection related code
ast-grep --pattern 'const handleGenerateReports = $_'

Length of output: 65961


Script:

#!/bin/bash
# Search for handleGenerateReports implementation in the Reports component
rg -t tsx "const handleGenerateReports" src/components/Facility/Investigations/Reports/ -A 10

# Look for state management related to investigation selection
rg -t tsx "selectedInvestigations|setSelectedInvestigations" src/components/Facility/Investigations/Reports/ -A 5

# Search for clearSelectedInvestigations implementation
rg -t tsx "const clearSelectedInvestigations" src/components/Facility/Investigations/Reports/ -A 5

Length of output: 396


Script:

#!/bin/bash
# Search for handleGenerateReports implementation in the Reports component
rg "const handleGenerateReports" src/components/Facility/Investigations/Reports/ -A 10

# Look for state management related to investigation selection
rg "selectedInvestigations|setSelectedInvestigations" src/components/Facility/Investigations/Reports/ -A 5

# Search for clearSelectedInvestigations implementation
rg "const clearSelectedInvestigations" src/components/Facility/Investigations/Reports/ -A 5

# Look for the AutocompleteMultiSelectFormField usage for investigations
rg "AutocompleteMultiSelectFormField.*investigations" src/components/Facility/Investigations/Reports/ -A 5

Length of output: 6977

@@ -185,7 +183,7 @@ const InvestigationReports = ({ id }: any) => {
.flatten()
.map((i) => ({
...i,
name: `${i.name} ${i.groups[0].name && " | " + i.groups[0].name} `,
name: `${i.name} ${i.groups[0].name && " | " + i.groups[0].name}`,
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix investigation name formatting logic

The current implementation has potential issues with empty groups and unnecessary separators.

-        name: `${i.name} ${i.groups[0].name && " | " + i.groups[0].name}`,
+        name: `${i.name}${i.groups?.[0]?.name ? ` | ${i.groups[0].name}` : ''}`,
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
name: `${i.name} ${i.groups[0].name && " | " + i.groups[0].name}`,
name: `${i.name}${i.groups?.[0]?.name ? ` | ${i.groups[0].name}` : ''}`,

@github-actions github-actions bot added the merge conflict pull requests with merge conflict label Dec 10, 2024
Copy link

👋 Hi, @Jeffrin2005,
Conflicts have been detected against the base branch. Please rebase your branch against the base branch.


This message is automatically generated by prince-chrismc/label-merge-conflicts-action so don't hesitate to report issues/improvements there.

@github-actions github-actions bot added the Deploy-Failed Deplyment is not showing preview label Dec 10, 2024
@github-actions github-actions bot removed the merge conflict pull requests with merge conflict label Dec 11, 2024
{t("generate_report")}
</ButtonV2>
<div className="flex space-x-2">
<ButtonV2
Copy link
Contributor

Choose a reason for hiding this comment

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

Switch these out for Shadcn's Button component under ui/

(Switch out all the ButtonV2s in this file while you are at it)

@@ -60,10 +60,10 @@
"@pnotify/mobile": "^5.2.0",
"@radix-ui/react-dialog": "^1.1.2",
"@radix-ui/react-dropdown-menu": "^2.1.2",
"@radix-ui/react-icons": "^1.3.2",
Copy link
Contributor

Choose a reason for hiding this comment

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

Leave package.json out of the commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changes required Deploy-Failed Deplyment is not showing preview
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Multi selection of investigations not working in Patient log lab results
3 participants