Skip to content

Commit 945619e

Browse files
authored
Linkify the firewall rules name cell (#1921)
linkify the firewall rules name cell the easy way
1 parent e2d82a4 commit 945619e

File tree

3 files changed

+30
-15
lines changed

3 files changed

+30
-15
lines changed

app/pages/project/networking/VpcPage/tabs/VpcFirewallRulesTab.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
type VpcFirewallRule,
1515
} from '@oxide/api'
1616
import {
17+
ButtonCell,
1718
createColumnHelper,
1819
DateCell,
1920
EnabledCell,
@@ -35,7 +36,6 @@ const colHelper = createColumnHelper<VpcFirewallRule>()
3536

3637
/** columns that don't depend on anything in `render` */
3738
const staticColumns = [
38-
colHelper.accessor('name', { header: 'Name' }),
3939
colHelper.accessor('priority', {
4040
header: 'Priority',
4141
cell: (info) => <div className="text-secondary">{info.getValue()}</div>,
@@ -88,6 +88,14 @@ export const VpcFirewallRulesTab = () => {
8888
// the whole thing can't be static because the action depends on setEditing
8989
const columns = useMemo(() => {
9090
return [
91+
colHelper.accessor('name', {
92+
header: 'Name',
93+
cell: (info) => (
94+
<ButtonCell onClick={() => setEditing(info.row.original)}>
95+
{info.getValue()}
96+
</ButtonCell>
97+
),
98+
}),
9199
...staticColumns,
92100
getActionsCol((rule: VpcFirewallRule) => [
93101
{ label: 'Edit', onActivate: () => setEditing(rule) },

app/test/e2e/firewall-rules.e2e.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -202,14 +202,8 @@ test('can update firewall rule', async ({ page }) => {
202202
const modal = page.getByRole('dialog', { name: 'Edit rule' })
203203
await expect(modal).toBeHidden()
204204

205-
// click more button on allow-icmp row to get menu, then click Edit
206-
await page
207-
.locator('role=row', { hasText: 'allow-icmp' })
208-
.locator('role=button[name="Row actions"]')
209-
.click()
210-
211-
// filter visible to distinguish from all the hidden menus' Edit button
212-
await page.locator('text="Edit" >> visible=true').click()
205+
// can click name cell to edit
206+
await page.getByRole('button', { name: 'allow-icmp' }).click()
213207

214208
// modal is now open
215209
await expect(modal).toBeVisible()

libs/table/cells/LinkCell.tsx

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,32 @@
77
*/
88
import { Link } from 'react-router-dom'
99

10+
import { classed } from '@oxide/util'
11+
1012
import type { Cell } from './Cell'
1113

14+
const linkClass =
15+
'link-with-underline group flex h-full w-full items-center text-sans-semi-md'
16+
17+
/** Pushes out the link area to the entire cell for improved clickability™ */
18+
const Pusher = classed.div`absolute inset-0 right-px group-hover:bg-raise`
19+
1220
export const linkCell =
1321
(makeHref: (value: string) => string) =>
1422
({ value }: Cell<string>) => {
1523
return (
16-
<Link
17-
className="link-with-underline group flex h-full w-full items-center text-sans-semi-md"
18-
to={makeHref(value)}
19-
>
20-
{/* Pushes out the link area to the entire cell for improved clickability™ */}
21-
<div className="absolute inset-0 right-px group-hover:bg-raise" />
24+
<Link className={linkClass} to={makeHref(value)}>
25+
<Pusher />
2226
<div className="relative">{value}</div>
2327
</Link>
2428
)
2529
}
30+
31+
export const ButtonCell = ({ children, ...props }: React.ComponentProps<'button'>) => {
32+
return (
33+
<button className={linkClass} {...props}>
34+
<Pusher />
35+
<div className="relative">{children}</div>
36+
</button>
37+
)
38+
}

0 commit comments

Comments
 (0)