PromucFlow_constructor/app/client/src/components/propertyControls/ColumnActionSelectorControl.tsx

149 lines
4.2 KiB
TypeScript
Raw Normal View History

2020-01-23 07:53:36 +00:00
import React from "react";
import BaseControl, { ControlProps } from "./BaseControl";
import { StyledPropertyPaneButton } from "./StyledControls";
2020-01-23 07:53:36 +00:00
import { generateReactKey } from "utils/generators";
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";
feat: Change navigate to UI (#14856) * Initial work to change navigate to UI * Remove console.logs * Adjust default parameters and getters/setters for page dropdown field * change url field getter so page names are not showm * Remove ../ from the imports Remove unnecessary todo * Add check for undefined fields * Add validations for url/page name, add error message * Make height auto to accommodate the flexible size of query param text box * Update dropdown list of pages when page names are updated * Set tab to url when a url has been entered, else default to page * Add feature tests * Add check on null value in isValueValidURL to ensure it does not crash the app * Remove unused ref * Fix bug when switch is selected and a new page addition let to page crash * Initial work to change navigate to UI * Remove console.logs * Adjust default parameters and getters/setters for page dropdown field * change url field getter so page names are not showm * Remove ../ from the imports Remove unnecessary todo * Add check for undefined fields * Add validations for url/page name, add error message * Make height auto to accommodate the flexible size of query param text box * Update dropdown list of pages when page names are updated * Set tab to url when a url has been entered, else default to page * Add feature tests * Add check on null value in isValueValidURL to ensure it does not crash the app * Remove unused ref * Fix bug when switch is selected and a new page addition let to page crash * Fix types and imports * Update the tests * Add ref back to the code Co-authored-by: Aishwarya UR <aishwarya@appsmith.com>
2022-09-16 04:30:16 +00:00
import ActionCreator from "components/editorComponents/ActionCreator";
feat: Migrate design system components import to design-system repo - I (#15562) * Icon component deleted and changed the imports in refrence places * design system package version changed * import changes * Delete TextInput.tsx * Change imports * Change single named import * Update package * Update package * Delete ScrollIndicator.tsx * Change imports * Icon import completed * Event type added * Changed Button component imports * import change button * Button onclick type fix * Label with Tooltip import changes * Changed breadcrumbs import * EmojiPicker and Emoji Reaction import changes * AppIcon import change * import bug fix * Menu Item import chnages * Icon selector imports changed * Delete LabelWithTooltip.tsx * Change imports across the app * Update package version * Update version number for design-system * Delete Checkbox.tsx * Remove the exports * Add lock file for ds package update * Change imports * default import -> named * Update release version * Make arg type explicit * Updated design-system to latest release * Missing file mysteriously comes back and is updated accordingly * changes design-system package version * Add types to arguments in the onChange for text input * onBlur type fix * Search component in property pane * WDS button changes reverted * package version bumped * conflict fix * Remove Dropdown, change imports * Category import fix * fix: table icon size import * Bump version of design system package * Yarn lock Co-authored-by: Tanvi Bhakta <tanvibhakta@gmail.com>
2022-08-22 05:09:39 +00:00
import { Size, Category } from "design-system";
feat: Change navigate to UI (#14856) * Initial work to change navigate to UI * Remove console.logs * Adjust default parameters and getters/setters for page dropdown field * change url field getter so page names are not showm * Remove ../ from the imports Remove unnecessary todo * Add check for undefined fields * Add validations for url/page name, add error message * Make height auto to accommodate the flexible size of query param text box * Update dropdown list of pages when page names are updated * Set tab to url when a url has been entered, else default to page * Add feature tests * Add check on null value in isValueValidURL to ensure it does not crash the app * Remove unused ref * Fix bug when switch is selected and a new page addition let to page crash * Initial work to change navigate to UI * Remove console.logs * Adjust default parameters and getters/setters for page dropdown field * change url field getter so page names are not showm * Remove ../ from the imports Remove unnecessary todo * Add check for undefined fields * Add validations for url/page name, add error message * Make height auto to accommodate the flexible size of query param text box * Update dropdown list of pages when page names are updated * Set tab to url when a url has been entered, else default to page * Add feature tests * Add check on null value in isValueValidURL to ensure it does not crash the app * Remove unused ref * Fix bug when switch is selected and a new page addition let to page crash * Fix types and imports * Update the tests * Add ref back to the code Co-authored-by: Aishwarya UR <aishwarya@appsmith.com>
2022-09-16 04:30:16 +00:00
2020-01-23 07:53:36 +00:00
export interface ColumnAction {
label?: string;
2020-01-23 07:53:36 +00:00
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)`
padding: 5px 0px;
2020-01-23 07:53:36 +00:00
position: absolute;
right: 0px;
2020-01-23 07:53:36 +00:00
cursor: pointer;
2020-03-30 08:55:52 +00:00
top: 0px;
&& svg path {
fill: ${(props) => props.theme.colors.propertyPane.deleteIconColor};
}
2020-03-30 08:55:52 +00:00
`;
const InputTextWrapper = styled.div`
margin-bottom: 8px;
width: calc(100% - 30px);
`;
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-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",
}}
>
<InputTextWrapper>
<InputText
evaluatedValue={columnAction.label}
label={columnAction.label || ""}
onChange={this.updateColumnActionLabel.bind(
this,
columnAction,
)}
theme={this.props.theme}
value={columnAction.label as string}
/>
</InputTextWrapper>
<Wrapper>
2020-04-20 05:42:46 +00:00
<ActionCreator
onValueChange={this.updateColumnActionFunction.bind(
this,
columnAction,
)}
value={columnAction.dynamicTrigger}
/>
</Wrapper>
2020-02-18 10:41:52 +00:00
<StyledDeleteIcon
height={20}
onClick={this.removeColumnAction.bind(this, columnAction)}
width={20}
2020-02-18 10:41:52 +00:00
/>
</div>
);
})}
2020-01-23 07:53:36 +00:00
<StyledPropertyPaneButton
category={Category.secondary}
icon="plus"
2020-01-23 07:53:36 +00:00
onClick={this.addColumnAction}
size={Size.medium}
tag="button"
text="New Button"
type="button"
2020-01-30 13:23:04 +00:00
/>
</>
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
};
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;