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

Resources redesign #10308

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

Conversation

Jacobjeevan
Copy link
Contributor

@Jacobjeevan Jacobjeevan commented Jan 30, 2025

Proposed Changes

image image

@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

Summary by CodeRabbit

Release Notes

  • Localization

    • Added comprehensive translations for resource statuses in English and other languages.
    • Removed "transfer in progress" translations in multiple languages.
  • Resource Management

    • Updated resource status constants with icons.
    • Introduced new resource list view with card-based layout.
    • Enhanced empty state handling for resources.
  • UI/UX Improvements

    • Refined resource filtering and display mechanisms.
    • Improved internationalization support.
  • Code Refactoring

    • Removed several resource-related components.
    • Updated routing for resource views to include facility context.

Copy link
Contributor

coderabbitai bot commented Jan 30, 2025

Walkthrough

This pull request introduces comprehensive changes to the resources management system, focusing on localization, routing, and component restructuring. The modifications span multiple files, including locale JSON files, routing configurations, and React components. The changes aim to enhance the resource management interface by updating status representations, improving localization support, and refactoring the resource list and related components.

Changes

File Change Summary
public/locale/en.json Added new localization entries for resource statuses, filters, and resource titles
public/locale/hi.json, kn.json, ta.json Removed transfer_in_progress translation
src/Routers/routes/ResourceRoutes.tsx Updated resource route to use ResourceList instead of previous View component
src/common/constants.tsx Replaced RESOURCE_CHOICES with RESOURCE_STATUS_CHOICES, adding icons to status representations
Deleted Components Removed ResourceBadges.tsx, ResourceBlock.tsx, ResourceBoard.tsx, ResourceCommons.tsx, ResourceFilter.tsx
src/components/Resource/ResourceList.tsx Completely refactored component with new rendering approach and query handling
src/components/Resource/ResourceDetailsUpdate.tsx Updated to use new RESOURCE_STATUS_CHOICES and improved localization

Assessment against linked issues

Objective Addressed Explanation
Redesign resources page (10285)
Follow encounters format (10285)

Possibly related PRs

  • Design of List View layout in Resource Page #9096: This PR adds new key-value pairs in the public/locale/en.json file for localization, including entries for resource statuses like "Approved" and "Pending," which are directly related to the changes made in the main PR that also modifies localization entries for resource statuses.
  • Feat: Display total no. of entities with heading in Organization #10092: This PR introduces new entries for entity counts in the public/locale/en.json file, which aligns with the localization enhancements made in the main PR, focusing on improving the internationalization of the application.
  • added * to all mandatory fields in resource request form #10314: While this PR primarily focuses on adding visual indicators for mandatory fields in the resource request form, it also emphasizes the importance of maintaining UI text in internationalization files, which is a common theme with the localization changes in the main PR.

Suggested labels

needs review, needs testing, P1

Suggested reviewers

  • Jacobjeevan

Poem

🐰 Hop, hop, resources in line,
Status badges now shine so fine!
Locales updated with care,
A rabbit's touch everywhere!
Code refactored, clean and bright,
Resources dancing 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 d3580a9 and 4cd3ec0.

📒 Files selected for processing (24)
  • src/CAREUI/display/Count.tsx (0 hunks)
  • src/CAREUI/interactive/FiltersSlideover.tsx (0 hunks)
  • src/CAREUI/interactive/SlideOver.tsx (0 hunks)
  • src/Routers/types.ts (0 hunks)
  • src/Utils/AutoSave.tsx (0 hunks)
  • src/Utils/primitives.ts (0 hunks)
  • src/Utils/useSegmentedRecorder.ts (0 hunks)
  • src/components/Common/DateInputV2.tsx (0 hunks)
  • src/components/Common/DateRangeInputV2.tsx (0 hunks)
  • src/components/Common/DateTextInput.tsx (0 hunks)
  • src/components/Common/GLocationPicker.tsx (0 hunks)
  • src/components/Common/QuantityInput.tsx (0 hunks)
  • src/components/Common/SortDropdown.tsx (0 hunks)
  • src/components/Common/Spinner.tsx (0 hunks)
  • src/components/Common/UserDetails.tsx (0 hunks)
  • src/components/Common/View.tsx (0 hunks)
  • src/components/Facility/FacilityBlock.tsx (0 hunks)
  • src/components/Form/FormFields/DateRangeFormField.tsx (0 hunks)
  • src/components/Form/SearchInput.tsx (0 hunks)
  • src/components/Form/Utils.ts (0 hunks)
  • src/components/Kanban/Board.tsx (0 hunks)
  • src/pages/Encounters/tabs/EncounterFeedTab.tsx (0 hunks)
  • src/types/notes/notes.ts (0 hunks)
  • src/types/permission/permission.ts (0 hunks)
💤 Files with no reviewable changes (24)
  • src/components/Common/Spinner.tsx
  • src/types/permission/permission.ts
  • src/components/Common/View.tsx
  • src/components/Form/FormFields/DateRangeFormField.tsx
  • src/Utils/primitives.ts
  • src/components/Facility/FacilityBlock.tsx
  • src/Routers/types.ts
  • src/components/Common/QuantityInput.tsx
  • src/types/notes/notes.ts
  • src/components/Form/SearchInput.tsx
  • src/components/Common/UserDetails.tsx
  • src/components/Common/DateTextInput.tsx
  • src/CAREUI/interactive/FiltersSlideover.tsx
  • src/pages/Encounters/tabs/EncounterFeedTab.tsx
  • src/components/Form/Utils.ts
  • src/components/Common/SortDropdown.tsx
  • src/components/Kanban/Board.tsx
  • src/components/Common/DateRangeInputV2.tsx
  • src/components/Common/DateInputV2.tsx
  • src/CAREUI/interactive/SlideOver.tsx
  • src/CAREUI/display/Count.tsx
  • src/components/Common/GLocationPicker.tsx
  • src/Utils/useSegmentedRecorder.ts
  • src/Utils/AutoSave.tsx
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Test
  • GitHub Check: CodeQL-Build
  • GitHub Check: cypress-run (1)
  • GitHub Check: OSSAR-Scan

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. (Beta)
  • @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 Jan 30, 2025

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 4cd3ec0
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/679cba172e990f0008aa9d10
😎 Deploy Preview https://deploy-preview-10308--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.

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

🧹 Nitpick comments (6)
src/components/Resource/ResourceList.tsx (5)

2-2: Consider using the useTranslation hook for better context alignment.
Directly importing t from "i18next" can work, but using the useTranslation hook from react-i18next often provides more robust context management and can help avoid unexpected behavior if multiple i18n instances are in use.


42-45: Avoid basing logic on display text.
COMPLETED and ACTIVE are derived by filtering the text field of RESOURCE_STATUS_CHOICES. Depending on translations or display text for logic can be fragile. Consider using IDs or status codes instead.


85-97: Add explicit error handling for the query.
While the isLoading state is handled, consider adding an onError callback or conditional rendering for errors to improve resiliency and user feedback when requests fail.


200-221: Reuse existing translation keys if applicable.
Based on prior learnings from AnveshNalimela, there's a recommendation to unify status translations under certain keys (e.g. "consent__status"). Verify whether reusing those keys (instead of "resource_status__${statusOption}") aligns with your global i18n strategy.


228-299: Consider splitting the rendering block into smaller components.
The mapping logic for resources, empty-state handling, and pagination result in a large JSX block. Refactoring into smaller subcomponents could improve readability and maintainability.

src/components/Resource/ResourceDetailsUpdate.tsx (1)

206-208: Confirm accurate translation keys for resource statuses.
optionLabel={(option) => t(\resource_status__${option}`)}` may require matching keys in your localization files. Use a stable ID/key rather than a user-facing string if your translations or statuses diverge in the future. Also consider adopting past recommendations from retrieved learnings about unifying status translation keys.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 81a6257 and a964e29.

📒 Files selected for processing (14)
  • public/locale/en.json (5 hunks)
  • public/locale/hi.json (0 hunks)
  • public/locale/kn.json (0 hunks)
  • public/locale/ml.json (0 hunks)
  • public/locale/ta.json (0 hunks)
  • src/Routers/routes/ResourceRoutes.tsx (1 hunks)
  • src/common/constants.tsx (1 hunks)
  • src/components/Resource/ResourceBadges.tsx (0 hunks)
  • src/components/Resource/ResourceBlock.tsx (0 hunks)
  • src/components/Resource/ResourceBoard.tsx (0 hunks)
  • src/components/Resource/ResourceCommons.tsx (0 hunks)
  • src/components/Resource/ResourceDetailsUpdate.tsx (2 hunks)
  • src/components/Resource/ResourceFilter.tsx (0 hunks)
  • src/components/Resource/ResourceList.tsx (1 hunks)
💤 Files with no reviewable changes (9)
  • src/components/Resource/ResourceBoard.tsx
  • src/components/Resource/ResourceBadges.tsx
  • public/locale/ta.json
  • src/components/Resource/ResourceBlock.tsx
  • src/components/Resource/ResourceCommons.tsx
  • src/components/Resource/ResourceFilter.tsx
  • public/locale/ml.json
  • public/locale/hi.json
  • public/locale/kn.json
🧰 Additional context used
📓 Learnings (1)
src/components/Resource/ResourceDetailsUpdate.tsx (1)
Learnt from: AnveshNalimela
PR: ohcnetwork/care_fe#9096
File: src/components/Resource/ResourceList.tsx:245-245
Timestamp: 2024-11-13T12:33:52.373Z
Learning: When displaying the resource status in `ResourceList.tsx`, use `{t("consent__status")}` instead of adding a new translation key `{t("resource_status")}`.
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: Redirect rules - care-ohc
  • GitHub Check: Header rules - care-ohc
  • GitHub Check: Pages changed - care-ohc
  • GitHub Check: cypress-run (1)
  • GitHub Check: CodeQL-Build
  • GitHub Check: OSSAR-Scan
🔇 Additional comments (5)
src/components/Resource/ResourceList.tsx (1)

47-59: Nice UX improvement with the new EmptyState component!
This is a clean, self-contained implementation for an empty-state view. It helps users easily see when no resources exist.

src/Routers/routes/ResourceRoutes.tsx (1)

3-8: Clean route definition transition.
Switching from <View> to <ResourceList> is straightforward and appears consistent with the new design. Double-check that all references to ListView have been removed in case they are still called in other files.

✅ Verification successful

Clean transition confirmed - no remaining ListView references
The codebase shows a complete transition to ResourceList with no remaining references to the old ListView or View components.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find any references to the old `ListView` or `View` usage in the repo.

rg -A 2 "ListView" 
rg -A 2 "View name=\"resource\""

Length of output: 51


Script:

#!/bin/bash
# First verify we can access the codebase
ls src/Routers/routes/ResourceRoutes.tsx

# Search for any View-related components with broader patterns
rg -i "view" src/
rg "from.*View" src/
rg "import.*View" src/

# Search for potential resource-related view components
rg -i "resource.*view" src/
rg -i "view.*resource" src/

Length of output: 26090

src/common/constants.tsx (1)

165-173: Well-structured resource status mapping with semantic icons!

The constant provides a clear mapping between status values and their visual representations, with semantically meaningful icons that enhance UX.

public/locale/en.json (2)

1734-1740: Comprehensive status translations with proper formatting!

The translations for resource statuses are well-structured and maintain consistency with the status values defined in the constants.


326-326: Clear empty state messages for better UX!

The empty state messages provide clear guidance to users when no resources are found and suggest next actions.

Also applies to: 1367-1367

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

🧹 Nitpick comments (1)
src/components/Resource/ResourceList.tsx (1)

265-359: Consider adding error boundary for the resource list.

The card grid implementation looks good, but it could benefit from error handling for failed resource loads.

+import { ErrorBoundary } from "@/components/ErrorBoundary";

 <div
   className="grid gap-4 sm:grid-cols-1 md:grid-cols-2 lg:grid-cols-3"
   data-cy="resource-list-cards"
 >
+  <ErrorBoundary>
     {isLoading ? (
       <CardGridSkeleton count={6} />
     ) : resources.length === 0 ? (
       <div className="col-span-full">
         <EmptyState />
       </div>
     ) : (
       // ... rest of the code
     )}
+  </ErrorBoundary>
 </div>
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a964e29 and d3580a9.

📒 Files selected for processing (8)
  • public/locale/en.json (7 hunks)
  • src/Routers/routes/ResourceRoutes.tsx (1 hunks)
  • src/components/Patient/PatientDetailsTab/ResourceRequests.tsx (1 hunks)
  • src/components/Resource/ResourceCreate.tsx (1 hunks)
  • src/components/Resource/ResourceDetails.tsx (5 hunks)
  • src/components/Resource/ResourceDetailsUpdate.tsx (5 hunks)
  • src/components/Resource/ResourceList.tsx (1 hunks)
  • src/components/ui/sidebar/facility-nav.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/Resource/ResourceDetailsUpdate.tsx
🧰 Additional context used
📓 Learnings (2)
src/components/Resource/ResourceCreate.tsx (1)
Learnt from: Jacobjeevan
PR: ohcnetwork/care_fe#9062
File: src/Routers/routes/ResourceRoutes.tsx:19-21
Timestamp: 2024-12-10T02:49:05.600Z
Learning: In the `ResourceCreate` component, `facilityId` can be optional.
src/Routers/routes/ResourceRoutes.tsx (1)
Learnt from: Jacobjeevan
PR: ohcnetwork/care_fe#9062
File: src/Routers/routes/ResourceRoutes.tsx:19-21
Timestamp: 2024-12-10T02:49:05.600Z
Learning: In the `ResourceCreate` component, `facilityId` can be optional.
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: cypress-run (1)
🔇 Additional comments (11)
src/components/ui/sidebar/facility-nav.tsx (1)

38-42: LGTM!

The change correctly aligns the resource URL with other facility-scoped links by incorporating the baseUrl. This ensures proper facility context in resource navigation.

src/components/Patient/PatientDetailsTab/ResourceRequests.tsx (1)

115-119: LGTM!

The change correctly updates the resource detail URL to include the origin facility's ID, maintaining proper facility context in navigation.

src/components/Resource/ResourceDetails.tsx (2)

206-212: LGTM!

The component's props have been correctly updated to include the required facilityId, aligning with the facility-scoped resource redesign.


272-274: Improved localization for resource status.

The status badge now uses a translation key format that better supports localization.

src/components/Resource/ResourceCreate.tsx (2)

133-133: LGTM!

The change correctly updates the post-creation navigation to include the facility ID, maintaining proper facility context.


Line range hint 47-49: Consider making facilityId optional.

According to the retrieved learnings from PR #9062, facilityId can be optional in the ResourceCreate component. However, the current interface declares it as a required number.

✅ Verification successful

Make facilityId optional and change type to string for consistency

The suggestion to make facilityId optional is valid and should be implemented along with changing its type from number to string for consistency with other components. The code already handles the optional case in the facility query with enabled: !!facilityId.

  • Change the interface to use facilityId?: string
  • Remove String() conversions as they won't be needed anymore
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify if facilityId is optional in other components
# Test: Search for components that make facilityId optional
rg -A 5 'facilityId\?' src/

Length of output: 5894


Script:

#!/bin/bash
# Check interface definition and usage of facilityId in ResourceCreate
ast-grep --pattern 'interface $_Props {
  $$$
  facilityId: $_
  $$$
}'  src/components/Resource/ResourceCreate.tsx

echo "=== Usage patterns ==="
rg -A 3 'facilityId' src/components/Resource/ResourceCreate.tsx

Length of output: 1316

src/Routers/routes/ResourceRoutes.tsx (1)

8-16: LGTM! Routes are properly scoped to facilities.

The route changes correctly implement facility-scoped resource management by:

  1. Including facilityId parameter in all resource routes
  2. Passing facilityId prop to all resource components

Note: Based on past learnings from PR #9062, facilityId can be optional in the ResourceCreate component, but it's correctly required here in the routes where facility context is needed.

src/components/Resource/ResourceList.tsx (3)

1-46: LGTM! Well-structured imports and constants.

The imports are properly organized by type (external libraries, utils, components) and the constants for status management are clearly defined.


48-60: LGTM! EmptyState component follows best practices.

The EmptyState component is well-implemented with:

  • Clear visual hierarchy
  • Proper use of icons and spacing
  • Internationalized text

62-101: LGTM! Data fetching implementation is robust.

The component properly:

  • Uses React Query for efficient data fetching
  • Handles pagination
  • Manages filter state
  • Scopes requests to the facility
public/locale/en.json (1)

326-326: LGTM! Comprehensive localization coverage.

The added localization strings provide complete coverage for:

  • Resource statuses
  • Search functionality
  • Empty states
  • Incoming/Outgoing filters

Also applies to: 1075-1075, 1368-1368, 1443-1443, 1736-1743

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rework Resources Page
2 participants