@quillsql/react 1.7.0 → 1.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/lib/AddToDashboardModal.js +249 -369
  2. package/lib/AddToDashboardModal.js.map +1 -1
  3. package/lib/BarList.js +92 -109
  4. package/lib/BarList.js.map +1 -1
  5. package/lib/Chart.js +364 -414
  6. package/lib/Chart.js.map +1 -1
  7. package/lib/Context.js +92 -84
  8. package/lib/Context.js.map +1 -1
  9. package/lib/Dashboard.js +181 -209
  10. package/lib/Dashboard.js.map +1 -1
  11. package/lib/DateRangePicker/Calendar.js +87 -91
  12. package/lib/DateRangePicker/Calendar.js.map +1 -1
  13. package/lib/DateRangePicker/DateRangePicker.js +70 -68
  14. package/lib/DateRangePicker/DateRangePicker.js.map +1 -1
  15. package/lib/DateRangePicker/DateRangePickerButton.js +46 -57
  16. package/lib/DateRangePicker/DateRangePickerButton.js.map +1 -1
  17. package/lib/DateRangePicker/dateRangePickerUtils.js +105 -99
  18. package/lib/DateRangePicker/dateRangePickerUtils.js.map +1 -1
  19. package/lib/DateRangePicker/index.js +8 -1
  20. package/lib/DateRangePicker/index.js.map +1 -1
  21. package/lib/PieChart.js +221 -225
  22. package/lib/PieChart.js.map +1 -1
  23. package/lib/QuillProvider.js +8 -18
  24. package/lib/QuillProvider.js.map +1 -1
  25. package/lib/ReportBuilder.js +430 -526
  26. package/lib/ReportBuilder.js.map +1 -1
  27. package/lib/SQLEditor.js +183 -268
  28. package/lib/SQLEditor.js.map +1 -1
  29. package/lib/Table.js +213 -256
  30. package/lib/Table.js.map +1 -1
  31. package/lib/TableChart.js +76 -75
  32. package/lib/TableChart.js.map +1 -1
  33. package/lib/assets/ArrowDownHeadIcon.js +5 -28
  34. package/lib/assets/ArrowDownHeadIcon.js.map +1 -1
  35. package/lib/assets/ArrowDownIcon.js +5 -28
  36. package/lib/assets/ArrowDownIcon.js.map +1 -1
  37. package/lib/assets/ArrowDownRightIcon.js +5 -28
  38. package/lib/assets/ArrowDownRightIcon.js.map +1 -1
  39. package/lib/assets/ArrowLeftHeadIcon.js +5 -28
  40. package/lib/assets/ArrowLeftHeadIcon.js.map +1 -1
  41. package/lib/assets/ArrowRightHeadIcon.js +5 -28
  42. package/lib/assets/ArrowRightHeadIcon.js.map +1 -1
  43. package/lib/assets/ArrowRightIcon.js +5 -28
  44. package/lib/assets/ArrowRightIcon.js.map +1 -1
  45. package/lib/assets/ArrowUpHeadIcon.js +5 -28
  46. package/lib/assets/ArrowUpHeadIcon.js.map +1 -1
  47. package/lib/assets/ArrowUpIcon.js +5 -28
  48. package/lib/assets/ArrowUpIcon.js.map +1 -1
  49. package/lib/assets/ArrowUpRightIcon.js +5 -28
  50. package/lib/assets/ArrowUpRightIcon.js.map +1 -1
  51. package/lib/assets/CalendarIcon.js +5 -28
  52. package/lib/assets/CalendarIcon.js.map +1 -1
  53. package/lib/assets/DoubleArrowLeftHeadIcon.js +5 -28
  54. package/lib/assets/DoubleArrowLeftHeadIcon.js.map +1 -1
  55. package/lib/assets/DoubleArrowRightHeadIcon.js +5 -28
  56. package/lib/assets/DoubleArrowRightHeadIcon.js.map +1 -1
  57. package/lib/assets/ExclamationFilledIcon.js +5 -28
  58. package/lib/assets/ExclamationFilledIcon.js.map +1 -1
  59. package/lib/assets/LoadingSpinner.js +5 -28
  60. package/lib/assets/LoadingSpinner.js.map +1 -1
  61. package/lib/assets/SearchIcon.js +5 -28
  62. package/lib/assets/SearchIcon.js.map +1 -1
  63. package/lib/assets/XCircleIcon.js +5 -28
  64. package/lib/assets/XCircleIcon.js.map +1 -1
  65. package/lib/assets/index.js +38 -16
  66. package/lib/assets/index.js.map +1 -1
  67. package/lib/components/BigModal/BigModal.js +45 -43
  68. package/lib/components/BigModal/BigModal.js.map +1 -1
  69. package/lib/components/Dropdown/Dropdown.js +57 -53
  70. package/lib/components/Dropdown/Dropdown.js.map +1 -1
  71. package/lib/components/Dropdown/DropdownItem.js +43 -40
  72. package/lib/components/Dropdown/DropdownItem.js.map +1 -1
  73. package/lib/components/Dropdown/index.js +10 -2
  74. package/lib/components/Dropdown/index.js.map +1 -1
  75. package/lib/components/Modal/Modal.js +45 -43
  76. package/lib/components/Modal/Modal.js.map +1 -1
  77. package/lib/components/Modal/index.js +8 -1
  78. package/lib/components/Modal/index.js.map +1 -1
  79. package/lib/components/selectUtils.js +20 -15
  80. package/lib/components/selectUtils.js.map +1 -1
  81. package/lib/contexts/BaseColorContext.js +5 -3
  82. package/lib/contexts/BaseColorContext.js.map +1 -1
  83. package/lib/contexts/HoveredValueContext.js +5 -3
  84. package/lib/contexts/HoveredValueContext.js.map +1 -1
  85. package/lib/contexts/RootStylesContext.js +5 -3
  86. package/lib/contexts/RootStylesContext.js.map +1 -1
  87. package/lib/contexts/SelectedValueContext.js +5 -3
  88. package/lib/contexts/SelectedValueContext.js.map +1 -1
  89. package/lib/contexts/index.js +14 -4
  90. package/lib/contexts/index.js.map +1 -1
  91. package/lib/hooks/index.js +14 -4
  92. package/lib/hooks/index.js.map +1 -1
  93. package/lib/hooks/useInternalState.js +9 -7
  94. package/lib/hooks/useInternalState.js.map +1 -1
  95. package/lib/hooks/useOnClickOutside.js +8 -6
  96. package/lib/hooks/useOnClickOutside.js.map +1 -1
  97. package/lib/hooks/useOnWindowResize.js +9 -7
  98. package/lib/hooks/useOnWindowResize.js.map +1 -1
  99. package/lib/hooks/useQuill.js +60 -111
  100. package/lib/hooks/useQuill.js.map +1 -1
  101. package/lib/hooks/useSelectOnKeyDown.js +17 -15
  102. package/lib/hooks/useSelectOnKeyDown.js.map +1 -1
  103. package/lib/index.js +22 -8
  104. package/lib/index.js.map +1 -1
  105. package/package.json +2 -16
  106. package/src/Dashboard.tsx +2 -2
  107. package/src/ReportBuilder.tsx +0 -1
  108. package/src/SQLEditor.tsx +0 -1
package/lib/SQLEditor.js CHANGED
@@ -1,63 +1,22 @@
1
- var __assign = (this && this.__assign) || function () {
2
- __assign = Object.assign || function(t) {
3
- for (var s, i = 1, n = arguments.length; i < n; i++) {
4
- s = arguments[i];
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
- t[p] = s[p];
7
- }
8
- return t;
9
- };
10
- return __assign.apply(this, arguments);
11
- };
12
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
- return new (P || (P = Promise))(function (resolve, reject) {
15
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
- step((generator = generator.apply(thisArg, _arguments || [])).next());
19
- });
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
20
4
  };
21
- var __generator = (this && this.__generator) || function (thisArg, body) {
22
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
- function verb(n) { return function (v) { return step([n, v]); }; }
25
- function step(op) {
26
- if (f) throw new TypeError("Generator is already executing.");
27
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
28
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
- if (y = 0, t) op = [op[0] & 2, t.value];
30
- switch (op[0]) {
31
- case 0: case 1: t = op; break;
32
- case 4: _.label++; return { value: op[1], done: false };
33
- case 5: _.label++; y = op[1]; op = [0]; continue;
34
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
- default:
36
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
- if (t[2]) _.ops.pop();
41
- _.trys.pop(); continue;
42
- }
43
- op = body.call(thisArg, _);
44
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
- }
47
- };
48
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.convertPostgresColumn = void 0;
7
+ const jsx_runtime_1 = require("react/jsx-runtime");
49
8
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
50
9
  // @ts-ignore
51
- import { useState, useContext, useEffect } from 'react';
52
- import MonacoEditor from '@monaco-editor/react';
10
+ const react_1 = require("react");
11
+ const react_2 = __importDefault(require("@monaco-editor/react"));
53
12
  // import './nightOwlLight.css';
54
- import axios from 'axios';
55
- import { ClientContext, SchemaContext, ThemeContext } from './Context';
56
- import { ChevronDownIcon, ChevronRightIcon, } from '@heroicons/react/20/solid';
57
- import { SpecialTable } from './Table';
58
- import { TailSpin } from 'react-loader-spinner';
59
- export function convertPostgresColumn(column) {
60
- var format;
13
+ const axios_1 = __importDefault(require("axios"));
14
+ const Context_1 = require("./Context");
15
+ const solid_1 = require("@heroicons/react/20/solid");
16
+ const Table_1 = require("./Table");
17
+ const react_loader_spinner_1 = require("react-loader-spinner");
18
+ function convertPostgresColumn(column) {
19
+ let format;
61
20
  switch (column.dataTypeID) {
62
21
  case 20: // int8
63
22
  case 21: // int2
@@ -85,6 +44,7 @@ export function convertPostgresColumn(column) {
85
44
  format: format,
86
45
  };
87
46
  }
47
+ exports.convertPostgresColumn = convertPostgresColumn;
88
48
  function defineEditorTheme(monaco, theme) {
89
49
  monaco.editor.defineTheme('onedark', {
90
50
  base: theme.darkMode ? 'vs-dark' : 'vs',
@@ -110,30 +70,26 @@ function setEditorTheme(editor, monaco) {
110
70
  console.log('ERROR: ', e);
111
71
  }
112
72
  }
113
- var QuillButton = function (_a) {
114
- var onClick = _a.onClick, label = _a.label, theme = _a.theme, secondary = _a.secondary;
115
- return (_jsx("button", __assign({ style: {
116
- borderRadius: '6px',
117
- backgroundColor: secondary
118
- ? (theme === null || theme === void 0 ? void 0 : theme.secondaryButtonColor) || '#FFFFFF'
119
- : theme === null || theme === void 0 ? void 0 : theme.primaryButtonColor,
120
- opacity: 1,
121
- paddingLeft: '16px',
122
- paddingRight: '16px',
123
- paddingTop: '10px',
124
- paddingBottom: '10px',
125
- fontSize: '14px',
126
- fontWeight: 600,
127
- color: secondary ? theme === null || theme === void 0 ? void 0 : theme.primaryTextColor : '#FFFFFF',
128
- cursor: 'pointer',
129
- outline: 'none',
130
- border: 'none',
131
- fontFamily: theme === null || theme === void 0 ? void 0 : theme.fontFamily,
132
- }, onClick: onClick }, { children: label })));
133
- };
134
- var QuillTextInput = function (_a) {
135
- var onChange = _a.onChange, value = _a.value, id = _a.id, placeholder = _a.placeholder, theme = _a.theme;
136
- return (_jsx("input", { style: {
73
+ const QuillButton = ({ onClick, label, theme, secondary, }) => ((0, jsx_runtime_1.jsx)("button", { style: {
74
+ borderRadius: '6px',
75
+ backgroundColor: secondary
76
+ ? theme?.secondaryButtonColor || '#FFFFFF'
77
+ : theme?.primaryButtonColor,
78
+ opacity: 1,
79
+ paddingLeft: '16px',
80
+ paddingRight: '16px',
81
+ paddingTop: '10px',
82
+ paddingBottom: '10px',
83
+ fontSize: '14px',
84
+ fontWeight: 600,
85
+ color: secondary ? theme?.primaryTextColor : '#FFFFFF',
86
+ cursor: 'pointer',
87
+ outline: 'none',
88
+ border: 'none',
89
+ fontFamily: theme?.fontFamily,
90
+ }, onClick: onClick, children: label }));
91
+ const QuillTextInput = ({ onChange, value, id, placeholder, theme, }) => {
92
+ return ((0, jsx_runtime_1.jsx)("input", { style: {
137
93
  display: 'flex',
138
94
  flexDirection: 'row',
139
95
  alignItems: 'center',
@@ -143,173 +99,134 @@ var QuillTextInput = function (_a) {
143
99
  height: 36,
144
100
  boxShadow: 'rgba(0, 0, 0, 0.1) 0px 1px 5px 0px',
145
101
  width: '445px',
146
- backgroundColor: (theme === null || theme === void 0 ? void 0 : theme.backgroundColor) || 'white',
147
- color: theme === null || theme === void 0 ? void 0 : theme.primaryTextColor,
102
+ backgroundColor: theme?.backgroundColor || 'white',
103
+ color: theme?.primaryTextColor,
148
104
  borderWidth: '1px',
149
- borderColor: (theme === null || theme === void 0 ? void 0 : theme.borderColor) || '#E7E7E7',
105
+ borderColor: theme?.borderColor || '#E7E7E7',
150
106
  borderStyle: 'solid',
151
107
  borderRadius: '6px',
152
108
  }, id: id, onChange: onChange, value: value, placeholder: placeholder }));
153
109
  };
154
- export default function QueryEditor(_a) {
155
- var _this = this;
156
- var _b = _a.containerStyle, containerStyle = _b === void 0 ? { height: '100vh' } : _b, ButtonComponent = _a.ButtonComponent, SecondaryButtonComponent = _a.SecondaryButtonComponent, TextInputComponent = _a.TextInputComponent, TableComponent = _a.TableComponent, AddToDashboardButton = _a.AddToDashboardButton, LoadingComponent = _a.LoadingComponent;
157
- var _c = useState(''), sqlPrompt = _c[0], setSqlPrompt = _c[1];
158
- var _d = useState(false), isOpen = _d[0], setIsOpen = _d[1];
159
- var client = useContext(ClientContext)[0];
160
- var theme = useContext(ThemeContext)[0];
161
- var _e = useState(''), query = _e[0], setQuery = _e[1];
162
- var _f = useState([]), rows = _f[0], setRows = _f[1];
163
- var _g = useState([]), columns = _g[0], setColumns = _g[1];
164
- var _h = useState([]), fields = _h[0], setFields = _h[1];
165
- var _j = useContext(SchemaContext), schema = _j[0], setSchema = _j[1];
166
- var _k = useState(''), errorMessage = _k[0], setErrorMessage = _k[1];
167
- var _l = useState(false), sqlResponseLoading = _l[0], setSqlResponseLoading = _l[1];
168
- var _m = useState(false), sqlQueryLoading = _m[0], setSqlQueryLoading = _m[1];
169
- var _o = useState(false), schemaLoading = _o[0], setSchemaLoading = _o[1];
170
- useEffect(function () {
171
- var isSubscribed = true;
172
- function getSchema() {
173
- return __awaiter(this, void 0, void 0, function () {
174
- var publicKey, environment, response3;
175
- return __generator(this, function (_a) {
176
- switch (_a.label) {
177
- case 0:
178
- publicKey = client.publicKey, environment = client.environment;
179
- setSchemaLoading(true);
180
- return [4 /*yield*/, axios.get("https://quill-344421.uc.r.appspot.com/schema2/".concat(publicKey, "/"), {
181
- headers: {
182
- Authorization: "Bearer ",
183
- environment: environment || undefined,
184
- },
185
- })];
186
- case 1:
187
- response3 = _a.sent();
188
- if (isSubscribed) {
189
- setSchema(response3.data.tables);
190
- setSchemaLoading(false);
191
- }
192
- return [2 /*return*/];
193
- }
194
- });
110
+ function QueryEditor({ containerStyle = { height: '100vh' }, ButtonComponent, SecondaryButtonComponent, TextInputComponent, TableComponent, AddToDashboardButton, LoadingComponent, }) {
111
+ const [sqlPrompt, setSqlPrompt] = (0, react_1.useState)('');
112
+ const [isOpen, setIsOpen] = (0, react_1.useState)(false);
113
+ const [client] = (0, react_1.useContext)(Context_1.ClientContext);
114
+ const [theme] = (0, react_1.useContext)(Context_1.ThemeContext);
115
+ const [query, setQuery] = (0, react_1.useState)('');
116
+ const [rows, setRows] = (0, react_1.useState)([]);
117
+ const [columns, setColumns] = (0, react_1.useState)([]);
118
+ const [fields, setFields] = (0, react_1.useState)([]);
119
+ const [schema, setSchema] = (0, react_1.useContext)(Context_1.SchemaContext);
120
+ const [errorMessage, setErrorMessage] = (0, react_1.useState)('');
121
+ const [sqlResponseLoading, setSqlResponseLoading] = (0, react_1.useState)(false);
122
+ const [sqlQueryLoading, setSqlQueryLoading] = (0, react_1.useState)(false);
123
+ const [schemaLoading, setSchemaLoading] = (0, react_1.useState)(false);
124
+ (0, react_1.useEffect)(() => {
125
+ let isSubscribed = true;
126
+ async function getSchema() {
127
+ const { publicKey, environment } = client;
128
+ setSchemaLoading(true);
129
+ const response3 = await axios_1.default.get(`https://quill-344421.uc.r.appspot.com/schema2/${publicKey}/`, {
130
+ headers: {
131
+ Authorization: `Bearer `,
132
+ environment: environment || undefined,
133
+ },
195
134
  });
135
+ if (isSubscribed) {
136
+ setSchema(response3.data.tables);
137
+ setSchemaLoading(false);
138
+ }
196
139
  }
197
140
  if (isSubscribed) {
198
141
  getSchema();
199
142
  }
200
- return function () {
143
+ return () => {
201
144
  isSubscribed = false;
202
145
  };
203
146
  }, []);
204
- var handleRunSqlPrompt = function () { return __awaiter(_this, void 0, void 0, function () {
205
- var publicKey, environment, response;
206
- return __generator(this, function (_a) {
207
- switch (_a.label) {
208
- case 0:
209
- publicKey = client.publicKey, environment = client.environment;
210
- setSqlResponseLoading(true);
211
- return [4 /*yield*/, axios.post("https://quill-344421.uc.r.appspot.com/quillai", {
212
- initialQuestion: sqlPrompt,
213
- publicKey: publicKey,
214
- }, {
215
- headers: {
216
- Authorization: "Bearer ",
217
- environment: environment || undefined,
218
- },
219
- })];
220
- case 1:
221
- response = _a.sent();
222
- setQuery(response.data.message);
223
- setSqlResponseLoading(false);
224
- return [2 /*return*/];
225
- }
147
+ const handleRunSqlPrompt = async () => {
148
+ const { publicKey, environment } = client;
149
+ setSqlResponseLoading(true);
150
+ const response = await axios_1.default.post(`https://quill-344421.uc.r.appspot.com/quillai`, {
151
+ initialQuestion: sqlPrompt,
152
+ publicKey: publicKey,
153
+ }, {
154
+ headers: {
155
+ Authorization: `Bearer `,
156
+ environment: environment || undefined,
157
+ },
226
158
  });
227
- }); };
228
- var handleRunQuery = function () { return __awaiter(_this, void 0, void 0, function () {
229
- var publicKey, customerId, environment, queryEndpoint, queryHeaders, withCredentials, response, e_1;
230
- return __generator(this, function (_a) {
231
- switch (_a.label) {
232
- case 0:
233
- publicKey = client.publicKey, customerId = client.customerId, environment = client.environment, queryEndpoint = client.queryEndpoint, queryHeaders = client.queryHeaders, withCredentials = client.withCredentials;
234
- _a.label = 1;
235
- case 1:
236
- _a.trys.push([1, 6, , 7]);
237
- response = void 0;
238
- setSqlQueryLoading(true);
239
- if (!queryEndpoint) return [3 /*break*/, 3];
240
- return [4 /*yield*/, axios.post(queryEndpoint, { metadata: { query: query, task: 'query' } }, { headers: queryHeaders, withCredentials: withCredentials })];
241
- case 2:
242
- response = _a.sent();
243
- return [3 /*break*/, 5];
244
- case 3: return [4 /*yield*/, axios.post("https://quill-344421.uc.r.appspot.com/dashquery", {
245
- query: query,
246
- }, {
247
- params: {
248
- orgId: customerId,
249
- publicKey: publicKey,
250
- },
251
- headers: {
252
- Authorization: "Bearer ",
253
- environment: environment || undefined,
254
- },
255
- })];
256
- case 4:
257
- response = _a.sent();
258
- _a.label = 5;
259
- case 5:
260
- if (response && response.data && response.data.errorMessage) {
261
- setSqlQueryLoading(false);
262
- setErrorMessage('Failed to run SQL query: ' + response.data.errorMessage);
263
- setRows([]);
264
- setColumns([]);
265
- setFields([]);
266
- return [2 /*return*/];
267
- }
268
- setSqlQueryLoading(false);
269
- setErrorMessage('');
270
- setRows(response.data.rows && response.data.rows.length
271
- ? response.data.rows
272
- : []);
273
- setColumns(response.data.fields.map(function (elem) { return convertPostgresColumn(elem); }));
274
- setFields(response.data.fields);
275
- return [3 /*break*/, 7];
276
- case 6:
277
- e_1 = _a.sent();
278
- console.log('ERROR: ', e_1);
279
- return [2 /*return*/];
280
- case 7: return [2 /*return*/];
159
+ setQuery(response.data.message);
160
+ setSqlResponseLoading(false);
161
+ };
162
+ const handleRunQuery = async () => {
163
+ const { publicKey, customerId, environment, queryEndpoint, queryHeaders, withCredentials, } = client;
164
+ try {
165
+ let response;
166
+ setSqlQueryLoading(true);
167
+ if (queryEndpoint) {
168
+ response = await axios_1.default.post(queryEndpoint, { metadata: { query, task: 'query' } }, { headers: queryHeaders, withCredentials });
281
169
  }
282
- });
283
- }); };
284
- var handleAddToDashboard = function () {
170
+ else {
171
+ response = await axios_1.default.post(`https://quill-344421.uc.r.appspot.com/dashquery`, {
172
+ query,
173
+ }, {
174
+ params: {
175
+ orgId: customerId,
176
+ publicKey: publicKey,
177
+ },
178
+ headers: {
179
+ Authorization: `Bearer `,
180
+ environment: environment || undefined,
181
+ },
182
+ });
183
+ }
184
+ if (response && response.data && response.data.errorMessage) {
185
+ setSqlQueryLoading(false);
186
+ setErrorMessage('Failed to run SQL query: ' + response.data.errorMessage);
187
+ setRows([]);
188
+ setColumns([]);
189
+ setFields([]);
190
+ return;
191
+ }
192
+ setSqlQueryLoading(false);
193
+ setErrorMessage('');
194
+ setRows(response.data.rows && response.data.rows.length
195
+ ? response.data.rows
196
+ : []);
197
+ setColumns(response.data.fields.map(elem => convertPostgresColumn(elem)));
198
+ setFields(response.data.fields);
199
+ }
200
+ catch (e) {
201
+ console.log('ERROR: ', e);
202
+ return;
203
+ }
204
+ };
205
+ const handleAddToDashboard = () => {
285
206
  setIsOpen(true);
286
207
  };
287
208
  /* all your useState and useContext calls and your useEffect hooks */
288
- var downloadCSV = function () {
209
+ const downloadCSV = () => {
289
210
  // report.rows
290
211
  if (!rows.length) {
291
212
  return;
292
213
  }
293
- var json = rows; // JSON data passed as a prop
294
- var fields = Object.keys(json[0]); // Assumes all objects have same keys
295
- var csvRows = [];
214
+ const json = rows; // JSON data passed as a prop
215
+ const fields = Object.keys(json[0]); // Assumes all objects have same keys
216
+ const csvRows = [];
296
217
  // Header row
297
218
  csvRows.push(fields.join(','));
298
- var _loop_1 = function (row) {
299
- var values = fields.map(function (field) { return JSON.stringify(row[field] || ''); });
300
- csvRows.push(values.join(','));
301
- };
302
219
  // Data rows
303
- for (var _i = 0, json_1 = json; _i < json_1.length; _i++) {
304
- var row = json_1[_i];
305
- _loop_1(row);
220
+ for (const row of json) {
221
+ const values = fields.map(field => JSON.stringify(row[field] || ''));
222
+ csvRows.push(values.join(','));
306
223
  }
307
224
  // Create CSV string and create a 'blob' with it
308
- var csvString = csvRows.join('\r\n');
309
- var csvBlob = new Blob([csvString], { type: 'text/csv' });
225
+ const csvString = csvRows.join('\r\n');
226
+ const csvBlob = new Blob([csvString], { type: 'text/csv' });
310
227
  // Create a download link and click it
311
- var downloadLink = document.createElement('a');
312
- downloadLink.download = "".concat(query, ".csv");
228
+ const downloadLink = document.createElement('a');
229
+ downloadLink.download = `${query}.csv`;
313
230
  downloadLink.href = URL.createObjectURL(csvBlob);
314
231
  downloadLink.style.display = 'none';
315
232
  document.body.appendChild(downloadLink);
@@ -317,28 +234,28 @@ export default function QueryEditor(_a) {
317
234
  document.body.removeChild(downloadLink);
318
235
  };
319
236
  /* rest of your methods */
320
- return (_jsx("div", __assign({ style: containerStyle }, { children: _jsx("div", __assign({ style: {
237
+ return ((0, jsx_runtime_1.jsx)("div", { style: containerStyle, children: (0, jsx_runtime_1.jsx)("div", { style: {
321
238
  height: 'calc(100%)',
322
239
  display: 'flex',
323
240
  flexDirection: 'column',
324
241
  padding: 0,
325
- } }, { children: _jsx("div", __assign({ style: { height: '100%', display: 'flex', flexDirection: 'column' } }, { children: _jsxs("div", __assign({ style: {
242
+ }, children: (0, jsx_runtime_1.jsx)("div", { style: { height: '100%', display: 'flex', flexDirection: 'column' }, children: (0, jsx_runtime_1.jsxs)("div", { style: {
326
243
  width: '100%',
327
244
  display: 'flex',
328
245
  height: '100%',
329
246
  flexDirection: 'row',
330
- } }, { children: [_jsx(SchemaListComponent, { schema: schema, theme: theme, LoadingComponent: LoadingComponent, loading: schemaLoading }), _jsxs("div", __assign({ style: {
247
+ }, children: [(0, jsx_runtime_1.jsx)(SchemaListComponent, { schema: schema, theme: theme, LoadingComponent: LoadingComponent, loading: schemaLoading }), (0, jsx_runtime_1.jsxs)("div", { style: {
331
248
  display: 'flex',
332
249
  flexDirection: 'column',
333
250
  width: 'calc(100% - 250px)',
334
- } }, { children: [_jsxs("div", __assign({ style: {
251
+ }, children: [(0, jsx_runtime_1.jsxs)("div", { style: {
335
252
  // TODO: change color
336
253
  height: 80,
337
254
  background: 'white',
338
255
  display: 'flex',
339
256
  flexDirection: 'row',
340
257
  alignItems: 'center',
341
- } }, { children: [_jsx("div", __assign({ style: { minWidth: 440, marginRight: 10 } }, { children: (TextInputComponent && (_jsx(TextInputComponent, { id: "ai-search", value: sqlPrompt, onChange: function (e) { return setSqlPrompt(e.target.value); }, placeholder: "Ask a question..." }))) || (_jsx(QuillTextInput, { id: "ai-search", value: sqlPrompt, onChange: function (e) { return setSqlPrompt(e.target.value); }, placeholder: "Ask a question...", theme: theme })) })), (ButtonComponent && (_jsx(ButtonComponent, { onClick: handleRunSqlPrompt, label: "Ask AI" }))) || (_jsx(QuillButton, { theme: theme, onClick: handleRunSqlPrompt, label: "Ask AI" }))] })), _jsx("div", __assign({ style: { height: 'calc(50% - 40px)' } }, { children: _jsx(SQLEditorComponent, { query: query, setQuery: setQuery, handleRunQuery: handleRunQuery, theme: theme, defineEditorTheme: defineEditorTheme, setEditorTheme: setEditorTheme, ButtonComponent: ButtonComponent, loading: sqlResponseLoading, LoadingComponent: LoadingComponent }) })), _jsxs("div", __assign({ style: {
258
+ }, children: [(0, jsx_runtime_1.jsx)("div", { style: { minWidth: 440, marginRight: 10 }, children: (TextInputComponent && ((0, jsx_runtime_1.jsx)(TextInputComponent, { id: "ai-search", value: sqlPrompt, onChange: e => setSqlPrompt(e.target.value), placeholder: "Ask a question..." }))) || ((0, jsx_runtime_1.jsx)(QuillTextInput, { id: "ai-search", value: sqlPrompt, onChange: e => setSqlPrompt(e.target.value), placeholder: "Ask a question...", theme: theme })) }), (ButtonComponent && ((0, jsx_runtime_1.jsx)(ButtonComponent, { onClick: handleRunSqlPrompt, label: "Ask AI" }))) || ((0, jsx_runtime_1.jsx)(QuillButton, { theme: theme, onClick: handleRunSqlPrompt, label: "Ask AI" }))] }), (0, jsx_runtime_1.jsx)("div", { style: { height: 'calc(50% - 40px)' }, children: (0, jsx_runtime_1.jsx)(SQLEditorComponent, { query: query, setQuery: setQuery, handleRunQuery: handleRunQuery, theme: theme, defineEditorTheme: defineEditorTheme, setEditorTheme: setEditorTheme, ButtonComponent: ButtonComponent, loading: sqlResponseLoading, LoadingComponent: LoadingComponent }) }), (0, jsx_runtime_1.jsxs)("div", { style: {
342
259
  height: 'calc(50% - 40px)',
343
260
  display: 'flex',
344
261
  flexDirection: 'column',
@@ -346,52 +263,52 @@ export default function QueryEditor(_a) {
346
263
  margin: 0,
347
264
  border: 'none',
348
265
  outline: 'none',
349
- } }, { children: [errorMessage && (_jsx("div", __assign({ style: {
350
- fontFamily: theme === null || theme === void 0 ? void 0 : theme.fontFamily,
351
- color: theme === null || theme === void 0 ? void 0 : theme.primaryTextColor,
266
+ }, children: [errorMessage && ((0, jsx_runtime_1.jsx)("div", { style: {
267
+ fontFamily: theme?.fontFamily,
268
+ color: theme?.primaryTextColor,
352
269
  fontSize: 15,
353
270
  fontWeight: '400',
354
- } }, { children: _jsx("div", __assign({ style: {
271
+ }, children: (0, jsx_runtime_1.jsx)("div", { style: {
355
272
  padding: 30,
356
273
  // TODO: change color
357
274
  background: 'rgba(0,0,0,0.02)',
358
275
  display: 'inline-block',
359
276
  flex: 0,
360
277
  borderRadius: 6,
361
- color: theme === null || theme === void 0 ? void 0 : theme.primaryTextColor,
362
- fontFamily: theme === null || theme === void 0 ? void 0 : theme.fontFamily,
363
- } }, { children: errorMessage })) }))), errorMessage
278
+ color: theme?.primaryTextColor,
279
+ fontFamily: theme?.fontFamily,
280
+ }, children: errorMessage }) })), errorMessage
364
281
  ? null
365
- : (TableComponent && (_jsx(TableComponent, { rows: rows, columns: columns, height: "calc(100% - 70px)" }))) || (_jsx(SpecialTable, { rows: rows, columns: columns, height: "calc(100% - 70px)", LoadingComponent: LoadingComponent, loading: sqlQueryLoading, theme: theme })), _jsx("div", __assign({ style: {
282
+ : (TableComponent && ((0, jsx_runtime_1.jsx)(TableComponent, { rows: rows, columns: columns, height: "calc(100% - 70px)" }))) || ((0, jsx_runtime_1.jsx)(Table_1.SpecialTable, { rows: rows, columns: columns, height: "calc(100% - 70px)", LoadingComponent: LoadingComponent, loading: sqlQueryLoading, theme: theme })), (0, jsx_runtime_1.jsx)("div", { style: {
366
283
  height: 70,
367
284
  // TODO: change color
368
- background: theme === null || theme === void 0 ? void 0 : theme.backgroundColor,
369
- } }, { children: rows.length ? (_jsxs("div", __assign({ style: {
285
+ background: theme?.backgroundColor,
286
+ }, children: rows.length ? ((0, jsx_runtime_1.jsxs)("div", { style: {
370
287
  display: 'flex',
371
288
  flexDirection: 'column',
372
289
  height: 70,
373
290
  border: 'none',
374
- } }, { children: [_jsx("div", { style: {
291
+ }, children: [(0, jsx_runtime_1.jsx)("div", { style: {
375
292
  height: 1,
376
293
  width: '100%',
377
294
  // TODO: change color
378
295
  // background: theme.borderColor,
379
- } }), _jsxs("div", __assign({ style: {
296
+ } }), (0, jsx_runtime_1.jsxs)("div", { style: {
380
297
  marginLeft: 0,
381
298
  height: 69,
382
299
  display: 'flex',
383
300
  alignItems: 'center',
384
301
  justifyContent: 'flex-end',
385
302
  paddingRight: 20,
386
- } }, { children: [(SecondaryButtonComponent && (_jsx(SecondaryButtonComponent, { onClick: downloadCSV, label: "Download CSV" }))) || (_jsx(QuillButton, { theme: theme, onClick: downloadCSV, label: "Download CSV", secondary: true })), AddToDashboardButton && _jsx("div", { style: { width: 10 } }), AddToDashboardButton && (_jsx(AddToDashboardButton
303
+ }, children: [(SecondaryButtonComponent && ((0, jsx_runtime_1.jsx)(SecondaryButtonComponent, { onClick: downloadCSV, label: "Download CSV" }))) || ((0, jsx_runtime_1.jsx)(QuillButton, { theme: theme, onClick: downloadCSV, label: "Download CSV", secondary: true })), AddToDashboardButton && (0, jsx_runtime_1.jsx)("div", { style: { width: 10 } }), AddToDashboardButton && ((0, jsx_runtime_1.jsx)(AddToDashboardButton
387
304
  // @ts-ignore
388
305
  , {
389
306
  // @ts-ignore
390
- rows: rows, columns: columns, query: query })), _jsx("div", {})] }))] }))) : null }))] }))] }))] })) })) })) })));
307
+ rows: rows, columns: columns, query: query })), (0, jsx_runtime_1.jsx)("div", {})] })] })) : null })] })] })] }) }) }) }));
391
308
  }
392
- var SQLEditorComponent = function (_a) {
393
- var query = _a.query, setQuery = _a.setQuery, handleRunQuery = _a.handleRunQuery, theme = _a.theme, defineEditorTheme = _a.defineEditorTheme, setEditorTheme = _a.setEditorTheme, ButtonComponent = _a.ButtonComponent, theme = _a.theme, loading = _a.loading, LoadingComponent = _a.LoadingComponent;
394
- return (_jsxs("div", __assign({ style: {
309
+ exports.default = QueryEditor;
310
+ const SQLEditorComponent = ({ query, setQuery, handleRunQuery, defineEditorTheme, setEditorTheme, ButtonComponent, theme, loading, LoadingComponent, }) => {
311
+ return ((0, jsx_runtime_1.jsxs)("div", { style: {
395
312
  background: theme.backgroundColor,
396
313
  // maxHeight: 700,
397
314
  width: '100%',
@@ -405,27 +322,27 @@ var SQLEditorComponent = function (_a) {
405
322
  borderTopRightRadius: 0,
406
323
  borderBottomRightRadius: 0,
407
324
  overflow: 'hidden',
408
- } }, { children: [loading ? (_jsxs("div", __assign({ style: {
325
+ }, children: [loading ? ((0, jsx_runtime_1.jsxs)("div", { style: {
409
326
  height: 'calc(100% - 70px)',
410
327
  width: '100%',
411
328
  display: 'flex',
412
329
  alignItems: 'center',
413
330
  justifyContent: 'center',
414
331
  background: '#F9F9F9',
415
- } }, { children: [LoadingComponent && _jsx(LoadingComponent, {}), !LoadingComponent && (_jsx(TailSpin, { height: 36, width: 36, color: "#364153" }))] }))) : (_jsx(MonacoEditor, { height: "calc(100% - 70px)", width: "100%", defaultLanguage: "pgsql", defaultValue: "", value: query, loading: _jsx("div", {}), options: {
332
+ }, children: [LoadingComponent && (0, jsx_runtime_1.jsx)(LoadingComponent, {}), !LoadingComponent && ((0, jsx_runtime_1.jsx)(react_loader_spinner_1.TailSpin, { height: 36, width: 36, color: "#364153" }))] })) : ((0, jsx_runtime_1.jsx)(react_2.default, { height: "calc(100% - 70px)", width: "100%", defaultLanguage: "pgsql", defaultValue: "", value: query, loading: (0, jsx_runtime_1.jsx)("div", {}), options: {
416
333
  wordWrap: 'on',
417
334
  minimap: {
418
335
  enabled: false,
419
336
  },
420
337
  padding: { top: 16 },
421
- }, onChange: function (query) { return setQuery(query); }, beforeMount: function (monaco) { return defineEditorTheme(monaco, theme); }, onMount: setEditorTheme })), _jsx("div", __assign({ style: {
338
+ }, onChange: query => setQuery(query), beforeMount: monaco => defineEditorTheme(monaco, theme), onMount: setEditorTheme })), (0, jsx_runtime_1.jsx)("div", { style: {
422
339
  display: 'flex',
423
340
  flexDirection: 'row',
424
341
  alignItems: 'center',
425
342
  height: 70,
426
- } }, { children: (ButtonComponent && (_jsx(ButtonComponent, { onClick: handleRunQuery, label: "Run query" }))) || (_jsx(QuillButton, { onClick: handleRunQuery, label: "Run query", theme: theme })) }))] })));
343
+ }, children: (ButtonComponent && ((0, jsx_runtime_1.jsx)(ButtonComponent, { onClick: handleRunQuery, label: "Run query" }))) || ((0, jsx_runtime_1.jsx)(QuillButton, { onClick: handleRunQuery, label: "Run query", theme: theme })) })] }));
427
344
  };
428
- var styles = {
345
+ const styles = {
429
346
  columnHeader: {
430
347
  boxSizing: 'border-box',
431
348
  flex: '150 0 auto',
@@ -457,10 +374,9 @@ var styles = {
457
374
  overflow: 'hidden',
458
375
  },
459
376
  };
460
- var SchemaListComponent = function (_a) {
461
- var schema = _a.schema, theme = _a.theme, loading = _a.loading, LoadingComponent = _a.LoadingComponent;
377
+ const SchemaListComponent = ({ schema, theme, loading, LoadingComponent }) => {
462
378
  if (loading) {
463
- return (_jsxs("div", __assign({ style: {
379
+ return ((0, jsx_runtime_1.jsxs)("div", { style: {
464
380
  background: theme.backgroundColor,
465
381
  // maxHeight: 700,
466
382
  width: 250,
@@ -474,9 +390,9 @@ var SchemaListComponent = function (_a) {
474
390
  display: 'flex',
475
391
  // alignItems: 'center',
476
392
  justifyContent: 'center',
477
- } }, { children: [_jsx("div", { style: { height: 100 } }), LoadingComponent && _jsx(LoadingComponent, {}), !LoadingComponent && (_jsx(TailSpin, { height: 36, width: 36, color: "#364153" }))] })));
393
+ }, children: [(0, jsx_runtime_1.jsx)("div", { style: { height: 100 } }), LoadingComponent && (0, jsx_runtime_1.jsx)(LoadingComponent, {}), !LoadingComponent && ((0, jsx_runtime_1.jsx)(react_loader_spinner_1.TailSpin, { height: 36, width: 36, color: "#364153" }))] }));
478
394
  }
479
- return (_jsx("div", __assign({ style: {
395
+ return ((0, jsx_runtime_1.jsx)("div", { style: {
480
396
  background: theme.backgroundColor,
481
397
  // maxHeight: 700,
482
398
  width: 250,
@@ -486,12 +402,11 @@ var SchemaListComponent = function (_a) {
486
402
  // maxHeight: "100%",
487
403
  paddingLeft: 20,
488
404
  paddingRight: 30,
489
- } }, { children: schema.map(function (elem, index) { return (_jsx(SchemaItem, { elem: elem, theme: theme, index: index }, elem.displayName + index)); }) })));
405
+ }, children: schema.map((elem, index) => ((0, jsx_runtime_1.jsx)(SchemaItem, { elem: elem, theme: theme, index: index }, elem.displayName + index))) }));
490
406
  };
491
- function SchemaItem(_a) {
492
- var elem = _a.elem, theme = _a.theme, index = _a.index;
493
- var _b = useState(index === 0), isOpen = _b[0], setIsOpen = _b[1];
494
- var schemaContainerStyle = {
407
+ function SchemaItem({ elem, theme, index }) {
408
+ const [isOpen, setIsOpen] = (0, react_1.useState)(index === 0);
409
+ const schemaContainerStyle = {
495
410
  display: 'flex',
496
411
  flexDirection: 'column',
497
412
  // WebkitTouchCallout: "none",
@@ -501,7 +416,7 @@ function SchemaItem(_a) {
501
416
  // msUserSelect: "none",
502
417
  // userSelect: "none",
503
418
  };
504
- var schemaRowStyle = {
419
+ const schemaRowStyle = {
505
420
  display: 'flex',
506
421
  flexDirection: 'row',
507
422
  alignItems: 'center',
@@ -509,10 +424,10 @@ function SchemaItem(_a) {
509
424
  justifyContent: 'space-between',
510
425
  cursor: 'pointer',
511
426
  };
512
- var schemaRowHoverStyle = {
427
+ const schemaRowHoverStyle = {
513
428
  background: theme.selectUnderlayColor,
514
429
  };
515
- return (_jsxs("div", __assign({ style: schemaContainerStyle }, { children: [_jsxs("div", __assign({ style: __assign(__assign({}, schemaRowStyle), (isOpen && schemaRowHoverStyle)), onClick: function () { return setIsOpen(!isOpen); } }, { children: [_jsx("p", __assign({ style: {
430
+ return ((0, jsx_runtime_1.jsxs)("div", { style: schemaContainerStyle, children: [(0, jsx_runtime_1.jsxs)("div", { style: { ...schemaRowStyle, ...(isOpen && schemaRowHoverStyle) }, onClick: () => setIsOpen(!isOpen), children: [(0, jsx_runtime_1.jsx)("p", { style: {
516
431
  marginLeft: theme.padding,
517
432
  fontSize: 13,
518
433
  color: '#384151',
@@ -522,8 +437,8 @@ function SchemaItem(_a) {
522
437
  margin: 0,
523
438
  textOverflow: 'ellipsis',
524
439
  overflow: 'hidden',
525
- fontFamily: theme === null || theme === void 0 ? void 0 : theme.fontFamily,
526
- }, title: elem.displayName }, { children: elem.displayName })), _jsx("div", __assign({ style: {
440
+ fontFamily: theme?.fontFamily,
441
+ }, title: elem.displayName, children: elem.displayName }), (0, jsx_runtime_1.jsx)("div", { style: {
527
442
  display: 'flex',
528
443
  alignItems: 'center',
529
444
  justifyContent: 'center',
@@ -532,19 +447,19 @@ function SchemaItem(_a) {
532
447
  paddingBottom: 12,
533
448
  paddingLeft: 0,
534
449
  cursor: 'pointer',
535
- } }, { children: isOpen ? (_jsx(ChevronDownIcon, { style: { height: 13, width: 13, color: theme.secondaryTextColor }, "aria-hidden": "true" })) : (_jsx(ChevronRightIcon, { style: { height: 13, width: 13, color: theme.secondaryTextColor }, "aria-hidden": "true" })) }))] })), isOpen ? (_jsx("div", __assign({ style: {
450
+ }, children: isOpen ? ((0, jsx_runtime_1.jsx)(solid_1.ChevronDownIcon, { style: { height: 13, width: 13, color: theme.secondaryTextColor }, "aria-hidden": "true" })) : ((0, jsx_runtime_1.jsx)(solid_1.ChevronRightIcon, { style: { height: 13, width: 13, color: theme.secondaryTextColor }, "aria-hidden": "true" })) })] }), isOpen ? ((0, jsx_runtime_1.jsx)("div", { style: {
536
451
  paddingBottom: theme.padding,
537
452
  display: 'flex',
538
453
  flexDirection: 'column',
539
454
  paddingLeft: theme.padding,
540
455
  paddingRight: theme.padding,
541
- } }, { children: elem.columns.map(function (elem, index) { return (_jsxs("div", __assign({ style: {
456
+ }, children: elem.columns.map((elem, index) => ((0, jsx_runtime_1.jsxs)("div", { style: {
542
457
  paddingTop: theme.padding,
543
458
  display: 'flex',
544
459
  flexDirection: 'row',
545
460
  alignItems: 'center',
546
461
  justifyContent: 'space-between',
547
- } }, { children: [_jsx("div", __assign({ title: elem.displayName,
462
+ }, children: [(0, jsx_runtime_1.jsx)("div", { title: elem.displayName,
548
463
  // className="text-gray-500"
549
464
  style: {
550
465
  fontSize: 12,
@@ -558,8 +473,8 @@ function SchemaItem(_a) {
558
473
  overflow: 'hidden',
559
474
  width: 200,
560
475
  maxWidth: 200,
561
- fontFamily: theme === null || theme === void 0 ? void 0 : theme.fontFamily,
562
- } }, { children: elem.displayName })), _jsx("div", __assign({
476
+ fontFamily: theme?.fontFamily,
477
+ }, children: elem.displayName }), (0, jsx_runtime_1.jsx)("div", {
563
478
  // className="text-gray-500"
564
479
  title: elem.displayName, style: {
565
480
  fontSize: 12,
@@ -567,7 +482,7 @@ function SchemaItem(_a) {
567
482
  color: theme.secondaryTextColor,
568
483
  padding: 0,
569
484
  margin: 0,
570
- fontFamily: theme === null || theme === void 0 ? void 0 : theme.fontFamily,
571
- } }, { children: elem.fieldType }))] }), elem.displayName + elem.index)); }) }))) : null] })));
485
+ fontFamily: theme?.fontFamily,
486
+ }, children: elem.fieldType })] }, elem.displayName + elem.index))) })) : null] }));
572
487
  }
573
488
  //# sourceMappingURL=SQLEditor.js.map