From 9d90fd2b8124537df0d0bccb273239db074fe992 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mose=20M=C3=BCller?= Date: Thu, 21 Dec 2023 10:30:21 +0100 Subject: [PATCH] displayName of components is now taken from WebSettingsContext --- frontend/src/components/AsyncMethodComponent.tsx | 14 +++++++++++--- frontend/src/components/ButtonComponent.tsx | 16 +++++++++++----- .../src/components/ColouredEnumComponent.tsx | 11 +++++++++-- frontend/src/components/DataServiceComponent.tsx | 12 ++++++++++-- frontend/src/components/EnumComponent.tsx | 11 +++++++++-- frontend/src/components/GenericComponent.tsx | 1 - frontend/src/components/ImageComponent.tsx | 11 +++++++++-- frontend/src/components/MethodComponent.tsx | 11 +++++++++-- frontend/src/components/NumberComponent.tsx | 11 +++++++++-- frontend/src/components/SliderComponent.tsx | 11 +++++++++-- frontend/src/components/StringComponent.tsx | 11 +++++++++-- 11 files changed, 95 insertions(+), 25 deletions(-) diff --git a/frontend/src/components/AsyncMethodComponent.tsx b/frontend/src/components/AsyncMethodComponent.tsx index d55538d..145b0fc 100644 --- a/frontend/src/components/AsyncMethodComponent.tsx +++ b/frontend/src/components/AsyncMethodComponent.tsx @@ -1,9 +1,10 @@ -import React, { useEffect, useRef } from 'react'; +import React, { useContext, useEffect, useRef } from 'react'; import { runMethod } from '../socket'; import { InputGroup, Form, Button } from 'react-bootstrap'; import { DocStringComponent } from './DocStringComponent'; import { getIdFromFullAccessPath } from '../utils/stringUtils'; import { LevelName } from './NotificationsComponent'; +import { WebSettingsContext } from '../WebSettings'; interface AsyncMethodProps { name: string; @@ -19,7 +20,14 @@ export const AsyncMethodComponent = React.memo((props: AsyncMethodProps) => { const { name, parentPath, docString, value: runningTask, addNotification } = props; const renderCount = useRef(0); const formRef = useRef(null); - const id = getIdFromFullAccessPath(parentPath.concat('.' + name)); + 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++; @@ -95,7 +103,7 @@ export const AsyncMethodComponent = React.memo((props: AsyncMethodProps) => {
Render count: {renderCount.current}
)}
- Function: {name} + Function: {displayName}
diff --git a/frontend/src/components/ButtonComponent.tsx b/frontend/src/components/ButtonComponent.tsx index 70be699..8d8f868 100644 --- a/frontend/src/components/ButtonComponent.tsx +++ b/frontend/src/components/ButtonComponent.tsx @@ -1,4 +1,5 @@ -import React, { useEffect, useRef } from 'react'; +import React, { useContext, useEffect, useRef } from 'react'; +import { WebSettingsContext } from '../WebSettings'; import { ToggleButton } from 'react-bootstrap'; import { setAttribute } from '../socket'; import { DocStringComponent } from './DocStringComponent'; @@ -16,11 +17,16 @@ interface ButtonComponentProps { } 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 { name, parentPath, value, readOnly, docString, addNotification } = 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); + const webSettings = useContext(WebSettingsContext); + let displayName = name; + + if (webSettings[fullAccessPath] && webSettings[fullAccessPath].displayName) { + displayName = webSettings[fullAccessPath].displayName; + } const renderCount = useRef(0); @@ -51,7 +57,7 @@ export const ButtonComponent = React.memo((props: ButtonComponentProps) => { value={parentPath} disabled={readOnly} onChange={(e) => setChecked(e.currentTarget.checked)}> - {buttonName} + {displayName} ); diff --git a/frontend/src/components/ColouredEnumComponent.tsx b/frontend/src/components/ColouredEnumComponent.tsx index 5863f7b..0f5f5c0 100644 --- a/frontend/src/components/ColouredEnumComponent.tsx +++ b/frontend/src/components/ColouredEnumComponent.tsx @@ -1,4 +1,5 @@ -import React, { useEffect, useRef } from 'react'; +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'; @@ -28,6 +29,12 @@ export const ColouredEnumComponent = React.memo((props: ColouredEnumComponentPro 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++; @@ -49,7 +56,7 @@ export const ColouredEnumComponent = React.memo((props: ColouredEnumComponentPro - {name} + {displayName} {readOnly ? ( // Display the Form.Control when readOnly is true @@ -38,7 +46,7 @@ export const DataServiceComponent = React.memo( onClick={() => setOpen(!open)} style={{ cursor: 'pointer' }} // Change cursor style on hover > - {fullAccessPath} {open ? : } + {displayName} {open ? : } diff --git a/frontend/src/components/EnumComponent.tsx b/frontend/src/components/EnumComponent.tsx index 03f556c..c486ecf 100644 --- a/frontend/src/components/EnumComponent.tsx +++ b/frontend/src/components/EnumComponent.tsx @@ -1,4 +1,5 @@ -import React, { useEffect, useRef } from 'react'; +import React, { useContext, useEffect, useRef } from 'react'; +import { WebSettingsContext } from '../WebSettings'; import { InputGroup, Form, Row, Col } from 'react-bootstrap'; import { setAttribute } from '../socket'; import { getIdFromFullAccessPath } from '../utils/stringUtils'; @@ -27,6 +28,12 @@ export const EnumComponent = React.memo((props: EnumComponentProps) => { 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++; @@ -48,7 +55,7 @@ export const EnumComponent = React.memo((props: EnumComponentProps) => { - {name} + {displayName} ); } else if (attribute.type === 'ColouredEnum') { - console.log(attribute); return ( { const [open, setOpen] = useState(true); 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++; @@ -41,7 +48,7 @@ export const ImageComponent = React.memo((props: ImageComponentProps) => { onClick={() => setOpen(!open)} style={{ cursor: 'pointer' }} // Change cursor style on hover > - {name} {open ? : } + {displayName} {open ? : } diff --git a/frontend/src/components/MethodComponent.tsx b/frontend/src/components/MethodComponent.tsx index cad7317..82cc9a4 100644 --- a/frontend/src/components/MethodComponent.tsx +++ b/frontend/src/components/MethodComponent.tsx @@ -1,4 +1,5 @@ -import React, { useState, useEffect, useRef } from 'react'; +import React, { useContext, useEffect, useRef, useState } from 'react'; +import { WebSettingsContext } from '../WebSettings'; import { runMethod } from '../socket'; import { Button, InputGroup, Form, Collapse } from 'react-bootstrap'; import { DocStringComponent } from './DocStringComponent'; @@ -23,6 +24,12 @@ export const MethodComponent = React.memo((props: MethodProps) => { const [functionCalls, setFunctionCalls] = useState([]); 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++; @@ -81,7 +88,7 @@ export const MethodComponent = React.memo((props: MethodProps) => {
Render count: {renderCount.current}
)}
setHideOutput(!hideOutput)} style={{ cursor: 'pointer' }}> - Function: {name} + Function: {displayName}
diff --git a/frontend/src/components/NumberComponent.tsx b/frontend/src/components/NumberComponent.tsx index 3e5220e..dd2481d 100644 --- a/frontend/src/components/NumberComponent.tsx +++ b/frontend/src/components/NumberComponent.tsx @@ -1,4 +1,5 @@ -import React, { useEffect, useRef, useState } from 'react'; +import React, { useContext, useEffect, useRef, useState } from 'react'; +import { WebSettingsContext } from '../WebSettings'; import { Form, InputGroup } from 'react-bootstrap'; import { setAttribute } from '../socket'; import { DocStringComponent } from './DocStringComponent'; @@ -148,6 +149,12 @@ export const NumberComponent = React.memo((props: NumberComponentProps) => { const [inputString, setInputString] = useState(props.value.toString()); 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++; @@ -309,7 +316,7 @@ export const NumberComponent = React.memo((props: NumberComponentProps) => {
- {showName && {name}} + {showName && {displayName}} { } = props; 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++; @@ -101,7 +108,7 @@ export const SliderComponent = React.memo((props: SliderComponentProps) => { - {name} + {displayName} { const [inputString, setInputString] = useState(props.value); 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++; @@ -65,7 +72,7 @@ export const StringComponent = React.memo((props: StringComponentProps) => { )} - {name} + {displayName}