import { createPortal } from 'react-dom' import { useDispatch } from 'react-redux' import { useEffect } from 'react' import PropTypes from 'prop-types' // Material import { Dialog, DialogContent, DialogTitle } from '@mui/material' import { TableViewOnly } from 'ui-component/table/Table' // Store import { HIDE_CANVAS_DIALOG, SHOW_CANVAS_DIALOG } from 'store/actions' import { baseURL } from 'store/constant' // API import configApi from 'api/config' import useApi from 'hooks/useApi' const NodeInfoDialog = ({ show, dialogProps, onCancel }) => { const portalElement = document.getElementById('portal') const dispatch = useDispatch() const getNodeConfigApi = useApi(configApi.getNodeConfig) useEffect(() => { if (dialogProps.data) { getNodeConfigApi.request(dialogProps.data) } // eslint-disable-next-line react-hooks/exhaustive-deps }, [dialogProps]) useEffect(() => { if (show) dispatch({ type: SHOW_CANVAS_DIALOG }) else dispatch({ type: HIDE_CANVAS_DIALOG }) return () => dispatch({ type: HIDE_CANVAS_DIALOG }) }, [show, dispatch]) const component = show ? ( {dialogProps.data && dialogProps.data.name && dialogProps.data.label && (
{dialogProps.data.name}
{dialogProps.data.label}
{dialogProps.data.id}
{dialogProps.data.version && (
version {dialogProps.data.version}
)}
)}
{dialogProps.data?.description && (
{dialogProps.data.description}
)} {getNodeConfigApi.data && getNodeConfigApi.data.length > 0 && ( )}
) : null return createPortal(component, portalElement) } NodeInfoDialog.propTypes = { show: PropTypes.bool, dialogProps: PropTypes.object, onCancel: PropTypes.func } export default NodeInfoDialog