PromucFlow_constructor/app/client/src/components/formControls/DatasourceLinkControl.tsx
Pawan Kumar db25d123da
chore: Add datasource link control (#39841)
/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: 456b2858fd9669ae8f683d34bf10261fc5a86228
> <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  -->
2025-03-21 13:23:44 +05:30

60 lines
1.7 KiB
TypeScript

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<DatasourceLinkControlProps> {
getControlType(): ControlType {
return "DATASOURCE_LINK";
}
render() {
return <DatasourceLink {...this.props} />;
}
}
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 (
<Button
UNSAFE_width="110px"
kind={kind}
onClick={onPress}
size={size}
startIcon={icon}
>
{text}
</Button>
);
}
export { DatasourceLinkControl };