ydb-embedded-ui 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +8 -0
- package/README.md +28 -0
- package/dist/HOCS/WithSearch/WithSearch.js +26 -0
- package/dist/HOCS/index.js +1 -0
- package/dist/assets/icons/bug.svg +1 -0
- package/dist/assets/icons/close.svg +1 -0
- package/dist/assets/icons/control-menu-button.svg +1 -0
- package/dist/assets/icons/databases.svg +3 -0
- package/dist/assets/icons/dots.svg +1 -0
- package/dist/assets/icons/server.svg +1 -0
- package/dist/assets/icons/settings-with-dot.svg +1 -0
- package/dist/assets/icons/settings.svg +1 -0
- package/dist/assets/icons/signIn.svg +1 -0
- package/dist/assets/icons/signOut.svg +1 -0
- package/dist/assets/icons/star.svg +1 -0
- package/dist/assets/icons/storage.svg +1 -0
- package/dist/assets/icons/support.svg +1 -0
- package/dist/assets/icons/user-check.svg +1 -0
- package/dist/assets/icons/user-secret.svg +1 -0
- package/dist/assets/icons/ydb.svg +4 -0
- package/dist/components/AsideNavigation/AsideHeader.scss +148 -0
- package/dist/components/AsideNavigation/AsideHeader.tsx +388 -0
- package/dist/components/AsideNavigation/AsideHeaderFooterItem/AsideHeaderFooterItem.scss +82 -0
- package/dist/components/AsideNavigation/AsideHeaderFooterItem/AsideHeaderFooterItem.tsx +138 -0
- package/dist/components/AsideNavigation/AsideHeaderFooterSlot/AsideHeaderFooterSlot.tsx +33 -0
- package/dist/components/AsideNavigation/AsideHeaderFooterSlot/SlotsContext.tsx +49 -0
- package/dist/components/AsideNavigation/AsideHeaderTooltip/AsideHeaderTooltip.scss +16 -0
- package/dist/components/AsideNavigation/AsideHeaderTooltip/AsideHeaderTooltip.tsx +37 -0
- package/dist/components/AsideNavigation/CompositeBar/CompositeBar.scss +108 -0
- package/dist/components/AsideNavigation/CompositeBar/CompositeBar.tsx +282 -0
- package/dist/components/AsideNavigation/Content/Content.tsx +35 -0
- package/dist/components/AsideNavigation/Drawer/Drawer.scss +76 -0
- package/dist/components/AsideNavigation/Drawer/Drawer.tsx +134 -0
- package/dist/components/AsideNavigation/Drawer/index.ts +1 -0
- package/dist/components/AsideNavigation/Logo/Logo.scss +44 -0
- package/dist/components/AsideNavigation/Logo/Logo.tsx +82 -0
- package/dist/components/AsideNavigation/Settings/README.md +92 -0
- package/dist/components/AsideNavigation/Settings/Settings.scss +113 -0
- package/dist/components/AsideNavigation/Settings/Settings.tsx +270 -0
- package/dist/components/AsideNavigation/Settings/SettingsMenu/SettingsMenu.scss +70 -0
- package/dist/components/AsideNavigation/Settings/SettingsMenu/SettingsMenu.tsx +141 -0
- package/dist/components/AsideNavigation/Settings/SettingsSearch/SettingsSearch.tsx +57 -0
- package/dist/components/AsideNavigation/Settings/collect-settings.ts +156 -0
- package/dist/components/AsideNavigation/Settings/filter-settings.ts +38 -0
- package/dist/components/AsideNavigation/Settings/helpers.ts +39 -0
- package/dist/components/AsideNavigation/Settings/i18n/en.json +5 -0
- package/dist/components/AsideNavigation/Settings/i18n/index.ts +11 -0
- package/dist/components/AsideNavigation/Settings/i18n/ru.json +5 -0
- package/dist/components/AsideNavigation/Settings/index.ts +1 -0
- package/dist/components/AsideNavigation/constants.ts +28 -0
- package/dist/components/AsideNavigation/helpers.ts +34 -0
- package/dist/components/AsideNavigation/i18n/en.json +4 -0
- package/dist/components/AsideNavigation/i18n/index.ts +11 -0
- package/dist/components/AsideNavigation/i18n/ru.json +4 -0
- package/dist/components/AsideNavigation/icons.ts +32 -0
- package/dist/components/AsideNavigation/types.ts +23 -0
- package/dist/components/Breadcrumbs/Breadcrumbs.js +25 -0
- package/dist/components/Breadcrumbs/Breadcrumbs.scss +4 -0
- package/dist/components/ClusterInfo/ClusterInfo.scss +65 -0
- package/dist/components/ClusterInfo/ClusterInfo.tsx +157 -0
- package/dist/components/Collapse/Collapse.js +84 -0
- package/dist/components/Collapse/Collapse.scss +70 -0
- package/dist/components/CriticalActionDialog/CriticalActionDialog.js +53 -0
- package/dist/components/CriticalActionDialog/CriticalActionDialog.scss +31 -0
- package/dist/components/EmptyState/EmptyState.js +48 -0
- package/dist/components/EmptyState/EmptyState.scss +70 -0
- package/dist/components/EntityStatus/EntityStatus.js +96 -0
- package/dist/components/EntityStatus/EntityStatus.scss +81 -0
- package/dist/components/FullGroupViewer/FullGroupViewer.js +149 -0
- package/dist/components/FullGroupViewer/FullGroupViewer.scss +32 -0
- package/dist/components/FullNodeViewer/FullNodeViewer.js +108 -0
- package/dist/components/FullNodeViewer/FullNodeViewer.scss +78 -0
- package/dist/components/GroupTreeViewer/GroupTreeViewer.js +86 -0
- package/dist/components/GroupTreeViewer/GroupTreeViewer.scss +17 -0
- package/dist/components/GroupViewer/GroupViewer.js +100 -0
- package/dist/components/GroupViewer/GroupViewer.scss +41 -0
- package/dist/components/Hotkey/Hotkey.js +102 -0
- package/dist/components/Icon/Icon.js +26 -0
- package/dist/components/InfoViewer/InfoViewer.js +47 -0
- package/dist/components/InfoViewer/InfoViewer.scss +48 -0
- package/dist/components/InternalLink/InternalLink.js +15 -0
- package/dist/components/NodesViewer/NodesViewer.js +183 -0
- package/dist/components/NodesViewer/NodesViewer.scss +66 -0
- package/dist/components/PDiskViewer/PDiskViewer.js +80 -0
- package/dist/components/PDiskViewer/PDiskViewer.scss +40 -0
- package/dist/components/Pagination/Pagination.js +63 -0
- package/dist/components/Pagination/Pagination.scss +25 -0
- package/dist/components/PoolBar/PoolBar.js +52 -0
- package/dist/components/PoolBar/PoolBar.scss +40 -0
- package/dist/components/PoolUsage/PoolUsage.js +54 -0
- package/dist/components/PoolUsage/PoolUsage.scss +65 -0
- package/dist/components/PoolsGraph/PoolsGraph.js +33 -0
- package/dist/components/PoolsGraph/PoolsGraph.scss +3 -0
- package/dist/components/ProblemFilter/ProblemFilter.js +24 -0
- package/dist/components/ProgressViewer/ProgressViewer.js +92 -0
- package/dist/components/ProgressViewer/ProgressViewer.scss +84 -0
- package/dist/components/SplitPane/SplitPane.js +368 -0
- package/dist/components/SplitPane/SplitPane.scss +107 -0
- package/dist/components/SplitPane/index.js +3 -0
- package/dist/components/Tablet/Tablet.js +61 -0
- package/dist/components/Tablet/Tablet.scss +49 -0
- package/dist/components/TabletsStatistic/TabletsStatistic.js +58 -0
- package/dist/components/TabletsStatistic/TabletsStatistic.scss +41 -0
- package/dist/components/TabletsViewer/TabletsViewer.js +44 -0
- package/dist/components/TabletsViewer/TabletsViewer.scss +37 -0
- package/dist/components/Tag/Tag.js +14 -0
- package/dist/components/Tag/Tag.scss +17 -0
- package/dist/components/Tags/Tags.js +36 -0
- package/dist/components/Tags/Tags.scss +5 -0
- package/dist/components/TenantOverview/TenantOverview.js +148 -0
- package/dist/components/TenantOverview/TenantOverview.scss +75 -0
- package/dist/components/TreeView/TreeView.js +60 -0
- package/dist/components/TreeView/TreeView.scss +30 -0
- package/dist/components/TruncatedQuery/TruncatedQuery.js +26 -0
- package/dist/components/TruncatedQuery/TruncatedQuery.scss +12 -0
- package/dist/containers/App/App.js +67 -0
- package/dist/containers/App/App.scss +154 -0
- package/dist/containers/App/Content.js +109 -0
- package/dist/containers/App/TipPopup/TipPopup.js +66 -0
- package/dist/containers/App/TipPopup/TipPopup.scss +42 -0
- package/dist/containers/AppIcons/AppIcons.js +477 -0
- package/dist/containers/AsideNavigation/AsideNavigation.scss +43 -0
- package/dist/containers/AsideNavigation/AsideNavigation.tsx +228 -0
- package/dist/containers/Authentication/Authentication.scss +37 -0
- package/dist/containers/Authentication/Authentication.tsx +89 -0
- package/dist/containers/Cluster/Cluster.js +168 -0
- package/dist/containers/Cluster/Cluster.scss +52 -0
- package/dist/containers/Group/Group.js +97 -0
- package/dist/containers/Group/Group.scss +6 -0
- package/dist/containers/Header/Header.js +88 -0
- package/dist/containers/Header/Header.scss +72 -0
- package/dist/containers/Header/Host/Host.js +66 -0
- package/dist/containers/Header/Host/Host.scss +43 -0
- package/dist/containers/Heatmap/Heatmap.js +246 -0
- package/dist/containers/Heatmap/Heatmap.scss +94 -0
- package/dist/containers/Heatmap/HeatmapCanvas/HeatmapCanvas.js +167 -0
- package/dist/containers/Heatmap/Histogram/Histogram.js +108 -0
- package/dist/containers/Heatmap/Histogram/Histogram.scss +49 -0
- package/dist/containers/Heatmap/util.js +110 -0
- package/dist/containers/Node/Node.js +184 -0
- package/dist/containers/Node/Node.scss +34 -0
- package/dist/containers/Node/NodePages.js +13 -0
- package/dist/containers/Nodes/Nodes.js +193 -0
- package/dist/containers/Nodes/Nodes.scss +50 -0
- package/dist/containers/Pdisk/Pdisk.js +159 -0
- package/dist/containers/Pdisk/Pdisk.scss +40 -0
- package/dist/containers/Pool/Pool.js +169 -0
- package/dist/containers/Pool/Pool.scss +32 -0
- package/dist/containers/ReduxTooltip/ReduxTooltip.js +108 -0
- package/dist/containers/ReduxTooltip/ReduxTooltip.scss +67 -0
- package/dist/containers/StorageV2/DiskStateProgressBar/DiskStateProgressBar.scss +81 -0
- package/dist/containers/StorageV2/DiskStateProgressBar/DiskStateProgressBar.tsx +56 -0
- package/dist/containers/StorageV2/Pdisk/Pdisk.scss +32 -0
- package/dist/containers/StorageV2/Pdisk/Pdisk.tsx +167 -0
- package/dist/containers/StorageV2/Storage.js +249 -0
- package/dist/containers/StorageV2/Storage.scss +57 -0
- package/dist/containers/StorageV2/StorageFilter/StorageFilter.js +39 -0
- package/dist/containers/StorageV2/StorageGroups/StorageGroups.scss +26 -0
- package/dist/containers/StorageV2/StorageGroups/StorageGroups.tsx +234 -0
- package/dist/containers/StorageV2/StorageNodes/StorageNodes.scss +30 -0
- package/dist/containers/StorageV2/StorageNodes/StorageNodes.tsx +135 -0
- package/dist/containers/StorageV2/Vdisk/Vdisk.js +250 -0
- package/dist/containers/StorageV2/Vdisk/Vdisk.scss +32 -0
- package/dist/containers/Tablet/Tablet.js +453 -0
- package/dist/containers/Tablet/Tablet.scss +88 -0
- package/dist/containers/Tablets/Tablets.js +306 -0
- package/dist/containers/Tablets/Tablets.scss +77 -0
- package/dist/containers/TabletsFilters/TabletsFilters.js +412 -0
- package/dist/containers/TabletsFilters/TabletsFilters.scss +104 -0
- package/dist/containers/Tenant/Acl/Acl.js +149 -0
- package/dist/containers/Tenant/Acl/Acl.scss +34 -0
- package/dist/containers/Tenant/Compute/Compute.js +110 -0
- package/dist/containers/Tenant/Compute/Compute.scss +6 -0
- package/dist/containers/Tenant/Describe/Describe.js +81 -0
- package/dist/containers/Tenant/Describe/Describe.scss +25 -0
- package/dist/containers/Tenant/Healthcheck/Healthcheck.js +116 -0
- package/dist/containers/Tenant/Healthcheck/Healthcheck.scss +64 -0
- package/dist/containers/Tenant/Healthcheck/IssuesViewer/IssueViewer.scss +164 -0
- package/dist/containers/Tenant/Healthcheck/IssuesViewer/IssuesViewer.js +185 -0
- package/dist/containers/Tenant/Network/Network.js +341 -0
- package/dist/containers/Tenant/Network/Network.scss +145 -0
- package/dist/containers/Tenant/Network/NodeNetwork/NodeNetwork.js +71 -0
- package/dist/containers/Tenant/Network/NodeNetwork/NodeNetwork.scss +52 -0
- package/dist/containers/Tenant/Preview/Preview.js +169 -0
- package/dist/containers/Tenant/Preview/Preview.scss +20 -0
- package/dist/containers/Tenant/QueryEditor/QueryEditor.js +649 -0
- package/dist/containers/Tenant/QueryEditor/QueryEditor.scss +71 -0
- package/dist/containers/Tenant/QueryEditor/QueryExplain/QueryExplain.js +168 -0
- package/dist/containers/Tenant/QueryEditor/QueryExplain/QueryExplain.scss +42 -0
- package/dist/containers/Tenant/QueryEditor/QueryResult/QueryResult.js +58 -0
- package/dist/containers/Tenant/QueryEditor/QueryResult/QueryResult.scss +24 -0
- package/dist/containers/Tenant/QueryEditor/SaveQuery/SaveQuery.js +171 -0
- package/dist/containers/Tenant/QueryEditor/SaveQuery/SaveQuery.scss +51 -0
- package/dist/containers/Tenant/QueryEditor/SavedQueries/SavedQueries.js +156 -0
- package/dist/containers/Tenant/QueryEditor/SavedQueries/SavedQueries.scss +82 -0
- package/dist/containers/Tenant/Schema/HotKeys/HotKeys.js +149 -0
- package/dist/containers/Tenant/Schema/HotKeys/HotKeys.scss +48 -0
- package/dist/containers/Tenant/Schema/Info/Info.js +84 -0
- package/dist/containers/Tenant/Schema/Info/Info.scss +3 -0
- package/dist/containers/Tenant/Schema/SchemaInfoViewer/SchemaInfoViewer.js +67 -0
- package/dist/containers/Tenant/Schema/SchemaInfoViewer/SchemaInfoViewer.scss +21 -0
- package/dist/containers/Tenant/Schema/SchemaMain/SchemaMain.js +439 -0
- package/dist/containers/Tenant/Schema/SchemaMain/SchemaMain.scss +90 -0
- package/dist/containers/Tenant/Schema/SchemaNode/SchemaNode.js +150 -0
- package/dist/containers/Tenant/Schema/SchemaNode/SchemaNode.scss +41 -0
- package/dist/containers/Tenant/Schema/SchemaPages.js +56 -0
- package/dist/containers/Tenant/Schema/SchemaTree/SchemaTree.js +115 -0
- package/dist/containers/Tenant/Schema/SchemaTree/SchemaTree.scss +13 -0
- package/dist/containers/Tenant/Schema/SchemaViewer/SchemaViewer.js +63 -0
- package/dist/containers/Tenant/Schema/SchemaViewer/SchemaViewer.scss +28 -0
- package/dist/containers/Tenant/Tenant.js +199 -0
- package/dist/containers/Tenant/Tenant.scss +94 -0
- package/dist/containers/Tenant/TenantPages.js +35 -0
- package/dist/containers/Tenant/TopQueries/TopQueries.js +184 -0
- package/dist/containers/Tenant/TopQueries/TopQueries.scss +53 -0
- package/dist/containers/Tenant/TopShards/TopShards.js +171 -0
- package/dist/containers/Tenant/TopShards/TopShards.scss +23 -0
- package/dist/containers/Tenants/Tenants.js +375 -0
- package/dist/containers/Tenants/Tenants.scss +73 -0
- package/dist/containers/UserSettings/UserSettings.tsx +57 -0
- package/dist/containers/Vdisk/Vdisk.js +160 -0
- package/dist/containers/Vdisk/Vdisk.scss +40 -0
- package/dist/containers/VdiskPdiskNode/VdiskPdiskNode.js +528 -0
- package/dist/containers/VdiskPdiskNode/VdiskPdiskNode.scss +60 -0
- package/dist/contexts/HistoryContext.ts +6 -0
- package/dist/index.css +11 -0
- package/dist/index.js +28 -0
- package/dist/index.test.js +5 -0
- package/dist/react-app-env.d.ts +1 -0
- package/dist/reportWebVitals.js +13 -0
- package/dist/routes.js +40 -0
- package/dist/services/api.js +224 -0
- package/dist/setupTests.js +5 -0
- package/dist/store/index.js +61 -0
- package/dist/store/reducers/authentication.js +77 -0
- package/dist/store/reducers/cluster.js +52 -0
- package/dist/store/reducers/clusterInfo.js +48 -0
- package/dist/store/reducers/clusterNodes.js +70 -0
- package/dist/store/reducers/describe.js +45 -0
- package/dist/store/reducers/executeQuery.js +158 -0
- package/dist/store/reducers/executeTopQueries.js +69 -0
- package/dist/store/reducers/explainQuery.js +174 -0
- package/dist/store/reducers/group.js +49 -0
- package/dist/store/reducers/healthcheckInfo.js +45 -0
- package/dist/store/reducers/heatmap.js +105 -0
- package/dist/store/reducers/host.js +44 -0
- package/dist/store/reducers/hotKeys.js +57 -0
- package/dist/store/reducers/index.js +78 -0
- package/dist/store/reducers/network.js +45 -0
- package/dist/store/reducers/node.js +42 -0
- package/dist/store/reducers/nodes.js +58 -0
- package/dist/store/reducers/olapStats.js +74 -0
- package/dist/store/reducers/pdisk.js +51 -0
- package/dist/store/reducers/pool.js +42 -0
- package/dist/store/reducers/preview.js +73 -0
- package/dist/store/reducers/schema.js +95 -0
- package/dist/store/reducers/schemaAcl.js +44 -0
- package/dist/store/reducers/settings.js +76 -0
- package/dist/store/reducers/shardsWorkload.js +75 -0
- package/dist/store/reducers/storage.js +280 -0
- package/dist/store/reducers/tablet.js +94 -0
- package/dist/store/reducers/tablets.js +90 -0
- package/dist/store/reducers/tabletsFilters.js +126 -0
- package/dist/store/reducers/tenant.js +76 -0
- package/dist/store/reducers/tenants.js +61 -0
- package/dist/store/reducers/tooltip.js +64 -0
- package/dist/store/reducers/vdisk.js +49 -0
- package/dist/store/state-url-mapping.js +133 -0
- package/dist/store/utils.js +55 -0
- package/dist/styles/mixins.scss +254 -0
- package/dist/styles/react-treeview.scss +45 -0
- package/dist/types/assets.d.ts +12 -0
- package/dist/types/react-list.d.ts +4 -0
- package/dist/types/window.d.ts +33 -0
- package/dist/utils/actionsConstants.js +4 -0
- package/dist/utils/constants.js +126 -0
- package/dist/utils/getNodesColumns.js +156 -0
- package/dist/utils/i18n/i18n.ts +7 -0
- package/dist/utils/i18n/index.ts +1 -0
- package/dist/utils/index.js +136 -0
- package/dist/utils/monaco.js +69 -0
- package/dist/utils/prepareQueryExplain.ts +101 -0
- package/dist/utils/tooltip.js +197 -0
- package/dist/utils/utils.js +75 -0
- package/package.json +89 -0
@@ -0,0 +1,649 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import PropTypes from 'prop-types';
|
3
|
+
import {connect} from 'react-redux';
|
4
|
+
import cn from 'bem-cn-lite';
|
5
|
+
import _ from 'lodash';
|
6
|
+
import MonacoEditor from 'react-monaco-editor';
|
7
|
+
import DataTable from '@yandex-cloud/react-data-table';
|
8
|
+
import {Button, Toaster, CopyToClipboard} from '@yandex-cloud/uikit';
|
9
|
+
import {Select} from '@yandex-cloud/uikit/build/esm/components/unstable/Select';
|
10
|
+
import SplitPane from '../../../components/SplitPane';
|
11
|
+
|
12
|
+
import Pagination from '../../../components/Pagination/Pagination';
|
13
|
+
import SaveQuery from './SaveQuery/SaveQuery';
|
14
|
+
import Icon from '../../../components/Icon/Icon';
|
15
|
+
import QueryResult from './QueryResult/QueryResult';
|
16
|
+
import QueryExplain from './QueryExplain/QueryExplain';
|
17
|
+
|
18
|
+
import {
|
19
|
+
sendQuery,
|
20
|
+
changeUserInput,
|
21
|
+
saveQueryToHistory,
|
22
|
+
goToPreviousQuery,
|
23
|
+
goToNextQuery,
|
24
|
+
selectRunAction,
|
25
|
+
RUN_ACTIONS_VALUES,
|
26
|
+
} from '../../../store/reducers/executeQuery';
|
27
|
+
import {getExplainQuery, getExplainQueryAst} from '../../../store/reducers/explainQuery';
|
28
|
+
import {showTooltip} from '../../../store/reducers/tooltip';
|
29
|
+
import {getSettingValue, setSettingValue} from '../../../store/reducers/settings';
|
30
|
+
import {THEME_KEY, DEFAULT_SIZE_RESULT_PANE_KEY, SAVED_QUERIES_KEY} from '../../../utils/constants';
|
31
|
+
import {prepareQueryResponse} from '../../../utils/index';
|
32
|
+
|
33
|
+
import {parseJson} from '../../../utils/utils';
|
34
|
+
|
35
|
+
import './QueryEditor.scss';
|
36
|
+
|
37
|
+
const toaster = new Toaster();
|
38
|
+
|
39
|
+
export const RUN_ACTIONS = [
|
40
|
+
{value: RUN_ACTIONS_VALUES.script, content: 'Run Script'},
|
41
|
+
{value: RUN_ACTIONS_VALUES.scan, content: 'Run Scan'},
|
42
|
+
];
|
43
|
+
|
44
|
+
const TABLE_SETTINGS = {
|
45
|
+
displayIndices: false,
|
46
|
+
syncHeadOnResize: true,
|
47
|
+
stickyHead: DataTable.MOVING,
|
48
|
+
sortable: false,
|
49
|
+
};
|
50
|
+
const EDITOR_OPTIONS = {
|
51
|
+
automaticLayout: true,
|
52
|
+
selectOnLineNumbers: true,
|
53
|
+
minimap: {
|
54
|
+
enabled: false,
|
55
|
+
},
|
56
|
+
};
|
57
|
+
|
58
|
+
const CONTEXT_MENU_GROUP_ID = 'navigation';
|
59
|
+
const RESULT_TYPES = {
|
60
|
+
EXECUTE: 'execute',
|
61
|
+
EXPLAIN: 'explain',
|
62
|
+
};
|
63
|
+
|
64
|
+
const b = cn('query-editor');
|
65
|
+
|
66
|
+
class QueryEditor extends React.Component {
|
67
|
+
static propTypes = {
|
68
|
+
sendQuery: PropTypes.func,
|
69
|
+
path: PropTypes.string,
|
70
|
+
response: PropTypes.oneOfType([PropTypes.bool, PropTypes.array]),
|
71
|
+
executeQuery: PropTypes.object,
|
72
|
+
explainQuery: PropTypes.object,
|
73
|
+
showTooltip: PropTypes.func,
|
74
|
+
theme: PropTypes.string,
|
75
|
+
};
|
76
|
+
|
77
|
+
state = {
|
78
|
+
resultType: RESULT_TYPES.EXECUTE,
|
79
|
+
runAction: RUN_ACTIONS[0].value,
|
80
|
+
};
|
81
|
+
|
82
|
+
editorRef = null;
|
83
|
+
|
84
|
+
componentDidMount() {
|
85
|
+
this.updateEditor();
|
86
|
+
|
87
|
+
window.addEventListener('resize', this.onChangeWindow);
|
88
|
+
window.addEventListener('storage', this.storageEventHandler);
|
89
|
+
}
|
90
|
+
|
91
|
+
checkIfHasUnsavedInput(e) {
|
92
|
+
e.preventDefault();
|
93
|
+
// Chrome requires returnValue to be set
|
94
|
+
e.returnValue = '';
|
95
|
+
}
|
96
|
+
|
97
|
+
componentWillUnmount() {
|
98
|
+
window.removeEventListener('resize', this.onChangeWindow);
|
99
|
+
window.removeEventListener('storage', this.storageEventHandler);
|
100
|
+
window.onbeforeunload = undefined;
|
101
|
+
}
|
102
|
+
|
103
|
+
componentDidUpdate() {
|
104
|
+
const {
|
105
|
+
explainQuery: {data},
|
106
|
+
executeQuery: {input, history},
|
107
|
+
} = this.props;
|
108
|
+
|
109
|
+
const hasUnsavedInput = input
|
110
|
+
? input !== history.queries[history.queries?.length - 1]
|
111
|
+
: false;
|
112
|
+
|
113
|
+
if (hasUnsavedInput) {
|
114
|
+
window.onbeforeunload = this.checkIfHasUnsavedInput;
|
115
|
+
} else {
|
116
|
+
window.onbeforeunload = undefined;
|
117
|
+
}
|
118
|
+
|
119
|
+
if (!data || this.state.resultType !== RESULT_TYPES.EXPLAIN) {
|
120
|
+
return;
|
121
|
+
}
|
122
|
+
}
|
123
|
+
|
124
|
+
editorDidMount = (editor, monaco) => {
|
125
|
+
this.editorRef = editor;
|
126
|
+
editor.focus();
|
127
|
+
editor.addAction({
|
128
|
+
id: 'run',
|
129
|
+
label: 'Run',
|
130
|
+
keybindings: [
|
131
|
+
// eslint-disable-next-line no-bitwise
|
132
|
+
monaco.KeyMod.CtrlCmd | monaco.KeyCode.Enter,
|
133
|
+
],
|
134
|
+
// A precondition for this action.
|
135
|
+
precondition: null,
|
136
|
+
// A rule to evaluate on top of the precondition in order to dispatch the keybindings.
|
137
|
+
keybindingContext: null,
|
138
|
+
contextMenuGroupId: CONTEXT_MENU_GROUP_ID,
|
139
|
+
contextMenuOrder: 1,
|
140
|
+
// Method that will be executed when the action is triggered.
|
141
|
+
// @param editor The editor instance is passed in as a convinience
|
142
|
+
run: () => {
|
143
|
+
this.handleSendClick();
|
144
|
+
},
|
145
|
+
});
|
146
|
+
|
147
|
+
editor.addAction({
|
148
|
+
id: 'previous-query',
|
149
|
+
label: 'Previous query',
|
150
|
+
keybindings: [
|
151
|
+
// eslint-disable-next-line no-bitwise
|
152
|
+
monaco.KeyMod.CtrlCmd | monaco.KeyCode.UpArrow,
|
153
|
+
],
|
154
|
+
contextMenuGroupId: CONTEXT_MENU_GROUP_ID,
|
155
|
+
contextMenuOrder: 2,
|
156
|
+
run: () => {
|
157
|
+
this.handlePreviousHistoryClick();
|
158
|
+
},
|
159
|
+
});
|
160
|
+
editor.addAction({
|
161
|
+
id: 'next-query',
|
162
|
+
label: 'Next query',
|
163
|
+
keybindings: [
|
164
|
+
// eslint-disable-next-line no-bitwise
|
165
|
+
monaco.KeyMod.CtrlCmd | monaco.KeyCode.DownArrow,
|
166
|
+
],
|
167
|
+
contextMenuGroupId: CONTEXT_MENU_GROUP_ID,
|
168
|
+
contextMenuOrder: 3,
|
169
|
+
run: () => {
|
170
|
+
this.handleNextHistoryClick();
|
171
|
+
},
|
172
|
+
});
|
173
|
+
|
174
|
+
editor.addAction({
|
175
|
+
id: 'explain',
|
176
|
+
label: 'Explain',
|
177
|
+
keybindings: [
|
178
|
+
// eslint-disable-next-line no-bitwise
|
179
|
+
monaco.KeyMod.CtrlCmd | monaco.KeyCode.KEY_E,
|
180
|
+
],
|
181
|
+
// A precondition for this action.
|
182
|
+
precondition: null,
|
183
|
+
// A rule to evaluate on top of the precondition in order to dispatch the keybindings.
|
184
|
+
keybindingContext: null,
|
185
|
+
contextMenuGroupId: CONTEXT_MENU_GROUP_ID,
|
186
|
+
contextMenuOrder: 4,
|
187
|
+
run: () => {
|
188
|
+
this.handleGetExplainQueryClick();
|
189
|
+
},
|
190
|
+
});
|
191
|
+
};
|
192
|
+
onChange = (newValue) => {
|
193
|
+
this.props.changeUserInput({input: newValue});
|
194
|
+
};
|
195
|
+
|
196
|
+
handleSendClick = () => {
|
197
|
+
const {
|
198
|
+
path,
|
199
|
+
executeQuery: {input, history, runAction},
|
200
|
+
sendQuery,
|
201
|
+
saveQueryToHistory,
|
202
|
+
} = this.props;
|
203
|
+
|
204
|
+
this.setState({resultType: RESULT_TYPES.EXECUTE});
|
205
|
+
sendQuery({query: input, database: path, action: runAction});
|
206
|
+
|
207
|
+
const {queries, currentIndex} = history;
|
208
|
+
if (input !== queries[currentIndex]) {
|
209
|
+
saveQueryToHistory(input);
|
210
|
+
}
|
211
|
+
};
|
212
|
+
|
213
|
+
handleCancelClick = () => {
|
214
|
+
this.props.cancelQuery();
|
215
|
+
};
|
216
|
+
|
217
|
+
handleGetExplainQueryClick = () => {
|
218
|
+
const {
|
219
|
+
path,
|
220
|
+
executeQuery: {input},
|
221
|
+
getExplainQuery,
|
222
|
+
} = this.props;
|
223
|
+
|
224
|
+
this.setState({resultType: RESULT_TYPES.EXPLAIN}, () => {
|
225
|
+
getExplainQuery({query: input, database: path});
|
226
|
+
});
|
227
|
+
};
|
228
|
+
|
229
|
+
handleAstQuery = () => {
|
230
|
+
const {
|
231
|
+
path,
|
232
|
+
executeQuery: {input},
|
233
|
+
getExplainQueryAst,
|
234
|
+
} = this.props;
|
235
|
+
getExplainQueryAst({query: input, database: path});
|
236
|
+
};
|
237
|
+
|
238
|
+
renderExecuteQuery = () => {
|
239
|
+
const {
|
240
|
+
executeQuery: {data, error, stats},
|
241
|
+
showTooltip,
|
242
|
+
} = this.props;
|
243
|
+
const result = this.getExecuteResult();
|
244
|
+
const shouldRenderAnswer = result.length || error;
|
245
|
+
|
246
|
+
if (!shouldRenderAnswer) {
|
247
|
+
return null;
|
248
|
+
}
|
249
|
+
|
250
|
+
let columns = [];
|
251
|
+
if (data && data.length > 0) {
|
252
|
+
columns = Object.keys(data[0]).map((key) => ({
|
253
|
+
name: key,
|
254
|
+
render: ({value}) => {
|
255
|
+
return (
|
256
|
+
<span
|
257
|
+
className={b('cell')}
|
258
|
+
onClick={(e) => showTooltip(e.target, value, 'cell')}
|
259
|
+
>
|
260
|
+
{value}
|
261
|
+
</span>
|
262
|
+
);
|
263
|
+
},
|
264
|
+
}));
|
265
|
+
}
|
266
|
+
|
267
|
+
const preparedData = prepareQueryResponse(data);
|
268
|
+
const content = columns.length ? (
|
269
|
+
<DataTable
|
270
|
+
columns={columns}
|
271
|
+
data={preparedData}
|
272
|
+
settings={TABLE_SETTINGS}
|
273
|
+
theme="common"
|
274
|
+
/>
|
275
|
+
) : (
|
276
|
+
<div>{result}</div>
|
277
|
+
);
|
278
|
+
return <QueryResult result={content} stats={stats} />;
|
279
|
+
};
|
280
|
+
|
281
|
+
renderExplainQuery = () => {
|
282
|
+
const {
|
283
|
+
explainQuery: {data, dataAst, error, loading, loadingAst},
|
284
|
+
theme,
|
285
|
+
} = this.props;
|
286
|
+
|
287
|
+
if (error) {
|
288
|
+
return error.data ? error.data : error;
|
289
|
+
} else if (!data && !loading) {
|
290
|
+
return 'Explain of query is empty';
|
291
|
+
} else if (!data) {
|
292
|
+
return null;
|
293
|
+
} else if (!data.nodes.length) {
|
294
|
+
return 'There is no explanation for the request';
|
295
|
+
}
|
296
|
+
|
297
|
+
return (
|
298
|
+
<QueryExplain
|
299
|
+
explain={data}
|
300
|
+
astQuery={this.handleAstQuery}
|
301
|
+
ast={dataAst?.ast}
|
302
|
+
loadingAst={loadingAst}
|
303
|
+
theme={theme}
|
304
|
+
/>
|
305
|
+
);
|
306
|
+
};
|
307
|
+
|
308
|
+
renderResult = () => {
|
309
|
+
const {resultType} = this.state;
|
310
|
+
|
311
|
+
let result;
|
312
|
+
switch (resultType) {
|
313
|
+
case RESULT_TYPES.EXECUTE:
|
314
|
+
result = this.renderExecuteQuery();
|
315
|
+
break;
|
316
|
+
case RESULT_TYPES.EXPLAIN:
|
317
|
+
result = this.renderExplainQuery();
|
318
|
+
break;
|
319
|
+
default:
|
320
|
+
result = null;
|
321
|
+
}
|
322
|
+
|
323
|
+
return result;
|
324
|
+
};
|
325
|
+
|
326
|
+
handlePreviousHistoryClick = () => {
|
327
|
+
const {
|
328
|
+
changeUserInput,
|
329
|
+
executeQuery: {history},
|
330
|
+
goToPreviousQuery,
|
331
|
+
} = this.props;
|
332
|
+
const {queries, currentIndex} = history;
|
333
|
+
|
334
|
+
if (this.previousButtonIsDisabled()) {
|
335
|
+
return;
|
336
|
+
}
|
337
|
+
|
338
|
+
goToPreviousQuery();
|
339
|
+
changeUserInput({input: queries[currentIndex - 1]});
|
340
|
+
};
|
341
|
+
|
342
|
+
handleNextHistoryClick = () => {
|
343
|
+
const {
|
344
|
+
changeUserInput,
|
345
|
+
executeQuery: {history},
|
346
|
+
goToNextQuery,
|
347
|
+
} = this.props;
|
348
|
+
const {queries, currentIndex} = history;
|
349
|
+
|
350
|
+
if (this.nextButtonIsDisabled()) {
|
351
|
+
return;
|
352
|
+
}
|
353
|
+
|
354
|
+
goToNextQuery();
|
355
|
+
changeUserInput({input: queries[currentIndex + 1]});
|
356
|
+
};
|
357
|
+
|
358
|
+
previousButtonIsDisabled = () => {
|
359
|
+
const {
|
360
|
+
history: {currentIndex},
|
361
|
+
} = this.props.executeQuery;
|
362
|
+
|
363
|
+
return currentIndex <= 0;
|
364
|
+
};
|
365
|
+
|
366
|
+
nextButtonIsDisabled = () => {
|
367
|
+
const {
|
368
|
+
history: {queries, currentIndex},
|
369
|
+
} = this.props.executeQuery;
|
370
|
+
|
371
|
+
return queries.length - 1 === currentIndex;
|
372
|
+
};
|
373
|
+
|
374
|
+
renderHistoryNavigation = () => {
|
375
|
+
return (
|
376
|
+
<div className={b('history-controls')}>
|
377
|
+
<span className={b('history-label')}>History:</span>
|
378
|
+
<Pagination
|
379
|
+
previous={{
|
380
|
+
handler: this.handlePreviousHistoryClick,
|
381
|
+
hotkeyHandler: this.handlePreviousHistoryClick,
|
382
|
+
hotkeyScope: 'all',
|
383
|
+
hotkey: 'ctrl+up, command+up',
|
384
|
+
tooltip: 'Previous query [ctrl+↑]',
|
385
|
+
disabled: this.previousButtonIsDisabled(),
|
386
|
+
}}
|
387
|
+
next={{
|
388
|
+
handler: this.handleNextHistoryClick,
|
389
|
+
hotkeyHandler: this.handleNextHistoryClick,
|
390
|
+
hotkeyScope: 'all',
|
391
|
+
hotkey: 'ctrl+down, command+down',
|
392
|
+
tooltip: 'Next query [ctrl+↓]',
|
393
|
+
disabled: this.nextButtonIsDisabled(),
|
394
|
+
}}
|
395
|
+
/>
|
396
|
+
</div>
|
397
|
+
);
|
398
|
+
};
|
399
|
+
|
400
|
+
getExecuteResult = () => {
|
401
|
+
const {
|
402
|
+
data = [],
|
403
|
+
error,
|
404
|
+
loading,
|
405
|
+
history: {queries},
|
406
|
+
} = this.props.executeQuery;
|
407
|
+
|
408
|
+
if (error) {
|
409
|
+
return error.data || error;
|
410
|
+
} else if (data.length > 0) {
|
411
|
+
return data;
|
412
|
+
} else if (!loading && queries.length) {
|
413
|
+
return 'The request was successful';
|
414
|
+
} else {
|
415
|
+
return '';
|
416
|
+
}
|
417
|
+
};
|
418
|
+
|
419
|
+
getPreparedResult = () => {
|
420
|
+
const {
|
421
|
+
executeQuery: {data},
|
422
|
+
} = this.props;
|
423
|
+
const columnDivider = '\t';
|
424
|
+
const rowDivider = '\n';
|
425
|
+
|
426
|
+
if (!data?.length) {
|
427
|
+
return '';
|
428
|
+
}
|
429
|
+
|
430
|
+
const columnHeaders = Object.keys(data[0]);
|
431
|
+
const rows = [columnHeaders].concat(data);
|
432
|
+
|
433
|
+
return rows
|
434
|
+
.map((item) => {
|
435
|
+
const row = [];
|
436
|
+
|
437
|
+
for (const field in item) {
|
438
|
+
if (typeof item[field] === 'object' || Array.isArray(item[field])) {
|
439
|
+
row.push(JSON.stringify(item[field]));
|
440
|
+
} else {
|
441
|
+
row.push(item[field]);
|
442
|
+
}
|
443
|
+
}
|
444
|
+
|
445
|
+
return row.join(columnDivider);
|
446
|
+
})
|
447
|
+
.join(rowDivider);
|
448
|
+
};
|
449
|
+
|
450
|
+
renderClipboardButton = () => {
|
451
|
+
const results = this.getPreparedResult();
|
452
|
+
const {resultType} = this.state;
|
453
|
+
const disabled = !results.length || resultType !== RESULT_TYPES.EXECUTE;
|
454
|
+
|
455
|
+
return (
|
456
|
+
<CopyToClipboard text={results} timeout={1000}>
|
457
|
+
{(state) => {
|
458
|
+
if (state === 'success') {
|
459
|
+
toaster.createToast({
|
460
|
+
name: 'Copied',
|
461
|
+
title: 'Results were copied to clipboard successfully',
|
462
|
+
type: state,
|
463
|
+
});
|
464
|
+
}
|
465
|
+
|
466
|
+
return (
|
467
|
+
<Button onClick={() => {}} disabled={disabled}>
|
468
|
+
Copy results
|
469
|
+
</Button>
|
470
|
+
);
|
471
|
+
}}
|
472
|
+
</CopyToClipboard>
|
473
|
+
);
|
474
|
+
};
|
475
|
+
|
476
|
+
onChangeWindow = _.throttle(() => {
|
477
|
+
this.updateEditor();
|
478
|
+
}, 100);
|
479
|
+
|
480
|
+
storageEventHandler = (event) => {
|
481
|
+
if (event.key === SAVED_QUERIES_KEY) {
|
482
|
+
this.props.setSettingValue(SAVED_QUERIES_KEY, event.newValue);
|
483
|
+
}
|
484
|
+
};
|
485
|
+
|
486
|
+
updateEditor = () => {
|
487
|
+
if (this.editorRef) {
|
488
|
+
this.editorRef.layout();
|
489
|
+
}
|
490
|
+
};
|
491
|
+
|
492
|
+
onChangeSplit = (size) => {
|
493
|
+
this.setDefaultSizeResultPane(size);
|
494
|
+
this.updateEditor();
|
495
|
+
};
|
496
|
+
setDefaultSizeResultPane = (size) => {
|
497
|
+
localStorage.setItem(DEFAULT_SIZE_RESULT_PANE_KEY, size);
|
498
|
+
};
|
499
|
+
getDefaultSizeResultPane = () => {
|
500
|
+
let size = parseInt(localStorage.getItem(DEFAULT_SIZE_RESULT_PANE_KEY), 10) || 250;
|
501
|
+
size = `${size}px`;
|
502
|
+
|
503
|
+
return size;
|
504
|
+
};
|
505
|
+
|
506
|
+
onSaveQueryHandler = (queryName) => {
|
507
|
+
const {
|
508
|
+
executeQuery: {input},
|
509
|
+
savedQueries = [],
|
510
|
+
setSettingValue,
|
511
|
+
} = this.props;
|
512
|
+
|
513
|
+
const queryIndex = savedQueries.findIndex(
|
514
|
+
(el) => el.name.toLowerCase() === queryName.toLowerCase(),
|
515
|
+
);
|
516
|
+
const newSavedQueries = [...savedQueries];
|
517
|
+
const newQuery = {name: queryName, body: input};
|
518
|
+
if (queryIndex !== -1) {
|
519
|
+
newSavedQueries[queryIndex] = newQuery;
|
520
|
+
} else {
|
521
|
+
newSavedQueries.push(newQuery);
|
522
|
+
}
|
523
|
+
|
524
|
+
setSettingValue(SAVED_QUERIES_KEY, JSON.stringify(newSavedQueries));
|
525
|
+
};
|
526
|
+
|
527
|
+
onDeleteQueryHandler = (queryName) => {
|
528
|
+
const {savedQueries = [], setSettingValue} = this.props;
|
529
|
+
const newSavedQueries = savedQueries.filter(
|
530
|
+
(el) => el.name.toLowerCase() !== queryName.toLowerCase(),
|
531
|
+
);
|
532
|
+
setSettingValue(SAVED_QUERIES_KEY, JSON.stringify(newSavedQueries));
|
533
|
+
};
|
534
|
+
|
535
|
+
render() {
|
536
|
+
const {executeQuery, explainQuery, theme, savedQueries, changeUserInput} = this.props;
|
537
|
+
const {runAction} = executeQuery;
|
538
|
+
const runIsDisabled = !executeQuery.input || executeQuery.loading;
|
539
|
+
const runText = _.find(RUN_ACTIONS, {value: runAction}).title;
|
540
|
+
const loadingResult = executeQuery.loading || explainQuery.loading;
|
541
|
+
const result = this.renderResult();
|
542
|
+
const showSecondPane = Boolean(result) || loadingResult;
|
543
|
+
const defaultSizeResultPane = this.getDefaultSizeResultPane();
|
544
|
+
|
545
|
+
return (
|
546
|
+
<div className={b()}>
|
547
|
+
<SplitPane
|
548
|
+
split="horizontal"
|
549
|
+
primary="second"
|
550
|
+
minSize={100}
|
551
|
+
maxSize={-57}
|
552
|
+
defaultSize={defaultSizeResultPane}
|
553
|
+
hidePane={!showSecondPane}
|
554
|
+
pane1Style={{minHeight: '50px'}}
|
555
|
+
onChange={this.onChangeSplit}
|
556
|
+
>
|
557
|
+
<div className={b('pane-wrapper')}>
|
558
|
+
<div className={b('monaco-wrapper')}>
|
559
|
+
<div className={b('monaco')}>
|
560
|
+
<MonacoEditor
|
561
|
+
language="sql"
|
562
|
+
value={executeQuery.input}
|
563
|
+
options={EDITOR_OPTIONS}
|
564
|
+
onChange={this.onChange}
|
565
|
+
editorDidMount={this.editorDidMount}
|
566
|
+
theme={`vs-${theme}`}
|
567
|
+
/>
|
568
|
+
</div>
|
569
|
+
</div>
|
570
|
+
<div className={b('controls')}>
|
571
|
+
<div className={b('control-run')}>
|
572
|
+
<Button
|
573
|
+
onClick={this.handleSendClick}
|
574
|
+
view="action"
|
575
|
+
pin="round-brick"
|
576
|
+
disabled={runIsDisabled}
|
577
|
+
loading={executeQuery.loading}
|
578
|
+
>
|
579
|
+
{runText}
|
580
|
+
</Button>
|
581
|
+
<Select
|
582
|
+
options={RUN_ACTIONS}
|
583
|
+
value={runAction}
|
584
|
+
disabled={runIsDisabled}
|
585
|
+
renderSwitcher={() => (
|
586
|
+
<div className={b('run-switcher')}>
|
587
|
+
<Button
|
588
|
+
view="action"
|
589
|
+
pin="brick-round"
|
590
|
+
disabled={runIsDisabled}
|
591
|
+
loading={executeQuery.loading}
|
592
|
+
>
|
593
|
+
<Icon name="chevron-down" width={16} height={16} />
|
594
|
+
</Button>
|
595
|
+
</div>
|
596
|
+
)}
|
597
|
+
onUpdate={(value) => {
|
598
|
+
this.props.selectRunAction(value);
|
599
|
+
}}
|
600
|
+
/>
|
601
|
+
</div>
|
602
|
+
<Button
|
603
|
+
onClick={this.handleGetExplainQueryClick}
|
604
|
+
disabled={!executeQuery.input}
|
605
|
+
loading={explainQuery.loading}
|
606
|
+
>
|
607
|
+
Explain
|
608
|
+
</Button>
|
609
|
+
{this.renderHistoryNavigation()}
|
610
|
+
{this.renderClipboardButton()}
|
611
|
+
<SaveQuery
|
612
|
+
savedQueries={savedQueries}
|
613
|
+
onSaveQuery={this.onSaveQueryHandler}
|
614
|
+
saveButtonDisabled={runIsDisabled}
|
615
|
+
changeUserInput={changeUserInput}
|
616
|
+
onDeleteQuery={this.onDeleteQueryHandler}
|
617
|
+
/>
|
618
|
+
</div>
|
619
|
+
</div>
|
620
|
+
{showSecondPane && <div className={b('pane-wrapper')}>{result}</div>}
|
621
|
+
</SplitPane>
|
622
|
+
</div>
|
623
|
+
);
|
624
|
+
}
|
625
|
+
}
|
626
|
+
|
627
|
+
const mapStateToProps = (state) => {
|
628
|
+
return {
|
629
|
+
executeQuery: state.executeQuery,
|
630
|
+
explainQuery: state.explainQuery,
|
631
|
+
theme: getSettingValue(state, THEME_KEY),
|
632
|
+
savedQueries: parseJson(getSettingValue(state, SAVED_QUERIES_KEY)),
|
633
|
+
};
|
634
|
+
};
|
635
|
+
|
636
|
+
const mapDispatchToProps = {
|
637
|
+
sendQuery,
|
638
|
+
changeUserInput,
|
639
|
+
saveQueryToHistory,
|
640
|
+
goToPreviousQuery,
|
641
|
+
goToNextQuery,
|
642
|
+
showTooltip,
|
643
|
+
getExplainQuery,
|
644
|
+
getExplainQueryAst,
|
645
|
+
setSettingValue,
|
646
|
+
selectRunAction,
|
647
|
+
};
|
648
|
+
|
649
|
+
export default connect(mapStateToProps, mapDispatchToProps)(QueryEditor);
|