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

chore: add code for paragraph-text morphing #36065

Merged
merged 8 commits into from
Sep 6, 2024

Conversation

jsartisan
Copy link
Contributor

@jsartisan jsartisan commented Sep 3, 2024

/ok-to-test tags="@tag.All"

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Enhanced configurability of input widgets with new dependency tracking and update mechanisms.
    • Introduced dynamic font size updates for paragraph widgets, improving typography control.
    • Expanded configuration options for paragraph widgets with a new fontStyle property.
    • Added a new type alias for input types, improving type safety and reliability.
    • Improved modularity by consolidating exports for better usability.
    • Introduced unit tests for font size update functionality, ensuring reliability.
    • Added unit tests for read-only update functionality, validating correct behavior across widget types.
  • Bug Fixes

    • Improved widget state management through the addition of read-only update hooks.

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/10719066708
Commit: 395574a
Cypress dashboard.
Tags: @tag.All
Spec:


Thu, 05 Sep 2024 12:06:57 UTC

Copy link
Contributor

coderabbitai bot commented Sep 3, 2024

Walkthrough

The recent changes enhance multiple widgets by introducing new properties, functions, and constants. Key updates include the addition of dependency tracking and update hooks for improved widget state management, as well as the establishment of constants for input types and font styles. These modifications collectively refine the configurability and operational behavior of the widgets within the application interface.

Changes

Files Change Summary
app/client/src/widgets/wds/WDSBaseInputWidget/... Added dependencies and updateHook properties to propertyPaneContentConfig; introduced isReadOnlyUpdateHook function; consolidated exports from types and constants.
app/client/src/widgets/wds/WDSParagraphWidget/... Added fontStyle to defaultsConfig; introduced updateHook for font size updates, enhancing typography settings.
app/client/src/widgets/wds/WDSInputWidget/... Updated imports for INPUT_TYPES and related constants to source from WDSBaseInputWidget, indicating a restructuring of input type definitions.
app/client/src/layoutSystems/anvil/integrations/sagas/... Modified getWidgetSessionValues function to process all keys in configMap, regardless of their values.
app/client/src/widgets/wds/WDSParagraphWidget/__tests__/... Introduced unit tests for fontSizeUpdateHook, validating its functionality across various font size inputs.
app/client/src/widgets/wds/WDSBaseInputWidget/__tests__/... Introduced unit tests for isReadOnlyUpdateHook, ensuring correct updates for various widget types based on read-only status.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Widget
    participant UpdateHook

    User->>Widget: Change property
    Widget->>UpdateHook: Trigger update
    UpdateHook->>Widget: Apply changes
    Widget->>User: Reflect updated state
Loading

🌟 In the realm of code, changes unfold,
New hooks and constants, a story told.
With dependencies tracked, widgets align,
A dance of updates, oh how they shine!
Font sizes mapped, properties flow,
In this world of widgets, watch them grow! 🌱


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

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.

@jsartisan
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

@github-actions github-actions bot added the skip-changelog Adding this label to a PR prevents it from being listed in the changelog label Sep 3, 2024
Copy link

github-actions bot commented Sep 3, 2024

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/10677230388.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 36065.
recreate: .

Copy link

github-actions bot commented Sep 3, 2024

⚠️ Cyclic Dependency Check:

This PR has increased the number of cyclic dependencies by 1, when compared with the release branch.

Refer this document to identify the cyclic dependencies introduced by this PR.

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

Outside diff range, codebase verification and nitpick comments (2)
app/client/src/widgets/wds/WDSParagraphWidget/helpers.ts (1)

6-27: Great work on the fontSizeUpdateHook function! The code is clean and well-structured.

A few observations and suggestions:

  1. The function signature is correctly typed and follows the expected pattern.
  2. Using a constant for mapping font size to widget type is a good practice as it keeps the mapping in a single place and makes it easy to update.
  3. Consider adding error handling for cases where the font size is not present in the mapping. This will make the function more robust and prevent unexpected behavior.

Here's an example of how you can add error handling:

  updates.push({
    propertyPath: "type",
-   propertyValue:
-     FONT_SIZE_TO_WIDGET_TYPE_MAP[
-       propertyValue as keyof typeof FONT_SIZE_TO_WIDGET_TYPE_MAP
-     ],
+   propertyValue: (() => {
+     const widgetType = FONT_SIZE_TO_WIDGET_TYPE_MAP[
+       propertyValue as keyof typeof FONT_SIZE_TO_WIDGET_TYPE_MAP
+     ];
+     if (!widgetType) {
+       console.error(`No widget type found for font size: ${propertyValue}`);
+       return props.type;
+     }
+     return widgetType;
+   })(),
  });

This will log an error if the font size is not present in the mapping and fallback to the current widget type.

Keep up the good work!

app/client/src/widgets/wds/WDSBaseInputWidget/helpers.ts (1)

6-40: Great job on the isReadOnlyUpdateHook function! The code is well-structured and follows a clear logic.

A few suggestions for improvement:

  1. Consider adding JSDoc comments to document the function's purpose, parameters, and return value. This will make it easier for other developers to understand and use the function.

  2. Consider extracting the array of widget types that are excluded from the readOnly update logic into a constant. This will make the code more readable and maintainable.

  3. Consider adding unit tests to ensure that the function behaves as expected for different input scenarios.

Overall, the code changes look good to me!

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4516129 and 260bfc9.

Files selected for processing (5)
  • app/client/src/widgets/wds/WDSBaseInputWidget/config/contentConfig.ts (2 hunks)
  • app/client/src/widgets/wds/WDSBaseInputWidget/helpers.ts (1 hunks)
  • app/client/src/widgets/wds/WDSParagraphWidget/config/propertyPaneConfig/styleConfig.ts (2 hunks)
  • app/client/src/widgets/wds/WDSParagraphWidget/constants.ts (1 hunks)
  • app/client/src/widgets/wds/WDSParagraphWidget/helpers.ts (1 hunks)
Files skipped from review due to trivial changes (1)
  • app/client/src/widgets/wds/WDSParagraphWidget/constants.ts
Additional comments not posted (4)
app/client/src/widgets/wds/WDSParagraphWidget/config/propertyPaneConfig/styleConfig.ts (2)

4-4: Great job importing the fontSizeUpdateHook! 👍

The import statement looks good. It's using the correct syntax and the relative import path seems to be pointing to the right location.


38-38: Excellent addition of the updateHook property! 🌟

Adding the updateHook property to the fontSize configuration is a great way to enhance the widget's responsiveness to font size changes.

The updateHook will be invoked whenever the fontSize property is updated, allowing you to perform any necessary actions or transformations based on the new font size value.

This is a clean and effective way to handle font size updates dynamically. Well done!

app/client/src/widgets/wds/WDSBaseInputWidget/config/contentConfig.ts (2)

3-3: The import statement looks good.

The isReadOnlyUpdateHook function is correctly imported from the ../helpers file and is used in the configuration array.


125-126: Great job adding the dependencies and updateHook properties!

The dependencies property correctly specifies that both type and inputType properties are related. This will help manage the dependencies between these properties.

The updateHook property is set to the imported isReadOnlyUpdateHook function, which will likely manage updates in a read-only context. This will improve the functionality of the widget by handling updates appropriately based on the read-only state.

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, codebase verification and nitpick comments (3)
app/client/src/widgets/wds/WDSParagraphWidget/helpers.ts (1)

6-27: Great job on the fontSizeUpdateHook function! The code is well-structured and follows best practices. 👏

A few additional suggestions to consider:

  1. You could add a comment above the function to explain its purpose and the expected input and output. This will make it easier for other developers to understand and use the function.

  2. You could add some error handling to the function to handle cases where the propertyValue is not a valid key in the FONT_SIZE_TO_WIDGET_TYPE_MAP. This will make the function more robust and prevent unexpected errors.

  3. You could use object destructuring to extract the propertyName and propertyValue from the props object. This will make the code more readable and concise.

Here's an example of how you could implement these suggestions:

/**
 * Updates the font size and widget type based on the provided property value.
 * @param props The widget props.
 * @param propertyName The name of the property to update.
 * @param propertyValue The value of the property to update.
 * @returns An array of property updates.
 */
export function fontSizeUpdateHook(
  props: WidgetProps,
  propertyName: string,
  propertyValue: string,
) {
  const { propertyName, propertyValue } = props;
  const updates: PropertyUpdates[] = [
    {
      propertyPath: propertyName,
      propertyValue,
    },
  ];

  const widgetType = FONT_SIZE_TO_WIDGET_TYPE_MAP[propertyValue as keyof typeof FONT_SIZE_TO_WIDGET_TYPE_MAP];
  if (widgetType) {
    updates.push({
      propertyPath: "type",
      propertyValue: widgetType,
    });
  } else {
    console.warn(`Invalid font size: ${propertyValue}`);
  }

  return updates;
}

Keep up the great work! Let me know if you have any questions or if there's anything else I can help with.

app/client/src/widgets/wds/WDSBaseInputWidget/helpers.ts (2)

6-40: Consider renaming the function to getReadOnlyUpdateHook for better clarity.

The current function name isReadOnlyUpdateHook is misleading as it doesn't return a boolean value. A more appropriate name would be getReadOnlyUpdateHook as it returns an array of PropertyUpdates.


20-24: Extract the condition for checking the widget type into a separate variable for better readability.

The condition for checking the widget type can be extracted into a separate variable to improve readability.

Apply this diff to extract the condition:

+  const isReadOnlyAllowed = !["WDS_CURRENCY_INPUT_WIDGET", "WDS_PHONE_INPUT_WIDGET"].includes(
+    props.type,
+  );
-  if (
-    !["WDS_CURRENCY_INPUT_WIDGET", "WDS_PHONE_INPUT_WIDGET"].includes(
-      props.type,
-    )
-  ) {
+  if (isReadOnlyAllowed) {
Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4516129 and 260bfc9.

Files selected for processing (5)
  • app/client/src/widgets/wds/WDSBaseInputWidget/config/contentConfig.ts (2 hunks)
  • app/client/src/widgets/wds/WDSBaseInputWidget/helpers.ts (1 hunks)
  • app/client/src/widgets/wds/WDSParagraphWidget/config/propertyPaneConfig/styleConfig.ts (2 hunks)
  • app/client/src/widgets/wds/WDSParagraphWidget/constants.ts (1 hunks)
  • app/client/src/widgets/wds/WDSParagraphWidget/helpers.ts (1 hunks)
Files skipped from review due to trivial changes (1)
  • app/client/src/widgets/wds/WDSParagraphWidget/constants.ts
Additional comments not posted (4)
app/client/src/widgets/wds/WDSParagraphWidget/config/propertyPaneConfig/styleConfig.ts (2)

4-4: Great job importing the fontSizeUpdateHook! 👍

The import statement is correctly written and the imported hook is used in the propertyPaneStyleConfig array.


38-38: Excellent work adding the updateHook property! 🌟

The updateHook property is correctly added to the object in the propertyPaneStyleConfig array. By assigning the fontSizeUpdateHook to the updateHook property, you have enhanced the functionality of the property pane related to typography.

This change allows for dynamic updates to the font size, making the widget more interactive and responsive. It's a great step towards improving the user experience and providing more flexibility in managing typography settings.

Keep up the good work! 😊

app/client/src/widgets/wds/WDSBaseInputWidget/config/contentConfig.ts (2)

3-3: Import looks good!

The isReadOnlyUpdateHook function is imported correctly from the ../helpers module.


125-126: Great job adding the dependencies and updateHook properties!

The dependencies property correctly specifies that the isReadOnly property depends on the type and inputType properties. This dependency tracking will ensure that the isReadOnly property is updated whenever the dependent properties change.

The updateHook property is set to the isReadOnlyUpdateHook function, which will be called whenever the isReadOnly property is updated. This dedicated update mechanism allows for custom behavior when the widget's read-only state changes.

These additions enhance the configurability and behavior of the widget, making it more robust and maintainable.

Comment on lines 20 to 37
if (
!["WDS_CURRENCY_INPUT_WIDGET", "WDS_PHONE_INPUT_WIDGET"].includes(
props.type,
)
) {
if (propertyValue) {
updates.push({
propertyPath: "type",
propertyValue: "WDS_KEY_VALUE_WIDGET",
});
} else {
updates.push({
propertyPath: "type",
propertyValue:
INPUT_TYPE_TO_WIDGET_TYPE_MAP[props.inputType as InputType],
});
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Simplify the logic by using a ternary operator.

The if-else block can be simplified by using a ternary operator. This will make the code more concise and readable.

Apply this diff to simplify the logic:

-  if (propertyValue) {
-    updates.push({
-      propertyPath: "type",
-      propertyValue: "WDS_KEY_VALUE_WIDGET",
-    });
-  } else {
-    updates.push({
-      propertyPath: "type",
-      propertyValue:
-        INPUT_TYPE_TO_WIDGET_TYPE_MAP[props.inputType as InputType],
-    });
-  }
+  updates.push({
+    propertyPath: "type",
+    propertyValue: propertyValue
+      ? "WDS_KEY_VALUE_WIDGET"
+      : INPUT_TYPE_TO_WIDGET_TYPE_MAP[props.inputType as InputType],
+  });
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 (
!["WDS_CURRENCY_INPUT_WIDGET", "WDS_PHONE_INPUT_WIDGET"].includes(
props.type,
)
) {
if (propertyValue) {
updates.push({
propertyPath: "type",
propertyValue: "WDS_KEY_VALUE_WIDGET",
});
} else {
updates.push({
propertyPath: "type",
propertyValue:
INPUT_TYPE_TO_WIDGET_TYPE_MAP[props.inputType as InputType],
});
}
}
if (
!["WDS_CURRENCY_INPUT_WIDGET", "WDS_PHONE_INPUT_WIDGET"].includes(
props.type,
)
) {
updates.push({
propertyPath: "type",
propertyValue: propertyValue
? "WDS_KEY_VALUE_WIDGET"
: INPUT_TYPE_TO_WIDGET_TYPE_MAP[props.inputType as InputType],
});
}

Copy link

github-actions bot commented Sep 3, 2024

Deploy-Preview-URL: https://ce-36065.dp.appsmith.com

Copy link

github-actions bot commented Sep 3, 2024

⚠️ Cyclic Dependency Check:

This PR has increased the number of cyclic dependencies by 1, when compared with the release branch.

Refer this document to identify the cyclic dependencies introduced by this PR.

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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 260bfc9 and 572f5ae.

Files selected for processing (12)
  • app/client/src/widgets/wds/WDSBaseInputWidget/helpers.ts (1 hunks)
  • app/client/src/widgets/wds/WDSBaseInputWidget/index.ts (1 hunks)
  • app/client/src/widgets/wds/WDSBaseInputWidget/types.ts (1 hunks)
  • app/client/src/widgets/wds/WDSEmailInputWidget/widget/index.tsx (1 hunks)
  • app/client/src/widgets/wds/WDSInputWidget/component/index.tsx (1 hunks)
  • app/client/src/widgets/wds/WDSInputWidget/component/types.ts (1 hunks)
  • app/client/src/widgets/wds/WDSInputWidget/widget/helper.ts (1 hunks)
  • app/client/src/widgets/wds/WDSInputWidget/widget/index.tsx (2 hunks)
  • app/client/src/widgets/wds/WDSMultilineInputWidget/widget/index.tsx (1 hunks)
  • app/client/src/widgets/wds/WDSNumberInputWidget/widget/index.tsx (1 hunks)
  • app/client/src/widgets/wds/WDSPasswordInputWidget/widget/index.tsx (1 hunks)
  • app/client/src/widgets/wds/WDSPhoneInputWidget/index.ts (1 hunks)
Files skipped from review due to trivial changes (3)
  • app/client/src/widgets/wds/WDSBaseInputWidget/types.ts
  • app/client/src/widgets/wds/WDSInputWidget/component/index.tsx
  • app/client/src/widgets/wds/WDSInputWidget/widget/index.tsx
Files skipped from review as they are similar to previous changes (1)
  • app/client/src/widgets/wds/WDSBaseInputWidget/helpers.ts
Additional comments not posted (13)
app/client/src/widgets/wds/WDSPhoneInputWidget/index.ts (1)

1-1: Great job enhancing the module's interface! 👍

Exporting all members from the ./constants module alongside the WDSPhoneInputWidget component is a wise decision. It improves the modularity of the code and makes it more convenient for consumers of this module to access the constants without needing separate imports.

This change aligns with the best practice of exposing related resources together, which can lead to cleaner and more maintainable code in the long run. Well done!

app/client/src/widgets/wds/WDSBaseInputWidget/index.ts (1)

5-6: Great work on enhancing the module's interface! 👍

The addition of the new export statements that include all exports from the ./types and ./constants modules is a fantastic way to improve the modularity and usability of the WDSBaseInputWidget. By consolidating the exports, you've made it easier for other parts of the codebase to import and use the necessary types and constants.

The changes are consistent with the existing export statements and follow the best practices for module design. Keep up the excellent work in making the codebase more maintainable and user-friendly!

app/client/src/widgets/wds/WDSInputWidget/component/types.ts (2)

2-2: Great work on consolidating the type definitions! 👍

Importing the InputType directly from the WDSBaseInputWidget module is a cleaner approach and helps maintain consistency across the codebase.


4-4: Nice job reorganizing the import statements! 🙌

Moving the BaseInputComponentProps import to a separate line enhances readability and follows a logical order.

app/client/src/widgets/wds/WDSEmailInputWidget/widget/index.tsx (1)

4-4: Verify the impact of the import change on the WDSEmailInputWidget and other widgets.

Great work on refactoring the widget hierarchy! The change in the import statement for INPUT_TYPES suggests a consolidation of input-related constants under a more generic base input widget.

Please ensure that this change does not introduce any unintended side effects or break the functionality of the WDSEmailInputWidget or other widgets that rely on the INPUT_TYPES constant.

To verify the impact, you can run the following script:

If the tests pass without any issues, then the change is good to go! Let me know if you have any questions or need further assistance.

app/client/src/widgets/wds/WDSNumberInputWidget/widget/index.tsx (1)

5-5: Great work on refactoring the import path for the INPUT_TYPES constant! This change promotes code reuse and maintainability.

By moving the INPUT_TYPES constant to the WDSBaseInputWidget level, you've made it accessible to all the widgets that extend the WDSBaseInputWidget class, including the WDSInputWidget and WDSNumberInputWidget classes. This refactor helps to centralize the constants and reduces duplication across the widget hierarchy.

Keep up the good work in identifying opportunities for code organization and reusability!

app/client/src/widgets/wds/WDSPasswordInputWidget/widget/index.tsx (2)

5-5: LGTM!

Excellent work on organizing the import statements! Grouping related imports together improves the readability of the code.


3-3: Verify the usage of INPUT_TYPES constant.

Great job refactoring the import path for INPUT_TYPES! It's important to ensure that this constant is still being used correctly within the file after this change.

Let's run the following script to verify the usage:

Verification successful

Let's try verifying the usage of INPUT_TYPES again by searching without specifying a file type. This should help us identify where and how INPUT_TYPES is used in the codebase.


Verification Successful: No Issues Found with INPUT_TYPES Import Change

The change in the import path for INPUT_TYPES in WDSPasswordInputWidget/widget/index.tsx does not affect its usage within the file, as there are no usages of INPUT_TYPES found there. The refactoring appears to be part of a broader reorganization and does not impact the functionality of the WDSPasswordInputWidget. Well done on maintaining the integrity of the code during refactoring!

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `INPUT_TYPES` constant.

# Test: Search for the usage of `INPUT_TYPES`. Expect: Only valid usages.
rg --type typescript -A 5 $'INPUT_TYPES'

Length of output: 74


Script:

#!/bin/bash
# Description: Verify the usage of `INPUT_TYPES` constant.

# Test: Search for the usage of `INPUT_TYPES` in TypeScript files.
rg 'INPUT_TYPES' --glob '*.ts' -A 5

Length of output: 11482

app/client/src/widgets/wds/WDSMultilineInputWidget/widget/index.tsx (2)

5-5: LGTM!

The reordering of the imports for MultilineInputIcon and MultilineInputThumbnail is a valid change. It improves the code organization and readability without affecting the widget's functionality.


4-4: Verify the impact of the import change on the widget's functionality.

The import source for INPUT_TYPES has been updated from widgets/wds/WDSInputWidget/constants to widgets/wds/WDSBaseInputWidget/constants. Let's ensure that this change does not introduce any breaking changes or affect the widget's behavior.

To verify the impact, we can run the following script:

If the tests pass, it indicates that the import change is safe and does not introduce any breaking changes. However, if there are any discrepancies, please investigate further and ensure that the widget's functionality remains intact.

Verification successful

Import Change Verification Successful

The import change for INPUT_TYPES to widgets/wds/WDSBaseInputWidget/constants is verified. The definition of INPUT_TYPES exists in the new source, and there is no evidence of incorrect usage in the WDSMultilineInputWidget class. This suggests that the change does not introduce any breaking changes or affect the widget's behavior.

  • INPUT_TYPES is correctly defined in WDSBaseInputWidget/constants.ts.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of INPUT_TYPES in the codebase.

# Test 1: Search for the usage of INPUT_TYPES in the WDSMultilineInputWidget. 
# Expect: The widget should still use the correct input type from the new import source.
ast-grep --lang typescript --pattern $'class WDSMultilineInputWidget {
  $$$
  static getDefaults() {
    return {
      $$$
      inputType: INPUT_TYPES.$_,
      $$$
    };
  }
  $$$
}'

# Test 2: Search for the definition of INPUT_TYPES in the new import source.
# Expect: The new import source should define the same input types as the old source.
rg --type typescript $'export const INPUT_TYPES' $(fd WDSBaseInputWidget/constants.ts)

Length of output: 311


Script:

#!/bin/bash
# Description: Re-verify the usage and definition of INPUT_TYPES in the codebase.

# Test 1: Search for the usage of INPUT_TYPES in the WDSMultilineInputWidget.
# Adjust the pattern to ensure it matches the correct usage.
ast-grep --lang typescript --pattern $'class WDSMultilineInputWidget {
  $$$
  static getDefaults() {
    return {
      $$$
      inputType: INPUT_TYPES.$_,
      $$$
    };
  }
  $$$
}'

# Test 2: Search for the definition of INPUT_TYPES in the new import source.
# Remove the file type specification to avoid errors.
rg 'export const INPUT_TYPES' $(fd WDSBaseInputWidget/constants.ts)

Length of output: 426

app/client/src/widgets/wds/WDSInputWidget/widget/helper.ts (3)

11-11: Great work restructuring the import paths! 👍

Changing the import path for InputType from a relative path to an absolute path improves the clarity and maintainability of the codebase. It aligns with the goal of consolidating related types within a centralized widget structure.

The code change is approved. Keep up the good work!


15-18: Excellent job updating the import paths for the constants! 🌟

Modifying the import path for INPUT_TYPE_TO_WIDGET_TYPE_MAP and INPUT_TYPES to source them from the base widget module enhances the cohesiveness of the codebase. It aligns with the goal of grouping related functionalities together and reducing the complexity of managing multiple import paths.

The code change is approved. Your efforts in improving the code structure are commendable!


20-20: Nice work simplifying the import statement! 🙌

Removing the reference to constants and directly importing getDefaultISDCode from widgets/wds/WDSPhoneInputWidget streamlines the import process. It aligns with the goal of improving the organizational structure and reducing complexity.

The code change is approved. Your attention to detail in refining the imports is appreciated!

@jsartisan
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 572f5ae and 67e8211.

Files selected for processing (3)
  • app/client/src/widgets/wds/WDSInputWidget/widget/helper.ts (1 hunks)
  • app/client/src/widgets/wds/WDSParagraphWidget/config/propertyPaneConfig/styleConfig.ts (2 hunks)
  • app/client/src/widgets/wds/WDSParagraphWidget/constants.ts (1 hunks)
Files skipped from review due to trivial changes (1)
  • app/client/src/widgets/wds/WDSInputWidget/widget/helper.ts
Files skipped from review as they are similar to previous changes (2)
  • app/client/src/widgets/wds/WDSParagraphWidget/config/propertyPaneConfig/styleConfig.ts
  • app/client/src/widgets/wds/WDSParagraphWidget/constants.ts

Copy link

github-actions bot commented Sep 3, 2024

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/10678794575.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 36065.
recreate: .

Copy link

github-actions bot commented Sep 3, 2024

Deploy-Preview-URL: https://ce-36065.dp.appsmith.com

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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 67e8211 and 68ce8f2.

Files selected for processing (1)
  • app/client/src/widgets/wds/WDSParagraphWidget/config/defaultsConfig.ts (1 hunks)
Additional comments not posted (1)
app/client/src/widgets/wds/WDSParagraphWidget/config/defaultsConfig.ts (1)

14-14: Great work on adding the fontStyle property to enhance the widget's styling capabilities! 👍

The addition of the fontStyle property to the defaultsConfig object is a valuable enhancement that allows for further customization of the WDSParagraphWidget's appearance. By initializing it with an empty string value, you've made it an optional configuration option that can be easily customized later based on specific requirements.

This change seamlessly integrates with the existing code structure and maintains consistency with the other properties in the defaultsConfig object. It expands the widget's styling flexibility without introducing any issues or altering the functionality of the existing properties.

Keep up the excellent work in improving the configurability and versatility of the widgets! 🌟

@jsartisan
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

github-actions bot commented Sep 3, 2024

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/10679329914.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 36065.
recreate: .

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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 68ce8f2 and 1b1d2ab.

Files selected for processing (2)
  • app/client/src/layoutSystems/anvil/integrations/sagas/anvilWidgetAdditionSagas/helpers.ts (1 hunks)
  • app/client/src/widgets/wds/WDSParagraphWidget/config/defaultsConfig.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • app/client/src/widgets/wds/WDSParagraphWidget/config/defaultsConfig.ts
Additional comments not posted (1)
app/client/src/layoutSystems/anvil/integrations/sagas/anvilWidgetAdditionSagas/helpers.ts (1)

Line range hint 47-54: Verify the impact of removing the conditional check.

The removal of the conditional check if (configMap[key] !== undefined) alters the control flow of the function. It now processes all keys in configMap, regardless of whether their corresponding values are undefined.

This change could lead to the generation of session storage keys for keys that previously would have been ignored, potentially affecting how widget session values are retrieved and stored.

To verify the impact, run the following script:

Additionally, consider adding a comment to document the new behavior:

// The function now processes all keys in `configMap`, regardless of whether 
// their corresponding values are `undefined`. This could lead to the generation
// of session storage keys for keys that previously would have been ignored.
for (const key in configMap) {
  // ...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved it to parent to avoid cyclic imports.

@@ -43,7 +43,6 @@ export function getWidgetSessionValues(
}

for (const key in configMap) {
if (configMap[key] === undefined) continue;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not required.

@@ -11,6 +11,7 @@ export const defaultsConfig = {
fontSize: "body",
textAlign: "left",
textColor: "neutral",
fontStyle: undefined,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need to add this, otherwise when hydrating values from session, we won't be able to get this key if not added here. Ideally WidgetFactory.widgetConfigMap.get(type) should return all keys with or without values. But for some reason, we are not getting fontStyle when the key is not added in the defualtsConfig. Noted this to check later.

@@ -32,7 +34,7 @@ export const propertyPaneStyleConfig = [
isJSConvertible: true,
isBindProperty: true,
isTriggerProperty: false,
isReusable: true,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

isReusable is not required for fontSize as discussed with taras.

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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1b1d2ab and e1b3c9f.

Files selected for processing (2)
  • app/client/src/widgets/wds/WDSParagraphWidget/constants.ts (1 hunks)
  • app/client/src/widgets/wds/WDSParagraphWidget/helpers.ts (1 hunks)
Files skipped from review due to trivial changes (1)
  • app/client/src/widgets/wds/WDSParagraphWidget/constants.ts
Files skipped from review as they are similar to previous changes (1)
  • app/client/src/widgets/wds/WDSParagraphWidget/helpers.ts

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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e1b3c9f and c8be2f8.

Files selected for processing (1)
  • app/client/src/widgets/wds/WDSParagraphWidget/tests/helpers.test.ts (1 hunks)
Additional comments not posted (1)
app/client/src/widgets/wds/WDSParagraphWidget/__tests__/helpers.test.ts (1)

4-38: Great job on the test case! The structure and assertions look good.

The test case for the fontSizeUpdateHook function is well-written and covers different scenarios. It tests the function with different font sizes and asserts that the function returns the correct updates for the font size and widget type.

The use of the expect function and the toEqual matcher is appropriate for comparing the expected and actual values.

Keep up the good work!

@jsartisan jsartisan added the ok-to-test Required label for CI label Sep 5, 2024
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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c8be2f8 and 395574a.

Files selected for processing (1)
  • app/client/src/widgets/wds/WDSBaseInputWidget/tests/helpers.test.ts (1 hunks)

Comment on lines +4 to +64
describe("isReadOnlyUpdateHook", () => {
it("should return the correct updates for input widget", () => {
const props1 = {
type: "WDS_INPUT_WIDGET",
inputType: "TEXT",
} as unknown as WidgetProps;

const updates = isReadOnlyUpdateHook(props1, "readOnly", true);
expect(updates).toEqual([
{ propertyPath: "readOnly", propertyValue: true },
{ propertyPath: "type", propertyValue: "WDS_KEY_VALUE_WIDGET" },
]);

const updates2 = isReadOnlyUpdateHook(props1, "readOnly", false);
expect(updates2).toEqual([
{ propertyPath: "readOnly", propertyValue: false },
{ propertyPath: "type", propertyValue: "WDS_INPUT_WIDGET" },
]);

const props2 = {
type: "WDS_EMAIL_INPUT_WIDGET",
inputType: "EMAIL",
} as unknown as WidgetProps;

const updates3 = isReadOnlyUpdateHook(props2, "readOnly", true);
expect(updates3).toEqual([
{ propertyPath: "readOnly", propertyValue: true },
{ propertyPath: "type", propertyValue: "WDS_KEY_VALUE_WIDGET" },
]);

const updates4 = isReadOnlyUpdateHook(props2, "readOnly", false);
expect(updates4).toEqual([
{ propertyPath: "readOnly", propertyValue: false },
{ propertyPath: "type", propertyValue: "WDS_EMAIL_INPUT_WIDGET" },
]);
});

it("should not change the type for currency widget", () => {
const props = {
type: "WDS_CURRENCY_INPUT_WIDGET",
inputType: "CURRENCY",
} as unknown as WidgetProps;

const updates = isReadOnlyUpdateHook(props, "readOnly", true);
expect(updates).toEqual([
{ propertyPath: "readOnly", propertyValue: true },
]);
});

it("should not change the type for phone widget", () => {
const props = {
type: "WDS_PHONE_INPUT_WIDGET",
inputType: "PHONE",
} as unknown as WidgetProps;

const updates = isReadOnlyUpdateHook(props, "readOnly", true);
expect(updates).toEqual([
{ propertyPath: "readOnly", propertyValue: true },
]);
});
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Comprehensive Review of Test Cases for isReadOnlyUpdateHook

General Observations:

  • The file introduces tests for the isReadOnlyUpdateHook function, which appears to handle property updates based on widget type and readOnly status.
  • The tests are well-structured and cover multiple scenarios, including different widget types and readOnly states.

Detailed Observations:

  1. Test Case for Input and Email Widgets (Lines 4-39):

    • The tests correctly simulate different scenarios for input and email widgets, checking the updates when the readOnly property is toggled.
    • The use of as unknown as WidgetProps for type assertion is a bit forceful. Consider using a more refined type or mock that closely resembles WidgetProps without resorting to unknown casting.
  2. Test Case for Currency Widget (Lines 41-51):

    • This test verifies that the type does not change when the widget is set to readOnly, which is a specific behavior presumably defined in the isReadOnlyUpdateHook function.
    • It's good to see that the test expects no change in the type property, which aligns with the intended behavior described.
  3. Test Case for Phone Widget (Lines 53-63):

    • Similar to the currency widget test, this checks for no change in type when readOnly is true.
    • Consistency in testing similar behaviors across different widget types is good for maintainability and understanding of the code.

Suggestions:

  • Refine Type Assertions: Instead of using as unknown as WidgetProps, create a more specific mock or utilize partials of WidgetProps to avoid broad type assertions.
  • Consider Additional Scenarios: Are there edge cases or error conditions that might affect the behavior of isReadOnlyUpdateHook? If so, adding tests to cover these scenarios would be beneficial.

Overall:

  • The tests are well-written and serve their purpose. However, minor improvements in type safety and possibly extending coverage could make them even better.

@jsartisan jsartisan merged commit 4c72fbe into release Sep 6, 2024
91 checks passed
@jsartisan jsartisan deleted the chore/update-heading-paragraph-morphing branch September 6, 2024 04:27
Shivam-z pushed a commit to Shivam-z/appsmith that referenced this pull request Sep 26, 2024
/ok-to-test tags="@tag.All"

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

## Summary by CodeRabbit

- **New Features**
- Enhanced configurability of input widgets with new dependency tracking
and update mechanisms.
- Introduced dynamic font size updates for paragraph widgets, improving
typography control.
- Expanded configuration options for paragraph widgets with a new
`fontStyle` property.
- Added a new type alias for input types, improving type safety and
reliability.
	- Improved modularity by consolidating exports for better usability.
- Introduced unit tests for font size update functionality, ensuring
reliability.
- Added unit tests for read-only update functionality, validating
correct behavior across widget types.

- **Bug Fixes**
- Improved widget state management through the addition of read-only
update hooks.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/10719066708>
> Commit: 395574a
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=10719066708&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.All`
> Spec:
> <hr>Thu, 05 Sep 2024 12:06:57 UTC
<!-- end of auto-generated comment: Cypress test results  -->

---------

Co-authored-by: Pawan Kumar <[email protected]>
@coderabbitai coderabbitai bot mentioned this pull request Jan 2, 2025
2 tasks
@coderabbitai coderabbitai bot mentioned this pull request Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ok-to-test Required label for CI skip-changelog Adding this label to a PR prevents it from being listed in the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants