diff --git a/.changeset/light-ladybugs-speak.md b/.changeset/light-ladybugs-speak.md new file mode 100644 index 000000000..a8db21596 --- /dev/null +++ b/.changeset/light-ladybugs-speak.md @@ -0,0 +1,5 @@ +--- +'renterd': minor +--- + +Alerts with large errors are now collapsed by default and have a control to expand and collapse the full contents. diff --git a/.changeset/mighty-news-float.md b/.changeset/mighty-news-float.md new file mode 100644 index 000000000..cf13d2ce4 --- /dev/null +++ b/.changeset/mighty-news-float.md @@ -0,0 +1,5 @@ +--- +'@siafoundation/design-system': minor +--- + +Added ExpandableText. diff --git a/apps/renterd-e2e/src/specs/alerts.spec.ts b/apps/renterd-e2e/src/specs/alerts.spec.ts index ac2417cc7..ad0bf55c8 100644 --- a/apps/renterd-e2e/src/specs/alerts.spec.ts +++ b/apps/renterd-e2e/src/specs/alerts.spec.ts @@ -18,10 +18,10 @@ test.afterEach(async () => { await afterTest() }) -test('alert data', async ({ page }) => { +test('churn alert and slab migration alert', async ({ page }) => { await navigateToAlerts({ page }) - // Churn alert + // Churn alert. const churnData = page.getByTestId('churn') await expect(churnData.getByText('churn: 37.54%')).toBeVisible() const churnDataContractB6 = churnData.getByTestId( @@ -37,7 +37,7 @@ test('alert data', async ({ page }) => { await expect(churnDataContractB6.getByText('30.00 KB')).toBeVisible() await expect(churnDataContractB6.getByText('30 B')).toBeVisible() - // Slab migration failed alert + // Slab migration failed alert. const objectsData = page.getByTestId('objects') await expect(objectsData.getByText('bucket1/nest2/file3.png')).toBeVisible() }) diff --git a/apps/renterd/contexts/alerts/columns.tsx b/apps/renterd/contexts/alerts/columns.tsx index e61991542..7eb85cc97 100644 --- a/apps/renterd/contexts/alerts/columns.tsx +++ b/apps/renterd/contexts/alerts/columns.tsx @@ -7,6 +7,7 @@ import { Separator, TableColumn, Text, + ExpandableText, } from '@siafoundation/design-system' import { AlertData, TableColumnId } from './types' import { dataFields } from './data' @@ -69,9 +70,11 @@ export const columns: AlertsTableColumn[] = [ ) : null} {data['error'] ? ( - - {data['error'] as string} - + ) : null} ) diff --git a/libs/design-system/src/core/ExpandableText.tsx b/libs/design-system/src/core/ExpandableText.tsx new file mode 100644 index 000000000..07a546e58 --- /dev/null +++ b/libs/design-system/src/core/ExpandableText.tsx @@ -0,0 +1,74 @@ +import { Button } from './Button' +import { Text } from './Text' +import { useState, useRef, useEffect } from 'react' +import { cx } from 'class-variance-authority' + +type Props = { + text: string + maxHeight?: number + size?: '10' | '12' | '14' | '16' | '18' | '20' + color?: 'subtle' | 'contrast' | 'green' | 'amber' | 'red' +} + +export function ExpandableText({ + text, + maxHeight = 96, + size = '12', + color = 'subtle', +}: Props) { + const [isExpanded, setIsExpanded] = useState(false) + const [canExpand, setCanExpand] = useState(false) + const contentRef = useRef(null) + + useEffect(() => { + if (contentRef.current) { + setCanExpand(contentRef.current.scrollHeight > maxHeight) + } + }, [maxHeight, text]) + + return ( +
+
+
+ + {text} + +
+ {!isExpanded && canExpand && ( +
+ )} +
+ {canExpand && ( +
+ +
+ )} +
+ ) +} diff --git a/libs/design-system/src/index.ts b/libs/design-system/src/index.ts index 21ef7c2bf..7508cc0b3 100644 --- a/libs/design-system/src/index.ts +++ b/libs/design-system/src/index.ts @@ -45,6 +45,7 @@ export * from './core/Switch' export * from './core/HoverCard' export * from './core/SelectCard' export * from './core/NavMenu' +export * from './core/ExpandableText' // components export * from './components/UserDropdownMenu'