import React, { useContext, useEffect, useRef } from 'react'; import { WebSettingsContext } from '../WebSettings'; import { InputGroup, Form, Row, Col } from 'react-bootstrap'; import { getIdFromFullAccessPath } from '../utils/stringUtils'; import { DocStringComponent } from './DocStringComponent'; import { LevelName } from './NotificationsComponent'; type EnumComponentProps = { name: string; parentPath: string; value: string; docString?: string; enumDict: Record; addNotification: (message: string, levelname?: LevelName) => void; changeCallback?: ( value: unknown, attributeName?: string, prefix?: string, callback?: (ack: unknown) => void ) => void; }; export const EnumComponent = React.memo((props: EnumComponentProps) => { const { name, parentPath: parentPath, value, docString, enumDict, addNotification, changeCallback = () => {} } = props; const renderCount = useRef(0); const fullAccessPath = [parentPath, name].filter((element) => element).join('.'); const id = getIdFromFullAccessPath(fullAccessPath); const webSettings = useContext(WebSettingsContext); let displayName = name; if (webSettings[fullAccessPath] && webSettings[fullAccessPath].displayName) { displayName = webSettings[fullAccessPath].displayName; } useEffect(() => { renderCount.current++; }); useEffect(() => { addNotification(`${parentPath}.${name} changed to ${value}.`); }, [props.value]); return (
{process.env.NODE_ENV === 'development' && (
Render count: {renderCount.current}
)} {displayName} changeCallback(event.target.value)}> {Object.entries(enumDict).map(([key, val]) => ( ))}
); });