Skip to content

chore: Add datasource link control#39841

Merged
jsartisan merged 3 commits intoreleasefrom
chore/datasource-link
Mar 21, 2025
Merged

chore: Add datasource link control#39841
jsartisan merged 3 commits intoreleasefrom
chore/datasource-link

Conversation

@jsartisan
Copy link
Contributor

@jsartisan jsartisan commented Mar 21, 2025

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

This PR adds an datasource link control that is required to on query page of AI datasource.

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced a new form control that allows users to navigate directly to datasource-related views.
    • Enhanced forms with dynamic styling capabilities, enabling sections to apply custom visual configurations.
  • Style

    • Adjusted the width of a key configuration button to improve layout consistency.
  • Bug Fixes

    • Resolved issues related to the application of inline styles in form components.

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/13986086739
Commit: 456b285
Cypress dashboard.
Tags: @tag.Sanity
Spec:


Fri, 21 Mar 2025 07:20:48 UTC

@github-actions github-actions bot added the skip-changelog Adding this label to a PR prevents it from being listed in the changelog label Mar 21, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 21, 2025

Walkthrough

This PR introduces updates to several form control components. Inline styles from section.zoneCustomStyle are applied to FieldWrapper and Zone in the UQIEditor’s FormRender. A new DatasourceLinkControl feature is implemented, adding a component, related interfaces, and its registration in the FormControlRegistry along with a new constant in formControlTypes. Additionally, the FunctionCallingConfigForm now specifies a fixed button width via the UNSAFE_width prop.

Changes

Files Change Summary
app/client/src/PluginActionEditor/.../FormRender.tsx Added inline style props to FieldWrapper and Zone to apply dynamic styles from section.zoneCustomStyle.
app/client/src/components/formControls/.../DatasourceLinkControl.tsx, app/client/src/utils/formControl/.../FormControlRegistry.tsx, app/client/src/utils/formControl/.../formControlTypes.ts Introduced a new DatasourceLinkControl feature with its component, interfaces, and registration using the DATASOURCE_LINK control type.
app/client/src/components/formControls/FunctionCallingConfigControl/.../FunctionCallingConfigForm.tsx Added the UNSAFE_width prop (set to "110px") to a Button component.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant D as DatasourceLinkControl
    participant P as useParentEntityInfo
    participant H as History
    U->>D: Click button
    D->>P: Retrieve parentEntityId
    P-->>D: Return parentEntityId
    D->>D: Construct URL using datasourcesEditorIdURL
    D->>H: history.push(URL)
    H-->>U: Navigate to new page
Loading

Possibly related PRs

Suggested labels

Enhancement, IDE Product, Task, IDE Pod

Suggested reviewers

  • KelvinOm
  • ayushpahwa

Poem

In code we craft a brand-new link,
Styles now flow in sync, we think.
A button fixed, a path defined,
Digital threads in form aligned.
Cheers to progress — code refined! 🚀


🪧 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.

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

🧹 Nitpick comments (5)
app/client/src/components/formControls/FunctionCallingConfigControl/components/FunctionCallingConfigForm.tsx (1)

62-62: Consider using a safer approach for width styling

The UNSAFE_width prop suggests this is using a non-standard or potentially deprecated approach for setting the button width. While it works, consider using styled-components or standard CSS classes for more maintainable styling.

-          UNSAFE_width="110px"
+          // Use styled extension or CSS class instead
+          UNSAFE_width="110px"
app/client/src/components/formControls/DatasourceLinkControl.tsx (4)

14-20: Prop 'href' is defined but never used.

The interface defines a href property, but it's not being used in the component implementation. If it's not needed, consider removing it to keep the interface clean and avoid confusion.

export interface DatasourceLinkControlProps extends ControlProps {
-  href: string;
  text: string;
  size?: ButtonProps["size"];
  kind?: ButtonProps["kind"];
  icon?: ButtonProps["startIcon"];
}

39-40: Add type validation for datasourceId.

The datasourceId is cast as string without checking if it exists. Add proper type validation to prevent potential runtime errors.

- datasourceId: props.datasourceId as string,
+ datasourceId: typeof props.datasourceId === 'string' ? props.datasourceId : '',

Also, consider adding this property to the DatasourceLinkControlProps interface for better type safety.


48-48: Consider making button width configurable.

The hardcoded width of "110px" may not be suitable for all use cases, especially with different text lengths or in different languages.

- UNSAFE_width="110px"
+ UNSAFE_width={props.width || "110px"}

And update the interface:

export interface DatasourceLinkControlProps extends ControlProps {
  // other properties
  width?: string;
}

31-57: Add error handling for missing or invalid datasourceId.

The component doesn't handle cases where datasourceId might be missing or invalid. Consider adding appropriate error handling to improve robustness.

function DatasourceLink(props: DatasourceLinkControlProps) {
  const { icon, kind = "secondary", size = "sm", text } = props;
  const ideType = getIDETypeByUrl(location.pathname);
  const { parentEntityId } = useParentEntityInfo(ideType);

+ // Early return if datasourceId is missing
+ if (!props.datasourceId) {
+   return (
+     <Button
+       UNSAFE_width="110px"
+       kind={kind}
+       size={size}
+       startIcon={icon}
+       disabled={true}
+     >
+       {text}
+     </Button>
+   );
+ }

  const onPress = useCallback(() => {
    const url = datasourcesEditorIdURL({
      baseParentEntityId: parentEntityId,
      datasourceId: props.datasourceId as string,
      params: { ...omit(getQueryParams(), "viewMode"), viewMode: false },
    });

    history.push(url);
  }, [parentEntityId, props.datasourceId]);

  // Rest of the component...
}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 193a6c4 and 5f2e4dd.

📒 Files selected for processing (5)
  • app/client/src/PluginActionEditor/components/PluginActionForm/components/UQIEditor/FormRender.tsx (2 hunks)
  • app/client/src/components/formControls/DatasourceLinkControl.tsx (1 hunks)
  • app/client/src/components/formControls/FunctionCallingConfigControl/components/FunctionCallingConfigForm.tsx (1 hunks)
  • app/client/src/utils/formControl/FormControlRegistry.tsx (2 hunks)
  • app/client/src/utils/formControl/formControlTypes.ts (1 hunks)
🔇 Additional comments (3)
app/client/src/utils/formControl/formControlTypes.ts (1)

27-27: Added new control type for datasource linking

The addition of DATASOURCE_LINK constant follows the established pattern in this file. This will enable the use of a new form control type for datasource navigation.

app/client/src/utils/formControl/FormControlRegistry.tsx (2)

50-53: Good import structure for the new component

Import structure follows TypeScript best practices by co-locating component and type imports.


247-256: Correctly implemented registration for new control type

The registration for the DATASOURCE_LINK control follows the established pattern in the registry. The implementation provides proper typing for the control props.

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

🧹 Nitpick comments (5)
app/client/src/components/formControls/FunctionCallingConfigControl/components/FunctionCallingConfigForm.tsx (1)

62-62: Consider using a design system token instead of hardcoded width

The UNSAFE_width="110px" property sets a fixed width for the button, but using hardcoded values can lead to inconsistencies in the UI. Consider using a design token for width if available in your design system.

-          UNSAFE_width="110px"
+          UNSAFE_width="var(--ads-v2-button-width-medium)" // or appropriate design token
app/client/src/components/formControls/DatasourceLinkControl.tsx (4)

14-20: Interface contains an unused property.

The href property defined in DatasourceLinkControlProps is never used in the component implementation. Navigation is handled via the onPress callback using datasourceId and datasourcesEditorIdURL.

export interface DatasourceLinkControlProps extends ControlProps {
-  href: string;
  text: string;
  size?: ButtonProps["size"];
  kind?: ButtonProps["kind"];
  icon?: ButtonProps["startIcon"];
}

39-40: Add type checking for datasourceId.

The datasourceId is cast as string without verifying its existence. Consider adding validation to prevent runtime errors.

-      datasourceId: props.datasourceId as string,
+      datasourceId: props.datasourceId ? String(props.datasourceId) : "",
       params: { ...omit(getQueryParams(), "viewMode"), viewMode: false },

48-48: Fixed width may cause UI issues with different text lengths.

Using a fixed width of "110px" might truncate longer button text or cause inconsistent spacing with shorter text. Consider using auto width or a more flexible approach.

-      UNSAFE_width="110px"
+      UNSAFE_width="auto"

36-44: Add error handling for navigation.

The onPress callback doesn't handle cases where parentEntityId or datasourceId might be undefined or invalid. Consider adding error handling to prevent unexpected navigation behavior.

const onPress = useCallback(() => {
+  if (!parentEntityId || !props.datasourceId) {
+    // Consider showing a notification or handling the error
+    return;
+  }
  const url = datasourcesEditorIdURL({
    baseParentEntityId: parentEntityId,
    datasourceId: props.datasourceId as string,
    params: { ...omit(getQueryParams(), "viewMode"), viewMode: false },
  });

  history.push(url);
}, [parentEntityId, props.datasourceId]);
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 193a6c4 and 5f2e4dd.

📒 Files selected for processing (5)
  • app/client/src/PluginActionEditor/components/PluginActionForm/components/UQIEditor/FormRender.tsx (2 hunks)
  • app/client/src/components/formControls/DatasourceLinkControl.tsx (1 hunks)
  • app/client/src/components/formControls/FunctionCallingConfigControl/components/FunctionCallingConfigForm.tsx (1 hunks)
  • app/client/src/utils/formControl/FormControlRegistry.tsx (2 hunks)
  • app/client/src/utils/formControl/formControlTypes.ts (1 hunks)
🔇 Additional comments (5)
app/client/src/utils/formControl/formControlTypes.ts (1)

27-27: LGTM: Added new DATASOURCE_LINK constant

The addition of this constant follows the established pattern in the file and will be used to register the new control type.

app/client/src/PluginActionEditor/components/PluginActionForm/components/UQIEditor/FormRender.tsx (2)

186-186: LGTM: Added custom styling support to FieldWrapper

Proper application of custom styles from the section configuration to the FieldWrapper component.


225-229: LGTM: Added custom styling support to Zone component

Good approach using the spread operator to apply all custom styles from section.zoneCustomStyle to the Zone component.

app/client/src/utils/formControl/FormControlRegistry.tsx (2)

50-53: LGTM: Clean import of DatasourceLinkControl

Import statement correctly brings in both the component and its type definition.


247-256: LGTM: Properly registered new DATASOURCE_LINK control

The registration follows the established pattern used for other controls in the registry.

@jsartisan jsartisan added the ok-to-test Required label for CI label Mar 21, 2025
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: 2

🧹 Nitpick comments (3)
app/client/src/components/formControls/DatasourceLinkControl.tsx (3)

14-20: Interface property defined but unused

The href property is defined in the interface but not used in the implementation. Consider removing it or implementing its usage.

export interface DatasourceLinkControlProps extends ControlProps {
-  href: string;
  text: string;
  size?: ButtonProps["size"];
  kind?: ButtonProps["kind"];
  icon?: ButtonProps["startIcon"];
}

39-39: Add null check for datasourceId

The component assumes datasourceId will be available and casts it directly to string. Consider adding validation to handle cases where it might be undefined.

-      datasourceId: props.datasourceId as string,
+      datasourceId: props.datasourceId ? String(props.datasourceId) : "",

31-57: Consider improving component reusability

The component tightly couples the navigation logic with the button UI. Consider extracting the navigation logic to a custom hook to improve reusability and testability.

+ // In a separate hook file
+ export function useDatasourceNavigation(datasourceId: string | undefined) {
+   const ideType = getIDETypeByUrl(location.pathname);
+   const { parentEntityId } = useParentEntityInfo(ideType);
+
+   return useCallback(() => {
+     if (!datasourceId) return;
+
+     const url = datasourcesEditorIdURL({
+       baseParentEntityId: parentEntityId,
+       datasourceId: String(datasourceId),
+       params: { ...omit(getQueryParams(), "viewMode"), viewMode: false },
+     });
+
+     history.push(url);
+   }, [parentEntityId, datasourceId]);
+ }

// In this component
function DatasourceLink(props: DatasourceLinkControlProps) {
  const { icon, kind = "secondary", size = "sm", text } = props;
-  const ideType = getIDETypeByUrl(location.pathname);
-  const { parentEntityId } = useParentEntityInfo(ideType);
-
-  const onPress = useCallback(() => {
-    const url = datasourcesEditorIdURL({
-      baseParentEntityId: parentEntityId,
-      datasourceId: props.datasourceId as string,
-      params: { ...omit(getQueryParams(), "viewMode"), viewMode: false },
-    });
-
-    history.push(url);
-  }, [parentEntityId, props.datasourceId]);
+  const onPress = useDatasourceNavigation(props.datasourceId);

  return (
    // ...
  );
}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between 266e72a and 456b285.

📒 Files selected for processing (1)
  • app/client/src/components/formControls/DatasourceLinkControl.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: perform-test / rts-build / build
  • GitHub Check: perform-test / client-build / client-build
  • GitHub Check: perform-test / server-build / server-unit-tests
  • GitHub Check: client-unit-tests / client-unit-tests
  • GitHub Check: client-lint / client-lint
  • GitHub Check: client-build / client-build
  • GitHub Check: client-check-cyclic-deps / check-cyclic-dependencies
  • GitHub Check: client-prettier / prettier-check
🔇 Additional comments (1)
app/client/src/components/formControls/DatasourceLinkControl.tsx (1)

22-29: Well-structured control component

Good implementation of the control component that follows the BaseControl pattern and properly encapsulates the rendering logic.

Comment on lines +14 to +20
export interface DatasourceLinkControlProps extends ControlProps {
href: string;
text: string;
size?: ButtonProps["size"];
kind?: ButtonProps["kind"];
icon?: ButtonProps["startIcon"];
}
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

Missing property in interface definition

The datasourceId property is used in the component implementation but not defined in the DatasourceLinkControlProps interface.

export interface DatasourceLinkControlProps extends ControlProps {
  href: string;
  text: string;
  size?: ButtonProps["size"];
  kind?: ButtonProps["kind"];
  icon?: ButtonProps["startIcon"];
+  datasourceId?: string;
}

Also applies to: 39-39


return (
<Button
UNSAFE_width="110px"
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Avoid using UNSAFE_ prefixed props

The UNSAFE_width prop suggests it might be deprecated or not recommended for general use. Consider using a more standard approach for setting width.


🌐 Web query:

Is UNSAFE_width a deprecated property in Appsmith Button component?

💡 Result:

Based on the provided documentation and resources, there is no evidence that UNSAFE_width is a documented or supported property for Appsmith's Button component[1][10]. The term "UNSAFE_width" doesn't appear in any official Appsmith widget documentation or recent GitHub issues regarding button components.

For width control in Button widgets, Appsmith provides these official methods:

  • Layout properties: Standard width configuration through property pane settings[1][12]
  • Dynamic styling: Programmatic control using JavaScript via setColor() method[1]
  • Theme alignment: Style buttons using theme properties (appsmith.theme)[4]
  • CSS overrides: Custom widget styling through CSS-in-JS patterns[6][11]

The "UNSAFE_" prefix typically indicates internal/experimental React APIs, but Appsmith's component API doesn't use this pattern for its widget properties[1][2]. For width modifications, use the standard width property or CSS-based approaches through Custom widgets[6][11].

For reference, here are the supported width-related patterns for buttons:

Approach Implementation Use Case
Property Pane Direct width adjustment in widget settings Basic layout control
JS Methods setColor() combined with icon positioning[7] Dynamic styling
Custom CSS Using Custom widget's CSS variables[6] Brand-specific designs
Theme Sync appsmith.theme properties for consistency[4] App-wide styling

Citations:


Action: Remove UNSAFE_width Prop for Consistency
The use of the UNSAFE_width prop in DatasourceLinkControl.tsx (line 48) isn’t supported by official Appsmith documentation. Since it doesn’t appear to be a documented or reliable property, please remove it and use a standard width configuration (e.g., via CSS or the widget’s property pane).

  • Remove UNSAFE_width="110px" on line 48.
  • Adopt one of the documented methods for width control as recommended in the Appsmith documentation.

@jsartisan jsartisan merged commit db25d12 into release Mar 21, 2025
45 checks passed
@jsartisan jsartisan deleted the chore/datasource-link branch March 21, 2025 07:53
github-actions bot pushed a commit to Zeral-Zhang/appsmith that referenced this pull request Apr 12, 2025
/ok-to-test tags="@tag.Sanity"

This PR adds an datasource link control that is required to on query
page of AI datasource.

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

## Summary by CodeRabbit

- **New Features**
- Introduced a new form control that allows users to navigate directly
to datasource-related views.
- Enhanced forms with dynamic styling capabilities, enabling sections to
apply custom visual configurations.

- **Style**
- Adjusted the width of a key configuration button to improve layout
consistency.

- **Bug Fixes**
- Resolved issues related to the application of inline styles in form
components.
<!-- 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/13986086739>
> Commit: 456b285
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=13986086739&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Sanity`
> Spec:
> <hr>Fri, 21 Mar 2025 07:20:48 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.

2 participants