-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
planDetails.tsx
77 lines (71 loc) · 2 KB
/
planDetails.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright 2022 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.
import React, { useState } from "react";
import { Helmet } from "react-helmet";
import { ArrowLeft } from "@cockroachlabs/icons";
import {
PlansSortedTable,
makeExplainPlanColumns,
PlanHashStats,
} from "./plansTable";
import { Button } from "../../button";
import { SqlBox, SqlBoxSize } from "../../sql";
interface PlanDetailsProps {
plans: PlanHashStats[];
}
export function PlanDetails({ plans }: PlanDetailsProps): React.ReactElement {
const [plan, setPlan] = useState<PlanHashStats | null>(null);
const handleDetails = (plan: PlanHashStats): void => {
setPlan(plan);
};
const backToPlanTable = (): void => {
setPlan(null);
};
if (plan) {
return renderExplainPlan(plan, backToPlanTable);
} else {
return renderPlanTable(plans, handleDetails);
}
}
function renderPlanTable(
plans: PlanHashStats[],
handleDetails: (plan: PlanHashStats) => void,
): React.ReactElement {
const columns = makeExplainPlanColumns(handleDetails);
return (
<PlansSortedTable
columns={columns}
data={plans}
className="statements-table"
/>
);
}
function renderExplainPlan(
plan: PlanHashStats,
backToPlanTable: () => void,
): React.ReactElement {
let explainPlan = plan.explain_plan === "" ? "unavailable" : plan.explain_plan;
return (
<div>
<Helmet title="Plan Details" />
<Button
onClick={backToPlanTable}
type="unstyled-link"
size="small"
icon={<ArrowLeft fontSize={"10px"} />}
iconPosition="left"
className="small-margin"
>
All Plans
</Button>
<SqlBox value={explainPlan} size={SqlBoxSize.large} />;
</div>
);
}