@quillsql/admin 1.0.0

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.
package/lib/Admin.js ADDED
@@ -0,0 +1,1750 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.formatDateBuckets = exports.isArrayOfValidDates = exports.isValidDate = exports.DropdownMenu = exports.classNames = exports.getPostgresBasicType = exports.convertPostgresColumn = exports.theme = void 0;
30
+ const jsx_runtime_1 = require("react/jsx-runtime");
31
+ const react_1 = require("react");
32
+ const react_2 = require("@quillsql/react");
33
+ const nightOwlLight_1 = __importDefault(require("prism-react-renderer/themes/nightOwlLight"));
34
+ const prism_react_renderer_1 = __importStar(require("prism-react-renderer"));
35
+ const react_3 = __importDefault(require("@monaco-editor/react"));
36
+ const ClientContext = (0, react_1.createContext)();
37
+ const EnvironmentContext = (0, react_1.createContext)();
38
+ const OrganizationsContext = (0, react_1.createContext)();
39
+ const OrganizationContext = (0, react_1.createContext)();
40
+ const ActiveQueryContext = (0, react_1.createContext)();
41
+ const TablesContext = (0, react_1.createContext)();
42
+ const SchemaContext = (0, react_1.createContext)();
43
+ const ActiveComponentContext = (0, react_1.createContext)();
44
+ const ReportIdContext = (0, react_1.createContext)();
45
+ function ContextProvider({ children }) {
46
+ const [client, setClient] = (0, react_1.useState)(null);
47
+ const [environment, setEnvironment] = (0, react_1.useState)("PRODUCTION");
48
+ const [organization, setOrganization] = (0, react_1.useState)(null);
49
+ const [organizations, setOrganizations] = (0, react_1.useState)([]);
50
+ const [activeQuery, setActiveQuery] = (0, react_1.useState)("");
51
+ const [tables, setTables] = (0, react_1.useState)([]);
52
+ const [schema, setSchema] = (0, react_1.useState)([]);
53
+ const [activeComponent, setActiveComponent] = (0, react_1.useState)("Dashboards");
54
+ const [reportId, setReportId] = (0, react_1.useState)(null);
55
+ return ((0, jsx_runtime_1.jsx)(ClientContext.Provider, { value: [client, setClient], children: (0, jsx_runtime_1.jsx)(EnvironmentContext.Provider, { value: [environment, setEnvironment], children: (0, jsx_runtime_1.jsx)(OrganizationsContext.Provider, { value: [organizations, setOrganizations], children: (0, jsx_runtime_1.jsx)(OrganizationContext.Provider, { value: [organization, setOrganization], children: (0, jsx_runtime_1.jsx)(SchemaContext.Provider, { value: [schema, setSchema], children: (0, jsx_runtime_1.jsx)(TablesContext.Provider, { value: [tables, setTables], children: (0, jsx_runtime_1.jsx)(ActiveQueryContext.Provider, { value: [activeQuery, setActiveQuery], children: (0, jsx_runtime_1.jsx)(ActiveComponentContext.Provider, { value: [activeComponent, setActiveComponent], children: (0, jsx_runtime_1.jsx)(ReportIdContext.Provider, { value: [reportId, setReportId], children: children }) }) }) }) }) }) }) }) }));
56
+ }
57
+ const CONTAINER = {
58
+ display: "flex",
59
+ flexDirection: "row",
60
+ height: "800px",
61
+ background: "white",
62
+ marginTop: 32,
63
+ width: "calc(100% - 50px)",
64
+ // borderRadius: 12,
65
+ overflow: "hidden",
66
+ borderRadius: 12,
67
+ // border: "1px solid #EDEDED",
68
+ boxShadow: "0px 1px 24px 0px rgba(0, 0, 0, 0.09)",
69
+ };
70
+ const customStyles = {
71
+ content: {
72
+ top: "50%",
73
+ left: "50%",
74
+ right: "auto",
75
+ bottom: "auto",
76
+ marginRight: "-50%",
77
+ border: "none",
78
+ transform: "translate(-50%, -50%)",
79
+ borderRadius: 6,
80
+ zIndex: 4,
81
+ boxShadow: "0px 2px 24px 0px rgb(63,82,149, 0.09)",
82
+ },
83
+ };
84
+ const THEME = {
85
+ /* Components font family */
86
+ // fontFamily: 'BlinkMacSystemFont',
87
+ fontFamily: "Inter",
88
+ /* Default font size */
89
+ fontSize: 14,
90
+ /* Header font size */
91
+ headerFontSize: 18,
92
+ editorDarkMode: true,
93
+ /* Primary color */
94
+ primaryColor: "#212121",
95
+ buttonUnderlayColor: "#000000",
96
+ /* Secondary color */
97
+ secondaryColor: "white",
98
+ selectedTabColor: "white",
99
+ /* When you select underlay */
100
+ selectUnderlayColor: "#F5F5F5",
101
+ /* Background color */
102
+ backgroundColor: "#FFFFFF",
103
+ editorBackgroundColor: "#FBFBFB",
104
+ elevatedCardColor: "#FFFFFF",
105
+ /* Primary font color */
106
+ fontColor: "#212121",
107
+ /* Secondary font color */
108
+ secondaryFontColor: "#777777",
109
+ selectedFontColor: "#212121",
110
+ unselectedFontColor: "#777777",
111
+ buttonLabelColor: "white",
112
+ buttonFontWeight: "500",
113
+ /* Label font weight */
114
+ labelFontWeight: "500",
115
+ /* Header font weight */
116
+ headerFontWeight: "500",
117
+ /* Selected font weight */
118
+ selectedFontWeight: "700",
119
+ /* Padding for containers */
120
+ padding: 25,
121
+ /* Border radius for selected Quill elements */
122
+ borderRadius: "8px",
123
+ /* Box shadow applied on Quill components */
124
+ boxShadow: "0px 1px 8px 0px rgb(63,82,149, 0.09)",
125
+ shadowColor: "rgba(0, 0, 0, 0.09)",
126
+ primaryButtonColor: "#212121",
127
+ };
128
+ const frontendApi = "clerk.withquill.com";
129
+ // const frontendApi = "clerk.romantic.quetzal-89.lcl.dev";
130
+ function Portal({ publicKey, queryEndpoint, theme, queryHeaders, organizationId, TextInputComponent, ButtonComponent, SecondaryButtonComponent, ModalComponent, SelectComponent, OrganizationSelectComponent, UserManagementComponent, }) {
131
+ return ((0, jsx_runtime_1.jsx)(ContextProvider, { children: (0, jsx_runtime_1.jsx)(Navigation, { theme: theme, publicKey: publicKey, organizationId: organizationId, queryEndpoint: queryEndpoint, queryHeaders: queryHeaders, TextInputComponent: TextInputComponent ||
132
+ (({ onChange, value, placeholder }) => ((0, jsx_runtime_1.jsx)("input", { style: {
133
+ display: "flex",
134
+ flexDirection: "row",
135
+ alignItems: "center",
136
+ paddingLeft: "12px",
137
+ paddingRight: "12px",
138
+ fontWeight: "medium",
139
+ height: 36,
140
+ boxShadow: "rgba(0, 0, 0, 0.1) 0px 1px 5px 0px",
141
+ width: "445px",
142
+ backgroundColor: theme?.backgroundColor || "white",
143
+ color: theme?.primaryTextColor,
144
+ borderWidth: "1px",
145
+ borderColor: theme?.borderColor || "#E7E7E7",
146
+ borderStyle: "solid",
147
+ borderRadius: "6px",
148
+ }, onChange: onChange, value: value, placeholder: placeholder }))), ButtonComponent: ButtonComponent ||
149
+ (({ onClick, label }) => ((0, jsx_runtime_1.jsx)("button", { style: {
150
+ height: 36,
151
+ background: theme.primaryButtonColor,
152
+ color: theme.backgroundColor,
153
+ display: "flex",
154
+ borderRadius: 6,
155
+ alignItems: "center",
156
+ justifyContent: "center",
157
+ outline: "none",
158
+ cursor: "pointer",
159
+ fontFamily: theme.fontFamily,
160
+ fontWeight: theme.buttonFontWeight || 600,
161
+ border: "none",
162
+ fontSize: 14,
163
+ paddingLeft: 20,
164
+ paddingRight: 20,
165
+ }, onClick: onClick, children: label }))), SecondaryButtonComponent: SecondaryButtonComponent ||
166
+ (({ onClick, label }) => ((0, jsx_runtime_1.jsx)("button", { style: {
167
+ height: 36,
168
+ background: "#F9FAFB",
169
+ color: theme.primaryTextColor,
170
+ display: "flex",
171
+ borderRadius: 6,
172
+ alignItems: "center",
173
+ justifyContent: "center",
174
+ outline: "none",
175
+ cursor: "pointer",
176
+ fontFamily: theme.fontFamily,
177
+ fontWeight: theme.buttonFontWeight || 600,
178
+ border: "none",
179
+ fontSize: 14,
180
+ paddingLeft: 20,
181
+ paddingRight: 20,
182
+ }, onClick: onClick, children: label }))), ModalComponent: ModalComponent ||
183
+ (({ isOpen, close, children }) => isOpen && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { style: {
184
+ position: "fixed",
185
+ top: "0",
186
+ right: "0",
187
+ bottom: "0",
188
+ left: "0",
189
+ zIndex: "50",
190
+ backgroundColor: "rgba(255, 255, 255, 0.8)",
191
+ backdropFilter: "blur(5px)",
192
+ }, onClick: close }), (0, jsx_runtime_1.jsx)("div", { style: {
193
+ // position: "absolute",
194
+ position: "fixed",
195
+ left: "50%",
196
+ top: "50%",
197
+ zIndex: "50",
198
+ // width: "100%",
199
+ // maxWidth: 1024,
200
+ maxHeight: "90vh",
201
+ display: "flex",
202
+ justifyContent: "center",
203
+ alignItems: "center",
204
+ transform: "translateX(-50%) translateY(-50%)",
205
+ background: "white",
206
+ borderRadius: 8,
207
+ borderStyle: "solid",
208
+ borderWidth: 1,
209
+ borderColor: "#e7e7e7",
210
+ overflow: "hidden",
211
+ padding: 30,
212
+ // zIndex: 1000,
213
+ }, children: children })] }))), OrganizationSelectComponent: OrganizationSelectComponent, UserManagementComponent: UserManagementComponent, SelectComponent: SelectComponent ||
214
+ (({ options, onChange, value }) => {
215
+ return ((0, jsx_runtime_1.jsxs)("div", { style: { position: "relative" }, children: [(0, jsx_runtime_1.jsx)("select", { style: {
216
+ width: "100%",
217
+ minWidth: 230,
218
+ outline: "none",
219
+ textAlign: "left",
220
+ whiteSpace: "nowrap",
221
+ overflow: "hidden",
222
+ textOverflow: "ellipsis",
223
+ borderRadius: 6,
224
+ WebkitAppearance: "none",
225
+ paddingLeft: 12,
226
+ paddingRight: 12,
227
+ height: 38,
228
+ borderWidth: theme.borderWidth,
229
+ borderColor: theme.borderColor,
230
+ background: theme.backgroundColor,
231
+ color: theme.primaryTextColor,
232
+ boxShadow: "0 1px 2px 0 rgba(0,0,0,.05)",
233
+ fontFamily: theme.fontFamily,
234
+ }, value: value, onChange: onChange, children: options.map((option) => ((0, jsx_runtime_1.jsx)("option", { value: option.value, label: option.label }))) }), (0, jsx_runtime_1.jsx)(ArrowDownHeadIcon, { style: {
235
+ height: "20px",
236
+ width: "20px",
237
+ flex: "none",
238
+ position: "absolute",
239
+ right: 8,
240
+ top: 9,
241
+ color: theme?.secondaryTextColor,
242
+ }, "aria-hidden": "true" })] }));
243
+ }) }) }));
244
+ }
245
+ exports.default = Portal;
246
+ const ArrowDownHeadIcon = ({ ...props }) => ((0, jsx_runtime_1.jsxs)("svg", { ...props, xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", width: "24", height: "24", children: [(0, jsx_runtime_1.jsx)("path", { fill: "none", d: "M0 0h24v24H0z" }), (0, jsx_runtime_1.jsx)("path", { fill: "currentColor", d: "M12 13.172l4.95-4.95 1.414 1.414L12 16 5.636 9.636 7.05 8.222z" })] }));
247
+ function Navigation({ TextInputComponent, ButtonComponent, SecondaryButtonComponent, ModalComponent, SelectComponent, OrganizationSelectComponent, UserManagementComponent, publicKey, organizationId, queryEndpoint, queryHeaders, }) {
248
+ // Get the user's first name
249
+ // const { user } = useUser();
250
+ // const location = useLocation();
251
+ const [client, setClient] = (0, react_1.useContext)(ClientContext);
252
+ const [environment, setEnvironment] = (0, react_1.useContext)(EnvironmentContext);
253
+ const [tables, setTables] = (0, react_1.useContext)(TablesContext);
254
+ const [organizations, setOrganizations] = (0, react_1.useContext)(OrganizationsContext);
255
+ const [organization, setOrganization] = (0, react_1.useContext)(OrganizationContext);
256
+ const [schema, setSchema] = (0, react_1.useContext)(SchemaContext);
257
+ const [activeComponent, setActiveComponent] = (0, react_1.useContext)(ActiveComponentContext);
258
+ const [reportId, setReportId] = (0, react_1.useContext)(ReportIdContext);
259
+ (0, react_1.useEffect)(() => {
260
+ let isSubscribed = true;
261
+ async function getClient() {
262
+ try {
263
+ const response1 = await fetch(
264
+ // `https://quill-344421.uc.r.appspot.com/schema2/62cda15d7c9fcca7bc0a3689/`,
265
+ `https://quill-344421.uc.r.appspot.com/client/${publicKey}/`, {
266
+ method: "GET",
267
+ headers: {
268
+ Authorization: `Bearer `,
269
+ },
270
+ });
271
+ const data1 = await response1.json();
272
+ setClient(data1.client);
273
+ const response = await fetch(
274
+ // `https://quill-344421.uc.r.appspot.com/schema2/62cda15d7c9fcca7bc0a3689/`,
275
+ `https://quill-344421.uc.r.appspot.com/schema2/${publicKey}/`, {
276
+ method: "GET",
277
+ headers: {
278
+ Authorization: `Bearer `,
279
+ },
280
+ });
281
+ if (!response.ok) {
282
+ throw new Error("Failed to fetch tables data");
283
+ }
284
+ const data = await response.json();
285
+ setTables(data.tables);
286
+ setSchema(data.tables);
287
+ }
288
+ catch (error) {
289
+ console.error("There was an error:", error);
290
+ }
291
+ }
292
+ if (isSubscribed) {
293
+ getClient();
294
+ }
295
+ return () => {
296
+ isSubscribed = false;
297
+ };
298
+ }, []);
299
+ (0, react_1.useEffect)(() => {
300
+ let isSubscribed = true;
301
+ async function getCustomers() {
302
+ // const url = `https://quill-344421.uc.r.appspot.com/orgs/62cda15d7c9fcca7bc0a3689/`
303
+ const url = `https://quill-344421.uc.r.appspot.com/orgs/${publicKey}/`;
304
+ const response = await fetch(url, {
305
+ method: "GET",
306
+ headers: {
307
+ Authorization: "Bearer ",
308
+ environment: environment,
309
+ },
310
+ });
311
+ // If you need to retrieve the JSON data from the response:
312
+ const data = await response.json();
313
+ setOrganizations([...data.orgs, { id: "", name: "All Organizations" }]);
314
+ if (environment === "STAGING") {
315
+ setOrganization(data.orgs.filter((org) => org.id === client.stagingAdminCustomerId)[0]);
316
+ }
317
+ else {
318
+ setOrganization(data.orgs.filter((org) => org.id === client.adminCustomerId)[0]);
319
+ }
320
+ }
321
+ if (isSubscribed && environment && client) {
322
+ getCustomers();
323
+ }
324
+ return () => {
325
+ isSubscribed = false;
326
+ };
327
+ }, [environment, client, activeComponent]);
328
+ if (!client) {
329
+ return null;
330
+ }
331
+ const renderComponentBasedOnName = () => {
332
+ switch (activeComponent) {
333
+ case "Dashboards":
334
+ return ((0, jsx_runtime_1.jsx)(Dashboards, { TextInputComponent: TextInputComponent, ButtonComponent: ButtonComponent, SecondaryButtonComponent: SecondaryButtonComponent, ModalComponent: ModalComponent, SelectComponent: SelectComponent, OrganizationSelectComponent: OrganizationSelectComponent, setReportId: setReportId }));
335
+ case "SQL editor":
336
+ return ((0, jsx_runtime_1.jsx)(QueryEditor, { TextInputComponent: TextInputComponent, ButtonComponent: ButtonComponent, SecondaryButtonComponent: SecondaryButtonComponent, ModalComponent: ModalComponent, SelectComponent: SelectComponent }));
337
+ case "Report":
338
+ return ((0, jsx_runtime_1.jsx)(ReportWrapper, { TextInputComponent: TextInputComponent, ButtonComponent: ButtonComponent, SecondaryButtonComponent: SecondaryButtonComponent, ModalComponent: ModalComponent, SelectComponent: SelectComponent }));
339
+ case "SQL views":
340
+ return ((0, jsx_runtime_1.jsx)(Tables, { TextInputComponent: TextInputComponent, ButtonComponent: ButtonComponent, SecondaryButtonComponent: SecondaryButtonComponent, ModalComponent: ModalComponent, SelectComponent: SelectComponent }));
341
+ default:
342
+ return ((0, jsx_runtime_1.jsx)(Dashboards, { TextInputComponent: TextInputComponent, ButtonComponent: ButtonComponent, SecondaryButtonComponent: SecondaryButtonComponent, OrganizationSelectComponent: OrganizationSelectComponent, ModalComponent: ModalComponent, SelectComponent: SelectComponent }));
343
+ }
344
+ };
345
+ return ((0, jsx_runtime_1.jsxs)("div", { style: {
346
+ display: "flex",
347
+ flexDirection: "column",
348
+ height: "100vh",
349
+ width: "100vw",
350
+ }, children: [activeComponent !== "Report" && ((0, jsx_runtime_1.jsxs)("nav", { style: {
351
+ zIndex: 2,
352
+ height: "70px",
353
+ width: "100%",
354
+ display: "flex",
355
+ flexDirection: "row",
356
+ justifyContent: "space-between",
357
+ alignItems: "center",
358
+ backgroundColor: "white",
359
+ padding: "0",
360
+ position: "fixed",
361
+ top: 0,
362
+ left: 0,
363
+ right: 0,
364
+ borderBottomWidth: 1,
365
+ borderTopWidth: 0,
366
+ borderLeftWidth: 0,
367
+ borderRightWidth: 0,
368
+ borderStyle: "solid",
369
+ borderColor: exports.theme.borderColor,
370
+ }, children: [(0, jsx_runtime_1.jsx)("div", { style: {
371
+ paddingTop: "18px",
372
+ paddingLeft: "14px",
373
+ paddingBottom: "18px",
374
+ width: 230,
375
+ }, children: (0, jsx_runtime_1.jsxs)("svg", { width: "45", height: "18", viewBox: "0 0 45 18", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [(0, jsx_runtime_1.jsx)("g", { clipPath: "url(#clip0_2489_282)", children: (0, jsx_runtime_1.jsx)("path", { d: "M18.634 17.3008H9.196C7.97867 17.3008 6.84933 17.1248 5.808 16.7728C4.78133 16.4061 3.894 15.8781 3.146 15.1888C2.398 14.4994 1.81133 13.6634 1.386 12.6808C0.960667 11.6981 0.748 10.5761 0.748 9.31478C0.748 8.14145 0.960667 7.06345 1.386 6.08078C1.826 5.09811 2.42 4.25478 3.168 3.55078C3.916 2.84678 4.796 2.30411 5.808 1.92278C6.82 1.52678 7.90533 1.32878 9.064 1.32878C10.2227 1.32878 11.308 1.52678 12.32 1.92278C13.332 2.31878 14.212 2.86878 14.96 3.57278C15.708 4.27678 16.2947 5.12011 16.72 6.10278C17.16 7.07078 17.38 8.14145 17.38 9.31478C17.38 9.87211 17.314 10.4148 17.182 10.9428C17.0647 11.4708 16.8813 11.9694 16.632 12.4388C16.3827 12.9081 16.06 13.3334 15.664 13.7148C15.268 14.0814 14.806 14.3821 14.278 14.6168V14.6608H18.634V17.3008ZM4.312 9.31478C4.312 9.98945 4.43667 10.6201 4.686 11.2068C4.93533 11.7934 5.27267 12.3068 5.698 12.7468C6.138 13.1721 6.644 13.5094 7.216 13.7588C7.788 14.0081 8.404 14.1328 9.064 14.1328C9.724 14.1328 10.34 14.0081 10.912 13.7588C11.484 13.5094 11.9827 13.1721 12.408 12.7468C12.848 12.3068 13.1927 11.7934 13.442 11.2068C13.6913 10.6201 13.816 9.98945 13.816 9.31478C13.816 8.64011 13.6913 8.00945 13.442 7.42278C13.1927 6.83611 12.848 6.33011 12.408 5.90478C11.9827 5.46478 11.484 5.12011 10.912 4.87078C10.34 4.62145 9.724 4.49678 9.064 4.49678C8.404 4.49678 7.788 4.62145 7.216 4.87078C6.644 5.12011 6.138 5.46478 5.698 5.90478C5.27267 6.33011 4.93533 6.83611 4.686 7.42278C4.43667 8.00945 4.312 8.64011 4.312 9.31478ZM29.3164 17.3008H26.1484V15.8488H26.1044C25.987 16.0541 25.833 16.2594 25.6424 16.4648C25.4664 16.6701 25.2464 16.8534 24.9824 17.0148C24.7184 17.1761 24.4177 17.3081 24.0804 17.4108C23.743 17.5134 23.3764 17.5648 22.9804 17.5648C22.1444 17.5648 21.4624 17.4401 20.9344 17.1908C20.421 16.9268 20.0177 16.5674 19.7244 16.1128C19.4457 15.6581 19.255 15.1228 19.1524 14.5068C19.0644 13.8908 19.0204 13.2234 19.0204 12.5048V6.60878H22.3204V11.8448C22.3204 12.1528 22.3277 12.4754 22.3424 12.8128C22.3717 13.1354 22.4377 13.4361 22.5404 13.7148C22.6577 13.9934 22.8264 14.2208 23.0464 14.3968C23.281 14.5728 23.611 14.6608 24.0364 14.6608C24.4617 14.6608 24.8064 14.5874 25.0704 14.4408C25.3344 14.2794 25.5324 14.0741 25.6644 13.8248C25.811 13.5608 25.9064 13.2674 25.9504 12.9448C25.9944 12.6221 26.0164 12.2848 26.0164 11.9328V6.60878H29.3164V17.3008ZM30.8172 6.60878H34.1172V17.3008H30.8172V6.60878ZM30.5532 3.24278C30.5532 2.71478 30.7365 2.26745 31.1032 1.90078C31.4845 1.51945 31.9392 1.32878 32.4672 1.32878C32.9952 1.32878 33.4425 1.51945 33.8092 1.90078C34.1905 2.26745 34.3812 2.71478 34.3812 3.24278C34.3812 3.77078 34.1905 4.22545 33.8092 4.60678C33.4425 4.97345 32.9952 5.15678 32.4672 5.15678C31.9392 5.15678 31.4845 4.97345 31.1032 4.60678C30.7365 4.22545 30.5532 3.77078 30.5532 3.24278ZM35.652 0.66878H38.952V17.3008H35.652V0.66878ZM40.4869 0.66878H43.7869V17.3008H40.4869V0.66878Z", fill: "#212121" }) }), (0, jsx_runtime_1.jsx)("defs", { children: (0, jsx_runtime_1.jsx)("clipPath", { id: "clip0_2489_282", children: (0, jsx_runtime_1.jsx)("rect", { width: "45", height: "18", fill: "white" }) }) })] }) }), (0, jsx_runtime_1.jsxs)("div", { style: { display: "flex", flexDirection: "row" }, children: [(0, jsx_runtime_1.jsx)("button", { style: {
376
+ color: "#212121",
377
+ backgroundColor: activeComponent === "Dashboards"
378
+ ? "#2121210A"
379
+ : "transparent",
380
+ padding: "8px 12px",
381
+ height: "38px",
382
+ marginBottom: "4px",
383
+ fontWeight: "bold",
384
+ fontSize: "0.875rem",
385
+ borderRadius: "4px",
386
+ transition: "background-color 0.3s",
387
+ border: "none",
388
+ outline: "none",
389
+ }, onClick: () => setActiveComponent("Dashboards"), children: "Dashboards" }), (0, jsx_runtime_1.jsx)("button", { style: {
390
+ color: "#212121",
391
+ backgroundColor: activeComponent === "SQL editor"
392
+ ? "#2121210A"
393
+ : "transparent",
394
+ padding: "8px 12px",
395
+ height: "38px",
396
+ marginBottom: "4px",
397
+ fontWeight: "bold",
398
+ fontSize: "0.875rem",
399
+ borderRadius: "4px",
400
+ transition: "background-color 0.3s",
401
+ border: "none",
402
+ outline: "none",
403
+ }, onClick: () => setActiveComponent("SQL editor"), children: "SQL editor" }), (0, jsx_runtime_1.jsx)("button", { style: {
404
+ color: "#212121",
405
+ backgroundColor: activeComponent === "SQL views" ? "#2121210A" : "transparent",
406
+ padding: "8px 12px",
407
+ height: "38px",
408
+ marginBottom: "4px",
409
+ fontWeight: "bold",
410
+ fontSize: "0.875rem",
411
+ borderRadius: "4px",
412
+ transition: "background-color 0.3s",
413
+ border: "none",
414
+ outline: "none",
415
+ }, onClick: () => setActiveComponent("SQL views"), children: "SQL views" })] }), (0, jsx_runtime_1.jsx)("div", { style: {
416
+ display: "flex",
417
+ flexDirection: "row",
418
+ minHeight: "50px",
419
+ justifyContent: "flex-end",
420
+ alignItems: "center",
421
+ paddingRight: "8px",
422
+ width: 230,
423
+ }, children: (0, jsx_runtime_1.jsx)(UserManagementComponent, {}) })] })), (0, jsx_runtime_1.jsx)("div", { style: {
424
+ display: "flex",
425
+ flexDirection: "column",
426
+ height: "100%",
427
+ width: "100%",
428
+ // marginTop: activeComponent !== 'Report' ? '70px' : undefined
429
+ }, children: (0, jsx_runtime_1.jsx)(react_2.QuillProvider
430
+ // organizationId={'2'}
431
+ // publicKey={client?._id}
432
+ , {
433
+ // organizationId={'2'}
434
+ // publicKey={client?._id}
435
+ organizationId: organizationId, publicKey: publicKey, environment: environment, theme: exports.theme, children: renderComponentBasedOnName() }) })] }));
436
+ }
437
+ exports.theme = {
438
+ fontFamily: "Inter; Helvetica",
439
+ backgroundColor: "#FFFFFF",
440
+ primaryTextColor: "#364153",
441
+ secondaryTextColor: "#6C727F",
442
+ chartLabelFontFamily: "Inter; Helvetica",
443
+ chartLabelColor: "#666666",
444
+ chartTickColor: "#CCCCCC",
445
+ chartColors: ["#6269E9", "#E14F62"],
446
+ borderColor: "#E5E7EB",
447
+ borderWidth: 1,
448
+ primaryButtonColor: "#212121",
449
+ };
450
+ function convertPostgresColumn(column) {
451
+ let format;
452
+ switch (column.dataTypeID) {
453
+ case 20: // int8
454
+ case 21: // int2
455
+ case 23: // int4
456
+ format = "whole_number";
457
+ break;
458
+ case 700: // float4
459
+ case 701: // float8
460
+ case 1700: // numeric
461
+ format = "two_decimal_places";
462
+ break;
463
+ case 1082: // date
464
+ case 1083: // time
465
+ case 1184: // timestamptz
466
+ case 1114: // timestamp
467
+ format = "MMM_dd_yyyy";
468
+ break;
469
+ case 1043: // varchar
470
+ default:
471
+ format = "string";
472
+ }
473
+ return {
474
+ label: column.name,
475
+ field: column.name,
476
+ format: format,
477
+ };
478
+ }
479
+ exports.convertPostgresColumn = convertPostgresColumn;
480
+ function getPostgresBasicType(column) {
481
+ let format;
482
+ // first check if column.dataTypeID exists
483
+ if (column.dataTypeID) {
484
+ switch (column.dataTypeID) {
485
+ case 20: // int8
486
+ case 21: // int2
487
+ case 23: // int4
488
+ case 700: // float4
489
+ case 701: // float8
490
+ case 1700: // numeric
491
+ format = "number";
492
+ break;
493
+ case 1082: // date
494
+ case 1083: // time
495
+ case 1184: // timestamptz
496
+ case 1114: // timestamp
497
+ format = "date";
498
+ break;
499
+ case 1043: // varchar
500
+ default:
501
+ format = "string";
502
+ }
503
+ }
504
+ else if (column.fieldType) {
505
+ // if column.dataTypeID doesn't exist, check column.fieldType
506
+ switch (column.fieldType) {
507
+ case "int8":
508
+ case "int2":
509
+ case "int4":
510
+ case "float4":
511
+ case "float8":
512
+ case "numeric":
513
+ format = "number";
514
+ break;
515
+ case "date":
516
+ case "time":
517
+ case "timestamptz":
518
+ case "timestamp":
519
+ format = "date";
520
+ break;
521
+ case "varchar":
522
+ default:
523
+ format = "string";
524
+ }
525
+ }
526
+ return format;
527
+ }
528
+ exports.getPostgresBasicType = getPostgresBasicType;
529
+ function classNames(...classes) {
530
+ return classes.filter(Boolean).join(" ");
531
+ }
532
+ exports.classNames = classNames;
533
+ function Dashboards({ setReportId, TextInputComponent, ButtonComponent, SecondaryButtonComponent, OrganizationSelectComponent, ModalComponent, SelectComponent, }) {
534
+ const [organizations] = (0, react_1.useContext)(OrganizationsContext);
535
+ const [organization, setOrganization] = (0, react_1.useContext)(OrganizationContext);
536
+ const [environment] = (0, react_1.useContext)(EnvironmentContext);
537
+ const [dashboards, setDashboards] = (0, react_1.useState)([]);
538
+ const [selectedDashboard, setSelectedDashboard] = (0, react_1.useState)("");
539
+ const [addFilterModalIsOpen, setAddFilterModalIsOpen] = (0, react_1.useState)(false);
540
+ const [editFilterModalIsOpen, setEditFilterModalIsOpen] = (0, react_1.useState)(false);
541
+ const [dashboardData, setDashboardData] = (0, react_1.useState)(null);
542
+ const [activeComponent, setActiveComponent] = (0, react_1.useContext)(ActiveComponentContext);
543
+ const [isOpen, setIsOpen] = (0, react_1.useState)(false);
544
+ const [client] = (0, react_1.useContext)(ClientContext);
545
+ // const navigate = useNavigate();
546
+ // useEffect(() => {
547
+ // if (customValue.length && customValue !== id && !userTyping) {
548
+ // navigate(`/dashboards/${customValue}`);
549
+ // // window.location.reload();
550
+ // }
551
+ // // } else {
552
+ // // navigate("/");
553
+ // // }
554
+ // }, [customValue, userTyping]);
555
+ console.log("IS CLIENT IN HERE: ", client);
556
+ (0, react_1.useEffect)(() => {
557
+ let isSubscribed = true;
558
+ async function getDashNames() {
559
+ const url = `https://quill-344421.uc.r.appspot.com/dashnames/${client._id}/`;
560
+ const response2 = await fetch(url, {
561
+ method: "GET",
562
+ headers: {
563
+ Authorization: "Bearer ",
564
+ environment: environment,
565
+ },
566
+ });
567
+ // If you need to retrieve the JSON data from the response:
568
+ const data = await response2.json();
569
+ const dashNames = data.dashboardNames.map((elem) => {
570
+ if (!elem) {
571
+ return { name: "null" };
572
+ }
573
+ return { name: elem };
574
+ });
575
+ setDashboards(dashNames);
576
+ setSelectedDashboard(dashNames[0].name);
577
+ }
578
+ if (isSubscribed) {
579
+ getDashNames();
580
+ }
581
+ return () => {
582
+ isSubscribed = false;
583
+ };
584
+ }, [environment]);
585
+ // useEffect(() => {
586
+ // if (id && id.length) {
587
+ // window.location.reload();
588
+ // }
589
+ // }, [id]);
590
+ const handleSetOrganization = (org) => {
591
+ setOrganization(null);
592
+ setTimeout(() => setOrganization(org), 50);
593
+ };
594
+ (0, react_1.useEffect)(() => {
595
+ async function getDashboardData() {
596
+ const url = new URL(`https://quill-344421.uc.r.appspot.com/dashconfig/`);
597
+ // Setting the search parameters for the URL
598
+ url.search = new URLSearchParams({
599
+ orgId: organization ? organization.id : "",
600
+ publicKey: client._id,
601
+ name: selectedDashboard,
602
+ }).toString();
603
+ const response2 = await fetch(url, {
604
+ method: "GET",
605
+ headers: {
606
+ Authorization: "Bearer ",
607
+ environment: environment,
608
+ },
609
+ });
610
+ // If you need to retrieve the JSON data from the response:
611
+ const data = await response2.json();
612
+ setDashboardData(data);
613
+ }
614
+ if (selectedDashboard && client) {
615
+ getDashboardData();
616
+ }
617
+ }, [selectedDashboard, organization, client]);
618
+ return ((0, jsx_runtime_1.jsxs)("div", { style: {
619
+ display: "flex",
620
+ flexDirection: "column",
621
+ paddingTop: "0px",
622
+ }, children: [(0, jsx_runtime_1.jsx)("div", { style: {
623
+ // width: 'calc(100vw - 30px)',
624
+ display: "flex",
625
+ position: "fixed",
626
+ backgroundColor: "white",
627
+ zIndex: 1,
628
+ left: 0,
629
+ right: 0,
630
+ top: 0,
631
+ flexDirection: "row",
632
+ paddingTop: 85,
633
+ alignItems: "center",
634
+ justifyContent: "space-between",
635
+ paddingLeft: "30px",
636
+ paddingRight: "30px",
637
+ borderBottomWidth: 1,
638
+ borderTopWidth: 0,
639
+ borderLeftWidth: 0,
640
+ borderRightWidth: 0,
641
+ borderStyle: "solid",
642
+ borderColor: exports.theme.borderColor,
643
+ paddingBottom: 20,
644
+ boxShadow: "0px 1px 4px 0px rgba(0, 0, 0, 0.07)",
645
+ // paddingRight: '50px',
646
+ // position: 'absolute'
647
+ // // zIndex: 10
648
+ }, children: (0, jsx_runtime_1.jsxs)("div", { style: {
649
+ display: "flex",
650
+ flexDirection: "row",
651
+ alignItems: "flex-end",
652
+ justifyContent: "space-between",
653
+ width: "100%",
654
+ // marginLeft: '25px'
655
+ }, children: [(0, jsx_runtime_1.jsx)("h1", { style: {
656
+ fontSize: "36px",
657
+ paddingTop: "0px",
658
+ fontWeight: "600",
659
+ color: "#384151",
660
+ margin: 0,
661
+ paddingBottom: 4,
662
+ }, children: "Dashboards" }), (0, jsx_runtime_1.jsxs)("div", { style: {
663
+ display: "flex",
664
+ flexDirection: "row",
665
+ alignItems: "center",
666
+ }, children: [(0, jsx_runtime_1.jsx)("div", { style: { width: "20px" } }), (0, jsx_runtime_1.jsx)("div", { style: { display: "flex", flexDirection: "column" }, children: (0, jsx_runtime_1.jsxs)("div", { style: {
667
+ display: "flex",
668
+ flexDirection: "row",
669
+ alignItems: "flex-end",
670
+ gap: 16,
671
+ }, children: [OrganizationSelectComponent && (0, jsx_runtime_1.jsx)(OrganizationSelectComponent, {}), (0, jsx_runtime_1.jsxs)("div", { style: { display: "flex", flexDirection: "column" }, children: [(0, jsx_runtime_1.jsx)("h1", { style: {
672
+ fontSize: "14px",
673
+ paddingTop: "0px",
674
+ marginTop: "0px",
675
+ marginBottom: "4px",
676
+ fontWeight: "600",
677
+ color: exports.theme.secondaryTextColor,
678
+ }, children: "Dashboard" }), (0, jsx_runtime_1.jsx)(SelectComponent, { options: dashboards.length
679
+ ? dashboards.map((elem) => {
680
+ return { value: elem.name, label: elem.name };
681
+ })
682
+ : [], onChange: (e) => setSelectedDashboard(e.target.value), value: selectedDashboard })] }), (0, jsx_runtime_1.jsx)("div", { style: {
683
+ minWidth: 238 - 120,
684
+ gap: 12,
685
+ display: "flex",
686
+ flexDirection: "row",
687
+ }, children: (0, jsx_runtime_1.jsx)(SecondaryButtonComponent, { label: "Create report", onClick: () => setActiveComponent("SQL editor") }) })] }) })] })] }) }), (0, jsx_runtime_1.jsx)("div", { style: { paddingTop: "190px", display: "inline-block" }, children: selectedDashboard && ((0, jsx_runtime_1.jsx)(react_2.Dashboard
688
+ // TODO: CHANGE
689
+ , {
690
+ // TODO: CHANGE
691
+ name: selectedDashboard,
692
+ // name='Customer Report'
693
+ containerStyle: {
694
+ // height: "850px",
695
+ paddingRight: 25,
696
+ // display: "block",
697
+ // width: 'calc(100% - 50px)'
698
+ }, onClickDashboardItem: (elem) => {
699
+ setReportId(elem._id);
700
+ setActiveComponent("Report");
701
+ } })) })] }));
702
+ }
703
+ function EditDashboardsModal({ ModalComponent, isOpen, setIsOpen, clientId }) {
704
+ const [dashboards, setDashboards] = (0, react_1.useState)([]);
705
+ (0, react_1.useEffect)(() => {
706
+ async function getDashboards(clientId) {
707
+ const url = `https://quill-344421.uc.r.appspot.com/dashs/${clientId}/`;
708
+ const response2 = await fetch(url, {
709
+ method: "GET",
710
+ headers: {
711
+ Authorization: "Bearer ", // Ensure you append your token after 'Bearer ' if needed
712
+ },
713
+ });
714
+ // If you need to retrieve the JSON data from the response:
715
+ const data = await response2.json();
716
+ }
717
+ if (clientId) {
718
+ getDashboards(clientId);
719
+ }
720
+ }, [clientId]);
721
+ return ((0, jsx_runtime_1.jsx)(ModalComponent, { isOpen: isOpen, close: () => setIsOpen(false), children: (0, jsx_runtime_1.jsx)("div", {}) }));
722
+ }
723
+ function DropdownMenu({ items, setSelected, selected, filterKey }) {
724
+ return ((0, jsx_runtime_1.jsx)("select", { onChange: (e) => {
725
+ setSelected(items.find((item) => item.name === e.target.value));
726
+ }, value: selected ? selected.name : "", children: items.slice(0, 50).map((item) => ((0, jsx_runtime_1.jsx)("option", { value: item.name, children: item.name }, item.name))) }));
727
+ }
728
+ exports.DropdownMenu = DropdownMenu;
729
+ function defineEditorTheme(monaco, theme) {
730
+ monaco.editor.defineTheme("onedark", {
731
+ base: theme.darkMode ? "vs-dark" : "vs",
732
+ inherit: true,
733
+ rules: [
734
+ {
735
+ token: "comment",
736
+ foreground: "#5d7988",
737
+ fontStyle: "italic",
738
+ },
739
+ { token: "constant", foreground: "#e06c75" },
740
+ ],
741
+ colors: {
742
+ "editor.background": "#F9F9F9",
743
+ },
744
+ });
745
+ }
746
+ function setEditorTheme(editor, monaco) {
747
+ try {
748
+ monaco.editor.setTheme("onedark");
749
+ }
750
+ catch (e) {
751
+ console.log("ERROR: ", e);
752
+ }
753
+ }
754
+ function Tables({ TextInputComponent, ButtonComponent, SecondaryButtonComponent, ModalComponent, SelectComponent, }) {
755
+ const [tables, setTables] = (0, react_1.useState)([]);
756
+ const [modalIsOpen, setIsOpen] = (0, react_1.useState)(false);
757
+ const [editModalIsOpen, setEditModalIsOpen] = (0, react_1.useState)(false);
758
+ const [name, setName] = (0, react_1.useState)("");
759
+ const [viewQuery, setViewQuery] = (0, react_1.useState)("");
760
+ const [editViewId, setEditViewId] = (0, react_1.useState)("");
761
+ const [editName, setEditName] = (0, react_1.useState)("");
762
+ const [editViewQuery, setEditViewQuery] = (0, react_1.useState)("");
763
+ const [client] = (0, react_1.useContext)(ClientContext);
764
+ const [code, setCode] = (0, react_1.useState)(``);
765
+ const [tableToBeDeleted, setTableToBeDeleted] = (0, react_1.useState)("");
766
+ const [deleteName, setDeleteName] = (0, react_1.useState)("");
767
+ const [deleteModalIsOpen, setDeleteModalIsOpen] = (0, react_1.useState)(false);
768
+ const closeDeleteModal = () => {
769
+ setDeleteModalIsOpen(false);
770
+ };
771
+ const openModal = () => {
772
+ setIsOpen(true);
773
+ setCode("");
774
+ };
775
+ const closeModal = () => {
776
+ setIsOpen(false);
777
+ setName("");
778
+ setViewQuery("");
779
+ };
780
+ const closeEditModal = () => {
781
+ setEditModalIsOpen(false);
782
+ setEditName("");
783
+ setEditViewQuery("");
784
+ };
785
+ const clickTableCell = (table) => {
786
+ setEditModalIsOpen(true);
787
+ setEditName(table.name);
788
+ setEditViewQuery(table.viewQuery);
789
+ setEditViewId(table._id);
790
+ setCode(table.viewQuery);
791
+ };
792
+ const handleDeleteTable = async () => {
793
+ if (deleteName !== tableToBeDeleted) {
794
+ alert("Table names must match");
795
+ return;
796
+ }
797
+ const response = await fetch(`https://quill-344421.uc.r.appspot.com/table/${client._id}/`, {
798
+ method: "POST",
799
+ headers: { Authorization: `Bearer ` },
800
+ body: JSON.stringify({
801
+ id: editViewId,
802
+ deleted: true,
803
+ }),
804
+ });
805
+ const data = await response.json();
806
+ if (data) {
807
+ setDeleteName("");
808
+ setDeleteModalIsOpen(false);
809
+ setEditModalIsOpen(false);
810
+ setEditName("");
811
+ setEditViewQuery("");
812
+ getTables();
813
+ }
814
+ };
815
+ const getTables = async () => {
816
+ const response = await fetch(`https://quill-344421.uc.r.appspot.com/schema2/${client._id}/`, {
817
+ method: "GET",
818
+ headers: { Authorization: `Bearer ` },
819
+ });
820
+ const data = await response.json();
821
+ setTables(data.tables);
822
+ };
823
+ (0, react_1.useEffect)(() => {
824
+ let isSubscribed = true;
825
+ if (isSubscribed && client) {
826
+ getTables();
827
+ }
828
+ return () => {
829
+ isSubscribed = false;
830
+ };
831
+ }, []);
832
+ const handleClickFirstDelete = () => {
833
+ setTableToBeDeleted(editName);
834
+ setDeleteModalIsOpen(true);
835
+ };
836
+ const handleEditTable = async () => {
837
+ if (!editName.length) {
838
+ alert("Please enter a table name.");
839
+ return;
840
+ }
841
+ if (!editViewQuery.length) {
842
+ alert("Please enter a table query.");
843
+ return;
844
+ }
845
+ if (editViewQuery[editViewQuery.length - 1] === ";") {
846
+ const response = await fetch(`https://quill-344421.uc.r.appspot.com/table/${client._id}/`, {
847
+ method: "POST",
848
+ headers: {
849
+ "Content-Type": "application/json",
850
+ Authorization: `Bearer `,
851
+ },
852
+ body: JSON.stringify({
853
+ viewQuery: editViewQuery.slice(0, -1),
854
+ name: editName,
855
+ id: editViewId,
856
+ }),
857
+ });
858
+ const data = await response.json();
859
+ if (data) {
860
+ closeEditModal();
861
+ getTables();
862
+ }
863
+ return;
864
+ }
865
+ const response = await fetch(`https://quill-344421.uc.r.appspot.com/table/${client._id}/`, {
866
+ method: "POST",
867
+ headers: {
868
+ "Content-Type": "application/json",
869
+ Authorization: `Bearer `,
870
+ },
871
+ body: JSON.stringify({
872
+ viewQuery: editViewQuery,
873
+ name: editName,
874
+ id: editViewId,
875
+ }),
876
+ });
877
+ const data = await response.json();
878
+ if (data) {
879
+ closeEditModal();
880
+ getTables();
881
+ }
882
+ };
883
+ const handleAddTable = async () => {
884
+ if (!name.length) {
885
+ alert("Please enter a table name.");
886
+ return;
887
+ }
888
+ if (!code.length) {
889
+ alert("Please enter a table query.");
890
+ return;
891
+ }
892
+ if (code[code.length - 1] === ";") {
893
+ const response = await fetch(`https://quill-344421.uc.r.appspot.com/table/${client._id}/`, {
894
+ method: "POST",
895
+ headers: {
896
+ "Content-Type": "application/json",
897
+ Authorization: `Bearer `,
898
+ },
899
+ body: JSON.stringify({
900
+ viewQuery: code.slice(0, -1),
901
+ name: name,
902
+ }),
903
+ });
904
+ const data = await response.json();
905
+ if (data) {
906
+ closeModal();
907
+ getTables();
908
+ }
909
+ return;
910
+ }
911
+ const response = await fetch(`https://quill-344421.uc.r.appspot.com/table/${client._id}/`, {
912
+ method: "POST",
913
+ headers: {
914
+ "Content-Type": "application/json",
915
+ Authorization: `Bearer `,
916
+ },
917
+ body: JSON.stringify({
918
+ viewQuery: code,
919
+ name: name,
920
+ }),
921
+ });
922
+ const data = await response.json();
923
+ if (data) {
924
+ closeModal();
925
+ getTables();
926
+ }
927
+ };
928
+ return ((0, jsx_runtime_1.jsxs)("div", { style: { paddingLeft: "50px", paddingRight: "50px" }, children: [(0, jsx_runtime_1.jsxs)("div", { style: {
929
+ width: "100%",
930
+ display: "flex",
931
+ flexDirection: "row",
932
+ alignItems: "center",
933
+ justifyContent: "space-between",
934
+ paddingTop: "90px",
935
+ paddingBottom: "25px",
936
+ }, children: [(0, jsx_runtime_1.jsx)("h1", { style: {
937
+ fontSize: "36px",
938
+ paddingTop: "0px",
939
+ marginTop: "0px",
940
+ fontWeight: "700",
941
+ color: "#384151",
942
+ }, children: "SQL views" }), (0, jsx_runtime_1.jsx)(ButtonComponent, { onClick: openModal, label: "Add view +" })] }), (0, jsx_runtime_1.jsx)("div", { style: { display: "flex", flexWrap: "wrap" }, children: tables.length
943
+ ? tables.map((table) => ((0, jsx_runtime_1.jsx)(TableCell, { table: table, clickTableCell: clickTableCell })))
944
+ : null }), (0, jsx_runtime_1.jsx)(ModalComponent, { isOpen: modalIsOpen, close: closeModal, children: (0, jsx_runtime_1.jsxs)("div", { className: "flex flex-col p-[6px]", children: [(0, jsx_runtime_1.jsx)("h1", { className: "text-3xl pt-[0px] mt-[0px] mb-[12px] font-bold text-[#212121]", children: "Add view" }), (0, jsx_runtime_1.jsx)("h3", { className: "font-semibold text-sm mb-[6px] text-[#212121]", children: "name" }), (0, jsx_runtime_1.jsx)(TextInputComponent, { placeholder: "Enter table display name...", onChange: (e) => setName(e.target.value), value: name }), (0, jsx_runtime_1.jsx)("h3", { className: "font-semibold text-sm mt-[12px] mb-[6px] text-[#212121]", children: "query" }), (0, jsx_runtime_1.jsx)("div", { style: {
945
+ background: exports.theme.backgroundColor,
946
+ // maxHeight: 700,
947
+ width: "800px",
948
+ height: "500px",
949
+ // minWidth: 450,
950
+ // overflowY: "scroll",
951
+ // padding: "20px 30px 20px 20px",
952
+ // marginLeft: 20,
953
+ borderTopLeftRadius: 6,
954
+ borderBottomLeftRadius: 6,
955
+ borderTopRightRadius: 0,
956
+ borderBottomRightRadius: 0,
957
+ overflow: "hidden",
958
+ }, children: (0, jsx_runtime_1.jsx)(react_3.default, { height: "500px", width: "100%", defaultLanguage: "pgsql", defaultValue: "", value: code, loading: (0, jsx_runtime_1.jsx)("div", {}), options: {
959
+ wordWrap: "on",
960
+ minimap: {
961
+ enabled: false,
962
+ },
963
+ padding: { top: 16 },
964
+ }, onChange: (query) => setCode(query), beforeMount: (monaco) => defineEditorTheme(monaco, exports.theme), onMount: setEditorTheme }) }), (0, jsx_runtime_1.jsx)(ButtonComponent, { label: "Add view +", onClick: handleAddTable })] }) }), (0, jsx_runtime_1.jsx)(ModalComponent, { isOpen: editModalIsOpen, close: closeEditModal, children: (0, jsx_runtime_1.jsxs)("div", { className: "flex flex-col p-[6px]", children: [(0, jsx_runtime_1.jsxs)("div", { style: {
965
+ display: "flex",
966
+ flexDirection: "row",
967
+ alignItems: "center",
968
+ justifyContent: "space-between",
969
+ // width: '100%'
970
+ }, children: [(0, jsx_runtime_1.jsx)("h1", { style: {
971
+ fontSize: "24px",
972
+ paddingTop: "0px",
973
+ marginTop: "0px",
974
+ marginBottom: "0px",
975
+ fontWeight: "bold",
976
+ color: "#384151",
977
+ }, children: "Edit view" }), (0, jsx_runtime_1.jsx)("button", { style: {
978
+ background: "transparent",
979
+ border: "none",
980
+ outline: "none",
981
+ height: 24,
982
+ width: 24,
983
+ cursor: "pointer",
984
+ }, onClick: closeEditModal, children: (0, jsx_runtime_1.jsxs)("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", "stroke-width": "2", "stroke-linecap": "round", "stroke-linejoin": "round", height: "24px", width: "24px", children: [(0, jsx_runtime_1.jsx)("line", { x1: "18", x2: "6", y1: "6", y2: "18" }), (0, jsx_runtime_1.jsx)("line", { x1: "6", x2: "18", y1: "6", y2: "18" })] }) })] }), (0, jsx_runtime_1.jsx)("h3", { style: {
985
+ fontWeight: "600",
986
+ fontSize: "14px",
987
+ marginBottom: "6px",
988
+ color: "#212121",
989
+ }, children: "name" }), (0, jsx_runtime_1.jsx)(TextInputComponent, { placeholder: "Enter table display name...", onChange: (e) => setEditName(e.target.value), value: editName }), (0, jsx_runtime_1.jsx)("h3", { style: {
990
+ fontWeight: "600",
991
+ fontSize: "14px",
992
+ marginBottom: "6px",
993
+ color: "#212121",
994
+ }, children: "query" }), (0, jsx_runtime_1.jsx)("div", { style: {
995
+ background: exports.theme.backgroundColor,
996
+ // maxHeight: 700,
997
+ width: "520px",
998
+ height: "300px",
999
+ // minWidth: 450,
1000
+ // overflowY: "scroll",
1001
+ // padding: "20px 30px 20px 20px",
1002
+ // marginLeft: 20,
1003
+ borderTopLeftRadius: 6,
1004
+ borderBottomLeftRadius: 6,
1005
+ borderTopRightRadius: 0,
1006
+ borderBottomRightRadius: 0,
1007
+ overflow: "hidden",
1008
+ }, children: (0, jsx_runtime_1.jsx)(react_3.default, { height: "300px", width: "520px", defaultLanguage: "pgsql", defaultValue: "", value: code, loading: (0, jsx_runtime_1.jsx)("div", {}), options: {
1009
+ wordWrap: "on",
1010
+ minimap: {
1011
+ enabled: false,
1012
+ },
1013
+ padding: { top: 16 },
1014
+ }, onChange: (query) => setCode(query), beforeMount: (monaco) => defineEditorTheme(monaco, exports.theme), onMount: setEditorTheme }) }), (0, jsx_runtime_1.jsxs)("div", { style: {
1015
+ display: "flex",
1016
+ flexDirection: "row",
1017
+ alignItems: "center",
1018
+ marginTop: 20,
1019
+ gap: 8,
1020
+ }, children: [(0, jsx_runtime_1.jsx)(ButtonComponent, { onClick: handleEditTable, label: "Save changes" }), (0, jsx_runtime_1.jsx)(SecondaryButtonComponent, { onClick: handleClickFirstDelete, label: "Delete" })] })] }) }), (0, jsx_runtime_1.jsx)(ModalComponent, { isOpen: deleteModalIsOpen, close: closeDeleteModal, children: (0, jsx_runtime_1.jsxs)("div", { style: {
1021
+ display: "flex",
1022
+ flexDirection: "column",
1023
+ padding: "6px",
1024
+ }, children: [(0, jsx_runtime_1.jsxs)("h1", { style: {
1025
+ fontSize: "1.25rem",
1026
+ paddingTop: "0px",
1027
+ marginTop: "0px",
1028
+ marginBottom: "12px",
1029
+ fontWeight: "bold",
1030
+ color: "#212121",
1031
+ }, children: ["Confirm delete \"", tableToBeDeleted, "\" view"] }), (0, jsx_runtime_1.jsx)("h3", { style: {
1032
+ fontWeight: "600",
1033
+ fontSize: "0.875rem",
1034
+ marginBottom: "6px",
1035
+ color: "#212121",
1036
+ }, children: "View name" }), (0, jsx_runtime_1.jsx)(TextInputComponent, { placeholder: "Type view name to confirm delete...", onChange: (e) => setDeleteName(e.target.value), value: deleteName }), (0, jsx_runtime_1.jsx)("div", { style: { height: 20 } }), (0, jsx_runtime_1.jsx)(ButtonComponent, { onClick: handleDeleteTable, label: `Confirm delete ${tableToBeDeleted}` })] }) })] }));
1037
+ }
1038
+ function Modal({ isOpen, onRequestClose, children }) {
1039
+ if (!isOpen) {
1040
+ return null;
1041
+ }
1042
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { style: {
1043
+ position: "fixed",
1044
+ top: "0",
1045
+ right: "0",
1046
+ bottom: "0",
1047
+ left: "0",
1048
+ zIndex: "50",
1049
+ backgroundColor: "rgba(255, 255, 255, 0.8)",
1050
+ backdropFilter: "blur(5px)",
1051
+ } }), (0, jsx_runtime_1.jsx)("div", { style: {
1052
+ // position: "absolute",
1053
+ position: "fixed",
1054
+ left: "50%",
1055
+ top: "50%",
1056
+ zIndex: "50",
1057
+ // width: "100%",
1058
+ // maxWidth: 1024,
1059
+ maxHeight: "90vh",
1060
+ display: "flex",
1061
+ justifyContent: "center",
1062
+ alignItems: "center",
1063
+ transform: "translateX(-50%) translateY(-50%)",
1064
+ background: "white",
1065
+ borderRadius: 8,
1066
+ borderStyle: "solid",
1067
+ borderWidth: 1,
1068
+ borderColor: "#e7e7e7",
1069
+ overflow: "hidden",
1070
+ padding: 30,
1071
+ // zIndex: 1000,
1072
+ }, children: children })] }));
1073
+ }
1074
+ function TableCell({ table, clickTableCell }) {
1075
+ const handleClickTableCell = () => {
1076
+ clickTableCell(table);
1077
+ };
1078
+ return ((0, jsx_runtime_1.jsxs)("div", { onClick: handleClickTableCell, style: {
1079
+ marginBottom: "54px",
1080
+ flex: 1,
1081
+ minWidth: "540px",
1082
+ maxWidth: "540px",
1083
+ cursor: "pointer",
1084
+ }, children: [(0, jsx_runtime_1.jsx)("div", { style: { display: "flex", flexDirection: "row", alignItems: "center" }, children: (0, jsx_runtime_1.jsx)("h3", { style: { color: "#384151" }, children: table.displayName }) }), (0, jsx_runtime_1.jsx)(prism_react_renderer_1.default, { ...prism_react_renderer_1.defaultProps, theme: nightOwlLight_1.default, code: table.viewQuery, language: "sql", children: ({ className, style, tokens, getLineProps, getTokenProps }) => ((0, jsx_runtime_1.jsx)("pre", { className: className, style: {
1085
+ ...style,
1086
+ textAlign: "left",
1087
+ margin: "1em 0",
1088
+ padding: "0.5em",
1089
+ overflow: "scroll",
1090
+ maxHeight: 120,
1091
+ maxWidth: 520,
1092
+ // lineHeight: "1.3em",
1093
+ // height: "1.3em",
1094
+ }, children: tokens.map((line, i) => ((0, jsx_runtime_1.jsx)("div", { ...getLineProps({ line, key: i }), children: line.map((token, key) => ((0, jsx_runtime_1.jsx)("span", { ...getTokenProps({ token, key }) }, key))) }, i))) })) })] }));
1095
+ }
1096
+ function QueryEditor({ TextInputComponent, ButtonComponent, SecondaryButtonComponent, ModalComponent, SelectComponent, }) {
1097
+ const [customerId, setCustomerId] = (0, react_1.useState)("");
1098
+ const [checked, setChecked] = (0, react_1.useState)(false);
1099
+ const [selected, setSelected] = (0, react_1.useState)("");
1100
+ const [userTyping, setUserTyping] = (0, react_1.useState)(false);
1101
+ const inputRef = (0, react_1.useRef)(null);
1102
+ const [organizations, setOrganizations] = (0, react_1.useState)([]);
1103
+ const [filteredOptions, setFilteredOptions] = (0, react_1.useState)([]);
1104
+ const [sqlPrompt, setSqlPrompt] = (0, react_1.useState)("");
1105
+ const [dashboardNames, setDashboardNames] = (0, react_1.useState)([]);
1106
+ const [selectedDashboardName, setSelectedDashboardName] = (0, react_1.useState)("");
1107
+ const [isOpen, setIsOpen] = (0, react_1.useState)(false);
1108
+ const [organization, setOrganization] = (0, react_1.useContext)(OrganizationContext);
1109
+ const [activeQuery, setActiveQuery] = (0, react_1.useContext)(ActiveQueryContext);
1110
+ const [client] = (0, react_1.useContext)(ClientContext);
1111
+ const [environment] = (0, react_1.useContext)(EnvironmentContext);
1112
+ const [query, setQuery] = (0, react_1.useState)(activeQuery);
1113
+ const [rows, setRows] = (0, react_1.useState)([]);
1114
+ const [columns, setColumns] = (0, react_1.useState)([]);
1115
+ const [fields, setFields] = (0, react_1.useState)([]);
1116
+ const [schema] = (0, react_1.useContext)(SchemaContext);
1117
+ const [errorMessage, setErrorMessage] = (0, react_1.useState)("");
1118
+ const [sqlResponseLoading, setSqlResponseLoading] = (0, react_1.useState)(false);
1119
+ const [activeComponent, setActiveComponent] = (0, react_1.useContext)(ActiveComponentContext);
1120
+ (0, react_1.useEffect)(() => {
1121
+ setQuery(activeQuery);
1122
+ }, [activeQuery]);
1123
+ (0, react_1.useEffect)(() => {
1124
+ let isSubscribed = true;
1125
+ async function getCustomers() {
1126
+ const url = `https://quill-344421.uc.r.appspot.com/orgs/62cda15d7c9fcca7bc0a3689/`;
1127
+ const response = await fetch(url, {
1128
+ method: "GET",
1129
+ headers: {
1130
+ Authorization: "Bearer ",
1131
+ environment: environment,
1132
+ },
1133
+ });
1134
+ // If you need to retrieve the JSON data from the response:
1135
+ const data = await response.json();
1136
+ const response2 = await fetch(`https://quill-344421.uc.r.appspot.com/dashnames/${client._id}/`, {
1137
+ method: "GET",
1138
+ headers: {
1139
+ Authorization: `Bearer `,
1140
+ environment: environment,
1141
+ },
1142
+ });
1143
+ const response2Data = await response2.json();
1144
+ setOrganizations([...data.orgs, { id: "", name: "All Organizations" }]);
1145
+ const dashNames = response2Data.dashboardNames.filter((elem) => elem !== null);
1146
+ setDashboardNames(dashNames);
1147
+ setSelectedDashboardName(dashNames[0]);
1148
+ setFilteredOptions(data.customerIds);
1149
+ }
1150
+ if (isSubscribed) {
1151
+ getCustomers();
1152
+ }
1153
+ return () => {
1154
+ isSubscribed = false;
1155
+ };
1156
+ }, [environment]);
1157
+ // const navigate = useNavigate();
1158
+ const editChart = async ({ report, values, yAxisFields, columns, query }) => {
1159
+ const { publicKey, customerId, authToken } = client;
1160
+ const { xAxisLabel, yAxisLabel, chartName, chartType, xAxisField, xAxisFormat, dashboardName, dateFieldTable, dateField, } = values;
1161
+ if (!chartName) {
1162
+ alert("Please enter a chart name");
1163
+ return;
1164
+ }
1165
+ for (let i = 0; i < yAxisFields.length; i++) {
1166
+ if (!yAxisFields[i].label && chartType !== "pie") {
1167
+ alert(`Please enter a label for column '${yAxisFields[i].field}'`);
1168
+ return;
1169
+ }
1170
+ }
1171
+ if (!client || !organization) {
1172
+ return;
1173
+ }
1174
+ const response = await fetch(`https://quill-344421.uc.r.appspot.com/dashedit/${client._id}/${organization.id}/`, {
1175
+ method: "POST",
1176
+ headers: {
1177
+ "Content-Type": "application/json",
1178
+ Authorization: `Bearer ${authToken}`,
1179
+ environment: environment || undefined,
1180
+ },
1181
+ body: JSON.stringify({
1182
+ name: chartName,
1183
+ xAxisField,
1184
+ yAxisFields,
1185
+ xAxisLabel,
1186
+ xAxisFormat,
1187
+ yAxisLabel,
1188
+ chartType,
1189
+ dashboardName,
1190
+ columns,
1191
+ dateField: { table: dateFieldTable, field: dateField },
1192
+ query: query,
1193
+ }),
1194
+ });
1195
+ const responseData = await response.json();
1196
+ if (!responseData) {
1197
+ return;
1198
+ }
1199
+ // setDashboard((dashboard) => {
1200
+ // return {
1201
+ // ...dashboard,
1202
+ // [response.data._id]: { ...existingVisualization, ...response.data }
1203
+ // }
1204
+ // })
1205
+ setIsOpen(false);
1206
+ setActiveComponent("/Dashboards");
1207
+ };
1208
+ const handleRunSqlPrompt = async () => {
1209
+ const { _id } = client;
1210
+ setSqlResponseLoading(true);
1211
+ const response = await fetch(`https://quill-344421.uc.r.appspot.com/quillai`, {
1212
+ method: "POST",
1213
+ headers: {
1214
+ Authorization: `Bearer `,
1215
+ environment: environment,
1216
+ "Content-Type": "application/json", // Important when sending JSON
1217
+ },
1218
+ body: JSON.stringify({
1219
+ initialQuestion: sqlPrompt,
1220
+ publicKey: _id,
1221
+ }),
1222
+ });
1223
+ const responseData = await response.json();
1224
+ setQuery(responseData.message);
1225
+ setSqlResponseLoading(false);
1226
+ };
1227
+ const handleRunQuery = async () => {
1228
+ const { _id } = client;
1229
+ try {
1230
+ const response = await fetch(`https://quill-344421.uc.r.appspot.com/dashquery?orgId=${organization && organization.id ? organization.id : ""}&publicKey=${_id}`, {
1231
+ method: "POST",
1232
+ headers: {
1233
+ Authorization: `Bearer `,
1234
+ environment: environment,
1235
+ "Content-Type": "application/json", // Important when sending JSON
1236
+ },
1237
+ body: JSON.stringify({
1238
+ query,
1239
+ }),
1240
+ });
1241
+ const responseData = await response.json();
1242
+ if (responseData && responseData.errorMessage) {
1243
+ setErrorMessage("Failed to run SQL query: " + responseData.errorMessage);
1244
+ setRows([]);
1245
+ setColumns([]);
1246
+ setFields([]);
1247
+ return;
1248
+ }
1249
+ setErrorMessage("");
1250
+ setRows(responseData.rows);
1251
+ setColumns(responseData.fields.map((elem) => convertPostgresColumn(elem)));
1252
+ setFields(responseData.fields);
1253
+ console.log("too easy");
1254
+ }
1255
+ catch (e) {
1256
+ console.log("ERROR: ", e);
1257
+ return;
1258
+ }
1259
+ };
1260
+ const handleAddToDashboard = () => {
1261
+ setIsOpen(true);
1262
+ };
1263
+ const newRows = (0, react_1.useMemo)(() => {
1264
+ return JSON.parse(JSON.stringify(rows));
1265
+ }, [rows]);
1266
+ /* all your useState and useContext calls and your useEffect hooks */
1267
+ const handleSetOrganization = (org) => {
1268
+ setOrganization(null);
1269
+ setTimeout(() => setOrganization(org), 50);
1270
+ };
1271
+ return ((0, jsx_runtime_1.jsxs)("div", { style: {
1272
+ display: "flex",
1273
+ flexDirection: "column",
1274
+ paddingTop: "70px",
1275
+ paddingLeft: "30px",
1276
+ paddingRight: "30px",
1277
+ }, children: [(0, jsx_runtime_1.jsx)("h1", { style: {
1278
+ fontSize: "36px",
1279
+ marginLeft: "20px",
1280
+ paddingTop: "0px",
1281
+ marginTop: "15px",
1282
+ fontWeight: "bold",
1283
+ color: "#384151",
1284
+ }, children: "SQL editor" }), (0, jsx_runtime_1.jsx)(SQLEditorComponent, { query: query, setQuery: setQuery, handleRunQuery: handleRunQuery, theme: exports.theme, defineEditorTheme: defineEditorTheme, setEditorTheme: setEditorTheme, rows: rows, columns: columns, fields: fields })] }));
1285
+ }
1286
+ const SQLEditorComponent = ({ query, setQuery, handleRunQuery, theme, defineEditorTheme, setEditorTheme, }) => {
1287
+ const [isOpen, setIsOpen] = (0, react_1.useState)(false);
1288
+ const [rows, setRows] = (0, react_1.useState)([]);
1289
+ const [columns, setColumns] = (0, react_1.useState)([]);
1290
+ const [fields, setFields] = (0, react_1.useState)([]);
1291
+ return ((0, jsx_runtime_1.jsxs)("div", { style: {
1292
+ background: theme.backgroundColor,
1293
+ // maxHeight: 700,
1294
+ // width: "100%",
1295
+ minWidth: 450,
1296
+ // overflowY: "scroll",
1297
+ // padding: "20px 30px 20px 20px",
1298
+ // marginLeft: 20,
1299
+ borderRadius: 6,
1300
+ overflow: "hidden",
1301
+ }, children: [(0, jsx_runtime_1.jsx)(react_2.SQLEditor, { defaultQuery: query, containerStyle: { height: "calc(100vh - 230px)", width: "100%" }, onChangeQuery: (query) => setQuery(query), onChangeData: (data) => setRows(data), onChangeColumns: (columns) => setColumns(columns), onChangeFields: (fields) => setFields(fields) }), rows.length > 0 && ((0, jsx_runtime_1.jsx)("button", { style: {
1302
+ height: 36,
1303
+ marginLeft: 300,
1304
+ marginTop: 20,
1305
+ background: theme.primaryButtonColor,
1306
+ color: theme.backgroundColor,
1307
+ display: "flex",
1308
+ borderRadius: 6,
1309
+ alignItems: "center",
1310
+ justifyContent: "center",
1311
+ outline: "none",
1312
+ cursor: "pointer",
1313
+ fontFamily: theme.fontFamily,
1314
+ fontWeight: theme.buttonFontWeight || 600,
1315
+ border: "none",
1316
+ fontSize: 14,
1317
+ paddingLeft: 20,
1318
+ paddingRight: 20,
1319
+ }, onClick: () => setIsOpen(true), children: "Add to dashboard" })), (0, jsx_runtime_1.jsx)(react_2.AddToDashboardModal, { isOpen: isOpen, setIsOpen: setIsOpen, rows: rows, columns: columns, query: query, showTableFormatOptions: true, showDateFieldOptions: true, showAccessControlOptions: true, fields: fields })] }));
1320
+ };
1321
+ const SchemaListComponent = ({ schema, theme }) => {
1322
+ return ((0, jsx_runtime_1.jsx)("div", { style: {
1323
+ background: theme.backgroundColor,
1324
+ maxHeight: 700,
1325
+ width: 300,
1326
+ minWidth: 300,
1327
+ overflowY: "scroll",
1328
+ // maxHeight: "100%",
1329
+ paddingLeft: 20,
1330
+ paddingRight: 20,
1331
+ }, children: schema.map((elem, index) => ((0, jsx_runtime_1.jsx)(SchemaItem, { elem: elem, theme: theme, index: index }, elem.displayName + index))) }));
1332
+ };
1333
+ function SchemaItem({ elem, theme, index }) {
1334
+ const [isOpen, setIsOpen] = (0, react_1.useState)(index === 0);
1335
+ const schemaContainerStyle = {
1336
+ display: "flex",
1337
+ flexDirection: "column",
1338
+ // WebkitTouchCallout: "none",
1339
+ // WebkitUserSelect: "none",
1340
+ // KhtmlUserSelect: "none",
1341
+ // MozUserSelect: "none",
1342
+ // msUserSelect: "none",
1343
+ // userSelect: "none",
1344
+ };
1345
+ const schemaRowStyle = {
1346
+ display: "flex",
1347
+ flexDirection: "row",
1348
+ alignItems: "center",
1349
+ width: "100%",
1350
+ justifyContent: "space-between",
1351
+ cursor: "pointer",
1352
+ };
1353
+ const schemaRowHoverStyle = {
1354
+ background: theme.selectUnderlayColor,
1355
+ };
1356
+ 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: {
1357
+ marginLeft: theme.padding,
1358
+ fontSize: theme.fontSize,
1359
+ color: "#384151",
1360
+ fontWeight: "500",
1361
+ }, children: elem.displayName }), (0, jsx_runtime_1.jsx)("div", { style: {
1362
+ display: "flex",
1363
+ alignItems: "center",
1364
+ justifyContent: "center",
1365
+ // paddingRight: 25,
1366
+ paddingTop: 20,
1367
+ paddingBottom: 20,
1368
+ paddingLeft: 0,
1369
+ cursor: "pointer",
1370
+ }, children: isOpen ? ((0, jsx_runtime_1.jsx)("svg", { xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", strokeWidth: 1.5, stroke: "currentColor", className: "h-5 w-5 text-gray-400", children: (0, jsx_runtime_1.jsx)("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M19.5 8.25l-7.5 7.5-7.5-7.5" }) })) : ((0, jsx_runtime_1.jsx)("svg", { xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", strokeWidth: 1.5, stroke: "currentColor", className: "h-5 w-5", children: (0, jsx_runtime_1.jsx)("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M8.25 4.5l7.5 7.5-7.5 7.5" }) })) })] }), isOpen ? ((0, jsx_runtime_1.jsx)("div", { style: {
1371
+ paddingBottom: theme.padding,
1372
+ display: "flex",
1373
+ flexDirection: "column",
1374
+ paddingLeft: theme.padding,
1375
+ paddingRight: theme.padding,
1376
+ }, children: elem.columns.map((elem, index) => ((0, jsx_runtime_1.jsxs)("div", { style: {
1377
+ paddingTop: theme.padding,
1378
+ display: "flex",
1379
+ flexDirection: "row",
1380
+ alignItems: "center",
1381
+ justifyContent: "space-between",
1382
+ }, children: [(0, jsx_runtime_1.jsx)("div", { title: elem.displayName, className: "text-gray-500", style: {
1383
+ fontSize: 13,
1384
+ // color: theme.secondaryFontColor,
1385
+ whiteSpace: "nowrap",
1386
+ padding: 0,
1387
+ margin: 0,
1388
+ textOverflow: "ellipsis",
1389
+ overflow: "hidden",
1390
+ width: 200,
1391
+ maxWidth: 200,
1392
+ }, children: elem.displayName }), (0, jsx_runtime_1.jsx)("div", { className: "text-gray-500", title: elem.displayName, style: {
1393
+ fontSize: 13,
1394
+ color: theme.secondaryFontColor,
1395
+ padding: 0,
1396
+ margin: 0,
1397
+ }, children: elem.fieldType })] }, elem.displayName + elem.index))) })) : null] }));
1398
+ }
1399
+ function defineEditorTheme(monaco, theme) {
1400
+ monaco.editor.defineTheme("onedark", {
1401
+ base: theme.darkMode ? "vs-dark" : "vs",
1402
+ inherit: true,
1403
+ rules: [
1404
+ {
1405
+ token: "comment",
1406
+ foreground: "#5d7988",
1407
+ fontStyle: "italic",
1408
+ },
1409
+ { token: "constant", foreground: "#e06c75" },
1410
+ ],
1411
+ colors: {
1412
+ "editor.background": "#F9F9F9",
1413
+ },
1414
+ });
1415
+ }
1416
+ function setEditorTheme(editor, monaco) {
1417
+ try {
1418
+ monaco.editor.setTheme("onedark");
1419
+ }
1420
+ catch (e) {
1421
+ console.log("ERROR: ", e);
1422
+ }
1423
+ }
1424
+ const theme = {
1425
+ fontFamily: "Inter; Helvetica",
1426
+ backgroundColor: "#FFFFFF",
1427
+ primaryTextColor: "#364153",
1428
+ secondaryTextColor: "#6C727F",
1429
+ chartLabelFontFamily: "Inter; Helvetica",
1430
+ chartLabelColor: "#666666",
1431
+ chartTickColor: "#CCCCCC",
1432
+ chartColors: ["#6269E9", "#E14F62"],
1433
+ borderColor: "#E5E7EB",
1434
+ labelFontWeight: 500,
1435
+ fontSize: 14,
1436
+ };
1437
+ function isValidDate(d) {
1438
+ return d instanceof Date && !isNaN(d);
1439
+ }
1440
+ exports.isValidDate = isValidDate;
1441
+ const isArrayOfValidDates = (arr, field) => arr.every((d) => new Date(d[field]) instanceof Date && !isNaN(new Date(d[field])));
1442
+ exports.isArrayOfValidDates = isArrayOfValidDates;
1443
+ function formatDateBuckets(startDate, endDate) {
1444
+ // Calculate the distance in hours
1445
+ const distanceInHours = Math.abs(differenceInHours(endDate, startDate));
1446
+ // Check if the distance is less than or equal to one hour
1447
+ if (distanceInHours <= 1) {
1448
+ return {
1449
+ unit: "hour",
1450
+ format: "h a",
1451
+ startOf: startOfHour,
1452
+ };
1453
+ }
1454
+ // Calculate the distance in days
1455
+ const distanceInDays = Math.abs(differenceInDays(endDate, startDate));
1456
+ // Check if the distance is less than or equal to one day
1457
+ if (distanceInDays <= 1) {
1458
+ return {
1459
+ unit: "day",
1460
+ format: "MMM d",
1461
+ startOf: startOfDay,
1462
+ };
1463
+ }
1464
+ // Calculate the distance in months
1465
+ const distanceInMonths = Math.abs(differenceInMonths(endDate, startDate));
1466
+ // Check if the distance is less than or equal to one month
1467
+ if (distanceInMonths <= 1) {
1468
+ return {
1469
+ unit: "month",
1470
+ format: "MMM yyyy",
1471
+ startOf: startOfMonth,
1472
+ };
1473
+ }
1474
+ // Calculate the distance in years
1475
+ const distanceInYears = Math.abs(differenceInYears(endDate, startDate));
1476
+ // Check if the distance is less than or equal to one year
1477
+ if (distanceInYears <= 1) {
1478
+ return {
1479
+ unit: "year",
1480
+ format: "yyyy",
1481
+ startOf: startOfYear,
1482
+ };
1483
+ }
1484
+ // Otherwise, the distance is more than one year
1485
+ return {
1486
+ unit: "year",
1487
+ format: "yyyy",
1488
+ startOf: startOfYear,
1489
+ };
1490
+ }
1491
+ exports.formatDateBuckets = formatDateBuckets;
1492
+ const POSTGRES_DATE_TYPES = [
1493
+ "timestamp",
1494
+ "date",
1495
+ "timestamptz",
1496
+ "time",
1497
+ "timetz",
1498
+ ];
1499
+ const FORMAT_OPTIONS = [
1500
+ { value: "whole_number", label: "whole number" },
1501
+ { value: "one_decimal_place", label: "one decimal place" },
1502
+ { value: "dollar_amount", label: "dollar amount" },
1503
+ { value: "MMM_yyyy", label: "month" },
1504
+ { value: "MMM_dd-MMM_dd", label: "week" },
1505
+ { value: "MMM_dd_yyyy", label: "day" },
1506
+ { value: "MMM_dd_hh:mm_ap_pm", label: "day and time" },
1507
+ { value: "hh_ap_pm", label: "hour" },
1508
+ { value: "percent", label: "percent" },
1509
+ { value: "string", label: "string" },
1510
+ ];
1511
+ function Report({ reportId, editChart, saveDashboardItem, isOpen, setIsOpen, isEditQueryOpen, setIsEditQueryOpen, SecondaryButtonComponent, ButtonComponent, deleteReport, updateQuery, }) {
1512
+ const { data, loading, error } = (0, react_2.useQuill)(reportId);
1513
+ const [client] = (0, react_1.useContext)(ClientContext);
1514
+ const [activeQuery, setActiveQuery] = (0, react_1.useContext)(ActiveQueryContext);
1515
+ const [activeComponent, setActiveComponent] = (0, react_1.useContext)(ActiveComponentContext);
1516
+ const downloadCSV = () => {
1517
+ // report.rows
1518
+ if (!data) {
1519
+ return;
1520
+ }
1521
+ const json = data.rows; // JSON data passed as a prop
1522
+ const fields = Object.keys(json[0]); // Assumes all objects have same keys
1523
+ const csvRows = [];
1524
+ // Header row
1525
+ csvRows.push(fields.join(","));
1526
+ // Data rows
1527
+ for (let row of json) {
1528
+ let values = fields.map((field) => JSON.stringify(row[field] || ""));
1529
+ csvRows.push(values.join(","));
1530
+ }
1531
+ // Create CSV string and create a 'blob' with it
1532
+ const csvString = csvRows.join("\r\n");
1533
+ const csvBlob = new Blob([csvString], { type: "text/csv" });
1534
+ // Create a download link and click it
1535
+ const downloadLink = document.createElement("a");
1536
+ downloadLink.download = "download.csv";
1537
+ downloadLink.href = URL.createObjectURL(csvBlob);
1538
+ downloadLink.style.display = "none";
1539
+ document.body.appendChild(downloadLink);
1540
+ downloadLink.click();
1541
+ document.body.removeChild(downloadLink);
1542
+ };
1543
+ const goBack = () => {
1544
+ setActiveComponent("Dashboards");
1545
+ };
1546
+ if (!data || loading) {
1547
+ return null;
1548
+ }
1549
+ if (error) {
1550
+ return (0, jsx_runtime_1.jsx)("div", { children: error });
1551
+ }
1552
+ return ((0, jsx_runtime_1.jsxs)("div", { style: { paddingLeft: 40, paddingRight: 40 }, children: [(0, jsx_runtime_1.jsxs)("div", { style: { display: "flex", flexDirection: "row", alignItems: "center" }, children: [(0, jsx_runtime_1.jsx)(SecondaryButtonComponent, { label: "\u2190 Back", onClick: goBack }), (0, jsx_runtime_1.jsx)("h1", { style: {
1553
+ fontSize: "24px",
1554
+ fontWeight: "bold",
1555
+ marginLeft: "16px",
1556
+ marginTop: "30px",
1557
+ marginBottom: "35px",
1558
+ color: exports.theme.primaryTextColor,
1559
+ }, children: data.name })] }), (0, jsx_runtime_1.jsx)(react_2.Chart, { chartId: reportId, colors: exports.theme.chartColors, containerStyle: {
1560
+ width: "calc(100vw - 80px)",
1561
+ height: data.chartType === "table" ? 600 : 400,
1562
+ } }), (0, jsx_runtime_1.jsxs)("div", { style: {
1563
+ display: "flex",
1564
+ alignItems: "center",
1565
+ gap: 16,
1566
+ marginTop: 20,
1567
+ }, children: [(0, jsx_runtime_1.jsx)(SecondaryButtonComponent, { label: "Edit chart", onClick: () => setIsOpen(true) }), (0, jsx_runtime_1.jsx)(SecondaryButtonComponent, { label: "Edit query", onClick: () => setIsEditQueryOpen(true) }), (0, jsx_runtime_1.jsx)(SecondaryButtonComponent, { label: "Open query", onClick: () => {
1568
+ setActiveQuery(data.queryString);
1569
+ setActiveComponent("SQL editor");
1570
+ } }), (0, jsx_runtime_1.jsx)(SecondaryButtonComponent, { label: "Delete", onClick: deleteReport })] }), (0, jsx_runtime_1.jsx)(react_2.Table
1571
+ // containerStyle={{ width: "80vw", height: 1100 }}
1572
+ , {
1573
+ // containerStyle={{ width: "80vw", height: 1100 }}
1574
+ containerStyle: { height: 400, width: "100%", marginTop: 24 }, chartId: reportId }), (0, jsx_runtime_1.jsx)(EditVisualizationModal, { isOpen: isOpen, setIsOpen: setIsOpen, report: data, editChart: editChart, data: data.rows, query: data.queryString, columns: data.columns, fields: data.fields }), (0, jsx_runtime_1.jsx)(EditQueryModal, { query: data.queryString, report: data, isOpen: isEditQueryOpen, setIsOpen: setIsEditQueryOpen, updateQuery: updateQuery })] }));
1575
+ }
1576
+ function EditQueryModal({ query, report, isOpen, setIsOpen, updateQuery }) {
1577
+ const [newQuery, setNewQuery] = (0, react_1.useState)(query);
1578
+ const hasQueryChanged = (0, react_1.useMemo)(() => {
1579
+ return newQuery !== query;
1580
+ }, [newQuery]);
1581
+ if (!query || !report) {
1582
+ return null;
1583
+ }
1584
+ return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: isOpen && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { className: "fixed inset-0 bg-black/30", "aria-hidden": "true" }), (0, jsx_runtime_1.jsx)("div", { className: "fixed inset-0 overflow-y-auto", "aria-modal": "true", role: "dialog", children: (0, jsx_runtime_1.jsx)("div", { className: "flex min-h-full items-center justify-center p-4", children: (0, jsx_runtime_1.jsxs)("div", {
1585
+ // style={{ overflow: "hidden" }}
1586
+ className: "bg-white px-7 py-7 rounded-lg", children: [(0, jsx_runtime_1.jsx)("div", { style: {
1587
+ fontFamily: exports.theme.fontFamily,
1588
+ color: exports.theme.primaryTextColor,
1589
+ fontSize: 20,
1590
+ fontWeight: 600,
1591
+ }, children: "Edit query" }), (0, jsx_runtime_1.jsx)("div", { style: {
1592
+ background: exports.theme.backgroundColor,
1593
+ height: 422,
1594
+ maxHeight: 422,
1595
+ marginTop: 24,
1596
+ minHeight: 422,
1597
+ width: 722,
1598
+ }, children: (0, jsx_runtime_1.jsx)("div", { style: {
1599
+ background: exports.theme.editorBackgroundColor || exports.theme.backgroundColor,
1600
+ marginRight: exports.theme.padding,
1601
+ borderBottomRightRadius: 4,
1602
+ borderBottomLeftRadius: 4,
1603
+ borderTopRightRadius: 4,
1604
+ borderTopLeftRadius: 4,
1605
+ overflow: "hidden",
1606
+ }, children: (0, jsx_runtime_1.jsx)(react_3.default, { height: "400px", defaultLanguage: "pgsql", defaultValue: "", value: newQuery, loading: (0, jsx_runtime_1.jsx)("div", {}), options: {
1607
+ wordWrap: "on",
1608
+ minimap: {
1609
+ enabled: false,
1610
+ },
1611
+ padding: { top: 16 },
1612
+ }, onChange: (query) => setNewQuery(query), beforeMount: (monaco) => defineEditorTheme(monaco, exports.theme), onMount: setEditorTheme }) }) }), (0, jsx_runtime_1.jsx)("button", {
1613
+ // disabled={isSubmitting}
1614
+ theme: exports.theme, onClick: hasQueryChanged
1615
+ ? () => updateQuery(report?._id, newQuery)
1616
+ : undefined,
1617
+ // editing
1618
+ className: `rounded-md ${hasQueryChanged ? "bg-opacity-100" : "bg-opacity-70"} bg-opacity-100 bg-[#384151] px-4 py-2.5 text-sm font-semibold text-white hover:bg-opacity-70 focus:outline-none focus-visible:ring-2 focus-visible:ring-white focus-visible:ring-opacity-75`, children: "Save changes" })] }) }) })] })) }));
1619
+ }
1620
+ function EditVisualizationModal({ isOpen, setIsOpen, report, editChart, columns, data, fields, query, }) {
1621
+ const [tables] = (0, react_1.useContext)(TablesContext);
1622
+ const [organization] = (0, react_1.useContext)(OrganizationContext);
1623
+ if (!report && !data?.length) {
1624
+ return null;
1625
+ }
1626
+ return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: isOpen && ((0, jsx_runtime_1.jsxs)("div", { className: "fixed inset-0 overflow-y-auto relative", style: { zIndex: 120 }, children: [(0, jsx_runtime_1.jsx)("div", { className: "absolute inset-0 bg-black/30", "aria-hidden": "true", onClick: () => setIsOpen(false) }), (0, jsx_runtime_1.jsx)("div", { className: "flex min-h-full items-center justify-center p-4", children: (0, jsx_runtime_1.jsx)("div", { className: "bg-white px-7 py-7 rounded-lg", children: (0, jsx_runtime_1.jsx)(react_2.AddToDashboardModal, { fields: fields, isOpen: isOpen, setIsOpen: setIsOpen, rows: data, columns: columns, query: query, report: report, showTableFormatOptions: true, showDateFieldOptions: true, showAccessControlOptions: true }) }) })] })) }));
1627
+ }
1628
+ function ReportWrapper({ SecondaryButtonComponent, ButtonComponent, ModalComponent, SelectComponent, }) {
1629
+ const [organization, setOrganization] = (0, react_1.useContext)(OrganizationContext);
1630
+ const [client] = (0, react_1.useContext)(ClientContext);
1631
+ const [environment] = (0, react_1.useContext)(EnvironmentContext);
1632
+ const [reportId, setReportId] = (0, react_1.useContext)(ReportIdContext);
1633
+ let [isOpen, setIsOpen] = (0, react_1.useState)(false);
1634
+ const [isEditQueryOpen, setIsEditQueryOpen] = (0, react_1.useState)(false);
1635
+ const [activeComponent, setActiveComponent] = (0, react_1.useContext)(ActiveComponentContext);
1636
+ const editChart = async ({ report, values, yAxisFields, columns }) => {
1637
+ const { publicKey, customerId, authToken } = client;
1638
+ const { xAxisLabel, yAxisLabel, chartName, chartType, xAxisField, xAxisFormat, dashboardName, dateFieldTable, dateField, template, } = values;
1639
+ if (!chartName) {
1640
+ alert("Please enter a chart name");
1641
+ return;
1642
+ }
1643
+ // if (!dashboardName) {
1644
+ // alert("Please choose a dashboard name");
1645
+ // return;
1646
+ // }
1647
+ // if (!xAxisLabel && chartType !== "pie" && chartType !== "table") {
1648
+ // alert("Please enter a label for the x-axis");
1649
+ // return;
1650
+ // }
1651
+ // if (!yAxisLabel && chartType !== "pie" && chartType !== "table") {
1652
+ // alert("Please enter a label for the y-axis");
1653
+ // return;
1654
+ // }
1655
+ for (let i = 0; i < yAxisFields.length; i++) {
1656
+ if (!yAxisFields[i].label && chartType !== "pie") {
1657
+ alert(`Please enter a label for column '${yAxisFields[i].field}'`);
1658
+ return;
1659
+ }
1660
+ }
1661
+ if (!client || !organization) {
1662
+ return;
1663
+ }
1664
+ const url = `https://quill-344421.uc.r.appspot.com/dashedit/${client._id}/${organization.id}/`;
1665
+ const requestBody = {
1666
+ dashboardItemId: id,
1667
+ name: chartName,
1668
+ xAxisField,
1669
+ yAxisFields,
1670
+ xAxisLabel,
1671
+ xAxisFormat,
1672
+ yAxisLabel,
1673
+ chartType,
1674
+ dashboardName,
1675
+ columns,
1676
+ dateField: { table: dateFieldTable, field: dateField },
1677
+ template,
1678
+ };
1679
+ const response = await fetch(url, {
1680
+ method: "POST",
1681
+ headers: {
1682
+ "Content-Type": "application/json",
1683
+ Authorization: `Bearer ${authToken}`,
1684
+ environment: environment || undefined,
1685
+ },
1686
+ body: JSON.stringify(requestBody),
1687
+ });
1688
+ // setDashboard((dashboard) => {
1689
+ // return {
1690
+ // ...dashboard,
1691
+ // [response.data._id]: { ...existingVisualization, ...response.data }
1692
+ // }
1693
+ // })
1694
+ setIsOpen(false);
1695
+ setActiveComponent("Dashboards");
1696
+ };
1697
+ const updateQuery = async (dashboardItemId, query) => {
1698
+ if (!client || !organization || !dashboardItemId || !query) {
1699
+ return;
1700
+ }
1701
+ const url = `https://quill-344421.uc.r.appspot.com/updatequery/${client._id}/${organization.id}/`;
1702
+ const requestBody = {
1703
+ dashboardItemId,
1704
+ query,
1705
+ };
1706
+ const response = await fetch(url, {
1707
+ method: "POST",
1708
+ headers: {
1709
+ "Content-Type": "application/json",
1710
+ Authorization: "Bearer ",
1711
+ environment: environment || undefined,
1712
+ },
1713
+ body: JSON.stringify(requestBody),
1714
+ });
1715
+ // To get JSON data from the response:
1716
+ const responseData = await response.json();
1717
+ if (responseData) {
1718
+ setIsEditQueryOpen(false);
1719
+ }
1720
+ };
1721
+ const deleteReport = async () => {
1722
+ const { publicKey, customerId, authToken } = client;
1723
+ if (!reportId) {
1724
+ return;
1725
+ }
1726
+ if (!client || !organization) {
1727
+ return;
1728
+ }
1729
+ const url = `https://quill-344421.uc.r.appspot.com/deletedash/${client._id}/${organization.id}/`;
1730
+ const requestBody = {
1731
+ dashboardItemId: reportId,
1732
+ };
1733
+ const response = await fetch(url, {
1734
+ method: "POST",
1735
+ headers: {
1736
+ "Content-Type": "application/json",
1737
+ Authorization: `Bearer ${authToken}`,
1738
+ environment: environment || undefined,
1739
+ },
1740
+ body: JSON.stringify(requestBody),
1741
+ });
1742
+ // To get JSON data from the response:
1743
+ const responseData = await response.json();
1744
+ if (responseData) {
1745
+ setActiveComponent("Dashboards");
1746
+ }
1747
+ };
1748
+ return ((0, jsx_runtime_1.jsx)(Report, { reportId: reportId, editChart: editChart, updateQuery: updateQuery, isOpen: isOpen, setIsOpen: setIsOpen, isEditQueryOpen: isEditQueryOpen, setIsEditQueryOpen: setIsEditQueryOpen, deleteReport: deleteReport, SecondaryButtonComponent: SecondaryButtonComponent, ButtonComponent: ButtonComponent, ModalComponent: ModalComponent, SelectComponent: SelectComponent }));
1749
+ }
1750
+ //# sourceMappingURL=Admin.js.map