Skip to content

Commit 01c76f9

Browse files
committed
fix(ui): add close button to field details panel
This commit adds a close button to the details panel so that the panel can be closed. It also fixes a bug where unused fields were clickable.
1 parent 4d4cd7f commit 01c76f9

File tree

4 files changed

+51
-16
lines changed

4 files changed

+51
-16
lines changed

graphql-usage-ui/src/App.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ function App() {
1515
setShowDetails(true);
1616
setSelectedField(field);
1717
};
18+
const handleClose = (): void => {
19+
setShowDetails(false);
20+
};
1821

1922
const [report, setReport] = useState<Report | null>(null);
2023
const hasReportLoaded = !!report;
@@ -64,7 +67,7 @@ function App() {
6467
onFieldClick={handleFieldClick}
6568
/>
6669
{showDetails && selectedField && (
67-
<DetailsPanel field={selectedField} />
70+
<DetailsPanel field={selectedField} onClose={handleClose} />
6871
)}
6972
</div>
7073
)}

graphql-usage-ui/src/DetailsPanel.tsx

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,39 @@ const DetailsPanelHeading: React.FC = ({ children }) => {
9292
);
9393
};
9494

95+
interface CloseButtonProps {
96+
onClick(): void;
97+
}
98+
99+
const CloseButton: React.FC<CloseButtonProps> = ({ onClick }) => {
100+
return (
101+
<div
102+
style={{
103+
margin: "-7px -8px -6px 0",
104+
cursor: "pointer",
105+
padding: "18px 16px 15px 12px",
106+
fontSize: "24px"
107+
}}
108+
onClick={onClick}
109+
>
110+
111+
</div>
112+
);
113+
};
114+
95115
interface Props {
96116
field: ReportField;
117+
onClose(): void;
97118
}
98119

99-
const DetailsPanel: React.FC<Props> = ({ field }) => {
120+
const DetailsPanel: React.FC<Props> = ({ field, onClose }) => {
100121
if (field.occurrences.length === 0) return null;
101122

102123
return (
103124
<Panel>
104125
<DetailsPanelHeader>
105126
<DetailsPanelTitle field={field} />
127+
<CloseButton onClick={onClose} />
106128
</DetailsPanelHeader>
107129
<DetailsPanelBody>
108130
<DetailsPanelHeading>Type</DetailsPanelHeading>

graphql-usage-ui/src/FieldLine.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,20 @@ const FieldLine: React.FC<Props> = ({ field, filter, onFieldClick }) => {
1717
const lowerCaseFilter = filter.toLowerCase();
1818
const fieldMatchesFilter = field.name.toLowerCase().includes(lowerCaseFilter);
1919
const typeMatchesFilter = field.type.toLowerCase().includes(lowerCaseFilter);
20-
const handleFieldClick = () => onFieldClick(field);
20+
const isClickable = field.occurrences.length > 0;
21+
const handleFieldClick = () => {
22+
if (isClickable) onFieldClick(field);
23+
};
2124

2225
return (
2326
<div
2427
style={{ display: "flex", alignItems: "center", paddingLeft: "16px" }}
2528
onClick={handleFieldClick}
2629
>
27-
<div className="field-line" style={{ padding: "10px 0px" }}>
30+
<div
31+
className={isClickable ? "clickable-field-line" : ""}
32+
style={{ padding: "10px 0px" }}
33+
>
2834
<FieldName highlight={!!filter && fieldMatchesFilter}>{name}</FieldName>
2935
<Delimiter token={":"} />{" "}
3036
<FieldType highlight={!!filter && typeMatchesFilter}>{type}</FieldType>

graphql-usage-ui/src/index.css

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,35 @@
11
body {
22
margin: 0;
3-
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
4-
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
3+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
4+
"Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
55
sans-serif;
66
-webkit-font-smoothing: antialiased;
77
-moz-osx-font-smoothing: grayscale;
88
}
99

10-
::-webkit-input-placeholder { /* Chrome/Opera/Safari */
11-
color: 'rgba(0, 0, 0, 0.3)';
10+
/* Chrome/Opera/Safari */
11+
::-webkit-input-placeholder {
12+
color: "rgba(0, 0, 0, 0.3)";
1213
}
13-
::-moz-placeholder { /* Firefox 19+ */
14-
color: 'rgba(0, 0, 0, 0.3)';
14+
/* Firefox 19+ */
15+
::-moz-placeholder {
16+
color: "rgba(0, 0, 0, 0.3)";
1517
}
16-
:-ms-input-placeholder { /* IE 10+ */
17-
color: 'rgba(0, 0, 0, 0.3)';
18+
/* IE 10+ */
19+
:-ms-input-placeholder {
20+
color: "rgba(0, 0, 0, 0.3)";
1821
}
19-
:-moz-placeholder { /* Firefox 18- */
20-
color: 'rgba(0, 0, 0, 0.3)';
22+
/* Firefox 18- */
23+
:-moz-placeholder {
24+
color: "rgba(0, 0, 0, 0.3)";
2125
}
2226

2327
code {
24-
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
28+
font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New",
2529
monospace;
2630
}
2731

28-
.field-line:hover {
32+
.clickable-field-line:hover {
2933
text-decoration: underline;
3034
cursor: pointer;
3135
}

0 commit comments

Comments
 (0)