import React, { useEffect } from "react"; import { InputGroup, Form, Row, Col } from "react-bootstrap"; import { DocStringComponent } from "./DocStringComponent"; import { LevelName } from "./NotificationsComponent"; import { SerializedObject, SerializedEnum } from "../types/SerializedObject"; import { propsAreEqual } from "../utils/propsAreEqual"; import useRenderCount from "../hooks/useRenderCount"; interface EnumComponentProps extends SerializedEnum { addNotification: (message: string, levelname?: LevelName) => void; displayName: string; id: string; changeCallback: (value: SerializedObject, callback?: (ack: unknown) => void) => void; } export const EnumComponent = React.memo((props: EnumComponentProps) => { const { addNotification, displayName, id, value, full_access_path: fullAccessPath, enum: enumDict, doc: docString, readonly: readOnly, changeCallback, } = props; const renderCount = useRenderCount(); useEffect(() => { addNotification(`${fullAccessPath} changed to ${value}.`); }, [value]); return (
{process.env.NODE_ENV === "development" &&
Render count: {renderCount}
} {displayName} {readOnly ? ( // Display the Form.Control when readOnly is true ) : ( // Display the Form.Select when readOnly is false changeCallback({ type: props.type, name: props.name, enum: enumDict, value: event.target.value, full_access_path: fullAccessPath, readonly: props.readonly, doc: props.doc, }) }> {Object.entries(enumDict).map(([key, val]) => ( ))} )}
); }, propsAreEqual); EnumComponent.displayName = "EnumComponent";