-
Notifications
You must be signed in to change notification settings - Fork 235
Expand file tree
/
Copy pathquery-result-tab.tsx
More file actions
58 lines (52 loc) · 1.76 KB
/
query-result-tab.tsx
File metadata and controls
58 lines (52 loc) · 1.76 KB
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
import { useStudioContext } from "@/context/driver-provider";
import { useSchema } from "@/context/schema-provider";
import { MultipleQueryResult } from "@/lib/sql/multiple-query";
import { useMemo, useState } from "react";
import AggregateResultButton from "../aggregate-result/aggregate-result-button";
import ExportResultButton from "../export/export-result-button";
import ResultTable from "../query-result-table";
import ResultStats from "../result-stat";
import OptimizeTableState from "../table-optimized/optimize-table-state";
export default function QueryResult({
result,
}: {
result: MultipleQueryResult;
}) {
const { databaseDriver } = useStudioContext();
const { schema } = useSchema();
// We cache the schema to prevent re-initial
// the state when schema changes and lost all the
// changes in the table
const [cachedSchemas] = useState(schema);
const data = useMemo(() => {
const state = OptimizeTableState.createFromResult({
driver: databaseDriver,
result: result.result,
schemas: cachedSchemas,
});
state.setReadOnlyMode(true);
state.setSql(result.sql);
return state;
}, [result, databaseDriver, cachedSchemas]);
const stats = result.result.stat;
return (
<div className="flex h-full w-full flex-col border-t">
<div className="grow overflow-hidden">
<ResultTable data={data} />
</div>
{stats && (
<div className="flex shrink-0 justify-between border-t">
<div className="flex p-1">
<ResultStats stats={stats} />
<div>
<ExportResultButton data={data} />
</div>
</div>
<div className="p-1 pr-3">
<AggregateResultButton data={data} />
</div>
</div>
)}
</div>
);
}