From db25d123da29da72c4d28610c9163ceb604cb0a1 Mon Sep 17 00:00:00 2001 From: Pawan Kumar Date: Fri, 21 Mar 2025 13:23:44 +0530 Subject: [PATCH] chore: Add datasource link control (#39841) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit /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: > Commit: 456b2858fd9669ae8f683d34bf10261fc5a86228 > Cypress dashboard. > Tags: `@tag.Sanity` > Spec: >
Fri, 21 Mar 2025 07:20:48 UTC --- .../components/UQIEditor/FormRender.tsx | 7 ++- .../formControls/DatasourceLinkControl.tsx | 59 +++++++++++++++++++ .../components/FunctionCallingConfigForm.tsx | 1 + .../utils/formControl/FormControlRegistry.tsx | 14 +++++ .../src/utils/formControl/formControlTypes.ts | 1 + 5 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 app/client/src/components/formControls/DatasourceLinkControl.tsx diff --git a/app/client/src/PluginActionEditor/components/PluginActionForm/components/UQIEditor/FormRender.tsx b/app/client/src/PluginActionEditor/components/PluginActionForm/components/UQIEditor/FormRender.tsx index 644c090f73..68bad74475 100644 --- a/app/client/src/PluginActionEditor/components/PluginActionForm/components/UQIEditor/FormRender.tsx +++ b/app/client/src/PluginActionEditor/components/PluginActionForm/components/UQIEditor/FormRender.tsx @@ -183,6 +183,7 @@ const FormRender = (props: Props) => { @@ -221,7 +222,11 @@ const FormRender = (props: Props) => { ? "single_column" : "double_column"; - return {children}; + return ( + + {children} + + ); } default: return children; diff --git a/app/client/src/components/formControls/DatasourceLinkControl.tsx b/app/client/src/components/formControls/DatasourceLinkControl.tsx new file mode 100644 index 0000000000..884c7ea152 --- /dev/null +++ b/app/client/src/components/formControls/DatasourceLinkControl.tsx @@ -0,0 +1,59 @@ +import React, { useCallback } from "react"; +import omit from "lodash/omit"; +import history from "utils/history"; +import { Button, type ButtonProps } from "@appsmith/ads"; +import type { ControlType } from "constants/PropertyControlConstants"; + +import BaseControl from "./BaseControl"; +import type { ControlProps } from "./BaseControl"; +import { useParentEntityInfo } from "ee/IDE/hooks/useParentEntityInfo"; +import { getIDETypeByUrl } from "ee/entities/IDE/utils"; +import { datasourcesEditorIdURL } from "ee/RouteBuilder"; +import { getQueryParams } from "utils/URLUtils"; + +export interface DatasourceLinkControlProps extends ControlProps { + href: string; + text: string; + size?: ButtonProps["size"]; + kind?: ButtonProps["kind"]; + icon?: ButtonProps["startIcon"]; +} + +class DatasourceLinkControl extends BaseControl { + getControlType(): ControlType { + return "DATASOURCE_LINK"; + } + render() { + return ; + } +} + +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]); + + return ( + + ); +} + +export { DatasourceLinkControl }; diff --git a/app/client/src/components/formControls/FunctionCallingConfigControl/components/FunctionCallingConfigForm.tsx b/app/client/src/components/formControls/FunctionCallingConfigControl/components/FunctionCallingConfigForm.tsx index 26a7cf0e05..20054d4c3a 100644 --- a/app/client/src/components/formControls/FunctionCallingConfigControl/components/FunctionCallingConfigForm.tsx +++ b/app/client/src/components/formControls/FunctionCallingConfigControl/components/FunctionCallingConfigForm.tsx @@ -59,6 +59,7 @@ export const FunctionCallingConfigForm = ({