File size: 1,327 Bytes
e3b65ea 53bc504 e3b65ea 53bc504 e3b65ea |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
import { useFetchFlow } from '@/hooks/flow-hooks';
import { Popover } from 'antd';
import get from 'lodash/get';
import React, { useMemo } from 'react';
import JsonView from 'react18-json-view';
import 'react18-json-view/src/style.css';
import { Operator } from '../../constant';
import { useReplaceIdWithText } from '../../hooks';
import styles from './index.less';
interface IProps extends React.PropsWithChildren {
nodeId: string;
}
const NodePopover = ({ children, nodeId }: IProps) => {
const { data } = useFetchFlow();
const component = useMemo(() => {
return get(data, ['dsl', 'components', nodeId], {});
}, [nodeId, data]);
const output = get(component, ['obj', 'params', 'output'], {});
const componentName = get(component, ['obj', 'component_name'], '');
const replacedOutput = useReplaceIdWithText(output);
const content =
componentName !== Operator.Answer ? (
<div
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
}}
>
<JsonView
src={replacedOutput}
displaySize={30}
className={styles.jsonView}
/>
</div>
) : undefined;
return (
<Popover content={content} placement="right" destroyTooltipOnHide>
{children}
</Popover>
);
};
export default NodePopover;
|