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

Made all mgramseva changes into workbench-develop #1438

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

mukund-egov
Copy link
Collaborator

No description provided.

@mukund-egov mukund-egov requested a review from a team as a code owner September 27, 2024 10:03
Copy link
Contributor

coderabbitai bot commented Sep 27, 2024

📝 Walkthrough

Walkthrough

The changes in this pull request involve formatting improvements and the addition of a new function in the MDMSAddV2.js file to enhance schema property handling. The updateAllPropertiesBasedOnUIOrder function is introduced to sort schema properties based on UI specifications. Minor formatting adjustments are also made in MDMSEdit.js for consistency, including import statements and function structures. Overall, the modifications aim to improve code readability and maintainability.

Changes

Files Change Summary
micro-ui/web/micro-ui-internals/packages/modules/workbench/src/pages/employee/MDMSAddV2.js Added a new function updateAllPropertiesBasedOnUIOrder to sort schema properties based on UI order; reformatted code for clarity.
micro-ui/web/micro-ui-internals/packages/modules/workbench/src/pages/employee/MDMSEdit.js Made formatting improvements including consistent spacing, semicolon usage, and minor adjustments to function structures.

Possibly related PRs

Suggested reviewers

  • jagankumar-egov

Poem

🐰 In the code where rabbits hop,
A function new, we cannot stop!
Sorting schemas, oh what a sight,
Making UI order just right!
With formatting done, the lines align,
Readable code, oh how it shines! 🌟


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

🧹 Outside diff range and nitpick comments (2)
micro-ui/web/micro-ui-internals/packages/modules/workbench/src/pages/employee/MDMSEdit.js (1)

48-48: Consider refactoring the assignment in the forEach callback.

The static analysis tool flagged an assignment within an expression on this line. While this is a common pattern in JavaScript, it might be worth considering a more explicit approach for improved readability and to satisfy the linter.

You could refactor this line to be more explicit:

uniqueFields.forEach((field) => {
  updatesToUiSchema[field] = { "ui:readonly": true };
});

This change separates the assignment from the forEach callback, making it clearer and potentially more maintainable.

🧰 Tools
🪛 Biome

[error] 48-48: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

micro-ui/web/micro-ui-internals/packages/modules/workbench/src/pages/employee/MDMSAddV2.js (1)

78-78: Simplify URL assignment using optional chaining

The ternary operator can be simplified by utilizing optional chaining and the logical OR operator for better readability.

Consider updating the code as follows:

- url: api ? api?.url : Digit.Utils.workbench.getMDMSActionURL(moduleName, masterName, "create"),
+ url: api?.url || Digit.Utils.workbench.getMDMSActionURL(moduleName, masterName, "create"),
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 6a343dc and 9e9d1b2.

📒 Files selected for processing (2)
  • micro-ui/web/micro-ui-internals/packages/modules/workbench/src/pages/employee/MDMSAddV2.js (3 hunks)
  • micro-ui/web/micro-ui-internals/packages/modules/workbench/src/pages/employee/MDMSEdit.js (3 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
micro-ui/web/micro-ui-internals/packages/modules/workbench/src/pages/employee/MDMSAddV2.js (1)

Pattern **/*.js: check

micro-ui/web/micro-ui-internals/packages/modules/workbench/src/pages/employee/MDMSEdit.js (1)

Pattern **/*.js: check

🪛 Biome
micro-ui/web/micro-ui-internals/packages/modules/workbench/src/pages/employee/MDMSAddV2.js

[error] 214-214: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 223-223: Do not access Object.prototype method 'hasOwnProperty' from target object.

It's recommended using Object.hasOwn() instead of using Object.hasOwnProperty().
See MDN web docs for more details.

(lint/suspicious/noPrototypeBuiltins)


[error] 230-230: Do not access Object.prototype method 'hasOwnProperty' from target object.

It's recommended using Object.hasOwn() instead of using Object.hasOwnProperty().
See MDN web docs for more details.

(lint/suspicious/noPrototypeBuiltins)

micro-ui/web/micro-ui-internals/packages/modules/workbench/src/pages/employee/MDMSEdit.js

[error] 48-48: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

🔇 Additional comments (10)
micro-ui/web/micro-ui-internals/packages/modules/workbench/src/pages/employee/MDMSEdit.js (7)

1-7: LGTM: Import statements and component declaration.

The changes in this section are primarily formatting improvements. The import statements have been reorganized for better readability, and the component declaration remains functionally the same.


7-11: LGTM: Hook usage and query parameter extraction.

The changes in this section are minor formatting improvements. The usage of hooks and extraction of query parameters remain functionally unchanged.


Line range hint 15-52: LGTM: State declarations and request criteria objects.

The changes in this section are primarily formatting improvements that enhance readability. The state declarations remain unchanged. In the reqCriteria object, a trailing comma has been added to the uniqueIdentifiers array, which is a common JavaScript style preference and helps prevent errors when adding new items to the array in the future.


54-66: LGTM: Utility functions closeToast and gotoView.

The changes to the closeToast and gotoView functions are purely formatting improvements. They enhance readability and maintain consistent styling with the rest of the file. The functionality of both functions remains unchanged.


68-80: LGTM: API hook usage and mutation setup.

The changes in this section are minor formatting improvements. The usage of custom API hooks for data fetching and the setup of the mutation hook for updating MDMS data remain functionally unchanged. The formatting enhances code readability.


Line range hint 82-115: LGTM: handleUpdate function with improved error handling.

The changes to the handleUpdate function are primarily formatting improvements that enhance readability. Additionally, there are some notable improvements:

  1. The success toast message now includes the id from the response, providing more specific feedback.
  2. The error message now includes the error code from the response, which can be helpful for debugging.
  3. The closeToast call in the error handler has been moved outside the setShowToast callback, ensuring it's always called after setting the toast.

These changes improve the user feedback and error handling capabilities of the component.

🧰 Tools
🪛 Biome

[error] 48-48: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


127-127: LGTM: Component export.

The change to the component export statement is a minor formatting improvement that aligns with the overall code style of the file.

micro-ui/web/micro-ui-internals/packages/modules/workbench/src/pages/employee/MDMSAddV2.js (3)

69-76: Initialization of request body is well-structured

The Mdms object within the request body is correctly structured and includes all necessary fields.


89-95: Review the necessity of the 2-second delay in gotoView

The setTimeout in gotoView delays navigation by 2 seconds. Ensure this delay is intentional and necessary for the user experience.

If the delay is not required, consider removing it:

-    setTimeout(() => {
       history.push(
         `/${window?.contextPath}/employee/workbench/mdms-view?moduleName=${moduleName}&masterName=${masterName}${from ? `&from=${from}` : ""}`
       );
-    }, 2000);
+    }, 0);

248-248: Integration of updateAllPropertiesBasedOnUIOrder function looks good

The schema is correctly updated by applying the updateAllPropertiesBasedOnUIOrder function, ensuring that properties are ordered according to the UI specifications.

Comment on lines +117 to +124
if (isLoading || isLoadingSchema || renderLoader) return <Loader />;

if(isLoading || isLoadingSchema || renderLoader ) return <Loader />

return (
<React.Fragment>
<MDMSAdd defaultFormData = {data?.data} screenType={"edit"} onSubmitEditAction={handleUpdate} updatesToUISchema ={schemaData?.updatesToUiSchema} />
{showToast && <Toast label={t(showToast.label)} error={showToast?.isError} onClose={()=>setShowToast(null)} ></Toast>}
<MDMSAdd defaultFormData={data?.data} screenType={"edit"} onSubmitEditAction={handleUpdate} updatesToUISchema={schemaData?.updatesToUiSchema} />
{showToast && <Toast label={t(showToast.label)} error={showToast?.isError} onClose={() => setShowToast(null)}></Toast>}
</React.Fragment>
)
}
);
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Issue: updatesToUISchema prop is not handled in MDMSAdd component.

The MDMSEdit.js file passes the updatesToUISchema prop to the MDMSAdd component. However, the base MDMSAdd.js does not handle this prop, which may lead to unintended behavior.

  • File: micro-ui/web/micro-ui-internals/packages/modules/workbench/src/pages/employee/MDMSAdd.js
🔗 Analysis chain

LGTM: Rendering logic with a new prop.

The changes to the rendering logic are mostly formatting improvements that enhance readability. However, there's a notable change:

  • The MDMSAdd component now receives an updatesToUISchema prop derived from schemaData.

This addition might affect the behavior of the MDMSAdd component.

Please verify that the MDMSAdd component correctly handles the updatesToUISchema prop and that it's being used as intended. You can run the following script to check the usage of this prop in the MDMSAdd component:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check the usage of updatesToUISchema prop in MDMSAdd component

# Test: Search for the MDMSAdd component definition and its usage
rg --type js -A 10 'const MDMSAdd =' micro-ui/web/micro-ui-internals/packages/modules/workbench/src/pages/employee/
rg --type js -A 5 '<MDMSAdd' micro-ui/web/micro-ui-internals/packages/modules/workbench/src/pages/employee/

Length of output: 8525


// Sort properties according to the orderArray
orderArray.forEach((key) => {
if (properties.hasOwnProperty(key)) {
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

Use Object.hasOwn() instead of hasOwnProperty

Accessing hasOwnProperty directly can be unsafe if the object has a custom hasOwnProperty property. It's recommended to use Object.hasOwn() for reliability.

Modify the code as follows:

- if (properties.hasOwnProperty(key)) {
+ if (Object.hasOwn(properties, key)) {
📝 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
if (properties.hasOwnProperty(key)) {
if (Object.hasOwn(properties, key)) {
🧰 Tools
🪛 Biome

[error] 223-223: Do not access Object.prototype method 'hasOwnProperty' from target object.

It's recommended using Object.hasOwn() instead of using Object.hasOwnProperty().
See MDN web docs for more details.

(lint/suspicious/noPrototypeBuiltins)


// Add remaining properties that were not in the orderArray
for (let key in properties) {
if (!sortedProperties.hasOwnProperty(key)) {
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

Use Object.hasOwn() instead of hasOwnProperty

For consistency and to prevent potential issues, replace hasOwnProperty with Object.hasOwn().

Update the code:

- if (!sortedProperties.hasOwnProperty(key)) {
+ if (!Object.hasOwn(sortedProperties, key)) {
📝 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
if (!sortedProperties.hasOwnProperty(key)) {
if (!Object.hasOwn(sortedProperties, key)) {
🧰 Tools
🪛 Biome

[error] 230-230: Do not access Object.prototype method 'hasOwnProperty' from target object.

It's recommended using Object.hasOwn() instead of using Object.hasOwnProperty().
See MDN web docs for more details.

(lint/suspicious/noPrototypeBuiltins)

let targetProperty = schema.definition.properties[propertyName];

// Check if the property has items and the x-ui-schema with a ui:order field
if (targetProperty.items && targetProperty.items["x-ui-schema"] && targetProperty.items["x-ui-schema"]["ui:order"]) {
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

Refactor conditional check using optional chaining

The conditional statement can be simplified by using optional chaining, enhancing readability and reducing code complexity.

Update the condition as follows:

- if (targetProperty.items && targetProperty.items["x-ui-schema"] && targetProperty.items["x-ui-schema"]["ui:order"]) {
+ if (targetProperty.items?.["x-ui-schema"]?.["ui:order"]) {
📝 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
if (targetProperty.items && targetProperty.items["x-ui-schema"] && targetProperty.items["x-ui-schema"]["ui:order"]) {
if (targetProperty.items?.["x-ui-schema"]?.["ui:order"]) {
🧰 Tools
🪛 Biome

[error] 214-214: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

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.

1 participant