Skip to content

Commit 986e6df

Browse files
authored
Provide sideModal prop to truncate differently in side modals (#3037)
* Provide sideModal prop to truncate differently in side modals * Slight adjustment to sideModal string length * Reuse component * adjust to 20 characters for edge case wide-with characters * Add sideModal to internet gateway edit sidemodal
1 parent 0a178bc commit 986e6df

File tree

6 files changed

+38
-23
lines changed

6 files changed

+38
-23
lines changed

app/pages/project/disks/DiskDetailSideModal.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import { ReadOnlySideModalForm } from '~/components/form/ReadOnlySideModalForm'
1515
import { DiskStateBadge, DiskTypeBadge } from '~/components/StateBadge'
1616
import { titleCrumb } from '~/hooks/use-crumbs'
1717
import { getDiskSelector, useDiskSelector } from '~/hooks/use-params'
18-
import { EmptyCell } from '~/table/cells/EmptyCell'
1918
import { PropertiesTable } from '~/ui/lib/PropertiesTable'
2019
import { ResourceLabel } from '~/ui/lib/SideModal'
2120
import { pb } from '~/util/path-builder'
@@ -73,7 +72,7 @@ export function DiskDetailSideModal({
7372
>
7473
<PropertiesTable>
7574
<PropertiesTable.IdRow id={disk.id} />
76-
<PropertiesTable.DescriptionRow description={disk.description} />
75+
<PropertiesTable.DescriptionRow description={disk.description} sideModal />
7776
<PropertiesTable.Row label="Size">{bytesToGiB(disk.size)} GiB</PropertiesTable.Row>
7877
<PropertiesTable.Row label="State">
7978
<DiskStateBadge state={disk.state.state} />
@@ -82,12 +81,8 @@ export function DiskDetailSideModal({
8281
<DiskTypeBadge diskType={disk.diskType} />
8382
</PropertiesTable.Row>
8483
{/* TODO: show attached instance by name like the table does? */}
85-
<PropertiesTable.Row label="Image ID">
86-
{disk.imageId ?? <EmptyCell />}
87-
</PropertiesTable.Row>
88-
<PropertiesTable.Row label="Snapshot ID">
89-
{disk.snapshotId ?? <EmptyCell />}
90-
</PropertiesTable.Row>
84+
<PropertiesTable.IdRow id={disk.imageId} label="Image ID" />
85+
<PropertiesTable.IdRow id={disk.snapshotId} label="Snapshot ID" />
9186
<PropertiesTable.Row label="Read only">
9287
<Badge color="neutral">{disk.readOnly ? 'True' : 'False'}</Badge>
9388
</PropertiesTable.Row>

app/pages/project/vpcs/internet-gateway-edit.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,10 @@ export default function EditInternetGatewayForm() {
134134
/>
135135
<PropertiesTable key={internetGateway.id}>
136136
<PropertiesTable.Row label="Name">{internetGateway.name}</PropertiesTable.Row>
137-
<PropertiesTable.DescriptionRow description={internetGateway.description} />
137+
<PropertiesTable.DescriptionRow
138+
description={internetGateway.description}
139+
sideModal
140+
/>
138141
<PropertiesTable.IdRow id={internetGateway.id} />
139142
</PropertiesTable>
140143

@@ -150,7 +153,10 @@ export default function EditInternetGatewayForm() {
150153
<PropertiesTable.Row label="Name">
151154
{gatewayIpAddress.name}
152155
</PropertiesTable.Row>
153-
<PropertiesTable.DescriptionRow description={gatewayIpAddress.description} />
156+
<PropertiesTable.DescriptionRow
157+
description={gatewayIpAddress.description}
158+
sideModal
159+
/>
154160
<PropertiesTable.Row label="IP Address">
155161
<CopyableIp ip={gatewayIpAddress.address} />
156162
</PropertiesTable.Row>

app/table/cells/DescriptionCell.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
import { EmptyCell } from '~/table/cells/EmptyCell'
1010
import { Truncate } from '~/ui/lib/Truncate'
1111

12-
export type Props = { text?: string; maxLength?: number }
12+
export type Props = { text?: string; maxLength?: number; sideModal?: boolean }
1313

14-
export const DescriptionCell = ({ text, maxLength = 48 }: Props) =>
15-
text ? <Truncate text={text} maxLength={maxLength} /> : <EmptyCell />
14+
export const DescriptionCell = ({ text, maxLength, sideModal }: Props) =>
15+
text ? (
16+
<Truncate text={text} maxLength={maxLength ?? (sideModal ? 20 : 48)} />
17+
) : (
18+
<EmptyCell />
19+
)

app/ui/lib/PropertiesTable.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import cn from 'classnames'
99
import type { ReactNode } from 'react'
1010

1111
import { DescriptionCell } from '~/table/cells/DescriptionCell'
12+
import { EmptyCell } from '~/table/cells/EmptyCell'
1213
import { isOneOf } from '~/util/children'
1314
import { invariant } from '~/util/invariant'
1415

@@ -69,15 +70,21 @@ PropertiesTable.Row = ({ label, children }: PropertiesTableRowProps) => (
6970
</>
7071
)
7172

72-
PropertiesTable.IdRow = ({ id }: { id: string }) => (
73-
<PropertiesTable.Row label="ID">
74-
<Truncate text={id} maxLength={32} hasCopyButton />
73+
PropertiesTable.IdRow = ({ id, label = 'ID' }: { id?: string | null; label?: string }) => (
74+
<PropertiesTable.Row label={label}>
75+
{id ? <Truncate text={id} maxLength={32} hasCopyButton /> : <EmptyCell />}
7576
</PropertiesTable.Row>
7677
)
7778

78-
PropertiesTable.DescriptionRow = ({ description }: { description: string }) => (
79+
PropertiesTable.DescriptionRow = ({
80+
description,
81+
sideModal,
82+
}: {
83+
description: string
84+
sideModal?: boolean
85+
}) => (
7986
<PropertiesTable.Row label="Description">
80-
<DescriptionCell text={description} />
87+
<DescriptionCell text={description} sideModal={sideModal} />
8188
</PropertiesTable.Row>
8289
)
8390

test/e2e/disks.e2e.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,11 @@ test('Create disk from snapshot with read-only', async ({ page }) => {
239239
const row = page.getByRole('row', { name: /a-new-disk/ })
240240
await expect(row.getByText('Read only', { exact: true })).toBeVisible()
241241

242-
// Verify snapshot ID in detail modal
242+
// Verify snapshot ID in detail modal (now truncated)
243243
await page.getByRole('link', { name: 'a-new-disk' }).click()
244244
const modal = page.getByRole('dialog', { name: 'Disk details' })
245-
await expect(modal.getByText('e6c58826-62fb-4205-820e-620407cd04e7')).toBeVisible()
245+
// The ID is truncated to 32 chars, but full ID is in aria-label
246+
await expect(modal.getByLabel('e6c58826-62fb-4205-820e-620407cd04e7')).toBeVisible()
246247
})
247248

248249
test('Create disk from image with read-only', async ({ page }) => {
@@ -259,8 +260,9 @@ test('Create disk from image with read-only', async ({ page }) => {
259260
const row = page.getByRole('row', { name: /a-new-disk/ })
260261
await expect(row.getByText('Read only', { exact: true })).toBeVisible()
261262

262-
// Verify image ID in detail modal
263+
// Verify image ID in detail modal (now truncated)
263264
await page.getByRole('link', { name: 'a-new-disk' }).click()
264265
const modal = page.getByRole('dialog', { name: 'Disk details' })
265-
await expect(modal.getByText('4700ecf1-8f48-4ecf-b78e-816ddb76aaca')).toBeVisible()
266+
// The ID is truncated to 32 chars, but full ID is in aria-label
267+
await expect(modal.getByLabel('4700ecf1-8f48-4ecf-b78e-816ddb76aaca')).toBeVisible()
266268
})

test/e2e/vpcs.e2e.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,8 @@ test('can view internet gateways', async ({ page }) => {
351351
await expect(page).toHaveURL(
352352
'/projects/mock-project/vpcs/mock-vpc/internet-gateways/internet-gateway-1'
353353
)
354-
const sidemodal = page.getByLabel('Internet Gateway')
354+
// Use getByRole instead of getByLabel to avoid matching truncated descriptions
355+
const sidemodal = page.getByRole('dialog', { name: 'Internet gateway' })
355356

356357
await expect(sidemodal.getByText('123.4.56.3')).toBeVisible()
357358

0 commit comments

Comments
 (0)