moves displayName and id to GenericComponent and pass them as props

This commit is contained in:
Mose Müller
2024-02-21 09:50:04 +01:00
parent 2f2544b978
commit 2d98ba51f4
12 changed files with 148 additions and 168 deletions

View File

@ -1,9 +1,7 @@
import React, { useContext, useEffect, useRef, useState } from 'react';
import { WebSettingsContext } from '../WebSettings';
import React, { useEffect, useRef, useState } from 'react';
import { Card, Collapse, Image } from 'react-bootstrap';
import { DocStringComponent } from './DocStringComponent';
import { ChevronDown, ChevronRight } from 'react-bootstrap-icons';
import { getIdFromFullAccessPath } from '../utils/stringUtils';
import { LevelName } from './NotificationsComponent';
type ImageComponentProps = {
@ -14,28 +12,25 @@ type ImageComponentProps = {
docString: string;
format: string;
addNotification: (message: string, levelname?: LevelName) => void;
displayName: string;
id: string;
};
export const ImageComponent = React.memo((props: ImageComponentProps) => {
const { name, parentPath, value, docString, format, addNotification } = props;
const { value, docString, format, addNotification, displayName, id } = props;
const renderCount = useRef(0);
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;
}
const fullAccessPath = [props.parentPath, props.name]
.filter((element) => element)
.join('.');
useEffect(() => {
renderCount.current++;
});
useEffect(() => {
addNotification(`${parentPath}.${name} changed.`);
addNotification(`${fullAccessPath} changed.`);
}, [props.value]);
return (