-
Notifications
You must be signed in to change notification settings - Fork 4.5k
chore: Add datasource link control #39841
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -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<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" | |||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainAvoid using UNSAFE_ prefixed props The 🌐 Web query: 💡 Result: Based on the provided documentation and resources, there is no evidence that For width control in Button widgets, Appsmith provides these official methods:
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:
Citations:
Action: Remove UNSAFE_width Prop for Consistency
|
|||||||||||||||||
| kind={kind} | |||||||||||||||||
| onClick={onPress} | |||||||||||||||||
| size={size} | |||||||||||||||||
| startIcon={icon} | |||||||||||||||||
| > | |||||||||||||||||
| {text} | |||||||||||||||||
| </Button> | |||||||||||||||||
| ); | |||||||||||||||||
| } | |||||||||||||||||
|
|
|||||||||||||||||
| export { DatasourceLinkControl }; | |||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing property in interface definition
The
datasourceIdproperty is used in the component implementation but not defined in theDatasourceLinkControlPropsinterface.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