PromucFlow_constructor/app/client/src/components/propertyControls/OptionControl.tsx
Aswath K 3824435f7d
chore: Adds analytics for Property Pane keyboard navigation (#13703)
* Adds analytics for DropdownControl

* Add isUpdatedViaKeyboard to WIDGET_PROPERTY_UPDATE

* fix: jest test for iconselectorcontrol

* refactor: Interaction analytics event dispatching moved to a hook

* refactor: event collection logic to HOC

* Analytics for SwitchControl

* Analytics for CodeEditor

* Analytics for InputTextControl

* Analytics for ColorPicker

* fix issue with ColorPicker

* refactor to re-use ref

* rename the hook to ts

* Analytics for StepControl

* Analytics for ButtonTabComponent

* Analytics for NumericInputControl

* Analytics for IconSelector

* fix: failed test

* Analytics for ActionSelector

* fix: failed jest test

* fix: jest test for StepControl

* Analytics for Option Control

* Analytics for LocationSearchControl

* Adds Analytics for Tab key

* analytics for Property pane connections

* Add analytics for widget name

* Adds analytics for copy & delete button

* fix issue with widget name analytics

* add useCallback for tab keydown handler for button

* Create separate Event handling for design system

* removes unused imports

* changes ADS_EVENT to DS_EVENT

* Changes AdsEventTypes to DSEventTypes

* Changes AdsEventDetail to DSEventDetail

* changes occurences of Ads to DS

* avoids creation of intermediate function

* removes trace of 'analytics' from DS components

* rename dispatchDSEvent to emitDSEvent

* fix: Cypress selector
2022-07-14 10:30:30 +05:30

49 lines
1.2 KiB
TypeScript

import React from "react";
import BaseControl, { ControlData, ControlProps } from "./BaseControl";
import { DropdownOption } from "components/constants";
import { KeyValueComponent } from "./KeyValueComponent";
import { isDynamicValue } from "utils/DynamicBindingUtils";
export type DropDownOptionWithKey = DropdownOption & {
key: string;
};
class OptionControl extends BaseControl<ControlProps> {
render() {
return (
<KeyValueComponent
pairs={this.props.propertyValue}
updatePairs={this.updateOptions}
/>
);
}
updateOptions = (options: DropdownOption[], isUpdatedViaKeyboard = false) => {
this.updateProperty("options", options, isUpdatedViaKeyboard);
};
static getControlType() {
return "OPTION_INPUT";
}
static canDisplayValueInUI(config: ControlData, value: any): boolean {
if (isDynamicValue(value)) return false;
try {
const pairs: DropdownOption[] = JSON.parse(value);
for (const x of pairs) {
const keys = Object.keys(x);
if (!keys.includes("label") || !keys.includes("value")) {
return false;
}
}
} catch {
return false;
}
return true;
}
}
export default OptionControl;