|
| 1 | +import { cn } from '@/features/common/utils' |
| 2 | + |
| 3 | +type TransactionTrProps = { |
| 4 | + transaction: Transaction |
| 5 | + cellHeight?: number |
| 6 | + lineWidth?: number |
| 7 | + hasParent?: boolean |
| 8 | + hasNextSibbling?: boolean |
| 9 | + hasChildren?: boolean |
| 10 | +} |
| 11 | +function TransactionTr({ transaction, hasParent = false, hasNextSibbling = false, hasChildren = false }: TransactionTrProps) { |
| 12 | + return ( |
| 13 | + <tr> |
| 14 | + <td className="p-0"> |
| 15 | + <div className={cn(`relative h-10 p-0 flex items-center`, 'px-0')}> |
| 16 | + {hasParent && ( |
| 17 | + <div className={cn('w-8', `border-primary border-l-2 border-b-2 rounded-bl-lg`, `h-[50%]`, `absolute top-0 left-0`)}></div> |
| 18 | + )} |
| 19 | + <div className={cn('inline ml-8')}>{transaction.name}</div> |
| 20 | + {hasParent && hasNextSibbling && ( |
| 21 | + <div className={cn('w-8', 'border-primary border-l-2', 'h-[22px]', 'absolute top-[18px] left-0')}></div> |
| 22 | + )} |
| 23 | + {hasChildren && !hasParent && ( |
| 24 | + <div |
| 25 | + className={cn( |
| 26 | + 'w-8', |
| 27 | + `border-primary border-l-2 border-t-2 rounded-tl-lg`, |
| 28 | + `h-[calc(50%+2px)]`, |
| 29 | + `absolute top-[calc(50%-2px)] left-0` |
| 30 | + )} |
| 31 | + ></div> |
| 32 | + )} |
| 33 | + {hasChildren && hasParent && ( |
| 34 | + <div |
| 35 | + className={cn('w-2 ml-4', 'border-primary border-l-2 border-t-2 rounded-tl-lg', 'h-[22px]', 'absolute top-[18px] left-0')} |
| 36 | + ></div> |
| 37 | + )} |
| 38 | + </div> |
| 39 | + {hasChildren && ( |
| 40 | + <div className={cn('relative', hasParent ? 'pl-4' : '')}> |
| 41 | + {hasNextSibbling && <div className={cn(`border-primary border-l-2`, `h-full`, 'absolute top-0 left-0')}></div>} |
| 42 | + <table> |
| 43 | + {transaction.transactions?.map((childTransaction, index, arr) => ( |
| 44 | + <TransactionTr |
| 45 | + transaction={childTransaction} |
| 46 | + hasChildren={childTransaction.transactions && childTransaction.transactions.length > 0} |
| 47 | + hasParent={true} |
| 48 | + hasNextSibbling={index < arr.length - 1} |
| 49 | + /> |
| 50 | + ))} |
| 51 | + </table> |
| 52 | + </div> |
| 53 | + )} |
| 54 | + </td> |
| 55 | + <td></td> |
| 56 | + </tr> |
| 57 | + ) |
| 58 | +} |
| 59 | + |
| 60 | +export function GroupPage() { |
| 61 | + const group: Transaction = { |
| 62 | + name: '', |
| 63 | + transactions: [ |
| 64 | + { name: '7VSN...' }, |
| 65 | + { |
| 66 | + name: 'NDQX...', |
| 67 | + transactions: [ |
| 68 | + { name: 'Inner 1' }, |
| 69 | + { name: 'Inner 2', transactions: [{ name: 'Inner 3' }, { name: 'Inner 5' }] }, |
| 70 | + { name: 'Inner 9' }, |
| 71 | + { name: 'Inner 4', transactions: [{ name: 'Inner 6' }, { name: 'Inner 7' }] }, |
| 72 | + { name: 'Inner 8' }, |
| 73 | + ], |
| 74 | + }, |
| 75 | + ], |
| 76 | + } |
| 77 | + |
| 78 | + return ( |
| 79 | + <table> |
| 80 | + {group.transactions?.map((transaction, index, arr) => ( |
| 81 | + <TransactionTr |
| 82 | + transaction={transaction} |
| 83 | + hasChildren={transaction.transactions && transaction.transactions.length > 0} |
| 84 | + hasParent={false} |
| 85 | + hasNextSibbling={index < arr.length - 1} |
| 86 | + /> |
| 87 | + ))} |
| 88 | + </table> |
| 89 | + ) |
| 90 | +} |
| 91 | + |
| 92 | +export type Transaction = { |
| 93 | + name: string |
| 94 | + transactions?: Transaction[] |
| 95 | +} |
0 commit comments