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

Fix: Bugs in valueset page #10738

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

Conversation

AdityaJ2305
Copy link
Contributor

@AdityaJ2305 AdityaJ2305 commented Feb 20, 2025

Proposed Changes

  • Fixes Bugs in valueset page #10695
  • Pagination in ValueSet
  • i18n for valuesetform
  • Navigate to list after creating new valueset
  • Options updated for status
  • Use Table from shadcn

@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 new localized labels, including a status indicator and a save action.
    • Enhanced the valueset form with dynamic translations for field labels, error messages, and submission feedback.
    • Added additional status options ("draft," "retired," and "unknown") for more flexible categorization.
    • Improved list filtering, pagination, and table presentation for a smoother browsing experience.
  • Refactor

    • Streamlined navigation after valueset creation to direct users to a unified administration view.

Copy link
Contributor

coderabbitai bot commented Feb 20, 2025

Walkthrough

This pull request introduces enhancements across localization and valueset components. It adds new translation keys to the localization file and integrates internationalization into forms. The valueset editor's create mutation now navigates to a general admin page without using a data parameter, and redundant imports have been removed. The valueset form’s validation schema and UI messages are updated for multilingual support, while the valueset list leverages a new hook for dynamic query filtering and pagination. Additionally, the valueset type definition is expanded to accommodate extra status options.

Changes

File(s) Change Summary
public/locale/en.json Added new localization keys "retired": "Retired" and "save_valuset": "Save ValueSet".
src/components/ValueSet/ValueSetEditor.tsx Updated the createMutation onSuccess callback to navigate to the admin valuesets page (removing the data parameter) and removed the unused ValuesetBase import.
src/components/ValueSet/ValueSetForm.tsx Integrated i18n support using the useTranslation hook; updated the form schema with translated error messages and labels; expanded the status field to include "draft", "retired", and "unknown"; updated button text accordingly.
src/components/ValueSet/ValueSetList.tsx Introduced the useFilters hook to manage dynamic query parameters; modified the useQuery call to incorporate filters; changed the button variant and status badge to use translations; added a Pagination component at the bottom.
src/types/valueset/valueset.ts Expanded the status property in the ValuesetBase interface to include "draft", "retired", and "unknown" alongside the existing "active" option.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Editor
    participant API
    participant Router

    User->>Editor: Submit new valueset
    Editor->>API: Trigger createMutation
    API-->>Editor: Return success
    Editor->>Router: Navigate to admin valuesets page
Loading
sequenceDiagram
    participant User
    participant ListComp as ValueSetList
    participant Filter as useFilters
    participant API
    participant Pager as Pagination

    User->>ListComp: Load valuesets page
    ListComp->>Filter: Retrieve query parameters (page, limit)
    ListComp->>API: Fetch valuesets with queryParams
    API-->>ListComp: Return valuesets data
    ListComp->>Pager: Render pagination with total count
Loading

Possibly related PRs

Suggested labels

needs review, tested

Suggested reviewers

  • rithviknishad
  • Jacobjeevan

Poem

I'm a bunny who loves to code,
Hopping through changes on the road.
New keys and hooks are here to stay,
With translations leading the way.
My little paws tap with delight 🐇,
Celebrating changes that shine so bright!


📜 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 1e18955 and e017bfa.

📒 Files selected for processing (1)
  • src/components/ValueSet/ValueSetForm.tsx (7 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/ValueSet/ValueSetForm.tsx
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Test
  • GitHub Check: lint
  • GitHub Check: OSSAR-Scan
  • GitHub Check: cypress-run (1)
  • GitHub Check: CodeQL-Build

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 Feb 20, 2025

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit e017bfa
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/67b81533bbc58000085aa638
😎 Deploy Preview https://deploy-preview-10738.preview.ohc.network
📱 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.

@AdityaJ2305 AdityaJ2305 marked this pull request as ready for review February 20, 2025 20:27
@AdityaJ2305 AdityaJ2305 requested a review from a team as a code owner February 20, 2025 20:27
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 comments (1)
src/components/ValueSet/ValueSetList.tsx (1)

89-97: 🛠️ Refactor suggestion

Update badge styling for new status values.

The badge styling only handles "active" status. Consider updating the styling to handle the new status values: "draft", "retired", and "unknown".

-                    className={
-                      valueset.status === "active"
-                        ? "bg-green-100 text-green-800 hover:bg-green-200"
-                        : "bg-red-100 text-red-800 hover:bg-red-200"
-                    }
+                    className={
+                      {
+                        active: "bg-green-100 text-green-800 hover:bg-green-200",
+                        draft: "bg-yellow-100 text-yellow-800 hover:bg-yellow-200",
+                        retired: "bg-red-100 text-red-800 hover:bg-red-200",
+                        unknown: "bg-gray-100 text-gray-800 hover:bg-gray-200",
+                      }[valueset.status]
+                    }
🧹 Nitpick comments (1)
public/locale/en.json (1)

1909-1911: New Translation Key for "retired" Status Added
The addition of "retired": "Retired" appears to correctly introduce a new label for the retired status, which aligns with the expanded status options on the ValueSet page. Please ensure that this key is referenced in the UI components (e.g., in the form validation or status dropdown) so that it displays properly.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 213fb25 and 440d9c0.

📒 Files selected for processing (5)
  • public/locale/en.json (2 hunks)
  • src/components/ValueSet/ValueSetEditor.tsx (1 hunks)
  • src/components/ValueSet/ValueSetForm.tsx (7 hunks)
  • src/components/ValueSet/ValueSetList.tsx (4 hunks)
  • src/types/valueset/valueset.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Test
  • GitHub Check: cypress-run (1)
  • GitHub Check: OSSAR-Scan
🔇 Additional comments (5)
src/types/valueset/valueset.ts (1)

29-29:

❓ Verification inconclusive

Verify handling of new status values across the application.

The status options have been expanded from "active"/"inactive" to include "draft", "retired", and "unknown". This is a breaking change that requires verification.

Run this script to find all usages of the status field:


🏁 Script executed:

#!/bin/bash
# Search for status field usage in components and tests
rg -A 5 'status[^a-zA-Z].*(?:active|inactive|draft|retired|unknown)'

Length of output: 21682


Review Update: Verify Status Handling Across Consumers

The status property in src/types/valueset/valueset.ts has been updated from "active" | "inactive" to "active" | "draft" | "retired" | "unknown". Our verification shows that:

  • Valueset Components

    • src/components/ValueSet/ValueSetForm.tsx now uses z.enum(["active", "draft", "retired", "unknown"]), reflecting the new options.
    • src/components/ValueSet/ValueSetList.tsx checks if valueset.status === "active" and applies alternative styling otherwise.
  • Other Usages

    • Multiple files (e.g., locale files and several questionnaire components) still reference legacy statuses such as "inactive". However, these appear to be in a different context (e.g., locations or questionnaire statuses) than the updated valueset type.

Action Required:

  • Review and Confirm: Verify that all consumers of the updated valueset status are handling the new states ("draft", "retired", and "unknown") correctly. In particular, double-check any binary logic (e.g., comparisons solely against "active") to ensure they address the expanded lifecycle adequately.
  • Testing: Ensure thorough testing of valueset workflows with the full set of status options to catch any unforeseen side-effects.
src/components/ValueSet/ValueSetEditor.tsx (1)

37-40: LGTM! Navigation flow simplified.

The change to navigate directly to the valuesets list after creation is a good improvement that simplifies the user flow.

src/components/ValueSet/ValueSetList.tsx (1)

19-21: LGTM! Pagination implemented correctly.

The useFilters hook is properly configured with a default limit of 15 items per page.

src/components/ValueSet/ValueSetForm.tsx (2)

347-401: LGTM! Comprehensive i18n integration.

The form has been properly internationalized with:

  • Translated validation messages
  • Translated field labels
  • Proper handling of all status options

425-425: LGTM! Clear indication of required fields.

The required attribute has been correctly added to mandatory fields: name, slug, and status.

Also applies to: 439-439, 467-467

@AdityaJ2305
Copy link
Contributor Author

@nihal467, I’ve made the changes based on my understanding of the expected behaviors. Please confirm if these changes align with the expected behavior for bugs other than the pagination one. If they do, kindly acknowledge this comment. Thanks!

cc: @Jacobjeevan @rithviknishad

@github-advanced-security
Copy link

This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation.

1 similar comment
@github-advanced-security
Copy link

This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation.

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 (4)
src/components/ValueSet/ValueSetList.tsx (4)

30-38: Add error handling to the query configuration.

While the query setup is correct, consider adding error handling to improve user experience.

 const { data: response, isLoading } = useQuery({
   queryKey: ["valuesets", qParams],
   queryFn: query(valuesetApi.list, {
     queryParams: {
       limit: resultsPerPage,
       offset: ((qParams.page ?? 1) - 1) * resultsPerPage,
     },
   }),
+  onError: (error) => {
+    // Handle error appropriately (e.g., show toast notification)
+    console.error('Failed to fetch valuesets:', error);
+  }
 });

111-113: Optimize description cell CSS classes.

The description cell has potentially redundant CSS classes. Consider simplifying:

-<TableCell className="px-6 py-4 truncate text-sm text-gray-900 break-words whitespace-normal">
+<TableCell className="px-6 py-4 text-sm text-gray-900 break-words">

The truncate class is unnecessary when using break-words and whitespace-normal.


96-109: Consider extracting status badge styles and translations.

The current implementation directly uses status values as translation keys and inline styles. Consider extracting these into constants for better maintainability.

+const STATUS_STYLES = {
+  active: "bg-green-100 text-green-800 hover:bg-green-200",
+  draft: "bg-yellow-100 text-yellow-800 hover:bg-yellow-200",
+  retired: "bg-red-100 text-red-800 hover:bg-red-200",
+  unknown: "bg-gray-100 text-gray-800 hover:bg-gray-200",
+} as const;
+
+const STATUS_TRANSLATION_KEYS = {
+  active: "status.active",
+  draft: "status.draft",
+  retired: "status.retired",
+  unknown: "status.unknown",
+} as const;

 <Badge
-  className={
-    {
-      active: "bg-green-100 text-green-800 hover:bg-green-200",
-      draft: "bg-yellow-100 text-yellow-800 hover:bg-yellow-200",
-      retired: "bg-red-100 text-red-800 hover:bg-red-200",
-      unknown: "bg-gray-100 text-gray-800 hover:bg-gray-200",
-    }[valueset.status]
-  }
+  className={STATUS_STYLES[valueset.status]}
 >
-  {t(valueset.status)}
+  {t(STATUS_TRANSLATION_KEYS[valueset.status])}
 </Badge>

135-135: Add loading state to pagination.

Consider disabling the pagination component while data is loading to prevent user interaction during fetch operations.

-<Pagination totalCount={response?.count ?? 0} />
+<Pagination totalCount={response?.count ?? 0} disabled={isLoading} />
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 440d9c0 and 1e18955.

📒 Files selected for processing (4)
  • public/locale/en.json (2 hunks)
  • src/components/ValueSet/ValueSetEditor.tsx (4 hunks)
  • src/components/ValueSet/ValueSetForm.tsx (7 hunks)
  • src/components/ValueSet/ValueSetList.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • public/locale/en.json
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: cypress-run (1)
🔇 Additional comments (9)
src/components/ValueSet/ValueSetList.tsx (2)

8-15: LGTM! Well-structured imports and hook setup.

The imports are logically organized, and the useFilters hook is properly configured with a reasonable default limit of 15 items per page.

Also applies to: 19-19, 27-29


27-29: LGTM! Pagination implementation meets PR objectives.

The pagination implementation is well-structured with:

  • Proper hook setup with default limit
  • Correct query parameter handling
  • Integration with the UI through the Pagination component

Also applies to: 30-38, 135-135

src/components/ValueSet/ValueSetEditor.tsx (2)

37-40: LGTM! Navigation simplified after valueset creation.

The change simplifies the navigation logic by directly routing to the valuesets list page instead of a specific valueset page, which is a more consistent approach.


48-52: Cache invalidation ensures UI consistency.

Good addition of cache invalidation after successful update. This ensures the valuesets list is refreshed with the latest data.

src/components/ValueSet/ValueSetForm.tsx (5)

5-5: LGTM! i18n support added correctly.

The useTranslation hook is properly imported and initialized for internationalization support.

Also applies to: 347-347


475-479: Status options expanded appropriately.

The status options have been expanded to include 'draft', 'retired', and 'unknown', replacing the previous 'inactive' option. This provides more granular control over the valueset lifecycle.


425-425: Required field indicators added consistently.

Good addition of required field indicators for name, slug, and status fields. This improves form usability by clearly indicating which fields are mandatory.

Also applies to: 439-439, 453-453, 467-467


492-492: Button text internationalized.

The submit button text is now properly internationalized using the translation function.


349-401:

✅ Verification successful

Verify translation keys exist in locale files.

The schema now uses translation keys for validation messages. Please ensure all these keys exist in the locale files:

  • field_required
  • name
  • slug
  • description
  • status
  • active
  • draft
  • retired
  • unknown
  • saving
  • save_valueset

🏁 Script executed:

#!/bin/bash
# Check if all required translation keys exist in locale files
rg -l "field_required|name|slug|description|status|active|draft|retired|unknown|saving|save_valueset" public/locale/

Length of output: 250


Translation Keys Verified in Locale Files

The verification script indicates that all required translation keys:

  • field_required
  • name
  • slug
  • description
  • status
  • active
  • draft
  • retired
  • unknown
  • saving
  • save_valueset

are present across the locale files (public/locale/en.json, kn.json, mr.json, ml.json, ta.json, hi.json). No further changes are necessary.

TableHead,
TableHeader,
TableRow,
} from "@/components/ui/table";
Copy link
Contributor

Choose a reason for hiding this comment

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

@AdityaJ2305 u can remove this , i have added this in my UI enhancement PR #10712

cc : @rithviknishad @Jacobjeevan

@AdityaJ2305
Copy link
Contributor Author

AdityaJ2305 commented Feb 21, 2025

@rithviknishad @Jacobjeevan , Ready for review and testing

PS: #10695 (comment)

@github-actions github-actions bot added the merge conflict pull requests with merge conflict label Feb 21, 2025
Copy link

Conflicts have been detected against the base branch. Please merge the base branch into your branch.
cc: @AdityaJ2305

See: https://docs.ohc.network/docs/contributing#how-to-resolve-merge-conflicts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changes required merge conflict pull requests with merge conflict
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bugs in valueset page
3 participants