Skip to content

Commit 8e5451a

Browse files
Bill LeoutsakosBill Leoutsakos
authored andcommitted
refactor(emcn): own shared resource row and tile chrome
1 parent 316fea0 commit 8e5451a

11 files changed

Lines changed: 439 additions & 287 deletions

File tree

‎apps/sim/app/workspace/[workspaceId]/components/resource-tile/index.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ export {
33
RESOURCE_TILE_FILL,
44
RESOURCE_TILE_PLAIN,
55
ResourceTile,
6-
} from '@/app/workspace/[workspaceId]/components/resource-tile/resource-tile'
6+
} from '@sim/emcn'

‎apps/sim/app/workspace/[workspaceId]/components/resource-tile/resource-tile.tsx‎

Lines changed: 0 additions & 33 deletions
This file was deleted.

‎apps/sim/app/workspace/[workspaceId]/settings/components/browser/browser.test.tsx‎

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,41 @@ vi.mock('@sim/browser-protocol', () => ({
2626
}))
2727

2828
vi.mock('@sim/emcn', () => ({
29-
/** `SettingsResourceRow` composes its tile classes with `cn`. */
3029
cn: (...classes: unknown[]) => classes.filter(Boolean).join(' '),
30+
ResourceRow: ({
31+
title,
32+
description,
33+
icon,
34+
trailing,
35+
onClick,
36+
clickLabel,
37+
disabled,
38+
}: {
39+
title: ReactNode
40+
description?: ReactNode
41+
icon?: ReactNode
42+
trailing?: ReactNode
43+
onClick?: () => void
44+
clickLabel?: string
45+
disabled?: boolean
46+
}) => (
47+
<div>
48+
{onClick && !disabled ? (
49+
<button type='button' aria-label={clickLabel} onClick={onClick}>
50+
{icon}
51+
{title}
52+
{description}
53+
</button>
54+
) : (
55+
<span>
56+
{icon}
57+
{title}
58+
{description}
59+
</span>
60+
)}
61+
{trailing}
62+
</div>
63+
),
3164
Chip: ({
3265
children,
3366
disabled,

‎apps/sim/app/workspace/[workspaceId]/settings/components/browser/components/passwords-view/passwords-view.test.tsx‎

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,41 @@ const { mockBridge, mockSearch, mockToast } = vi.hoisted(() => ({
1515
}))
1616

1717
vi.mock('@sim/emcn', () => ({
18-
/** `SettingsResourceRow` composes its tile classes with `cn`. */
1918
cn: (...classes: unknown[]) => classes.filter(Boolean).join(' '),
19+
ResourceRow: ({
20+
title,
21+
description,
22+
icon,
23+
trailing,
24+
onClick,
25+
clickLabel,
26+
disabled,
27+
}: {
28+
title: ReactNode
29+
description?: ReactNode
30+
icon?: ReactNode
31+
trailing?: ReactNode
32+
onClick?: () => void
33+
clickLabel?: string
34+
disabled?: boolean
35+
}) => (
36+
<div>
37+
{onClick && !disabled ? (
38+
<button type='button' aria-label={clickLabel} onClick={onClick}>
39+
{icon}
40+
{title}
41+
{description}
42+
</button>
43+
) : (
44+
<span>
45+
{icon}
46+
{title}
47+
{description}
48+
</span>
49+
)}
50+
{trailing}
51+
</div>
52+
),
2053
ArrowLeft: () => <span />,
2154
ArrowRight: () => <span />,
2255
ChipConfirmModal: ({
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,2 @@
1-
export {
2-
RESOURCE_LIST_GRID,
3-
RESOURCE_LIST_STACK,
4-
RESOURCE_ROW_ARROW_CLASSES,
5-
SettingsResourceRow,
6-
} from './settings-resource-row'
1+
export { RESOURCE_LIST_GRID, RESOURCE_LIST_STACK, RESOURCE_ROW_ARROW_CLASSES } from '@sim/emcn'
2+
export { SettingsResourceRow } from './settings-resource-row'
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* @vitest-environment jsdom
3+
*/
4+
import { renderToStaticMarkup } from 'react-dom/server'
5+
import { describe, expect, it } from 'vitest'
6+
import { SettingsResourceRow } from './settings-resource-row'
7+
8+
describe('SettingsResourceRow', () => {
9+
it('renders a real Next link beside interactive trailing controls', () => {
10+
const html = renderToStaticMarkup(
11+
<SettingsResourceRow
12+
title='Knowledge base'
13+
description='Connected resource'
14+
href='/workspace/example/knowledge'
15+
clickLabel='Open knowledge base'
16+
navigable
17+
trailing={<button type='button'>More actions</button>}
18+
/>
19+
)
20+
const container = document.createElement('div')
21+
container.innerHTML = html
22+
23+
const link = container.querySelector('a')
24+
const action = container.querySelector('button')
25+
expect(link?.getAttribute('href')).toBe('/workspace/example/knowledge')
26+
expect(link?.getAttribute('aria-label')).toBe('Open knowledge base')
27+
expect(link?.getAttribute('aria-describedby')).toBe(container.querySelector('span[id]')?.id)
28+
expect(link?.contains(action ?? null)).toBe(false)
29+
expect(action?.textContent).toBe('More actions')
30+
})
31+
})

0 commit comments

Comments
 (0)