Property Pane Controls
- Fixes #121, #122, #123, #124, #90, #46, #65, #100, #101, #68, #102
2019-10-24 05:24:45 +00:00
|
|
|
import React from "react";
|
2019-09-09 09:08:54 +00:00
|
|
|
import BaseWidget, { WidgetProps, WidgetState } from "./BaseWidget";
|
2019-11-25 05:07:27 +00:00
|
|
|
import { WidgetType } from "constants/WidgetConstants";
|
2020-03-06 09:45:21 +00:00
|
|
|
import ButtonComponent, {
|
|
|
|
|
ButtonType,
|
|
|
|
|
} from "components/designSystems/blueprint/ButtonComponent";
|
2021-03-30 05:29:03 +00:00
|
|
|
import { EventType } from "constants/AppsmithActionConstants/ActionConstants";
|
2019-11-22 13:12:39 +00:00
|
|
|
import { VALIDATION_TYPES } from "constants/WidgetValidation";
|
2020-08-28 17:23:07 +00:00
|
|
|
import * as Sentry from "@sentry/react";
|
2020-10-12 13:01:19 +00:00
|
|
|
import withMeta, { WithMeta } from "./MetaHOC";
|
2019-03-18 13:50:24 +00:00
|
|
|
|
2020-04-13 08:24:13 +00:00
|
|
|
class ButtonWidget extends BaseWidget<ButtonWidgetProps, ButtonWidgetState> {
|
2019-10-30 10:23:20 +00:00
|
|
|
onButtonClickBound: (event: React.MouseEvent<HTMLElement>) => void;
|
2020-10-12 13:01:19 +00:00
|
|
|
clickWithRecaptchaBound: (token: string) => void;
|
2019-10-30 10:23:20 +00:00
|
|
|
constructor(props: ButtonWidgetProps) {
|
|
|
|
|
super(props);
|
|
|
|
|
this.onButtonClickBound = this.onButtonClick.bind(this);
|
2020-10-12 13:01:19 +00:00
|
|
|
this.clickWithRecaptchaBound = this.clickWithRecaptcha.bind(this);
|
2020-03-06 09:45:21 +00:00
|
|
|
this.state = {
|
|
|
|
|
isLoading: false,
|
|
|
|
|
};
|
2019-10-30 10:23:20 +00:00
|
|
|
}
|
|
|
|
|
|
2021-02-16 10:29:08 +00:00
|
|
|
static getPropertyPaneConfig() {
|
|
|
|
|
return [
|
|
|
|
|
{
|
|
|
|
|
sectionName: "General",
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
propertyName: "text",
|
|
|
|
|
label: "Label",
|
|
|
|
|
helpText: "Sets the label of the button",
|
|
|
|
|
controlType: "INPUT_TEXT",
|
|
|
|
|
placeholderText: "Enter label text",
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
2021-04-21 14:34:25 +00:00
|
|
|
validation: VALIDATION_TYPES.TEXT,
|
2021-02-16 10:29:08 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "buttonStyle",
|
|
|
|
|
label: "Button Style",
|
|
|
|
|
controlType: "DROP_DOWN",
|
|
|
|
|
helpText: "Changes the style of the button",
|
|
|
|
|
options: [
|
|
|
|
|
{
|
|
|
|
|
label: "Primary Button",
|
|
|
|
|
value: "PRIMARY_BUTTON",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "Secondary Button",
|
|
|
|
|
value: "SECONDARY_BUTTON",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "Danger Button",
|
|
|
|
|
value: "DANGER_BUTTON",
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
isBindProperty: false,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "isVisible",
|
|
|
|
|
label: "Visible",
|
|
|
|
|
helpText: "Controls the visibility of the widget",
|
|
|
|
|
controlType: "SWITCH",
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
2021-04-21 14:34:25 +00:00
|
|
|
validation: VALIDATION_TYPES.BOOLEAN,
|
2021-02-16 10:29:08 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "isDisabled",
|
|
|
|
|
label: "Disabled",
|
|
|
|
|
controlType: "SWITCH",
|
|
|
|
|
helpText: "Disables clicks to this widget",
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
2021-04-21 14:34:25 +00:00
|
|
|
validation: VALIDATION_TYPES.BOOLEAN,
|
2021-02-16 10:29:08 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "googleRecaptchaKey",
|
|
|
|
|
label: "Google Recaptcha Key",
|
|
|
|
|
helpText: "Sets Google Recaptcha v3 site key for button",
|
|
|
|
|
controlType: "INPUT_TEXT",
|
|
|
|
|
placeholderText: "Enter google recaptcha key",
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
2021-04-21 14:34:25 +00:00
|
|
|
validation: VALIDATION_TYPES.TEXT,
|
2021-02-16 10:29:08 +00:00
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sectionName: "Actions",
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
helpText: "Triggers an action when the button is clicked",
|
|
|
|
|
propertyName: "onClick",
|
|
|
|
|
label: "onClick",
|
|
|
|
|
controlType: "ACTION_SELECTOR",
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: true,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-12 13:01:19 +00:00
|
|
|
static getMetaPropertiesMap(): Record<string, any> {
|
|
|
|
|
return {
|
|
|
|
|
recaptchaToken: undefined,
|
|
|
|
|
};
|
|
|
|
|
}
|
2020-02-18 10:41:52 +00:00
|
|
|
|
2021-04-23 05:43:13 +00:00
|
|
|
onButtonClick(e: React.MouseEvent<HTMLElement>) {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
|
2020-02-18 10:41:52 +00:00
|
|
|
if (this.props.onClick) {
|
2020-03-06 09:45:21 +00:00
|
|
|
this.setState({
|
|
|
|
|
isLoading: true,
|
|
|
|
|
});
|
2020-02-18 10:41:52 +00:00
|
|
|
super.executeAction({
|
|
|
|
|
dynamicString: this.props.onClick,
|
|
|
|
|
event: {
|
|
|
|
|
type: EventType.ON_CLICK,
|
2020-03-06 09:45:21 +00:00
|
|
|
callback: this.handleActionComplete,
|
2020-02-18 10:41:52 +00:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
2019-09-17 10:11:50 +00:00
|
|
|
}
|
|
|
|
|
|
2020-10-12 13:01:19 +00:00
|
|
|
clickWithRecaptcha(token: string) {
|
|
|
|
|
if (this.props.onClick) {
|
|
|
|
|
this.setState({
|
|
|
|
|
isLoading: true,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
this.props.updateWidgetMetaProperty("recaptchaToken", token, {
|
|
|
|
|
dynamicString: this.props.onClick,
|
|
|
|
|
event: {
|
|
|
|
|
type: EventType.ON_CLICK,
|
|
|
|
|
callback: this.handleActionComplete,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-06 09:45:21 +00:00
|
|
|
handleActionComplete = () => {
|
|
|
|
|
this.setState({
|
|
|
|
|
isLoading: false,
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2019-03-18 15:10:30 +00:00
|
|
|
getPageView() {
|
2019-03-18 13:50:24 +00:00
|
|
|
return (
|
|
|
|
|
<ButtonComponent
|
2019-10-31 05:28:11 +00:00
|
|
|
buttonStyle={this.props.buttonStyle}
|
2019-03-18 13:50:24 +00:00
|
|
|
widgetId={this.props.widgetId}
|
|
|
|
|
key={this.props.widgetId}
|
2019-11-05 05:09:50 +00:00
|
|
|
widgetName={this.props.widgetName}
|
2019-09-17 10:11:50 +00:00
|
|
|
text={this.props.text}
|
Property Pane Controls
- Fixes #121, #122, #123, #124, #90, #46, #65, #100, #101, #68, #102
2019-10-24 05:24:45 +00:00
|
|
|
disabled={this.props.isDisabled}
|
2020-11-26 11:21:23 +00:00
|
|
|
onClick={!this.props.isDisabled ? this.onButtonClickBound : undefined}
|
2020-03-06 09:45:21 +00:00
|
|
|
isLoading={this.props.isLoading || this.state.isLoading}
|
|
|
|
|
type={this.props.buttonType || ButtonType.BUTTON}
|
2020-10-12 13:01:19 +00:00
|
|
|
googleRecaptchaKey={this.props.googleRecaptchaKey}
|
|
|
|
|
clickWithRecaptcha={this.clickWithRecaptchaBound}
|
2019-03-18 13:50:24 +00:00
|
|
|
/>
|
2019-09-09 09:08:54 +00:00
|
|
|
);
|
2019-03-18 13:50:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getWidgetType(): WidgetType {
|
2019-09-09 09:08:54 +00:00
|
|
|
return "BUTTON_WIDGET";
|
2019-03-18 13:50:24 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-13 10:45:49 +00:00
|
|
|
export type ButtonStyle =
|
|
|
|
|
| "PRIMARY_BUTTON"
|
|
|
|
|
| "SECONDARY_BUTTON"
|
|
|
|
|
| "SUCCESS_BUTTON"
|
|
|
|
|
| "DANGER_BUTTON";
|
2019-09-12 08:11:25 +00:00
|
|
|
|
2020-10-12 13:01:19 +00:00
|
|
|
export interface ButtonWidgetProps extends WidgetProps, WithMeta {
|
2019-08-29 11:22:09 +00:00
|
|
|
text?: string;
|
2019-09-13 10:45:49 +00:00
|
|
|
buttonStyle?: ButtonStyle;
|
2020-02-18 10:41:52 +00:00
|
|
|
onClick?: string;
|
2019-09-19 11:29:24 +00:00
|
|
|
isDisabled?: boolean;
|
Property Pane Controls
- Fixes #121, #122, #123, #124, #90, #46, #65, #100, #101, #68, #102
2019-10-24 05:24:45 +00:00
|
|
|
isVisible?: boolean;
|
2020-03-06 09:45:21 +00:00
|
|
|
buttonType?: ButtonType;
|
2020-10-12 13:01:19 +00:00
|
|
|
googleRecaptchaKey?: string;
|
2019-03-18 13:50:24 +00:00
|
|
|
}
|
|
|
|
|
|
2020-04-13 08:24:13 +00:00
|
|
|
interface ButtonWidgetState extends WidgetState {
|
|
|
|
|
isLoading: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-09 09:08:54 +00:00
|
|
|
export default ButtonWidget;
|
2020-10-12 13:01:19 +00:00
|
|
|
export const ProfiledButtonWidget = Sentry.withProfiler(withMeta(ButtonWidget));
|