11import moment from 'moment' ;
22import { List , Button , Space , Tag , Typography , Popover } from 'antd' ;
33import { getExecutionsHistory } from '../../containers/HistoryContainer/utils' ;
4- import { ExecutionItem } from '../../containers/HistoryContainer/types' ;
54import { styles } from '../../styles' ;
6- import { detectFormat , convertToFormat } from '../../utils/format' ;
5+ import { convertToFormat } from '../../utils/format' ;
76import {
87 MinusCircleOutlined ,
98} from '@ant-design/icons' ;
9+ import { ServiceEntity } from "../../types" ;
1010
1111const { Text } = Typography ;
1212
1313export interface HistoryContainerItemProps {
14- item : ExecutionItem ;
15- setResource : ( v : string ) => void ;
16- setUrl : ( v : string ) => void ;
17- setExpression : ( v : string ) => void ;
14+ entity : ServiceEntity ;
15+ setEntity : ( v : ServiceEntity ) => void ;
1816}
1917
2018function HistoryContainerItem ( props : HistoryContainerItemProps ) {
21- const { item , setResource , setUrl , setExpression } = props ;
22- const { response, url, expression, status, requestType } = item ;
23- const formattedDate = moment ( item . dateTime ) . format ( 'YYYY-MM-DD HH:mm' )
19+ const { entity , setEntity } = props ;
20+ const { response, url, expression, status, requestType } = entity ;
21+ const formattedDate = moment ( entity . dateTime ) . format ( 'YYYY-MM-DD HH:mm' )
2422 const onClick = ( ) => {
25- setResource ( response ) ;
26- setUrl ( url ) ;
27- setExpression ( expression ) ;
23+ setEntity ( {
24+ ...entity ,
25+ ...{
26+ response : response ,
27+ url : url ,
28+ expression : expression ,
29+ }
30+ } )
2831 }
2932 const truncateToPreview = ( text : string , maxLength = 35 ) : string => {
3033 return text . length <= maxLength ? text : text . slice ( 0 , maxLength ) + '...' ;
3134 }
3235 const content = (
3336 < div style = { { maxWidth : 500 } } >
34- < p > < code > { status === "not-asked" ? truncateToPreview ( convertToFormat ( response , 'json' ) , 1000 ) : url } </ code > </ p >
37+ < p > < code > { status === "not-asked" ? truncateToPreview ( convertToFormat ( response ?? '' , 'json' ) , 1000 ) : url } </ code > </ p >
3538 < p > < code > { expression } </ code > </ p >
3639 </ div >
3740 ) ;
3841
3942 const itemContent = status === "not-asked" ?
40- { tagColor : "default" , tagIcon : < MinusCircleOutlined /> , tagText : '' , previewText : JSON . parse ( convertToFormat ( response , 'json' ) ) ?. [ 'resourceType' ] } :
41- { tagColor : status , tagIcon : null , tagText : requestType . toUpperCase ( ) , previewText : url }
43+ { tagColor : "default" , tagIcon : < MinusCircleOutlined /> , tagText : '' , previewText : JSON . parse ( convertToFormat ( response ?? '' , 'json' ) ) ?. [ 'resourceType' ] } :
44+ { tagColor : status , tagIcon : null , tagText : requestType ? .toUpperCase ( ) , previewText : url }
4245
4346 return (
4447 < Space >
@@ -52,15 +55,14 @@ function HistoryContainerItem(props: HistoryContainerItemProps) {
5255}
5356
5457
55- export function HistoryContainer ( props : Omit < HistoryContainerItemProps , "item" > ) {
56- const renderItem = ( item : ExecutionItem ) => {
58+ export function HistoryContainer ( props : HistoryContainerItemProps ) {
59+ const renderItem = ( entity : ServiceEntity ) => {
5760 return (
5861 < List . Item >
5962 < HistoryContainerItem
60- item = { item }
61- setResource = { props . setResource }
62- setUrl = { props . setUrl }
63- setExpression = { props . setExpression } />
63+ entity = { entity }
64+ setEntity = { props . setEntity }
65+ />
6466 </ List . Item >
6567 ) ;
6668 }
0 commit comments