diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 32187fa..6684542 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -4,6 +4,7 @@ import { ButtonComponent } from './components/ButtonComponent'; import { socket } from './socket'; import { NumberComponent } from './components/NumberComponent'; import { SliderComponent } from './components/SliderComponent'; +import { EnumComponent } from './components/EnumComponent'; type AttributeType = | 'str' @@ -11,7 +12,8 @@ type AttributeType = | 'float' | 'int' | 'method' - | 'Subclass' + | 'DataService' + | 'Enum' | 'NumberSlider'; type ValueType = boolean | string | number | object; @@ -22,6 +24,7 @@ interface Attribute { doc?: string | null; parameters?: Record; async?: boolean; + enum?: Record; } type MyData = Record; @@ -168,6 +171,18 @@ const App = () => { /> ); + } else if (value.type === 'Enum') { + return ( +
+ +
+ ); } else if (!value.async) { return (
diff --git a/frontend/src/components/EnumComponent.tsx b/frontend/src/components/EnumComponent.tsx new file mode 100644 index 0000000..42cdf9d --- /dev/null +++ b/frontend/src/components/EnumComponent.tsx @@ -0,0 +1,59 @@ +import React, { useEffect, useRef, useState } from 'react'; +import { + OverlayTrigger, + Badge, + Tooltip, + InputGroup, + Form, + Row, + Col +} from 'react-bootstrap'; +import { socket } from '../socket'; +import { DocStringComponent } from './DocStringComponent'; + +interface EnumComponentProps { + name: string; + parent_path: string; + value: string; + docString?: string; + enumDict: Record; +} + +export const EnumComponent = React.memo((props: EnumComponentProps) => { + const renderCount = useRef(0); + + useEffect(() => { + renderCount.current++; + }); + + const { name, parent_path, value, docString, enumDict } = props; + + const handleValueChange = (newValue: string) => { + socket.emit('frontend_update', { + name: name, + value: { value: newValue } + }); + }; + + return ( +
+

Render count: {renderCount.current}

+ + + + {name} + handleValueChange(event.target.value)}> + {Object.entries(enumDict).map(([key, val]) => ( + + ))} + + + +
+ ); +});