Skip to content

Commit 1889ea3

Browse files
committed
feat(renterd): alerts collapse large errors
1 parent 7afc02c commit 1889ea3

File tree

6 files changed

+96
-6
lines changed

6 files changed

+96
-6
lines changed

.changeset/light-ladybugs-speak.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'renterd': minor
3+
---
4+
5+
Alerts with large errors are now collapsed by default and have a control to expand and collapse the full contents.

.changeset/mighty-news-float.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@siafoundation/design-system': minor
3+
---
4+
5+
Added ExpandableText.

apps/renterd-e2e/src/specs/alerts.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ test.afterEach(async () => {
1818
await afterTest()
1919
})
2020

21-
test('alert data', async ({ page }) => {
21+
test('churn alert and slab migration alert', async ({ page }) => {
2222
await navigateToAlerts({ page })
2323

24-
// Churn alert
24+
// Churn alert.
2525
const churnData = page.getByTestId('churn')
2626
await expect(churnData.getByText('churn: 37.54%')).toBeVisible()
2727
const churnDataContractB6 = churnData.getByTestId(
@@ -37,7 +37,7 @@ test('alert data', async ({ page }) => {
3737
await expect(churnDataContractB6.getByText('30.00 KB')).toBeVisible()
3838
await expect(churnDataContractB6.getByText('30 B')).toBeVisible()
3939

40-
// Slab migration failed alert
40+
// Slab migration failed alert.
4141
const objectsData = page.getByTestId('objects')
4242
await expect(objectsData.getByText('bucket1/nest2/file3.png')).toBeVisible()
4343
})

apps/renterd/contexts/alerts/columns.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
Separator,
88
TableColumn,
99
Text,
10+
ExpandableText,
1011
} from '@siafoundation/design-system'
1112
import { AlertData, TableColumnId } from './types'
1213
import { dataFields } from './data'
@@ -69,9 +70,11 @@ export const columns: AlertsTableColumn[] = [
6970
</Text>
7071
) : null}
7172
{data['error'] ? (
72-
<Text size="12" color="subtle">
73-
{data['error'] as string}
74-
</Text>
73+
<ExpandableText
74+
text={data['error'] as string}
75+
size="12"
76+
color="subtle"
77+
/>
7578
) : null}
7679
</div>
7780
)
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
'use client'
2+
3+
import { Button } from './Button'
4+
import { Text } from './Text'
5+
import { useState, useRef, useEffect } from 'react'
6+
import { cx } from 'class-variance-authority'
7+
8+
type Props = {
9+
text: string
10+
maxHeight?: number
11+
size?: React.ComponentProps<typeof Text>['size']
12+
color?: React.ComponentProps<typeof Text>['color']
13+
}
14+
15+
export function ExpandableText({
16+
text,
17+
maxHeight = 96,
18+
size = '12',
19+
color = 'subtle',
20+
}: Props) {
21+
const [isExpanded, setIsExpanded] = useState(false)
22+
const [canExpand, setCanExpand] = useState(false)
23+
const contentRef = useRef<HTMLDivElement>(null)
24+
25+
useEffect(() => {
26+
if (contentRef.current) {
27+
setCanExpand(contentRef.current.scrollHeight > maxHeight)
28+
}
29+
}, [maxHeight, text])
30+
31+
return (
32+
<div className="flex flex-col gap-1">
33+
<div className="relative">
34+
<div
35+
ref={contentRef}
36+
className="overflow-hidden transition-[max-height] duration-300"
37+
style={{ maxHeight: !isExpanded ? maxHeight : undefined }}
38+
>
39+
<Text size={size} color={color}>
40+
{text}
41+
</Text>
42+
</div>
43+
{!isExpanded && canExpand && (
44+
<div
45+
className={cx(
46+
'absolute bottom-0 left-0 right-0 h-[48px]',
47+
'bg-gradient-to-b from-transparent',
48+
'dark:via-graydark-50/80 dark:to-graydark-50',
49+
'via-gray-50/80 to-gray-50'
50+
)}
51+
/>
52+
)}
53+
</div>
54+
{canExpand && (
55+
<div
56+
className={cx(
57+
'flex justify-center',
58+
isExpanded && 'sticky bottom-2 z-10'
59+
)}
60+
>
61+
<Button
62+
variant="gray"
63+
size="small"
64+
onClick={() => setIsExpanded(!isExpanded)}
65+
className={cx(
66+
isExpanded && 'bg-gray-50 dark:bg-graydark-50',
67+
isExpanded && 'shadow-md'
68+
)}
69+
>
70+
{isExpanded ? 'Show less' : 'Show more'}
71+
</Button>
72+
</div>
73+
)}
74+
</div>
75+
)
76+
}

libs/design-system/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export * from './core/Switch'
4545
export * from './core/HoverCard'
4646
export * from './core/SelectCard'
4747
export * from './core/NavMenu'
48+
export * from './core/ExpandableText'
4849

4950
// components
5051
export * from './components/UserDropdownMenu'

0 commit comments

Comments
 (0)