diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 365c15d..b99d30d 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -258,6 +258,7 @@ const App = () => {
Render count: {renderCount.current}
)} @@ -99,11 +99,7 @@ export const AsyncMethodComponent = React.memo((props: AsyncMethodProps) => { diff --git a/frontend/src/components/ButtonComponent.tsx b/frontend/src/components/ButtonComponent.tsx index 468c7de..e6aae9e 100644 --- a/frontend/src/components/ButtonComponent.tsx +++ b/frontend/src/components/ButtonComponent.tsx @@ -2,6 +2,7 @@ import React, { useEffect, useRef } from 'react'; import { ToggleButton } from 'react-bootstrap'; import { emit_update } from '../socket'; import { DocStringComponent } from './DocStringComponent'; +import { getIdFromFullAccessPath } from '../utils/stringUtils'; interface ButtonComponentProps { name: string; @@ -17,6 +18,7 @@ export const ButtonComponent = React.memo((props: ButtonComponentProps) => { const { name, parentPath, value, readOnly, docString, mapping, addNotification } = props; const buttonName = mapping ? (value ? mapping[0] : mapping[1]) : name; + const id = getIdFromFullAccessPath(parentPath.concat('.' + name)); const renderCount = useRef(0); @@ -33,14 +35,14 @@ export const ButtonComponent = React.memo((props: ButtonComponentProps) => { }; return ( -Render count: {renderCount.current}
)}Render count: {renderCount.current}
)} diff --git a/frontend/src/components/DataServiceComponent.tsx b/frontend/src/components/DataServiceComponent.tsx index 7640cb1..ae4d38e 100644 --- a/frontend/src/components/DataServiceComponent.tsx +++ b/frontend/src/components/DataServiceComponent.tsx @@ -3,8 +3,10 @@ import React from 'react'; import { Card, Collapse } from 'react-bootstrap'; import { ChevronDown, ChevronRight } from 'react-bootstrap-icons'; import { Attribute, GenericComponent } from './GenericComponent'; +import { getIdFromFullAccessPath } from '../utils/stringUtils'; type DataServiceProps = { + name: string; props: DataServiceJSON; parentPath?: string; isInstantUpdate: boolean; @@ -15,21 +17,29 @@ export type DataServiceJSON = RecordRender count: {renderCount.current}
)} diff --git a/frontend/src/components/MethodComponent.tsx b/frontend/src/components/MethodComponent.tsx index be0f67f..29678ed 100644 --- a/frontend/src/components/MethodComponent.tsx +++ b/frontend/src/components/MethodComponent.tsx @@ -2,6 +2,7 @@ import React, { useState, useEffect, useRef } from 'react'; import { emit_update } from '../socket'; import { Button, InputGroup, Form, Collapse } from 'react-bootstrap'; import { DocStringComponent } from './DocStringComponent'; +import { getIdFromFullAccessPath } from '../utils/stringUtils'; interface MethodProps { name: string; @@ -19,6 +20,7 @@ export const MethodComponent = React.memo((props: MethodProps) => { const [hideOutput, setHideOutput] = useState(false); // Add a new state variable to hold the list of function calls const [functionCalls, setFunctionCalls] = useState([]); + const id = getIdFromFullAccessPath(parentPath.concat('.' + name)); useEffect(() => { renderCount.current++; @@ -69,9 +71,7 @@ export const MethodComponent = React.memo((props: MethodProps) => { }); return ( -Render count: {renderCount.current}
)} diff --git a/frontend/src/components/NumberComponent.tsx b/frontend/src/components/NumberComponent.tsx index 4a3a10b..af126f5 100644 --- a/frontend/src/components/NumberComponent.tsx +++ b/frontend/src/components/NumberComponent.tsx @@ -3,6 +3,7 @@ import { Form, InputGroup } from 'react-bootstrap'; import { emit_update } from '../socket'; import { DocStringComponent } from './DocStringComponent'; import '../App.css'; +import { getIdFromFullAccessPath } from '../utils/stringUtils'; // TODO: add button functionality @@ -131,14 +132,14 @@ export const NumberComponent = React.memo((props: NumberComponentProps) => { const [cursorPosition, setCursorPosition] = useState(null); // Create a state for the input string const [inputString, setInputString] = useState(props.value.toString()); + const fullAccessPath = parentPath.concat('.' + name); + const id = getIdFromFullAccessPath(fullAccessPath); useEffect(() => { renderCount.current++; // Set the cursor position after the component re-renders - const inputElement = document.getElementsByName( - parentPath.concat('.' + name) - )[0] as HTMLInputElement; + const inputElement = document.getElementsByName(id)[0] as HTMLInputElement; if (inputElement && cursorPosition !== null) { inputElement.setSelectionRange(cursorPosition, cursorPosition); } @@ -275,7 +276,7 @@ export const NumberComponent = React.memo((props: NumberComponentProps) => { }; return ( -Render count: {renderCount.current}
)} @@ -287,7 +288,7 @@ export const NumberComponent = React.memo((props: NumberComponentProps) => { type="text" value={inputString} disabled={readOnly} - name={parentPath.concat('.' + name)} + name={fullAccessPath} onKeyDown={handleKeyDown} onBlur={handleBlur} className={isInstantUpdate && !readOnly ? 'instantUpdate' : ''} diff --git a/frontend/src/components/SliderComponent.tsx b/frontend/src/components/SliderComponent.tsx index 2f3d8f5..7d47bcf 100644 --- a/frontend/src/components/SliderComponent.tsx +++ b/frontend/src/components/SliderComponent.tsx @@ -4,6 +4,7 @@ import { emit_update } from '../socket'; import { DocStringComponent } from './DocStringComponent'; import { Slider } from '@mui/material'; import { NumberComponent } from './NumberComponent'; +import { getIdFromFullAccessPath } from '../utils/stringUtils'; interface SliderComponentProps { name: string; @@ -21,11 +22,6 @@ interface SliderComponentProps { export const SliderComponent = React.memo((props: SliderComponentProps) => { const renderCount = useRef(0); const [open, setOpen] = useState(false); - - useEffect(() => { - renderCount.current++; - }); - const { name, parentPath, @@ -38,6 +34,12 @@ export const SliderComponent = React.memo((props: SliderComponentProps) => { isInstantUpdate, addNotification } = props; + const fullAccessPath = parentPath.concat('.' + name); + const id = getIdFromFullAccessPath(fullAccessPath); + + useEffect(() => { + renderCount.current++; + }); useEffect(() => { addNotification(`${parentPath}.${name} changed to ${value}.`); @@ -102,7 +104,7 @@ export const SliderComponent = React.memo((props: SliderComponentProps) => { }; return ( -Render count: {renderCount.current}
)} diff --git a/frontend/src/components/StringComponent.tsx b/frontend/src/components/StringComponent.tsx index 46f5f11..11db630 100644 --- a/frontend/src/components/StringComponent.tsx +++ b/frontend/src/components/StringComponent.tsx @@ -3,6 +3,7 @@ import { Form, InputGroup } from 'react-bootstrap'; import { emit_update } from '../socket'; import { DocStringComponent } from './DocStringComponent'; import '../App.css'; +import { getIdFromFullAccessPath } from '../utils/stringUtils'; // TODO: add button functionality @@ -22,6 +23,8 @@ export const StringComponent = React.memo((props: StringComponentProps) => { const renderCount = useRef(0); const [inputString, setInputString] = useState(props.value); + const fullAccessPath = parentPath.concat('.' + name); + const id = getIdFromFullAccessPath(fullAccessPath); useEffect(() => { renderCount.current++; @@ -55,7 +58,7 @@ export const StringComponent = React.memo((props: StringComponentProps) => { }; return ( -Render count: {renderCount.current}
)}