diff --git a/frontend/src/components/ButtonComponent.tsx b/frontend/src/components/ButtonComponent.tsx index 4ae75d0..3718051 100644 --- a/frontend/src/components/ButtonComponent.tsx +++ b/frontend/src/components/ButtonComponent.tsx @@ -1,7 +1,6 @@ import React, { useContext, useEffect, useRef } from 'react'; import { WebSettingsContext } from '../WebSettings'; import { ToggleButton } from 'react-bootstrap'; -import { setAttribute } from '../socket'; import { DocStringComponent } from './DocStringComponent'; import { getIdFromFullAccessPath } from '../utils/stringUtils'; import { LevelName } from './NotificationsComponent'; @@ -14,10 +13,24 @@ type ButtonComponentProps = { docString: string; mapping?: [string, string]; // Enforce a tuple of two strings addNotification: (message: string, levelname?: LevelName) => void; + changeCallback?: ( + value: unknown, + attributeName?: string, + prefix?: string, + callback?: (ack: unknown) => void + ) => void; }; export const ButtonComponent = React.memo((props: ButtonComponentProps) => { - const { name, parentPath, value, readOnly, docString, addNotification } = props; + const { + name, + parentPath, + value, + readOnly, + docString, + addNotification, + changeCallback = () => {} + } = props; // const buttonName = props.mapping ? (value ? props.mapping[0] : props.mapping[1]) : name; const fullAccessPath = [parentPath, name].filter((element) => element).join('.'); const id = getIdFromFullAccessPath(fullAccessPath); @@ -39,7 +52,7 @@ export const ButtonComponent = React.memo((props: ButtonComponentProps) => { }, [props.value]); const setChecked = (checked: boolean) => { - setAttribute(name, parentPath, checked); + changeCallback(checked); }; return ( diff --git a/frontend/src/components/ColouredEnumComponent.tsx b/frontend/src/components/ColouredEnumComponent.tsx index f3e9a47..d559169 100644 --- a/frontend/src/components/ColouredEnumComponent.tsx +++ b/frontend/src/components/ColouredEnumComponent.tsx @@ -1,7 +1,6 @@ import React, { useContext, useEffect, useRef } from 'react'; import { WebSettingsContext } from '../WebSettings'; import { InputGroup, Form, Row, Col } from 'react-bootstrap'; -import { setAttribute } from '../socket'; import { DocStringComponent } from './DocStringComponent'; import { getIdFromFullAccessPath } from '../utils/stringUtils'; import { LevelName } from './NotificationsComponent'; @@ -14,6 +13,12 @@ type ColouredEnumComponentProps = { readOnly: boolean; enumDict: Record; addNotification: (message: string, levelname?: LevelName) => void; + changeCallback?: ( + value: unknown, + attributeName?: string, + prefix?: string, + callback?: (ack: unknown) => void + ) => void; }; export const ColouredEnumComponent = React.memo((props: ColouredEnumComponentProps) => { @@ -24,7 +29,8 @@ export const ColouredEnumComponent = React.memo((props: ColouredEnumComponentPro docString, enumDict, readOnly, - addNotification + addNotification, + changeCallback = () => {} } = props; const renderCount = useRef(0); const fullAccessPath = [parentPath, name].filter((element) => element).join('.'); @@ -44,10 +50,6 @@ export const ColouredEnumComponent = React.memo((props: ColouredEnumComponentPro addNotification(`${parentPath}.${name} changed to ${value}.`); }, [props.value]); - const handleValueChange = (newValue: string) => { - setAttribute(name, parentPath, newValue); - }; - return (
{process.env.NODE_ENV === 'development' && ( @@ -72,7 +74,7 @@ export const ColouredEnumComponent = React.memo((props: ColouredEnumComponentPro aria-label="coloured-enum-select" value={value} style={{ backgroundColor: enumDict[value] }} - onChange={(event) => handleValueChange(event.target.value)}> + onChange={(event) => changeCallback(event.target.value)}> {Object.entries(enumDict).map(([key]) => (