import React, { JSXElementConstructor, useEffect } from "react"; import { FieldArray, WrappedFieldArrayProps } from "redux-form"; import styled from "styled-components"; import { Icon } from "@blueprintjs/core"; import { FormIcons } from "icons/FormIcons"; import BaseControl, { ControlProps, ControlData } from "./BaseControl"; import TextField from "components/editorComponents/form/fields/TextField"; import { ControlType } from "constants/PropertyControlConstants"; import { Colors } from "constants/Colors"; //TODO: combine it with KeyValueArrayControl and deprecate KeyValueInputControl type KeyValueRowProps = { name: string; label: string; rightIcon?: JSXElementConstructor<{ height: number; width: number }>; description?: string; actionConfig?: any; extraData?: ControlData[]; isRequired?: boolean; }; export interface KeyValueInputControlProps extends ControlProps { name: string; label: string; rightIcon?: JSXElementConstructor<{ height: number; width: number }>; description?: string; actionConfig?: any; } const FormRowWithLabel = styled.div` display: flex; flex: 1; flex-direction: row; & svg { cursor: pointer; } `; function KeyValueRow(props: KeyValueRowProps & WrappedFieldArrayProps) { useEffect(() => { // Always maintain 1 row if (props.fields.length < 1) { for (let i = props.fields.length; i < 1; i += 1) { props.fields.push({ key: "", value: "" }); } } }, [props.fields]); return (