PromucFlow_constructor/app/client/src/components/propertyControls/ColumnActionSelectorControl.tsx
Druthi Polisetty 939cd2a217
fix: Passsing dataTreePath to CodeEditor for AI events (#26601)
## Description
Fixed issue where the propertyPath, widgetType was not being passed to
the AI events.

##PR fixes following issue(s)
Fixes #26690 

#### Media

#### Type of change
- Bug fix (non-breaking change which fixes an issue)

## Testing
>
#### How Has This Been Tested?
> Please describe the tests that you ran to verify your changes. Also
list any relevant details for your test configuration.
> Delete anything that is not relevant
- [ ] Manual
- [ ] JUnit
- [ ] Jest
- [ ] Cypress
>
>
#### Test Plan
> Add Testsmith test cases links that relate to this PR
>
>
#### Issues raised during DP testing
> Link issues raised during DP testing for better visiblity and tracking
(copy link from comments dropped on this PR)
>
>
>
## Checklist:
#### Dev activity
- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] PR is being merged under a feature flag


#### QA activity:
- [ ] [Speedbreak
features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-)
have been covered
- [ ] Test plan covers all impacted features and [areas of
interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-)
- [ ] Test plan has been peer reviewed by project stakeholders and other
QA members
- [ ] Manually tested functionality on DP
- [ ] We had an implementation alignment call with stakeholders post QA
Round 2
- [ ] Cypress test cases have been added and approved by SDET/manual QA
- [ ] Added `Test Plan Approved` label after Cypress tests were reviewed
- [ ] Added `Test Plan Approved` label after JUnit tests were reviewed
2023-09-01 17:43:24 +05:30

150 lines
4.3 KiB
TypeScript

import React from "react";
import styled from "styled-components";
import type { ControlProps } from "./BaseControl";
import BaseControl from "./BaseControl";
import { generateReactKey } from "utils/generators";
import { InputText } from "components/propertyControls/InputTextControl";
import ActionCreator from "components/editorComponents/ActionCreator";
import { Button } from "design-system";
export interface ColumnAction {
label?: string;
id: string;
dynamicTrigger: string;
}
const StyledDeleteButton = styled(Button)`
padding: 5px 0px;
position: absolute;
right: 0px;
cursor: pointer;
top: 0px;
`;
const InputTextWrapper = styled.div`
margin-bottom: 8px;
width: calc(100% - 30px);
`;
const Wrapper = styled.div`
margin-bottom: 8px;
`;
class ColumnActionSelectorControl extends BaseControl<ColumnActionSelectorControlProps> {
render() {
const { propertyName, widgetProperties } = this.props;
return (
<>
{this.props.propertyValue &&
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>
<ActionCreator
action={this.props.label}
additionalControlData={{}}
dataTreePath=""
onValueChange={this.updateColumnActionFunction.bind(
this,
columnAction,
)}
propertyName={propertyName}
value={columnAction.dynamicTrigger}
widgetName={widgetProperties.widgetName}
widgetType={widgetProperties.type}
/>
</Wrapper>
<StyledDeleteButton
isIconButton
kind="tertiary"
onClick={this.removeColumnAction.bind(this, columnAction)}
size="sm"
startIcon="delete-bin-line"
/>
</div>
);
})}
<Button
kind="secondary"
onClick={this.addColumnAction}
size="md"
startIcon="plus"
>
New Button
</Button>
</>
);
}
updateColumnActionLabel = (
columnAction: ColumnAction,
newValue: React.ChangeEvent<HTMLTextAreaElement> | string,
) => {
let value = newValue;
if (typeof newValue !== "string") {
value = newValue.target.value;
}
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);
};
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);
};
removeColumnAction = (columnAction: ColumnAction) => {
const update = this.props.propertyValue.filter(
(a: ColumnAction) => a.id !== columnAction.id,
);
this.updateProperty(this.props.propertyName, update);
};
addColumnAction = () => {
const columnActions = this.props.propertyValue || [];
const update = columnActions.concat([
{
label: "Action",
id: generateReactKey(),
actionPayloads: [],
},
]);
this.updateProperty(this.props.propertyName, update);
};
static getControlType() {
return "COLUMN_ACTION_SELECTOR";
}
}
export type ColumnActionSelectorControlProps = ControlProps;
export default ColumnActionSelectorControl;