Skip to content

Commit e9d7261

Browse files
committed
remove unneeded things
1 parent 88cbf7f commit e9d7261

File tree

14 files changed

+115
-945
lines changed

14 files changed

+115
-945
lines changed

src/components/ErrorBoundary.tsx

Lines changed: 47 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { Component, ErrorInfo, ReactNode } from "react";
2+
import { css } from "@emotion/css";
23
import { ErrorState, toErrorState } from "../types/error-types";
3-
import { logError } from "../utils/logger";
44

55
interface Props {
66
children: ReactNode;
@@ -12,12 +12,43 @@ interface State {
1212
error?: ErrorState;
1313
}
1414

15-
/**
16-
* Error Boundary component
17-
*
18-
* Catches React errors and prevents the entire panel from crashing.
19-
* Displays error information and provides recovery options.
20-
*/
15+
const errorContainerStyle = css`
16+
padding: 16px;
17+
`;
18+
19+
const errorBoxStyle = css`
20+
border: 1px solid #f44336;
21+
border-radius: 4px;
22+
padding: 12px;
23+
background-color: #ffebee;
24+
color: #c62828;
25+
`;
26+
27+
const errorTitleStyle = css`
28+
margin: 0 0 8px 0;
29+
font-size: 16px;
30+
`;
31+
32+
const errorMessageStyle = css`
33+
margin: 0 0 8px 0;
34+
font-size: 14px;
35+
`;
36+
37+
const errorDetailsStyle = css`
38+
margin: 8px 0;
39+
padding: 8px;
40+
background-color: #fff;
41+
font-size: 12px;
42+
overflow: auto;
43+
max-height: 200px;
44+
`;
45+
46+
const errorHintStyle = css`
47+
margin: 8px 0 0 0;
48+
font-size: 13px;
49+
font-style: italic;
50+
`;
51+
2152
export class ErrorBoundary extends Component<Props, State> {
2253
constructor(props: Props) {
2354
super(props);
@@ -34,57 +65,31 @@ export class ErrorBoundary extends Component<Props, State> {
3465
}
3566

3667
componentDidCatch(error: Error, errorInfo: ErrorInfo): void {
37-
logError("ErrorBoundary", "Caught error in component tree", {
38-
error: error.message,
68+
console.error("ErrorBoundary caught error:", error.message, {
3969
stack: error.stack,
4070
componentStack: errorInfo.componentStack,
4171
});
4272

43-
const errorState = toErrorState(error);
44-
45-
if (this.props.onError) {
46-
this.props.onError(errorState);
73+
if (this.props.onError && this.state.error) {
74+
this.props.onError(this.state.error);
4775
}
4876
}
4977

5078
render() {
5179
if (this.state.hasError && this.state.error) {
5280
return (
53-
<div style={{ padding: "16px" }}>
54-
<div
55-
style={{
56-
border: "1px solid #f44336",
57-
borderRadius: "4px",
58-
padding: "12px",
59-
backgroundColor: "#ffebee",
60-
color: "#c62828",
61-
}}
62-
>
63-
<h3 style={{ margin: "0 0 8px 0", fontSize: "16px" }}>Error</h3>
64-
<p style={{ margin: "0 0 8px 0", fontSize: "14px" }}>
81+
<div className={errorContainerStyle}>
82+
<div className={errorBoxStyle}>
83+
<h3 className={errorTitleStyle}>Error</h3>
84+
<p className={errorMessageStyle}>
6585
{this.state.error.message}
6686
</p>
6787
{this.state.error.details && (
68-
<pre
69-
style={{
70-
margin: "8px 0",
71-
padding: "8px",
72-
backgroundColor: "#fff",
73-
fontSize: "12px",
74-
overflow: "auto",
75-
maxHeight: "200px",
76-
}}
77-
>
88+
<pre className={errorDetailsStyle}>
7889
{this.state.error.details}
7990
</pre>
8091
)}
81-
<p
82-
style={{
83-
margin: "8px 0 0 0",
84-
fontSize: "13px",
85-
fontStyle: "italic",
86-
}}
87-
>
92+
<p className={errorHintStyle}>
8893
{this.state.error.resolutionHint}
8994
</p>
9095
</div>

src/components/ErrorDisplay.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@ interface Props {
66
error: ErrorState;
77
}
88

9-
/**
10-
* Error Display component
11-
*
12-
* Displays error states using Grafana's Alert component.
13-
* Shows user-friendly messages with resolution hints.
14-
*/
159
export const ErrorDisplay: React.FC<Props> = ({ error }) => {
1610
const severity = ERROR_SEVERITY[error.type];
1711

src/components/ExplainPanel.tsx

Lines changed: 21 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
/**
2-
* Explain Panel Component
3-
*
4-
* Main panel component for PostgreSQL EXPLAIN visualization.
5-
* Orchestrates data extraction, validation, and rendering.
6-
*/
7-
8-
import React, { useMemo } from "react";
1+
import React from "react";
92
import { PanelProps } from "@grafana/data";
103
import { PanelOptions } from "../types/panel-options";
114
import {
@@ -19,76 +12,39 @@ import { validatePlan } from "../services/planValidator";
1912
import { VueMount } from "./VueMount";
2013
import { ErrorBoundary } from "./ErrorBoundary";
2114
import { ErrorDisplay } from "./ErrorDisplay";
22-
import { LoadingSpinner } from "./LoadingSpinner";
23-
import { logDebug, logError } from "../utils/logger";
24-
25-
const CONTEXT = "ExplainPanel";
2615

2716
interface Props extends PanelProps<PanelOptions> {}
2817

29-
/**
30-
* ExplainPanel
31-
*
32-
* Main panel component that:
33-
* 1. Extracts EXPLAIN data from DataFrame
34-
* 2. Validates JSON structure
35-
* 3. Renders visualization using Vue/PEV2
36-
* 4. Handles errors gracefully
37-
*/
3818
export const ExplainPanel: React.FC<Props> = ({
3919
options,
4020
data,
4121
width,
4222
height,
4323
}) => {
44-
logDebug(CONTEXT, "Rendering ExplainPanel", {
45-
options,
46-
seriesCount: data.series.length,
47-
width,
48-
height,
49-
});
50-
51-
// Process data and handle errors
52-
const result = useMemo(() => {
53-
try {
54-
// Extract plan data from DataFrame
55-
const planData = extractPlanData(data.series, options.planFieldName);
56-
57-
// Handle no data case
58-
if (!planData) {
59-
const errorState: ErrorState = {
60-
type: ErrorType.NO_DATA,
61-
message: "No data available",
62-
resolutionHint:
63-
"Configure a query to return EXPLAIN output. Use EXPLAIN (FORMAT JSON) SELECT ... or EXPLAIN SELECT ...",
64-
};
65-
return { type: "error" as const, error: errorState };
66-
}
67-
68-
// Validate and parse plan
24+
let result: { type: "success"; plan: any } | { type: "error"; error: ErrorState };
25+
26+
try {
27+
const planData = extractPlanData(data.series, options.planFieldName);
28+
29+
if (!planData) {
30+
const errorState: ErrorState = {
31+
type: ErrorType.NO_DATA,
32+
message: "No data available",
33+
resolutionHint:
34+
"Configure a query to return EXPLAIN output. Use EXPLAIN (FORMAT JSON) SELECT ... or EXPLAIN SELECT ...",
35+
};
36+
result = { type: "error" as const, error: errorState };
37+
} else {
6938
const plan = validatePlan(planData);
70-
71-
logDebug(CONTEXT, "Plan extracted and validated successfully");
72-
73-
return { type: "success" as const, plan };
74-
} catch (error) {
75-
logError(CONTEXT, "Error processing plan data", error);
76-
77-
// Convert error to ErrorState
78-
const errorState =
79-
error instanceof PlanError ? error.toErrorState() : toErrorState(error);
80-
81-
return { type: "error" as const, error: errorState };
39+
result = { type: "success" as const, plan };
8240
}
83-
}, [data.series, options.planFieldName]);
41+
} catch (error) {
42+
const errorState =
43+
error instanceof PlanError ? error.toErrorState() : toErrorState(error);
44+
result = { type: "error" as const, error: errorState };
45+
}
8446

85-
// Render error state
8647
if (result.type === "error") {
87-
// For NO_DATA, show info message instead of error
88-
if (result.error.type === ErrorType.NO_DATA) {
89-
return <ErrorDisplay error={result.error} />;
90-
}
91-
9248
return <ErrorDisplay error={result.error} />;
9349
}
9450

src/components/LoadingSpinner.tsx

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

src/components/SimplePanel.tsx

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

0 commit comments

Comments
 (0)