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 documentation for property pane config #36880

Merged
merged 8 commits into from
Nov 7, 2024

Conversation

jsartisan
Copy link
Contributor

@jsartisan jsartisan commented Oct 15, 2024

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

Summary by CodeRabbit

  • New Features

    • Introduced a new PropertyControlFactory class for managing property controls.
    • Added new properties to the PropertyPaneControlConfig interface, enhancing customization and validation options.
    • Implemented methods for creating and registering control builders, improving the flexibility of property controls.
  • Documentation

    • Enhanced JSDoc comments for existing properties and methods, providing clearer guidance on their usage.
    • Updated documentation for the PropertyPaneSectionConfig, PropertyPaneControlConfig, and ValidationConfigParams interfaces to clarify their functionality.

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/11716829822
Commit: 62df826
Cypress dashboard.
Tags: @tag.Anvil
Spec:


Thu, 07 Nov 2024 05:15:44 UTC

Copy link
Contributor

coderabbitai bot commented Oct 15, 2024

Walkthrough

This pull request introduces a new PropertyControlFactory class that manages controls for a property pane, featuring methods for registering control builders and creating controls based on various parameters. Additionally, it enhances the PropertyPaneSectionConfig, PropertyPaneControlConfig, and ValidationConfigParams interfaces with improved documentation and new properties. The changes focus on clarifying the purpose and usage of these interfaces, while maintaining the existing functionality and logic throughout the codebase.

Changes

File Path Change Summary
app/client/src/constants/PropertyControlConstants.tsx Updated PropertyPaneSectionConfig, PropertyPaneControlConfig, and ValidationConfigParams interfaces with new properties and enhanced documentation.
app/client/src/utils/PropertyControlFactory.tsx Introduced PropertyControlFactory class with methods for registering control builders and creating controls.
app/client/src/pages/Editor/PropertyPane/PropertyControlsGenerator.tsx Streamlined type casting for searchResults in generatePropertyControl function, retaining existing logic.

Possibly related PRs

Suggested labels

IDE Product, Task, ok-to-test

Suggested reviewers

  • AmanAgarwal041
  • albinAppsmith
  • ApekshaBhosale

Poem

In the realm of code, a change has bloomed,
New properties added, documentation groomed.
A factory for controls, oh what a delight,
Managing properties, making everything right!
With clarity and structure, we dance and we sing,
In the world of development, let joy be our spring! 🎉


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.

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 jsartisan changed the title add some docs chore: Add documentation for property pane config Oct 15, 2024
@github-actions github-actions bot added the skip-changelog Adding this label to a PR prevents it from being listed in the changelog label Oct 15, 2024
@jsartisan jsartisan marked this pull request as draft October 15, 2024 11:38
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 and nitpick comments (9)
app/client/src/constants/PropertyControlConstants.tsx (7)

59-63: Well done on adding the id property, class!

The addition of the id property with its detailed JSDoc comment is a commendable effort. It's like adding a name tag to each student in our class – it helps us keep track of everyone!

However, let's make it even better. Can you tell me what type of string this id is? Is it a UUID, a sequential number, or something else? Adding this information would be like specifying what kind of name tag we're using.

Consider adding more specificity to the JSDoc comment:

/**
 * Unique identifier for the control. Used for internal tracking and debugging.
 * It is added by `addPropertyConfigIds` function in `WidgetProvider/factory/helpers.ts`.
 * @type {string} The id is typically a [specify the format, e.g., UUID, sequential number].
 */
id?: string;

85-89: Excellent addition of the customJSControl property, students!

This new property is like giving our class a special project option. It allows for more advanced and customized controls, which is fantastic for those students who want to go the extra mile!

The example you've provided with the COMPUTE_VALUE control is very helpful. It's like explaining that this special project could be used in a science fair to showcase complex experiments.

To make it even clearer for all our students, let's add a bit more context:

/**
 * Used in special cases where we want a custom control instead of a regular text input control.
 * This allows for more complex interactions or computations within the property pane.
 * @example
 * The `COMPUTE_VALUE` control is used in the table widget to provide access to the currentRow
 * in controls within the table columns, enabling row-specific computations.
 */
customJSControl?: string;

This way, even our less experienced students will understand the power and purpose of this property!


90-94: A gold star for adding the controlType property!

This property is like choosing which subject we're teaching in class. It's essential for determining how we interact with our students (or in this case, how users interact with the property).

Your comment pointing to where we can find the full list of supported controls is very helpful. It's like having a syllabus that tells us all the subjects we can teach!

Let's make it even more informative for our fellow teachers:

/**
 * Specifies the type of property control to be used.
 * This determines the UI component and behavior of the property in the property pane.
 * @type {ControlType}
 * @required
 * @see {ControlTypes} for the full list of supported controls in `app/client/src/components/propertyControls/index.ts`.
 */
controlType: ControlType;

This way, we're not just telling where to find the information, but also emphasizing its importance and how it relates to the UI. It's like giving a brief introduction to the subject before diving into the lesson!


153-156: Good job adding the validation property, but let's expand our lesson plan!

Adding validation is like setting the grading criteria for our assignments. It's crucial for ensuring that the data our students (users) input meets our standards.

However, your current explanation is a bit too brief. It's like telling students "This is a test" without explaining what it's testing or how it will be graded.

Let's provide a more comprehensive explanation:

/**
 * Specifies the validation rules for the property.
 * This helps ensure data integrity and provides immediate feedback to users.
 * @type {ValidationConfig}
 * @optional
 * @example
 * validation: {
 *   type: ValidationTypes.NUMBER,
 *   params: {
 *     min: 0,
 *     max: 100,
 *     default: 50
 *   }
 * }
 * @see {ValidationConfig} for the full structure of validation options.
 */
validation?: ValidationConfig;

This expanded comment is like giving a detailed rubric. It explains what the validation does, provides an example, and points to where more information can be found. This will help our fellow teachers (developers) understand and use the validation properly!


157-166: Excellent addition of the additionalAutoComplete property!

This property is like giving our students a customized dictionary for their assignments. It helps them complete their work more efficiently by suggesting relevant terms.

Your explanation is good, but let's make it even more helpful for our fellow teachers.

Let's enhance the JSDoc comment with an example:

/**
 * Callback function to provide additional autocomplete data for the autocomplete list.
 * This is useful for adding context-specific suggestions that aren't part of the standard autocomplete.
 * 
 * @param props - Current widget properties
 * @returns {AdditionalDynamicDataTree} Additional autocomplete data
 * 
 * @example
 * additionalAutoComplete: (props) => ({
 *   customCategory: {
 *     data1: {},
 *     data2: {},
 *   },
 * })
 */
additionalAutoComplete?: (props: any) => AdditionalDynamicDataTree;

This expanded comment is like providing a sample lesson plan along with the teaching guidelines. It shows other teachers (developers) exactly how they might use this feature in their own "classrooms" (widgets).


172-176: A round of applause for adding the dynamicDependencies property!

This property is like having a flexible curriculum that adapts to each student's needs. It allows us to determine what prerequisites are needed for a lesson in real-time.

Your explanation does a good job of distinguishing this from the static dependencies. However, let's make it even clearer for our fellow educators.

Let's enhance the JSDoc comment:

/**
 * Determines dependencies dynamically during the rendering of the property control.
 * Unlike static `dependencies`, this allows for context-sensitive dependency resolution.
 * 
 * @param {WidgetProps} widget - The current widget properties
 * @returns {string[]} An array of property names that this property depends on
 * 
 * @example
 * dynamicDependencies: (widget) => {
 *   return widget.isAdvancedMode ? ['advancedProperty1', 'advancedProperty2'] : ['basicProperty'];
 * }
 */
dynamicDependencies?: (widget: WidgetProps) => string[];

This expanded comment is like providing a detailed lesson plan that explains not just what we're doing, but why and how. The example shows other teachers (developers) how they might use this feature to create more adaptive and context-aware widgets.


217-220: Good effort on adding the defaultValue property, but let's flesh out our lesson plan!

Adding a default value is like providing a starting point for our students' assignments. It's very helpful, especially for complex properties.

However, your current explanation is a bit too concise. It's like telling students "Start here" without explaining why or how this starting point was chosen.

Let's provide a more comprehensive explanation:

/**
 * Specifies the default value for the property.
 * This value is used when the property is first initialized or reset.
 * 
 * @type {unknown}
 * @optional
 * 
 * @example
 * // For a number property
 * defaultValue: 0
 * 
 * // For a string property
 * defaultValue: "Hello, World!"
 * 
 * // For a boolean property
 * defaultValue: false
 * 
 * @note The type of the default value should match the expected type of the property.
 */
defaultValue?: unknown;

This expanded comment is like providing a detailed introduction to our lesson. It explains what the default value does, provides examples for different types of properties, and includes a note about type matching. This will help our fellow teachers (developers) understand how to use default values effectively in their own "lessons" (widgets)!

app/client/src/utils/PropertyControlFactory.tsx (2)

16-16: Correct the grammatical error in the class documentation.

Remember, clear and grammatically correct documentation is essential for maintainability. In line 16, it should read 'This class manages' instead of 'This classes manages' to ensure proper grammar.


Line range hint 71-74: Refactor exception handling to use a custom Error subclass.

Proper exception handling is crucial for robustness. Currently, you're throwing an object that implements an interface, which won't preserve the error's stack trace and runtime properties. It's better to extend the built-in Error class to create a custom exception. This way, you maintain all the benefits of standard error handling.

Apply this diff to refactor the exception handling:

+export class ControlCreationException extends Error {
+  constructor(message: string) {
+    super(message);
+    this.name = "ControlCreationException";
+  }
+}

...

- const ex: ControlCreationException = {
-   message:
-     "Control Builder not registered for control type " +
-     controlData.controlType,
- };
- throw ex;
+ throw new ControlCreationException(
+   "Control Builder not registered for control type " +
+   controlData.controlType,
+ );
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 3032adc and 02f9cba.

📒 Files selected for processing (2)
  • app/client/src/constants/PropertyControlConstants.tsx (4 hunks)
  • app/client/src/utils/PropertyControlFactory.tsx (1 hunks)
🧰 Additional context used

Copy link

This PR has not seen activitiy for a while. It will be closed in 7 days unless further activity is detected.

@github-actions github-actions bot added the Stale label Oct 23, 2024
@jsartisan jsartisan marked this pull request as ready for review October 29, 2024 05:18
@jsartisan jsartisan requested a review from a team as a code owner October 29, 2024 05:18
@jsartisan jsartisan requested a review from riodeuno October 29, 2024 05:18
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 and nitpick comments (4)
app/client/src/constants/PropertyControlConstants.tsx (4)

20-86: Excellent work on documenting the PropertyPaneSectionConfig interface! 📚

Class, I'm pleased to see such thorough documentation! However, let's enhance it further with some practical examples to help our fellow developers better understand the usage.

Consider adding example usage for the sectionName and children properties. Here's a suggested addition to the JSDoc:

  /**
   * Title displayed at the top of a collapsible section in the property pane.
+  * 
+  * @example
+  * sectionName: "Basic Configuration"
   */
  sectionName: string;

  /**
   * Array of properties that should go inside the section.
+  * 
+  * @example
+  * children: [
+  *   {
+  *     controlType: "INPUT_TEXT",
+  *     propertyName: "title",
+  *     label: "Title",
+  *   }
+  * ]
   */
  children: PropertyPaneConfig[];

Line range hint 191-197: Time to address those TODO comments, class! 🎯

I notice several eslint-disable comments with TODOs. Let's improve type safety by replacing any with proper types.

Consider replacing the any type with a more specific type:

  updateHook?: (
-   // TODO: Fix this the next time the file is edited
-   // eslint-disable-next-line @typescript-eslint/no-explicit-any
-   props: any,
+   props: WidgetProps,
    propertyName: string,
-   // eslint-disable-next-line @typescript-eslint/no-explicit-any
-   propertyValue: any,
+   propertyValue: unknown,
  ) => Array<PropertyUpdates> | undefined;

  hidden?: (
-   // eslint-disable-next-line @typescript-eslint/no-explicit-any
-   props: any,
+   props: WidgetProps,
    propertyPath: string
  ) => boolean;

Also applies to: 205-207


Line range hint 366-376: Let's improve our type definitions here, students! 📝

The validation function parameters could be more specific than any.

Let's enhance type safety:

  fn?: (
    value: unknown,
-   // TODO: Fix this the next time the file is edited
-   // eslint-disable-next-line @typescript-eslint/no-explicit-any
-   props: any,
+   props: WidgetProps,
-   // eslint-disable-next-line @typescript-eslint/no-explicit-any
-   _?: any,
+   _?: unknown,
-   // eslint-disable-next-line @typescript-eslint/no-explicit-any
-   moment?: any,
+   moment?: moment.Moment,
  ) => ValidationResponse;

Don't forget to import the moment type if you make this change:

import type { Moment } from 'moment';

Line range hint 1-421: Outstanding documentation effort! Let's add some cross-references! 🌟

The documentation is thorough, but we can make it even better by adding cross-references between related interfaces.

Consider adding @see tags to link related properties and interfaces. For example:

  /**
   * Validation configuration for the property
+   * @see ValidationConfig
+   * @see ValidationConfigParams
   */
  validation?: ValidationConfig;

This will help developers navigate the documentation more effectively.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 02f9cba and 62df826.

📒 Files selected for processing (2)
  • app/client/src/constants/PropertyControlConstants.tsx (5 hunks)
  • app/client/src/pages/Editor/PropertyPane/PropertyControlsGenerator.tsx (1 hunks)
🔇 Additional comments (1)
app/client/src/pages/Editor/PropertyPane/PropertyControlsGenerator.tsx (1)

133-133: Class, let's examine this type assertion removal!

I notice you've removed the explicit type casting from searchResults. While this suggests that TypeScript can now correctly infer the types, let's verify that the type safety is maintained.

Let's run a quick type-check to ensure everything is in order:

Remember class, type safety is crucial! If the types match correctly, this change actually improves code clarity by removing redundant type assertions.

Copy link

github-actions bot commented Nov 5, 2024

This PR has been closed because of inactivity.

@github-actions github-actions bot closed this Nov 5, 2024
@jsartisan jsartisan reopened this Nov 6, 2024
@jsartisan
Copy link
Contributor Author

@riodeuno Can you check if it's okay to merge this? We can improve the comments further later on.

@riodeuno
Copy link
Contributor

riodeuno commented Nov 6, 2024

@jsartisan yes, please go ahead with this. I'm approving it

@github-actions github-actions bot removed the Stale label Nov 6, 2024
@jsartisan jsartisan added the ok-to-test Required label for CI label Nov 7, 2024
@jsartisan jsartisan merged commit 9ffcb64 into release Nov 7, 2024
64 checks passed
@jsartisan jsartisan deleted the chore/property-pane-documentation branch November 7, 2024 10:11
github-actions bot pushed a commit to Zeral-Zhang/appsmith that referenced this pull request Nov 20, 2024
/ok-to-test tags="@tag.Anvil"

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

- **New Features**
- Introduced a new `PropertyControlFactory` class for managing property
controls.
- Added new properties to the `PropertyPaneControlConfig` interface,
enhancing customization and validation options.
- Implemented methods for creating and registering control builders,
improving the flexibility of property controls.

- **Documentation**
- Enhanced JSDoc comments for existing properties and methods, providing
clearer guidance on their usage.
- Updated documentation for the `PropertyPaneSectionConfig`,
`PropertyPaneControlConfig`, and `ValidationConfigParams` interfaces to
clarify their functionality.
<!-- 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/11716829822>
> Commit: 62df826
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=11716829822&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Anvil`
> Spec:
> <hr>Thu, 07 Nov 2024 05:15:44 UTC
<!-- end of auto-generated comment: Cypress test results  -->
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.

4 participants