Skip to content

Commit 6884f9c

Browse files
add visual cues for configured locators
1 parent d935b37 commit 6884f9c

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/views/BrowserTestEditor/ActionForms/forms/LocatorForm.tsx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
Popover,
66
RadioGroup,
77
Separator,
8+
Text,
89
Tooltip,
910
} from '@radix-ui/themes'
1011
import { WholeWordIcon } from 'lucide-react'
@@ -60,6 +61,12 @@ export function LocatorForm({
6061

6162
const currentLocator = values[current] ?? initializeLocatorValues(current)
6263

64+
const configuredTypes = new Set(
65+
Object.entries(values)
66+
.filter(([, locator]) => locator && isLocatorConfigured(locator))
67+
.map(([type]) => type)
68+
)
69+
6370
const handleChangeCurrent = (type: LocatorOptions['current']) => {
6471
if (dirtyTypes.has(current)) {
6572
setTouchedTypes((prev) => {
@@ -131,7 +138,12 @@ export function LocatorForm({
131138
.filter(([type]) => type !== 'text')
132139
.map(([type, label]) => (
133140
<RadioGroup.Item value={type} key={type}>
134-
{label}
141+
<Text
142+
weight={configuredTypes.has(type) ? 'medium' : 'regular'}
143+
color={configuredTypes.has(type) ? undefined : 'gray'}
144+
>
145+
{label}
146+
</Text>
135147
</RadioGroup.Item>
136148
))}
137149
</RadioGroup.Root>
@@ -365,6 +377,14 @@ function initializeLocatorValues(type: ActionLocator['type']): ActionLocator {
365377
}
366378
}
367379

380+
function isLocatorConfigured(locator: ActionLocator | undefined): boolean {
381+
if (!locator) return false
382+
383+
// Since validateLocator only checks for empty values, we re-use it to check if the locator is configured.
384+
// This isn't perfect, but it's a good enough approximation.
385+
return validateLocator(locator).isValid
386+
}
387+
368388
function addIfAbsent<T>(set: Set<T>, value: T) {
369389
return set.has(value) ? set : new Set(set).add(value)
370390
}

0 commit comments

Comments
 (0)