From 965e717c865cab1b465b2cc0c8c04c98bafcb054 Mon Sep 17 00:00:00 2001 From: RinYato Date: Sun, 28 Jul 2024 12:28:29 +0700 Subject: [PATCH] refactor: cleanup and remove unnecessary exports --- ...uery-explain.tsx => query-explanation.tsx} | 40 +++++++++---------- src/components/gui/query-result.tsx | 2 +- 2 files changed, 20 insertions(+), 22 deletions(-) rename src/components/gui/{query-explain.tsx => query-explanation.tsx} (73%) diff --git a/src/components/gui/query-explain.tsx b/src/components/gui/query-explanation.tsx similarity index 73% rename from src/components/gui/query-explain.tsx rename to src/components/gui/query-explanation.tsx index 84fdf1a2..a6e2b1cd 100644 --- a/src/components/gui/query-explain.tsx +++ b/src/components/gui/query-explanation.tsx @@ -2,19 +2,19 @@ import { DatabaseResultSet } from "@/drivers/base-driver"; import { useMemo } from "react"; import { z } from "zod"; -export interface QueryExplanationProps { +interface QueryExplanationProps { data: DatabaseResultSet; } -export interface ExplainRow { +interface ExplanationRow { id: number; parent: number; notused: number; detail: string; } -export type ExplainRowWithChildren = ExplainRow & { - children?: ExplainRowWithChildren[]; +type ExplanationRowWithChildren = ExplanationRow & { + children: ExplanationRowWithChildren[]; }; const queryExplanationRowSchema = z.object({ @@ -28,9 +28,9 @@ export function isExplainQueryPlan(sql: string) { return sql.toLowerCase().startsWith("explain query plan"); } -function buildQueryExplanationTree(nodes: ExplainRow[]) { - const map: Record = {}; - const tree: ExplainRowWithChildren[] = []; +function buildQueryExplanationTree(nodes: ExplanationRow[]) { + const map: Record = {}; + const tree: ExplanationRowWithChildren[] = []; nodes.forEach((node) => { map[node.id] = { ...node, children: [] }; @@ -63,16 +63,6 @@ export function QueryExplanation(props: QueryExplanationProps) { }; }, [props.data]); - const treeDom = useMemo(() => { - if (tree._tag === "ERROR") return null; - - return tree.value.map((node) => ( -
  • - -
  • - )); - }, [tree]); - if (tree._tag === "ERROR") { // The row structure doesn't match the explanation structure return ( @@ -86,12 +76,20 @@ export function QueryExplanation(props: QueryExplanationProps) { return (
    -
      {treeDom}
    +
      + {tree.value.map((node) => ( +
    • + +
    • + ))} +
    ); } -function RenderQueryExplanationItem(props: { item: ExplainRowWithChildren }) { +function RenderQueryExplanationItem(props: { + item: ExplanationRowWithChildren; +}) { return (
    @@ -99,13 +97,13 @@ function RenderQueryExplanationItem(props: { item: ExplainRowWithChildren }) {

    {props.item.detail}

    - {props.item.children && ( + {props.item.children.length > 0 && (
      {props.item.children.map((child) => { return (
    • diff --git a/src/components/gui/query-result.tsx b/src/components/gui/query-result.tsx index 719ce9cd..53ac33d4 100644 --- a/src/components/gui/query-result.tsx +++ b/src/components/gui/query-result.tsx @@ -5,7 +5,7 @@ import ResultTable from "./query-result-table"; import ResultStats from "./result-stat"; import { useMemo } from "react"; import OptimizeTableState from "./table-optimized/OptimizeTableState"; -import { QueryExplanation, isExplainQueryPlan } from "./query-explain"; +import { QueryExplanation, isExplainQueryPlan } from "./query-explanation"; export default function QueryResult({ result,