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

ui fixes. #1897

Merged
merged 5 commits into from
Nov 26, 2024
Merged

ui fixes. #1897

merged 5 commits into from
Nov 26, 2024

Conversation

suryansh-egov
Copy link
Collaborator

@suryansh-egov suryansh-egov commented Nov 26, 2024

Choose the appropriate template for your PR:

Summary by CodeRabbit

  • New Features

    • Enhanced handling of boundary types and localization data in the Boundary Relation creation process.
    • Improved user feedback mechanisms for template generation and status completion.
  • Bug Fixes

    • Refined error handling for empty boundary types during creation.
    • Enhanced error handling within polling mechanisms for clearer feedback.
  • Improvements

    • Streamlined formatting for boundary type labels and translation keys.
    • Updated UI components for better navigation and display of information.

@suryansh-egov suryansh-egov requested a review from a team as a code owner November 26, 2024 12:01
Copy link
Contributor

coderabbitai bot commented Nov 26, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request introduces modifications to the BoundaryRelationCreate and ViewHierarchy components. In BoundaryRelationCreate, enhancements include improved handling of boundary types, localization data, and refined error handling for empty boundary types. The ViewHierarchy component sees changes in polling logic, error handling, and formatting of boundary type labels. Both components aim to enhance user feedback and ensure consistent data processing while maintaining the overall control flow.

Changes

File Change Summary
.../campaign-manager/src/pages/employee/BoundaryRelationCreate.js - Updated logic for handling boundary types, ensuring consistent trimming and formatting.
- Modified addParents function for correct parent type setting.
- Refined error handling for empty boundary types.
- Adjusted polling error handling for clearer feedback.
.../campaign-manager/src/pages/employee/ViewHierarchy.js - Removed maximum retries check in polling, simplifying logic.
- Updated boundary type label handling for cleaner formatting.
- Enhanced polling behavior to allow retries post-errors.
- Minor UI adjustments for feedback mechanisms.

Possibly related PRs

Suggested reviewers

  • jagankumar-egov
  • nipunarora-eGov

Poem

🐰 In the garden of code, we hop and play,
With boundaries trimmed, we clear the way.
Errors are caught, and feedback is bright,
In our micro-ui, everything feels right!
So let’s celebrate this change with cheer,
For a smoother journey, we hold dear! 🌼


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.

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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between 85ab966 and 48dbe71.

📒 Files selected for processing (2)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/BoundaryRelationCreate.js (2 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/ViewHierarchy.js (6 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/BoundaryRelationCreate.js (1)

Pattern **/*.js: check

health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/ViewHierarchy.js (1)

Pattern **/*.js: check

🪛 Biome (1.9.4)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/BoundaryRelationCreate.js

[error] 347-347: Template literals are preferred over string concatenation.

Unsafe fix: Use a template literal.

(lint/style/useTemplate)

health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/ViewHierarchy.js

[error] 400-400: Template literals are preferred over string concatenation.

Unsafe fix: Use a template literal.

(lint/style/useTemplate)


[error] 419-419: Template literals are preferred over string concatenation.

Unsafe fix: Use a template literal.

(lint/style/useTemplate)


[error] 451-451: Template literals are preferred over string concatenation.

Unsafe fix: Use a template literal.

(lint/style/useTemplate)

🔇 Additional comments (1)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/BoundaryRelationCreate.js (1)

343-343: 🛠️ Refactor suggestion

Add error handling for empty boundary types

The code should validate boundary types before processing.

Add validation before processing:

+ const validateBoundaryType = (type) => {
+   if (!type?.trim()) {
+     throw new Error(t("INVALID_BOUNDARY_TYPE"));
+   }
+   return type;
+ };

 const local = [

Also applies to: 344-344

coderabbitai[bot]
coderabbitai bot previously approved these changes Nov 26, 2024
Copy link
Collaborator

@jagankumar-egov jagankumar-egov left a comment

Choose a reason for hiding this comment

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

put al these trim and formating in a single function

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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between 48dbe71 and ad097ea.

📒 Files selected for processing (2)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/BoundaryRelationCreate.js (3 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/ViewHierarchy.js (7 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/BoundaryRelationCreate.js (1)

Pattern **/*.js: check

health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/ViewHierarchy.js (1)

Pattern **/*.js: check

🪛 Biome (1.9.4)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/BoundaryRelationCreate.js

[error] 350-350: Template literals are preferred over string concatenation.

Unsafe fix: Use a template literal.

(lint/style/useTemplate)

health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/ViewHierarchy.js

[error] 374-374: Template literals are preferred over string concatenation.

Unsafe fix: Use a template literal.

(lint/style/useTemplate)

🔇 Additional comments (3)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/ViewHierarchy.js (2)

545-546: LGTM: Back button enabled

The back button is now correctly enabled, allowing users to navigate back to the boundary home page.


356-363: ⚠️ Potential issue

Reintroduce polling timeout to prevent resource leaks

The removal of the polling timeout could lead to resource leaks if the operation hangs. The timeout provides a safety net to ensure the polling eventually terminates.

Apply this diff to reintroduce the polling timeout:

-          // const timeoutDuration = (maxRetries + 1) * pollInterval;
-          // setTimeout(() => {
-          //   if (retries < maxRetries) {
-          //     // Only reject if not already resolved
-          //     setDataCreationGoing(false);
-          //     reject(new Error("Polling timeout"));
-          //   }
-          // }, timeoutDuration);
+          const timeoutDuration = (maxRetries + 1) * pollInterval;
+          setTimeout(() => {
+            if (retries < maxRetries) {
+              // Only reject if not already resolved
+              setDataCreationGoing(false);
+              reject(new Error("Polling timeout"));
+            }
+          }, timeoutDuration);

Likely invalid or redundant comment.

health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/BoundaryRelationCreate.js (1)

423-434: Parent boundary type assignment needs improvement

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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between ad097ea and 2a75bd7.

📒 Files selected for processing (2)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/BoundaryRelationCreate.js (3 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/ViewHierarchy.js (8 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/BoundaryRelationCreate.js (1)

Pattern **/*.js: check

health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/ViewHierarchy.js (1)

Pattern **/*.js: check

🪛 Biome (1.9.4)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/BoundaryRelationCreate.js

[error] 350-350: Template literals are preferred over string concatenation.

Unsafe fix: Use a template literal.

(lint/style/useTemplate)

health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/ViewHierarchy.js

[error] 374-374: Template literals are preferred over string concatenation.

Unsafe fix: Use a template literal.

(lint/style/useTemplate)

🔇 Additional comments (5)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/ViewHierarchy.js (5)

112-112: LGTM: Improved error handling with localized message

The error handling has been enhanced with a proper localized message for the "in progress" state.


545-546: LGTM: Enabled back button navigation

The back button has been correctly enabled to allow navigation to the boundary home page.


310-314: ⚠️ Potential issue

Reintroduce maximum retries check

Removing the maximum retries check could lead to infinite polling if the operation never completes or fails silently. This may cause unnecessary server load and poor user experience.

Apply this diff to reintroduce the maximum retries check:

-              // if (retries >= maxRetries) {
-              //   setDataCreationGoing(false);
-              //   reject(new Error("Max retries reached"));
-              //   return;
-              // }
+              if (retries >= maxRetries) {
+                setDataCreationGoing(false);
+                reject(new Error("Max retries reached"));
+                return;
+              }

356-363: ⚠️ Potential issue

Reintroduce polling timeout

By commenting out the timeout for the polling operation, the promise may never resolve or reject if the operation does not complete. This can result in resource leaks and a poor user experience.

Apply this diff to reintroduce the polling timeout:

-          // const timeoutDuration = (maxRetries + 1) * pollInterval;
-          // setTimeout(() => {
-          //   if (retries < maxRetries) {
-          //     // Only reject if not already resolved
-          //     setDataCreationGoing(false);
-          //     reject(new Error("Polling timeout"));
-          //   }
-          // }, timeoutDuration);
+          const timeoutDuration = (maxRetries + 1) * pollInterval;
+          setTimeout(() => {
+            if (retries < maxRetries) {
+              // Only reject if not already resolved
+              setDataCreationGoing(false);
+              reject(new Error("Polling timeout"));
+            }
+          }, timeoutDuration);

373-375: 🛠️ Refactor suggestion

Use template literals for string interpolation

The string concatenation in the trimming function can be simplified using template literals for better readability and maintainability.

Apply this diff to use template literals:

 const trimming = (val)=>{
-      return `${t(( hierarchyType + "_" + val.trim().replace(/[\s_]+/g, '')).toUpperCase())}`;
+      return t(`${hierarchyType}_${val.trim().replace(/[\s_]+/g, '')}`.toUpperCase());
 }
🧰 Tools
🪛 Biome (1.9.4)

[error] 374-374: Template literals are preferred over string concatenation.

Unsafe fix: Use a template literal.

(lint/style/useTemplate)

Comment on lines +329 to +331
const trimming = (val) => {
return val.trim().replace(/[\s_]+/g, '');
};
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add input validation and documentation to the trimming function

The function should handle edge cases and document its purpose.

+/**
+ * Standardizes boundary type strings by removing whitespace and underscores
+ * @param {string} val - The boundary type string to format
+ * @returns {string} The formatted boundary type string
+ * @throws {Error} If the input is null, undefined, or empty
+ */
 const trimming = (val) => {
+    if (!val) {
+        throw new Error('Boundary type cannot be empty');
+    }
     return val.trim().replace(/[\s_]+/g, '');
 };
📝 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
const trimming = (val) => {
return val.trim().replace(/[\s_]+/g, '');
};
/**
* Standardizes boundary type strings by removing whitespace and underscores
* @param {string} val - The boundary type string to format
* @returns {string} The formatted boundary type string
* @throws {Error} If the input is null, undefined, or empty
*/
const trimming = (val) => {
if (!val) {
throw new Error('Boundary type cannot be empty');
}
return val.trim().replace(/[\s_]+/g, '');
};

Comment on lines +423 to +433
item.boundaryType = trimming(item.boundaryType).toUpperCase();
if (idx === 0) {
if (newHierarchy) item.parentBoundaryType = null;
else {
if (boundaryData.length === 0) item.parentBoundaryType = null;
else item.parentBoundaryType = boundaryData[boundaryData.length - 1].boundaryType.trim();
else item.parentBoundaryType = boundaryData[boundaryData.length - 1].boundaryType;

}
}
if (idx > 0) {
item.parentBoundaryType = prevItems[idx - 1].boundaryType.trim();
item.parentBoundaryType = trimming(prevItems[idx - 1].boundaryType);
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Simplify parent boundary type assignment logic

The current implementation can be made more concise while maintaining the same functionality.

-item.boundaryType = trimming(item.boundaryType).toUpperCase();
+const formatBoundaryType = (type) => trimming(type).toUpperCase();
+item.boundaryType = formatBoundaryType(item.boundaryType);

 if (idx === 0) {
-    if (newHierarchy) item.parentBoundaryType = null;
-    else {
-        if (boundaryData.length === 0) item.parentBoundaryType = null;
-        else item.parentBoundaryType = boundaryData[boundaryData.length - 1].boundaryType;
-    }
+    item.parentBoundaryType = (!newHierarchy && boundaryData.length > 0)
+        ? boundaryData[boundaryData.length - 1].boundaryType
+        : null;
 }
 if (idx > 0) {
-    item.parentBoundaryType = trimming(prevItems[idx - 1].boundaryType);
+    item.parentBoundaryType = formatBoundaryType(prevItems[idx - 1].boundaryType);
 }
📝 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
item.boundaryType = trimming(item.boundaryType).toUpperCase();
if (idx === 0) {
if (newHierarchy) item.parentBoundaryType = null;
else {
if (boundaryData.length === 0) item.parentBoundaryType = null;
else item.parentBoundaryType = boundaryData[boundaryData.length - 1].boundaryType.trim();
else item.parentBoundaryType = boundaryData[boundaryData.length - 1].boundaryType;
}
}
if (idx > 0) {
item.parentBoundaryType = prevItems[idx - 1].boundaryType.trim();
item.parentBoundaryType = trimming(prevItems[idx - 1].boundaryType);
const formatBoundaryType = (type) => trimming(type).toUpperCase();
item.boundaryType = formatBoundaryType(item.boundaryType);
if (idx === 0) {
item.parentBoundaryType = (!newHierarchy && boundaryData.length > 0)
? boundaryData[boundaryData.length - 1].boundaryType
: null;
}
if (idx > 0) {
item.parentBoundaryType = formatBoundaryType(prevItems[idx - 1].boundaryType);
}

Comment on lines +347 to +360
const local = [
...boundaryData.map(item => ({
code: `${hierarchyType}_${trimming(item.boundaryType)}`.toUpperCase(),
message: `${t((defaultHierarchyType + "_" + item?.boundaryType).toUpperCase())}`,
module: `hcm-boundary-${hierarchyType.toLowerCase()}`,
locale: locale
})),
...newBoundaryData.map(item => ({
code: `${hierarchyType}_${trimming(item.boundaryType)}`.toUpperCase(),
message: item.boundaryType.trim(),
module: `hcm-boundary-${hierarchyType.toLowerCase()}`,
locale: locale
}))
];
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve consistency and readability in message formatting

  1. The message formatting is inconsistent between boundaryData and newBoundaryData items
  2. String concatenation should be replaced with template literals
 const local = [
     ...boundaryData.map(item => ({
-        code: `${hierarchyType}_${trimming(item.boundaryType)}`.toUpperCase(),
-        message: `${t((defaultHierarchyType + "_" + item?.boundaryType).toUpperCase())}`,
+        code: `${hierarchyType}_${trimming(item.boundaryType)}`.toUpperCase(),
+        message: t(`${defaultHierarchyType}_${item?.boundaryType}`.toUpperCase()),
         module: `hcm-boundary-${hierarchyType.toLowerCase()}`,
         locale: locale
     })),
     ...newBoundaryData.map(item => ({
         code: `${hierarchyType}_${trimming(item.boundaryType)}`.toUpperCase(),
-        message: item.boundaryType.trim(),
+        message: t(`${defaultHierarchyType}_${item.boundaryType}`.toUpperCase()),
         module: `hcm-boundary-${hierarchyType.toLowerCase()}`,
         locale: locale
     }))
 ];
📝 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
const local = [
...boundaryData.map(item => ({
code: `${hierarchyType}_${trimming(item.boundaryType)}`.toUpperCase(),
message: `${t((defaultHierarchyType + "_" + item?.boundaryType).toUpperCase())}`,
module: `hcm-boundary-${hierarchyType.toLowerCase()}`,
locale: locale
})),
...newBoundaryData.map(item => ({
code: `${hierarchyType}_${trimming(item.boundaryType)}`.toUpperCase(),
message: item.boundaryType.trim(),
module: `hcm-boundary-${hierarchyType.toLowerCase()}`,
locale: locale
}))
];
const local = [
...boundaryData.map(item => ({
code: `${hierarchyType}_${trimming(item.boundaryType)}`.toUpperCase(),
message: t(`${defaultHierarchyType}_${item?.boundaryType}`.toUpperCase()),
module: `hcm-boundary-${hierarchyType.toLowerCase()}`,
locale: locale
})),
...newBoundaryData.map(item => ({
code: `${hierarchyType}_${trimming(item.boundaryType)}`.toUpperCase(),
message: t(`${defaultHierarchyType}_${item.boundaryType}`.toUpperCase()),
module: `hcm-boundary-${hierarchyType.toLowerCase()}`,
locale: locale
}))
];
🧰 Tools
🪛 Biome (1.9.4)

[error] 350-350: Template literals are preferred over string concatenation.

Unsafe fix: Use a template literal.

(lint/style/useTemplate)

@jagankumar-egov jagankumar-egov merged commit 82f25b2 into console Nov 26, 2024
3 checks passed
@jagankumar-egov jagankumar-egov deleted the feature/nb branch November 26, 2024 13:17
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.

2 participants