Skip to content

Commit a8a263b

Browse files
change presentation of multiple options
1 parent 6e5fba2 commit a8a263b

File tree

4 files changed

+54
-40
lines changed

4 files changed

+54
-40
lines changed
Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import { css } from '@emotion/react'
2-
import { Fragment } from 'react'
3-
41
interface SelectOption {
52
value?: string
63
label?: string
@@ -15,31 +12,20 @@ function quote(str: string) {
1512
return `"${str}"`
1613
}
1714

18-
function formatOption(option: SelectOption | string) {
15+
export function formatOption(option: SelectOption | string) {
1916
if (typeof option === 'string') {
2017
return quote(option)
2118
}
2219

2320
if (option.label !== undefined) {
24-
return option.label.length ? (
25-
option.label
26-
) : (
27-
<span
28-
css={css`
29-
opacity: 0.8;
30-
font-style: italic;
31-
`}
32-
>
33-
(empty)
34-
</span>
35-
)
21+
return `label: ${quote(option.label)}`
3622
}
3723

3824
if (option.index !== undefined) {
39-
return option.index.toString()
25+
return `index: ${option.index.toString()}`
4026
}
4127

42-
return quote(option.value ?? '')
28+
return `value: ${quote(option.value ?? '')}`
4329
}
4430

4531
export function SelectOptions({ options }: SelectOptionsProps) {
@@ -51,16 +37,5 @@ export function SelectOptions({ options }: SelectOptionsProps) {
5137
return <code>{formatOption(options[0]!)}</code>
5238
}
5339

54-
const last = options[options.length - 1]!
55-
56-
return (
57-
<>
58-
{options.slice(0, -1).map((option, index) => (
59-
<Fragment key={index}>
60-
<code>{formatOption(option)}</code>,{' '}
61-
</Fragment>
62-
))}{' '}
63-
and <code>{formatOption(last)}</code>
64-
</>
65-
)
40+
return <>{options.length} options</>
6641
}

src/components/BrowserEventList/EventDescription/EventDescription.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { SelectOptions } from '@/components/Browser/SelectOptions'
21
import { BrowserEvent } from '@/schemas/recording'
32
import { NodeSelector } from '@/schemas/selectors'
43
import { exhaustive } from '@/utils/typescript'
@@ -7,6 +6,7 @@ import { AssertDescription } from './AssertDescription'
76
import { ClickDescription } from './ClickDescription'
87
import { InputChangeDescription } from './InputChangeDescription'
98
import { PageNavigationDescription } from './PageNavigationDescription'
9+
import { SelectChangeDescription } from './SelectChangeDescription'
1010
import { Selector } from './Selector'
1111
import { WaitForDescription } from './WaitForDescription'
1212

@@ -58,15 +58,7 @@ export function EventDescription({
5858
)
5959

6060
case 'select-change':
61-
return (
62-
<>
63-
Selected <SelectOptions options={event.selected} /> from{' '}
64-
<Selector
65-
selectors={event.target.selectors}
66-
onHighlight={onHighlight}
67-
/>
68-
</>
69-
)
61+
return <SelectChangeDescription event={event} onHighlight={onHighlight} />
7062

7163
case 'submit-form':
7264
return (
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { css } from '@emotion/react'
2+
3+
import { formatOption, SelectOptions } from '@/components/Browser/SelectOptions'
4+
import { Tooltip } from '@/components/primitives/Tooltip'
5+
import { SelectChangeEvent } from '@/schemas/recording'
6+
import { NodeSelector } from '@/schemas/selectors'
7+
8+
import { Selector } from './Selector'
9+
10+
interface SelectChangeDescriptionProps {
11+
event: SelectChangeEvent
12+
onHighlight: (selector: NodeSelector | null) => void
13+
}
14+
15+
export function SelectChangeDescription({
16+
event,
17+
onHighlight,
18+
}: SelectChangeDescriptionProps) {
19+
return (
20+
<>
21+
Selected
22+
<Tooltip
23+
content={event.selected
24+
.map((option) => formatOption(option))
25+
.join(', ')}
26+
>
27+
<div
28+
css={css`
29+
gap: calc(var(--studio-spacing-1) * 1.5);
30+
flex-shrink: 1;
31+
padding: calc(var(--studio-spacing-1) * 0.5)
32+
calc(var(--studio-spacing-1) * 1.5);
33+
overflow: hidden;
34+
background-color: var(--gray-3);
35+
color: var(--gray-12);
36+
border-radius: 3px;
37+
font-size: var(--studio-font-size-1);
38+
`}
39+
>
40+
<SelectOptions options={event.selected} />
41+
</div>
42+
</Tooltip>{' '}
43+
from{' '}
44+
<Selector selectors={event.target.selectors} onHighlight={onHighlight} />
45+
</>
46+
)
47+
}

src/components/primitives/Code.tsx

Whitespace-only changes.

0 commit comments

Comments
 (0)