2019-11-05 05:09:50 +00:00
|
|
|
import React from "react";
|
2022-06-16 09:47:35 +00:00
|
|
|
import BaseControl, { ControlData, ControlProps } from "./BaseControl";
|
2021-09-09 15:10:22 +00:00
|
|
|
import { DropdownOption } from "components/constants";
|
2020-04-01 08:09:57 +00:00
|
|
|
import { KeyValueComponent } from "./KeyValueComponent";
|
2022-06-16 09:47:35 +00:00
|
|
|
import { isDynamicValue } from "utils/DynamicBindingUtils";
|
2019-12-18 17:05:28 +00:00
|
|
|
|
2020-04-01 08:09:57 +00:00
|
|
|
export type DropDownOptionWithKey = DropdownOption & {
|
2020-03-19 03:07:31 +00:00
|
|
|
key: string;
|
|
|
|
|
};
|
|
|
|
|
|
2020-04-01 08:09:57 +00:00
|
|
|
class OptionControl extends BaseControl<ControlProps> {
|
2019-11-05 05:09:50 +00:00
|
|
|
render() {
|
|
|
|
|
return (
|
2020-04-01 08:09:57 +00:00
|
|
|
<KeyValueComponent
|
|
|
|
|
pairs={this.props.propertyValue}
|
|
|
|
|
updatePairs={this.updateOptions}
|
|
|
|
|
/>
|
2019-11-05 05:09:50 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-14 05:00:30 +00:00
|
|
|
updateOptions = (options: DropdownOption[], isUpdatedViaKeyboard = false) => {
|
|
|
|
|
this.updateProperty("options", options, isUpdatedViaKeyboard);
|
2019-11-05 05:09:50 +00:00
|
|
|
};
|
|
|
|
|
|
2020-04-14 05:35:16 +00:00
|
|
|
static getControlType() {
|
2019-11-05 05:09:50 +00:00
|
|
|
return "OPTION_INPUT";
|
|
|
|
|
}
|
2022-06-16 09:47:35 +00:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
2019-11-05 05:09:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default OptionControl;
|