Skip to content

Commit e4815ea

Browse files
committed
review changes
1 parent 08e6d48 commit e4815ea

File tree

3 files changed

+85
-60
lines changed

3 files changed

+85
-60
lines changed

src/components/ElementInfo.js

+3-60
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,9 @@
11
import React from 'react';
22
import { useAppContext } from './Context';
33
import QueryAdvise from './QueryAdvise';
4+
import Queries from './Queries';
45

5-
import { getExpression, getFieldName, getQueryAdvise } from '../lib';
6-
7-
function Section({ children }) {
8-
return <div className="space-y-3">{children}</div>;
9-
}
10-
11-
function Heading({ children }) {
12-
return <h3 className="font-bold text-xs">{children}</h3>;
13-
}
14-
15-
function Field({ method, data }) {
16-
const { jsEditorRef, parsed } = useAppContext();
17-
18-
const isActive = parsed.expression?.method === method;
19-
const field = getFieldName(method);
20-
const value = data[field];
21-
22-
const handleClick = value
23-
? () => {
24-
const expr = getExpression({ method, data });
25-
jsEditorRef.current.setValue(expr);
26-
}
27-
: undefined;
28-
29-
return (
30-
<div
31-
className={`text-xs field ${isActive ? 'active' : ''}`}
32-
data-clickable={!!handleClick}
33-
onClick={handleClick}
34-
>
35-
<div className="text-gray-800 font-light">{field}</div>
36-
<div className="truncate">
37-
{value || <span className="text-gray-400">n/a</span>}
38-
</div>
39-
</div>
40-
);
41-
}
6+
import { getQueryAdvise } from '../lib';
427

438
// for inputs, the role will only work if there is also a type attribute
449
function ElementInfo() {
@@ -60,29 +25,7 @@ function ElementInfo() {
6025

6126
<div className="my-6 border-b" />
6227

63-
<div className="grid grid-cols-2 gap-4">
64-
<Section>
65-
<Heading>1. Queries Accessible to Everyone</Heading>
66-
<Field method="getByRole" data={data} />
67-
<Field method="getByLabelText" data={data} />
68-
<Field method="getByPlaceholderText" data={data} />
69-
<Field method="getByText" data={data} />
70-
<Field method="getByDisplayValue" data={data} />
71-
</Section>
72-
73-
<div className="space-y-8">
74-
<Section>
75-
<Heading>2. Semantic Queries</Heading>
76-
<Field method="getByAltText" data={data} />
77-
<Field method="getByTitle" data={data} />
78-
</Section>
79-
80-
<Section>
81-
<Heading>3. TestId</Heading>
82-
<Field method="getByTestId" data={data} />
83-
</Section>
84-
</div>
85-
</div>
28+
{!parsed.error && <Queries data={data} />}
8629
</div>
8730
);
8831
}

src/components/Queries.js

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import React from 'react';
2+
import { useAppContext } from './Context';
3+
4+
import { getExpression, getFieldName } from '../lib';
5+
6+
function Section({ children }) {
7+
return <div className="space-y-3">{children}</div>;
8+
}
9+
10+
function Heading({ children }) {
11+
return <h3 className="font-bold text-xs">{children}</h3>;
12+
}
13+
14+
function Field({ method, data }) {
15+
const { jsEditorRef, parsed } = useAppContext();
16+
17+
const isActive = parsed.expression?.method === method;
18+
const field = getFieldName(method);
19+
const value = data[field];
20+
21+
const handleClick = value
22+
? () => {
23+
const expr = getExpression({ method, data });
24+
jsEditorRef.current.setValue(expr);
25+
}
26+
: undefined;
27+
28+
return (
29+
<div
30+
className={`text-xs field ${isActive ? 'active' : ''}`}
31+
data-clickable={!!handleClick}
32+
onClick={handleClick}
33+
>
34+
<div className="text-gray-800 font-light">{field}</div>
35+
<div className="truncate">
36+
{value || <span className="text-gray-400">n/a</span>}
37+
</div>
38+
</div>
39+
);
40+
}
41+
42+
// for inputs, the role will only work if there is also a type attribute
43+
function Queries({ data }) {
44+
if (!data) {
45+
return <div />;
46+
}
47+
48+
return (
49+
<div>
50+
<div className="grid grid-cols-2 gap-4">
51+
<Section>
52+
<Heading>1. Queries Accessible to Everyone</Heading>
53+
<Field method="getByRole" data={data} />
54+
<Field method="getByLabelText" data={data} />
55+
<Field method="getByPlaceholderText" data={data} />
56+
<Field method="getByText" data={data} />
57+
<Field method="getByDisplayValue" data={data} />
58+
</Section>
59+
60+
<div className="space-y-8">
61+
<Section>
62+
<Heading>2. Semantic Queries</Heading>
63+
<Field method="getByAltText" data={data} />
64+
<Field method="getByTitle" data={data} />
65+
</Section>
66+
67+
<Section>
68+
<Heading>3. TestId</Heading>
69+
<Field method="getByTestId" data={data} />
70+
</Section>
71+
</div>
72+
</div>
73+
</div>
74+
);
75+
}
76+
77+
export default Queries;

src/components/QueryAdvise.js

+5
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ function QueryAdvise({ data, advise }) {
135135
&gt; {parsed.error}
136136
</div>
137137
)}
138+
{parsed.errorBody && (
139+
<div className="font-mono cursor-pointer text-xs">
140+
{parsed.errorBody}
141+
</div>
142+
)}
138143
</div>
139144
<div className="min-h-8">{suggestion}</div>
140145
</div>

0 commit comments

Comments
 (0)