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

71 lines
1.9 KiB
TypeScript
Raw Normal View History

2020-01-23 07:53:36 +00:00
import React from "react";
import BaseControl, { ControlData, ControlProps } from "./BaseControl";
2020-04-20 05:42:46 +00:00
// import DynamicActionCreator from "components/editorComponents/DynamicActionCreator";
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";
import {
DSEventDetail,
DSEventTypes,
DS_EVENT,
emitInteractionAnalyticsEvent,
} from "utils/AppsmithUtils";
2020-01-23 07:53:36 +00:00
2020-02-18 10:41:52 +00:00
class ActionSelectorControl extends BaseControl<ControlProps> {
componentRef = React.createRef<HTMLDivElement>();
componentDidMount() {
this.componentRef.current?.addEventListener(
DS_EVENT,
this.handleAdsEvent as (arg0: Event) => void,
);
}
componentWillUnmount() {
this.componentRef.current?.removeEventListener(
DS_EVENT,
this.handleAdsEvent as (arg0: Event) => void,
);
}
handleAdsEvent = (e: CustomEvent<DSEventDetail>) => {
if (
e.detail.component === "TreeDropdown" &&
e.detail.event === DSEventTypes.KEYPRESS
) {
emitInteractionAnalyticsEvent(this.componentRef.current, {
key: e.detail.meta.key,
});
e.stopPropagation();
}
};
handleValueUpdate = (newValue: string, isUpdatedViaKeyboard = false) => {
const { propertyName, propertyValue } = this.props;
if (!propertyValue && !newValue) return;
this.updateProperty(propertyName, newValue, isUpdatedViaKeyboard);
2020-01-23 07:53:36 +00:00
};
render() {
2020-02-18 10:41:52 +00:00
const { propertyValue } = this.props;
2020-01-23 07:53:36 +00:00
return (
2020-04-20 05:42:46 +00:00
<ActionCreator
additionalAutoComplete={this.props.additionalAutoComplete}
onValueChange={this.handleValueUpdate}
ref={this.componentRef}
value={propertyValue}
/>
2020-01-23 07:53:36 +00:00
);
}
static getControlType() {
2020-01-23 07:53:36 +00:00
return "ACTION_SELECTOR";
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
static canDisplayValueInUI(config: ControlData, value: any): boolean {
return true;
}
2020-01-23 07:53:36 +00:00
}
2020-02-18 10:41:52 +00:00
export default ActionSelectorControl;