2019-11-07 10:15:33 +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";
|
|
|
|
|
import RadioGroupComponent from "components/designSystems/blueprint/RadioGroupComponent";
|
2020-02-18 10:41:52 +00:00
|
|
|
import { EventType } from "constants/ActionConstants";
|
2020-03-16 07:59:07 +00:00
|
|
|
import {
|
|
|
|
|
WidgetPropertyValidationType,
|
|
|
|
|
BASE_WIDGET_VALIDATION,
|
2020-10-21 04:25:32 +00:00
|
|
|
} from "utils/WidgetValidation";
|
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-06 09:01:51 +00:00
|
|
|
import withMeta, { WithMeta } from "./MetaHOC";
|
2019-03-21 12:10:32 +00:00
|
|
|
|
2019-09-13 10:45:49 +00:00
|
|
|
class RadioGroupWidget extends BaseWidget<RadioGroupWidgetProps, WidgetState> {
|
2021-02-16 10:29:08 +00:00
|
|
|
static getPropertyPaneConfig() {
|
|
|
|
|
return [
|
|
|
|
|
{
|
|
|
|
|
sectionName: "General",
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
helpText:
|
|
|
|
|
"Displays a list of options for a user to select. Values must be unique",
|
|
|
|
|
propertyName: "options",
|
|
|
|
|
label: "Options",
|
|
|
|
|
controlType: "OPTION_INPUT",
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
helpText: "Selects a value of the options entered by default",
|
|
|
|
|
propertyName: "defaultOptionValue",
|
|
|
|
|
label: "Default Selected Value",
|
|
|
|
|
placeholderText: "Enter option value",
|
|
|
|
|
controlType: "INPUT_TEXT",
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "isRequired",
|
|
|
|
|
label: "Required",
|
|
|
|
|
helpText: "Makes input to the widget mandatory",
|
|
|
|
|
controlType: "SWITCH",
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
helpText: "Controls the visibility of the widget",
|
|
|
|
|
propertyName: "isVisible",
|
|
|
|
|
label: "Visible",
|
|
|
|
|
controlType: "SWITCH",
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "isDisabled",
|
|
|
|
|
label: "Disabled",
|
|
|
|
|
helpText: "Disables input to this widget",
|
|
|
|
|
controlType: "SWITCH",
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sectionName: "Actions",
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
helpText:
|
|
|
|
|
"Triggers an action when a user changes the selected option",
|
|
|
|
|
propertyName: "onSelectionChange",
|
|
|
|
|
label: "onSelectionChange",
|
|
|
|
|
controlType: "ACTION_SELECTOR",
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: true,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
}
|
2019-11-22 13:12:39 +00:00
|
|
|
static getPropertyValidationMap(): WidgetPropertyValidationType {
|
|
|
|
|
return {
|
2020-03-16 07:59:07 +00:00
|
|
|
...BASE_WIDGET_VALIDATION,
|
2019-11-22 13:12:39 +00:00
|
|
|
label: VALIDATION_TYPES.TEXT,
|
2020-02-03 11:49:20 +00:00
|
|
|
options: VALIDATION_TYPES.OPTIONS_DATA,
|
2019-11-22 13:12:39 +00:00
|
|
|
selectedOptionValue: VALIDATION_TYPES.TEXT,
|
2020-03-16 07:59:07 +00:00
|
|
|
defaultOptionValue: VALIDATION_TYPES.TEXT,
|
2020-03-06 09:45:21 +00:00
|
|
|
isRequired: VALIDATION_TYPES.BOOLEAN,
|
2020-07-06 08:16:42 +00:00
|
|
|
// onSelectionChange: VALIDATION_TYPES.ACTION_SELECTOR,
|
2019-11-22 13:12:39 +00:00
|
|
|
};
|
|
|
|
|
}
|
2020-01-17 09:28:26 +00:00
|
|
|
static getDerivedPropertiesMap() {
|
|
|
|
|
return {
|
|
|
|
|
selectedOption:
|
|
|
|
|
"{{_.find(this.options, { value: this.selectedOptionValue })}}",
|
2020-03-06 09:45:21 +00:00
|
|
|
isValid: `{{ this.isRequired ? !!this.selectedOptionValue : true }}`,
|
2020-06-09 12:04:38 +00:00
|
|
|
value: `{{this.selectedOptionValue}}`,
|
2020-01-17 09:28:26 +00:00
|
|
|
};
|
|
|
|
|
}
|
2020-03-13 07:24:03 +00:00
|
|
|
|
2020-04-17 16:15:09 +00:00
|
|
|
static getDefaultPropertiesMap(): Record<string, string> {
|
|
|
|
|
return {
|
|
|
|
|
selectedOptionValue: "defaultOptionValue",
|
|
|
|
|
};
|
2020-03-13 07:24:03 +00:00
|
|
|
}
|
|
|
|
|
|
2020-04-17 16:15:09 +00:00
|
|
|
static getMetaPropertiesMap(): Record<string, any> {
|
|
|
|
|
return {
|
2020-04-21 07:54:23 +00:00
|
|
|
selectedOptionValue: undefined,
|
2020-04-17 16:15:09 +00:00
|
|
|
};
|
2020-03-13 07:24:03 +00:00
|
|
|
}
|
2020-04-17 16:15:09 +00:00
|
|
|
|
2019-03-21 12:10:32 +00:00
|
|
|
getPageView() {
|
|
|
|
|
return (
|
|
|
|
|
<RadioGroupComponent
|
|
|
|
|
widgetId={this.props.widgetId}
|
2019-11-05 05:09:50 +00:00
|
|
|
onRadioSelectionChange={this.onRadioSelectionChange}
|
2019-03-21 12:10:32 +00:00
|
|
|
key={this.props.widgetId}
|
2020-05-25 09:32:01 +00:00
|
|
|
label={`${this.props.label}`}
|
2019-11-05 05:09:50 +00:00
|
|
|
selectedOptionValue={this.props.selectedOptionValue}
|
2019-03-21 12:10:32 +00:00
|
|
|
options={this.props.options}
|
2019-12-03 04:41:10 +00:00
|
|
|
isLoading={this.props.isLoading}
|
2020-08-07 13:17:15 +00:00
|
|
|
isDisabled={this.props.isDisabled}
|
2019-03-21 12:10:32 +00:00
|
|
|
/>
|
2019-09-09 09:08:54 +00:00
|
|
|
);
|
2019-03-21 12:10:32 +00:00
|
|
|
}
|
|
|
|
|
|
2019-11-05 05:09:50 +00:00
|
|
|
onRadioSelectionChange = (updatedValue: string) => {
|
2020-10-06 16:47:16 +00:00
|
|
|
this.props.updateWidgetMetaProperty("selectedOptionValue", updatedValue, {
|
|
|
|
|
dynamicString: this.props.onSelectionChange,
|
|
|
|
|
event: {
|
|
|
|
|
type: EventType.ON_OPTION_CHANGE,
|
|
|
|
|
},
|
|
|
|
|
});
|
2019-11-05 05:09:50 +00:00
|
|
|
};
|
|
|
|
|
|
2019-03-21 12:10:32 +00:00
|
|
|
getWidgetType(): WidgetType {
|
2019-09-09 09:08:54 +00:00
|
|
|
return "RADIO_GROUP_WIDGET";
|
2019-03-21 12:10:32 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-12 08:11:25 +00:00
|
|
|
export interface RadioOption {
|
2019-09-13 10:45:49 +00:00
|
|
|
label: string;
|
|
|
|
|
value: string;
|
2019-09-12 08:11:25 +00:00
|
|
|
}
|
|
|
|
|
|
2020-10-06 09:01:51 +00:00
|
|
|
export interface RadioGroupWidgetProps extends WidgetProps, WithMeta {
|
2019-08-29 11:22:09 +00:00
|
|
|
label: string;
|
2019-09-13 10:45:49 +00:00
|
|
|
options: RadioOption[];
|
2019-11-05 05:09:50 +00:00
|
|
|
selectedOptionValue: string;
|
2020-02-18 10:41:52 +00:00
|
|
|
onSelectionChange: string;
|
2020-02-24 14:55:09 +00:00
|
|
|
defaultOptionValue: string;
|
2020-03-06 09:45:21 +00:00
|
|
|
isRequired?: boolean;
|
2019-03-21 12:10:32 +00:00
|
|
|
}
|
|
|
|
|
|
2019-09-13 10:45:49 +00:00
|
|
|
export default RadioGroupWidget;
|
2020-10-06 09:01:51 +00:00
|
|
|
export const ProfiledRadioGroupWidget = Sentry.withProfiler(
|
|
|
|
|
withMeta(RadioGroupWidget),
|
|
|
|
|
);
|