Skip to content

Commit 5047c10

Browse files
committed
chore: more compact style
1 parent 55babcb commit 5047c10

File tree

2 files changed

+25
-21
lines changed

2 files changed

+25
-21
lines changed

src/features/transactions/pages/group-page.tsx

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import SvgCircle from '@/features/common/components/svg/circle'
22
import SvgPointerLeft from '@/features/common/components/svg/pointer-left'
33
import SvgPointerRight from '@/features/common/components/svg/pointer-right'
44
import { cn } from '@/features/common/utils'
5+
import { isDefined } from '@/utils/is-defined'
56
import { useMemo } from 'react'
67

78
type TransactionArrow = {
@@ -12,22 +13,20 @@ type TransactionArrow = {
1213

1314
type TransactionRowProps = {
1415
transaction: Transaction
15-
cellHeight?: number
16-
lineWidth?: number
1716
hasParent?: boolean
1817
hasNextSibbling?: boolean
1918
hasChildren?: boolean
2019
accounts: string[]
2120
indentLevel?: number
22-
verticalBars?: number[]
21+
verticalBars: (number | undefined)[]
2322
}
2423
function TransactionRow({
2524
transaction,
2625
accounts,
2726
hasParent = false,
2827
hasNextSibbling = false,
2928
hasChildren = false,
30-
indentLevel = 0,
29+
indentLevel,
3130
verticalBars,
3231
}: TransactionRowProps) {
3332
const transactionArrow = useMemo(() => calcTransactionArrow(transaction, accounts), [accounts, transaction])
@@ -37,21 +36,17 @@ function TransactionRow({
3736
<div className={cn('p-0 relative pr-8')}>
3837
{
3938
// The side vertical bars when there are nested items
40-
verticalBars &&
41-
verticalBars.length &&
42-
verticalBars
43-
.filter((b) => b > 0)
44-
.map((b, i) => (
45-
<div
46-
key={i}
47-
className={cn('h-full border-primary absolute')}
48-
style={{ marginLeft: b * graphConfig.indentationWidth, borderLeftWidth: `${graphConfig.lineWidth}px` }}
49-
></div>
50-
))
39+
(verticalBars ?? []).filter(isDefined).map((b, i) => (
40+
<div
41+
key={i}
42+
className={cn('h-full border-primary absolute')}
43+
style={{ marginLeft: b * graphConfig.indentationWidth, borderLeftWidth: `${graphConfig.lineWidth}px` }}
44+
></div>
45+
))
5146
}
5247
<div
5348
className={cn(`relative h-full p-0 flex items-center`, 'px-0')}
54-
style={{ marginLeft: indentLevel * graphConfig.indentationWidth }}
49+
style={{ marginLeft: (indentLevel ?? 0) * graphConfig.indentationWidth }}
5550
>
5651
{
5752
// The connection between this transaction and the parent
@@ -69,7 +64,7 @@ function TransactionRow({
6964
<div
7065
className={cn('inline')}
7166
style={{
72-
marginLeft: `${graphConfig.indentationWidth + 8}px`,
67+
marginLeft: hasParent ? `${graphConfig.indentationWidth + 8}px` : `16px`,
7368
}}
7469
>
7570
{transaction.name}
@@ -94,7 +89,7 @@ function TransactionRow({
9489
<div
9590
className={cn('w-2', 'border-primary rounded-tl-lg', 'absolute left-0')}
9691
style={{
97-
marginLeft: `${graphConfig.indentationWidth}px`,
92+
marginLeft: indentLevel != null ? `${graphConfig.indentationWidth}px` : undefined,
9893
borderLeftWidth: `${graphConfig.lineWidth}px`,
9994
borderTopWidth: `${graphConfig.lineWidth}px`,
10095
height: `calc(50% + ${graphConfig.lineWidth}px)`,
@@ -143,8 +138,8 @@ function TransactionRow({
143138
hasParent={true}
144139
hasNextSibbling={index < arr.length - 1}
145140
accounts={accounts}
146-
indentLevel={indentLevel + 1}
147-
verticalBars={[...(verticalBars ?? []), hasNextSibbling ? indentLevel : 0]}
141+
indentLevel={indentLevel == null ? 0 : indentLevel + 1}
142+
verticalBars={[...(verticalBars ?? []), hasNextSibbling ? indentLevel ?? 0 : undefined]}
148143
/>
149144
))}
150145
</>
@@ -189,6 +184,11 @@ export function GroupPage() {
189184
},
190185
],
191186
},
187+
{
188+
name: 'Inner 6',
189+
sender: 'Account 3',
190+
receiver: 'Account 1',
191+
},
192192
],
193193
},
194194
{ name: 'Inner 9', sender: 'Account 2', receiver: 'Account 6' },
@@ -257,6 +257,7 @@ export function GroupPage() {
257257
hasParent={false}
258258
hasNextSibbling={index < arr.length - 1}
259259
accounts={accounts}
260+
verticalBars={[]}
260261
/>
261262
))}
262263
</div>
@@ -319,7 +320,7 @@ function calcTransactionArrow(transaction: Transaction, accounts: string[]): Tra
319320
const graphConfig = {
320321
rowHeight: 40,
321322
colWidth: 128,
322-
indentationWidth: 32,
323+
indentationWidth: 20,
323324
lineWidth: 2,
324325
circleDimension: 20,
325326
}

src/utils/is-defined.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const isDefined = <T>(x: T): x is Exclude<T, undefined> => x !== undefined
2+
3+
export const isNotNullOrUndefined = <T>(x: T): x is Exclude<T, undefined | null> => x !== undefined && x !== null

0 commit comments

Comments
 (0)