This repository was archived by the owner on Aug 23, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 816
Expand file tree
/
Copy pathQueryEditor.tsx
More file actions
91 lines (86 loc) · 3.2 KB
/
QueryEditor.tsx
File metadata and controls
91 lines (86 loc) · 3.2 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import React, { useEffect, useState } from 'react';
import { useParams } from 'react-router-dom';
import SplitPane from 'react-split-pane';
import AppHeader from '../app-header/AppHeader';
import { debouncedResizeChart } from '../common/tauChartRef';
import SchemaInfoLoader from '../schema/SchemaInfoLoader';
import { connectConnectionClient, loadQuery } from '../stores/editor-actions';
import useShortcuts from '../utilities/use-shortcuts';
import DocumentTitle from './DocumentTitle';
import EditorNavProtection from './EditorNavProtection';
import EditorPaneRightSidebar from './EditorPaneRightSidebar';
import EditorPaneSchemaSidebar from './EditorPaneSchemaSidebar';
import EditorPaneVis from './EditorPaneVis';
import NotFoundModal from './NotFoundModal';
import QueryEditorResultPane from './QueryEditorResultPane';
import QueryEditorSqlEditor from './QueryEditorSqlEditor';
import QuerySaveModal from './QuerySaveModal';
import Toolbar from './Toolbar';
import UnsavedQuerySelector from './UnsavedQuerySelector';
interface Params {
queryId?: string;
}
function QueryEditor() {
const [showNotFound, setShowNotFound] = useState(false);
const { queryId = '' } = useParams<Params>();
useShortcuts();
// On queryId change from URL string, load query as needed.
// If queryId does not exist, it is because the route is hitting `/queries/new` which avoids sending a queryId param
// In the case of new query, the state is already set.
// Either user landed here fresh (new query is set by default)
// or they clicked new query button, which resets state on click.
// Calling resetNewQuery here should not be necessary.
// If query is not found, show the not found modal to inform user and prompt to start new query.
useEffect(() => {
setShowNotFound(false);
if (queryId === '') {
connectConnectionClient();
} else if (queryId) {
loadQuery(queryId).then(({ error, data }) => {
if (error || !data) {
return setShowNotFound(true);
}
connectConnectionClient();
});
}
}, [queryId]);
return (
<div
style={{
height: '100vh',
width: '100%',
display: 'flex',
flexDirection: 'column',
}}
>
<AppHeader />
<Toolbar />
<div style={{ position: 'relative', flexGrow: 1 }}>
<EditorPaneRightSidebar queryId={queryId}>
<EditorPaneSchemaSidebar queryId={queryId}>
{/* @ts-expect-error SplitPane types are off */}
<SplitPane
split="horizontal"
minSize={100}
defaultSize={'60%'}
maxSize={-100}
onChange={() => debouncedResizeChart(queryId)}
>
<EditorPaneVis queryId={queryId}>
<QueryEditorSqlEditor />
</EditorPaneVis>
<QueryEditorResultPane />
</SplitPane>
</EditorPaneSchemaSidebar>
</EditorPaneRightSidebar>
</div>
<UnsavedQuerySelector queryId={queryId} />
<DocumentTitle queryId={queryId} />
<SchemaInfoLoader />
<QuerySaveModal />
<NotFoundModal visible={showNotFound} queryId={queryId} />
<EditorNavProtection />
</div>
);
}
export default QueryEditor;