2020-01-23 07:53:36 +00:00
|
|
|
import React from "react";
|
|
|
|
|
|
|
|
|
|
import BaseControl, { ControlProps } from "./BaseControl";
|
2020-02-26 12:44:56 +00:00
|
|
|
import { StyledPropertyPaneButton } from "./StyledControls";
|
2020-01-23 07:53:36 +00:00
|
|
|
import { generateReactKey } from "utils/generators";
|
2020-01-24 10:44:15 +00:00
|
|
|
import styled from "constants/DefaultTheme";
|
2020-01-23 07:53:36 +00:00
|
|
|
import { AnyStyledComponent } from "styled-components";
|
|
|
|
|
import { FormIcons } from "icons/FormIcons";
|
2020-02-18 10:41:52 +00:00
|
|
|
import { InputText } from "components/propertyControls/InputTextControl";
|
2020-04-20 05:42:46 +00:00
|
|
|
import { ActionCreator } from "components/editorComponents/actioncreator/ActionCreator";
|
2020-02-18 10:41:52 +00:00
|
|
|
|
2020-01-23 07:53:36 +00:00
|
|
|
export interface ColumnAction {
|
|
|
|
|
label: string;
|
|
|
|
|
id: string;
|
2020-02-18 10:41:52 +00:00
|
|
|
dynamicTrigger: string;
|
2020-01-23 07:53:36 +00:00
|
|
|
}
|
|
|
|
|
const StyledDeleteIcon = styled(FormIcons.DELETE_ICON as AnyStyledComponent)`
|
2020-04-03 06:56:13 +00:00
|
|
|
padding: 5px 0px;
|
2020-01-23 07:53:36 +00:00
|
|
|
position: absolute;
|
2020-06-03 04:44:11 +00:00
|
|
|
right: 0px;
|
2020-01-23 07:53:36 +00:00
|
|
|
cursor: pointer;
|
2020-03-30 08:55:52 +00:00
|
|
|
top: 0px;
|
|
|
|
|
`;
|
|
|
|
|
|
2020-06-03 04:44:11 +00:00
|
|
|
const InputTextWrapper = styled.div`
|
|
|
|
|
margin-bottom: 8px;
|
|
|
|
|
width: calc(100% - 30px);
|
|
|
|
|
`;
|
|
|
|
|
|
2020-04-03 06:56:13 +00:00
|
|
|
const Wrapper = styled.div`
|
|
|
|
|
margin-bottom: 8px;
|
2020-01-23 07:53:36 +00:00
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
class ColumnActionSelectorControl extends BaseControl<
|
2020-02-18 10:41:52 +00:00
|
|
|
ColumnActionSelectorControlProps
|
2020-01-23 07:53:36 +00:00
|
|
|
> {
|
|
|
|
|
render() {
|
|
|
|
|
return (
|
2020-02-26 12:44:56 +00:00
|
|
|
<React.Fragment>
|
2020-01-23 07:53:36 +00:00
|
|
|
{this.props.propertyValue &&
|
2020-02-18 10:41:52 +00:00
|
|
|
this.props.propertyValue.map((columnAction: ColumnAction) => {
|
|
|
|
|
return (
|
|
|
|
|
<div
|
|
|
|
|
key={columnAction.id}
|
|
|
|
|
style={{
|
|
|
|
|
position: "relative",
|
|
|
|
|
}}
|
|
|
|
|
>
|
2020-06-03 04:44:11 +00:00
|
|
|
<InputTextWrapper>
|
2020-04-03 06:56:13 +00:00
|
|
|
<InputText
|
|
|
|
|
label={columnAction.label}
|
|
|
|
|
value={columnAction.label}
|
|
|
|
|
onChange={this.updateColumnActionLabel.bind(
|
|
|
|
|
this,
|
|
|
|
|
columnAction,
|
|
|
|
|
)}
|
2020-08-19 05:52:19 +00:00
|
|
|
evaluatedValue={columnAction.label}
|
2020-04-03 06:56:13 +00:00
|
|
|
isValid={true}
|
|
|
|
|
/>
|
2020-06-03 04:44:11 +00:00
|
|
|
</InputTextWrapper>
|
2020-04-03 06:56:13 +00:00
|
|
|
<Wrapper>
|
2020-04-20 05:42:46 +00:00
|
|
|
<ActionCreator
|
2020-04-03 06:56:13 +00:00
|
|
|
value={columnAction.dynamicTrigger}
|
|
|
|
|
isValid={(columnAction as any).isValid}
|
|
|
|
|
validationMessage={(columnAction as any).message}
|
|
|
|
|
onValueChange={this.updateColumnActionFunction.bind(
|
|
|
|
|
this,
|
|
|
|
|
columnAction,
|
|
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
</Wrapper>
|
2020-02-18 10:41:52 +00:00
|
|
|
<StyledDeleteIcon
|
|
|
|
|
height={20}
|
|
|
|
|
width={20}
|
|
|
|
|
onClick={this.removeColumnAction.bind(this, columnAction)}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
})}
|
2020-01-23 07:53:36 +00:00
|
|
|
<StyledPropertyPaneButton
|
2020-05-25 12:20:55 +00:00
|
|
|
text={"New Button"}
|
2020-01-23 07:53:36 +00:00
|
|
|
icon={"plus"}
|
|
|
|
|
color={"#FFFFFF"}
|
|
|
|
|
minimal={true}
|
|
|
|
|
onClick={this.addColumnAction}
|
2020-01-30 13:23:04 +00:00
|
|
|
/>
|
2020-02-26 12:44:56 +00:00
|
|
|
</React.Fragment>
|
2020-01-23 07:53:36 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-18 10:41:52 +00:00
|
|
|
updateColumnActionLabel = (
|
|
|
|
|
columnAction: ColumnAction,
|
|
|
|
|
newValue: React.ChangeEvent<HTMLTextAreaElement> | string,
|
|
|
|
|
) => {
|
|
|
|
|
let value = newValue;
|
|
|
|
|
if (typeof newValue !== "string") {
|
|
|
|
|
value = newValue.target.value;
|
2020-01-23 07:53:36 +00:00
|
|
|
}
|
2020-02-18 10:41:52 +00:00
|
|
|
const update = this.props.propertyValue.map((a: ColumnAction) => {
|
|
|
|
|
if (a.id === columnAction.id) return { ...a, label: value };
|
|
|
|
|
return a;
|
|
|
|
|
});
|
|
|
|
|
this.updateProperty(this.props.propertyName, update);
|
2020-01-23 07:53:36 +00:00
|
|
|
};
|
|
|
|
|
|
2020-02-18 10:41:52 +00:00
|
|
|
updateColumnActionFunction = (
|
|
|
|
|
columnAction: ColumnAction,
|
|
|
|
|
newValue: string,
|
|
|
|
|
) => {
|
|
|
|
|
const update = this.props.propertyValue.map((a: ColumnAction) => {
|
|
|
|
|
if (a.id === columnAction.id) return { ...a, dynamicTrigger: newValue };
|
|
|
|
|
return a;
|
|
|
|
|
});
|
|
|
|
|
this.updateProperty(this.props.propertyName, update);
|
2020-01-23 07:53:36 +00:00
|
|
|
};
|
|
|
|
|
|
2020-02-18 10:41:52 +00:00
|
|
|
removeColumnAction = (columnAction: ColumnAction) => {
|
|
|
|
|
const update = this.props.propertyValue.filter(
|
|
|
|
|
(a: ColumnAction) => a.id !== columnAction.id,
|
|
|
|
|
);
|
|
|
|
|
this.updateProperty(this.props.propertyName, update);
|
2020-01-23 07:53:36 +00:00
|
|
|
};
|
|
|
|
|
addColumnAction = () => {
|
|
|
|
|
const columnActions = this.props.propertyValue || [];
|
2020-02-18 10:41:52 +00:00
|
|
|
const update = columnActions.concat([
|
|
|
|
|
{
|
|
|
|
|
label: "Action",
|
|
|
|
|
id: generateReactKey(),
|
|
|
|
|
actionPayloads: [],
|
|
|
|
|
},
|
|
|
|
|
]);
|
2020-01-23 07:53:36 +00:00
|
|
|
|
2020-02-18 10:41:52 +00:00
|
|
|
this.updateProperty(this.props.propertyName, update);
|
2020-01-23 07:53:36 +00:00
|
|
|
};
|
|
|
|
|
|
2020-04-14 05:35:16 +00:00
|
|
|
static getControlType() {
|
2020-01-23 07:53:36 +00:00
|
|
|
return "COLUMN_ACTION_SELECTOR";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export type ColumnActionSelectorControlProps = ControlProps;
|
|
|
|
|
|
2020-02-18 10:41:52 +00:00
|
|
|
export default ColumnActionSelectorControl;
|