|
1 | 1 | import SvgCircle from '@/features/common/components/svg/circle' |
2 | 2 | import SvgPointerLeft from '@/features/common/components/svg/pointer-left' |
3 | 3 | import SvgPointerRight from '@/features/common/components/svg/pointer-right' |
| 4 | +import { Tooltip, TooltipContent, TooltipTrigger } from '@/features/common/components/tooltip' |
4 | 5 | import { cn } from '@/features/common/utils' |
| 6 | +import { fixedForwardRef } from '@/utils/fixed-forward-ref' |
5 | 7 | import { isDefined } from '@/utils/is-defined' |
6 | 8 | import { useMemo } from 'react' |
7 | 9 |
|
@@ -82,40 +84,42 @@ function ConnectionToChildren({ indentLevel }: { indentLevel: number | undefined |
82 | 84 | ) |
83 | 85 | } |
84 | 86 |
|
85 | | -function DisplayArrow({ arrow: transactionArrow }: { arrow: Arrow }) { |
| 87 | +const DisplayArrow = fixedForwardRef(({ arrow, ...rest }: { arrow: Arrow }, ref?: React.LegacyRef<HTMLDivElement>) => { |
86 | 88 | return ( |
87 | 89 | <div |
88 | 90 | className={cn('flex items-center justify-center')} |
89 | 91 | style={{ |
90 | 92 | // 2 and 3 are the number to offset the name column |
91 | | - gridColumnStart: transactionArrow.from + 2, |
92 | | - gridColumnEnd: transactionArrow.to + 3, |
| 93 | + gridColumnStart: arrow.from + 2, |
| 94 | + gridColumnEnd: arrow.to + 3, |
93 | 95 | }} |
| 96 | + ref={ref} |
| 97 | + {...rest} |
94 | 98 | > |
95 | 99 | <SvgCircle width={graphConfig.circleDimension} height={graphConfig.circleDimension}></SvgCircle> |
96 | 100 | <div |
97 | 101 | style={{ |
98 | | - width: `calc(${(100 - 100 / (transactionArrow.to - transactionArrow.from + 1)).toFixed(2)}% - ${graphConfig.circleDimension}px)`, |
| 102 | + width: `calc(${(100 - 100 / (arrow.to - arrow.from + 1)).toFixed(2)}% - ${graphConfig.circleDimension}px)`, |
99 | 103 | height: `${graphConfig.circleDimension}px`, |
100 | 104 | }} |
101 | 105 | className="relative text-primary" |
102 | 106 | > |
103 | | - {transactionArrow.direction === 'rightToLeft' && <SvgPointerLeft className={cn('absolute top-0 left-0')} />} |
| 107 | + {arrow.direction === 'rightToLeft' && <SvgPointerLeft className={cn('absolute top-0 left-0')} />} |
104 | 108 | <div className={cn('border-primary h-1/2')} style={{ borderBottomWidth: graphConfig.lineWidth }}></div> |
105 | | - {transactionArrow.direction === 'leftToRight' && <SvgPointerRight className={cn('absolute top-0 right-0')} />} |
| 109 | + {arrow.direction === 'leftToRight' && <SvgPointerRight className={cn('absolute top-0 right-0')} />} |
106 | 110 | </div> |
107 | 111 | <SvgCircle width={graphConfig.circleDimension} height={graphConfig.circleDimension}></SvgCircle> |
108 | 112 | </div> |
109 | 113 | ) |
110 | | -} |
| 114 | +}) |
111 | 115 |
|
112 | | -function DisplaySelfTransaction() { |
| 116 | +const DisplaySelfTransaction = fixedForwardRef((props: object, ref?: React.LegacyRef<HTMLDivElement>) => { |
113 | 117 | return ( |
114 | | - <div className={cn('flex items-center justify-center')}> |
| 118 | + <div ref={ref} className={cn('flex items-center justify-center')} {...props}> |
115 | 119 | <SvgCircle width={graphConfig.circleDimension} height={graphConfig.circleDimension}></SvgCircle> |
116 | 120 | </div> |
117 | 121 | ) |
118 | | -} |
| 122 | +}) |
119 | 123 |
|
120 | 124 | type TransactionRowProps = { |
121 | 125 | transaction: Transaction |
@@ -153,8 +157,28 @@ function TransactionRow({ |
153 | 157 | </div> |
154 | 158 | {accounts.map((_, index) => { |
155 | 159 | if (index < arrow.from || index > arrow.to) return <div key={index}></div> |
156 | | - if (index === arrow.from && index === arrow.to) return <DisplaySelfTransaction key={index} /> |
157 | | - if (index === arrow.from) return <DisplayArrow key={index} arrow={arrow} /> |
| 160 | + if (index === arrow.from && index === arrow.to) |
| 161 | + return ( |
| 162 | + <Tooltip key={index}> |
| 163 | + <TooltipTrigger asChild> |
| 164 | + <DisplaySelfTransaction /> |
| 165 | + </TooltipTrigger> |
| 166 | + <TooltipContent> |
| 167 | + <div className={cn('p-4')}>Transaction: {transaction.name}</div> |
| 168 | + </TooltipContent> |
| 169 | + </Tooltip> |
| 170 | + ) |
| 171 | + if (index === arrow.from) |
| 172 | + return ( |
| 173 | + <Tooltip key={index}> |
| 174 | + <TooltipTrigger asChild> |
| 175 | + <DisplayArrow key={index} arrow={arrow} /> |
| 176 | + </TooltipTrigger> |
| 177 | + <TooltipContent> |
| 178 | + <div className={cn('p-4')}>Transaction: {transaction.name}</div> |
| 179 | + </TooltipContent> |
| 180 | + </Tooltip> |
| 181 | + ) |
158 | 182 | else return null |
159 | 183 | })} |
160 | 184 |
|
|
0 commit comments