@quillsql/admin 1.2.5 → 1.2.7

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 (73) hide show
  1. package/lib/Admin.d.ts +83 -27
  2. package/lib/Admin.js +118 -1247
  3. package/lib/Admin.js.map +1 -1
  4. package/lib/AdminProvider.d.ts +103 -0
  5. package/lib/AdminProvider.js +238 -0
  6. package/lib/AdminProvider.js.map +1 -0
  7. package/lib/components/DropDownMenu.d.ts +9 -0
  8. package/lib/components/DropDownMenu.js +38 -0
  9. package/lib/components/DropDownMenu.js.map +1 -0
  10. package/lib/components/EnvSelectPopover.d.ts +12 -0
  11. package/lib/components/EnvSelectPopover.js +147 -0
  12. package/lib/components/EnvSelectPopover.js.map +1 -0
  13. package/lib/components/OrgSelect.d.ts +10 -0
  14. package/lib/components/OrgSelect.js +29 -0
  15. package/lib/components/OrgSelect.js.map +1 -0
  16. package/lib/components/index.d.ts +4 -0
  17. package/lib/components/index.js +15 -0
  18. package/lib/components/index.js.map +1 -0
  19. package/lib/icons/ArrowDownHeadIcon.d.ts +4 -0
  20. package/lib/icons/ArrowDownHeadIcon.js +6 -0
  21. package/lib/icons/ArrowDownHeadIcon.js.map +1 -0
  22. package/lib/icons/index.d.ts +1 -0
  23. package/lib/icons/index.js +9 -0
  24. package/lib/icons/index.js.map +1 -0
  25. package/lib/index.d.ts +4 -0
  26. package/lib/index.js +9 -1
  27. package/lib/index.js.map +1 -1
  28. package/lib/modals/EditDashboardsModal.d.ts +19 -0
  29. package/lib/modals/EditDashboardsModal.js +94 -0
  30. package/lib/modals/EditDashboardsModal.js.map +1 -0
  31. package/lib/modals/PromoteDashModal.d.ts +16 -0
  32. package/lib/modals/PromoteDashModal.js +103 -0
  33. package/lib/modals/PromoteDashModal.js.map +1 -0
  34. package/lib/modals/PromoteViewModal.d.ts +12 -0
  35. package/lib/modals/PromoteViewModal.js +101 -0
  36. package/lib/modals/PromoteViewModal.js.map +1 -0
  37. package/lib/modals/ReorderDashboardModal.d.ts +8 -0
  38. package/lib/modals/ReorderDashboardModal.js +125 -0
  39. package/lib/modals/ReorderDashboardModal.js.map +1 -0
  40. package/lib/modals/index.d.ts +4 -0
  41. package/lib/modals/index.js +15 -0
  42. package/lib/modals/index.js.map +1 -0
  43. package/lib/primitives/ButtonPrimitive.d.ts +9 -0
  44. package/lib/primitives/ButtonPrimitive.js +25 -0
  45. package/lib/primitives/ButtonPrimitive.js.map +1 -0
  46. package/lib/primitives/HeaderPrimitive.d.ts +8 -0
  47. package/lib/primitives/HeaderPrimitive.js +12 -0
  48. package/lib/primitives/HeaderPrimitive.js.map +1 -0
  49. package/lib/primitives/ModalPrimitive.d.ts +10 -0
  50. package/lib/primitives/ModalPrimitive.js +49 -0
  51. package/lib/primitives/ModalPrimitive.js.map +1 -0
  52. package/lib/primitives/SecondaryButtonPrimitive.d.ts +9 -0
  53. package/lib/primitives/SecondaryButtonPrimitive.js +25 -0
  54. package/lib/primitives/SecondaryButtonPrimitive.js.map +1 -0
  55. package/lib/primitives/SelectPrimitive.d.ts +14 -0
  56. package/lib/primitives/SelectPrimitive.js +39 -0
  57. package/lib/primitives/SelectPrimitive.js.map +1 -0
  58. package/lib/primitives/TextInputPrimitive.d.ts +10 -0
  59. package/lib/primitives/TextInputPrimitive.js +26 -0
  60. package/lib/primitives/TextInputPrimitive.js.map +1 -0
  61. package/lib/primitives/index.d.ts +6 -0
  62. package/lib/primitives/index.js +19 -0
  63. package/lib/primitives/index.js.map +1 -0
  64. package/lib/public_components/DashboardBuilder.d.ts +5 -0
  65. package/lib/public_components/DashboardBuilder.js +164 -0
  66. package/lib/public_components/DashboardBuilder.js.map +1 -0
  67. package/lib/public_components/DashboardManager.d.ts +5 -0
  68. package/lib/public_components/DashboardManager.js +241 -0
  69. package/lib/public_components/DashboardManager.js.map +1 -0
  70. package/lib/public_components/SQLViewManager.d.ts +4 -0
  71. package/lib/public_components/SQLViewManager.js +391 -0
  72. package/lib/public_components/SQLViewManager.js.map +1 -0
  73. package/package.json +3 -2
package/lib/Admin.js CHANGED
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
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;
29
+ exports.ReorderableList = exports.ReportWrapper = exports.formatDateBuckets = exports.isArrayOfValidDates = exports.isValidDate = exports.setEditorTheme = exports.defineEditorTheme = exports.SQLEditorComponent = exports.TableCell = exports.AddDashboardModal = exports.classNames = exports.getPostgresBasicType = exports.convertPostgresColumn = exports.theme = exports.AddFilterModal = exports.EditFiltersModal = void 0;
30
30
  const jsx_runtime_1 = require("react/jsx-runtime");
31
31
  // @ts-ignore
32
32
  const react_1 = require("react");
@@ -37,27 +37,11 @@ const react_3 = __importDefault(require("@monaco-editor/react"));
37
37
  const core_1 = require("@dnd-kit/core");
38
38
  const sortable_1 = require("@dnd-kit/sortable");
39
39
  const utilities_1 = require("@dnd-kit/utilities");
40
- const ClientContext = (0, react_1.createContext)();
41
- const EnvironmentContext = (0, react_1.createContext)();
42
- const OrganizationsContext = (0, react_1.createContext)();
43
- const OrganizationContext = (0, react_1.createContext)();
44
- const ActiveQueryContext = (0, react_1.createContext)();
45
- const TablesContext = (0, react_1.createContext)();
46
- const SchemaContext = (0, react_1.createContext)();
47
- const ActiveComponentContext = (0, react_1.createContext)();
48
- const ReportIdContext = (0, react_1.createContext)();
49
- function ContextProvider({ children }) {
50
- const [client, setClient] = (0, react_1.useState)(null);
51
- const [environment, setEnvironment] = (0, react_1.useState)("PRODUCTION");
52
- const [organization, setOrganization] = (0, react_1.useState)(null);
53
- const [organizations, setOrganizations] = (0, react_1.useState)([]);
54
- const [activeQuery, setActiveQuery] = (0, react_1.useState)("");
55
- const [tables, setTables] = (0, react_1.useState)([]);
56
- const [schema, setSchema] = (0, react_1.useState)([]);
57
- const [activeComponent, setActiveComponent] = (0, react_1.useState)("Dashboards");
58
- const [reportId, setReportId] = (0, react_1.useState)(null);
59
- 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 }) }) }) }) }) }) }) }) }));
60
- }
40
+ const components_1 = require("./components");
41
+ const AdminProvider_1 = require("./AdminProvider");
42
+ const primitives_1 = require("./primitives");
43
+ const DashboardBuilder_1 = __importDefault(require("./public_components/DashboardBuilder"));
44
+ const SQLViewManager_1 = __importDefault(require("./public_components/SQLViewManager"));
61
45
  const CONTAINER = {
62
46
  display: "flex",
63
47
  flexDirection: "row",
@@ -146,21 +130,22 @@ const defaultTheme = {
146
130
  fontSize: 14,
147
131
  };
148
132
  function EditFiltersModal({ isOpen, dashboardData, selectedDashboard, client, setIsOpen, filters, dateFilter, openAddFilterModal, ModalComponent, TextInputComponent, ButtonComponent, HeaderComponent, SelectComponent, selectedEditDashboard, dashNames, setSelectedEditDashboard, SecondaryButtonComponent, }) {
133
+ const { state, dispatch } = (0, AdminProvider_1.useAdmin)();
149
134
  const [selectedDashboardName, setSelectedDashboardName] = (0, react_1.useState)("");
150
135
  (0, react_1.useEffect)(() => {
151
136
  setSelectedDashboardName(selectedDashboard);
152
137
  }, [selectedDashboard]);
153
138
  const [newFilters, setNewFilters] = (0, react_1.useState)([]);
154
139
  const [newDateFilter, setNewDateFilter] = (0, react_1.useState)(null);
155
- const [tables] = (0, react_1.useContext)(TablesContext);
140
+ // const [tables, setTables] = useContext<TablesContextType>(TablesContext);
156
141
  const [selectedTable, setSelectedTable] = (0, react_1.useState)(null);
157
142
  const [field, setField] = (0, react_1.useState)("");
158
143
  (0, react_1.useEffect)(() => {
159
- if (tables.length) {
160
- setSelectedTable(tables[0]);
161
- setField(tables[0].columns.map((elem) => elem.name)[0]);
144
+ if (state.tables.length) {
145
+ setSelectedTable(state.tables[0]);
146
+ setField(state.tables[0].columns.map((elem) => elem.name)[0]);
162
147
  }
163
- }, [tables]);
148
+ }, [state.tables]);
164
149
  (0, react_1.useEffect)(() => {
165
150
  if (dashboardData && dashboardData.filters) {
166
151
  setNewFilters(dashboardData.filters);
@@ -387,7 +372,7 @@ function EditFiltersModal({ isOpen, dashboardData, selectedDashboard, client, se
387
372
  fontSize: 14,
388
373
  fontWeight: "600",
389
374
  marginBottom: 3,
390
- }, children: "Table" }), (0, jsx_runtime_1.jsx)(SelectComponent, { defaultValue: "", value: selectedTable ? selectedTable.name : "", onChange: (e) => setSelectedTable(tables.find((table) => table.name === e)), options: tables.map((table) => {
375
+ }, children: "Table" }), (0, jsx_runtime_1.jsx)(SelectComponent, { defaultValue: "", value: selectedTable ? selectedTable.name : "", onChange: (e) => setSelectedTable(state.tables.find((table) => table.name === e)), options: state.tables.map((table) => {
391
376
  return { label: table.name, value: table.name };
392
377
  }) })] }), (0, jsx_runtime_1.jsxs)("div", { style: {
393
378
  display: "flex",
@@ -424,20 +409,21 @@ function EditFiltersModal({ isOpen, dashboardData, selectedDashboard, client, se
424
409
  }, children: (0, jsx_runtime_1.jsx)("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", fill: "#4C5462", width: "20", height: "20", children: (0, jsx_runtime_1.jsx)("path", { "fill-rule": "evenodd", d: "M5.47 5.47a.75.75 0 011.06 0L12 10.94l5.47-5.47a.75.75 0 111.06 1.06L13.06 12l5.47 5.47a.75.75 0 11-1.06 1.06L12 13.06l-5.47 5.47a.75.75 0 01-1.06-1.06L10.94 12 5.47 6.53a.75.75 0 010-1.06z", clipRule: "evenodd" }) }) })] }) })] })] }));
425
410
  }) }))] }), (0, jsx_runtime_1.jsx)("div", { style: { height: 24 } }), (0, jsx_runtime_1.jsx)(ButtonComponent, { onClick: handleSubmitDashboardChanges, label: "Save changes" })] }) }));
426
411
  }
412
+ exports.EditFiltersModal = EditFiltersModal;
427
413
  function AddFilterModal({ isOpen, selectedDashboard, client, setIsOpen, ModalComponent, TextInputComponent, SelectComponent, HeaderComponent, ButtonComponent, openAddDashboardModal, }) {
428
- const [tables] = (0, react_1.useContext)(TablesContext);
429
414
  const [selectedTable, setSelectedTable] = (0, react_1.useState)(null);
430
415
  const [name, setName] = (0, react_1.useState)("");
431
416
  const [field, setField] = (0, react_1.useState)("");
432
417
  const [filterType, setFilterType] = (0, react_1.useState)("string");
433
418
  const [dateRange, setDateRange] = (0, react_1.useState)([new Date(), new Date()]);
419
+ const { state, dispatch } = (0, AdminProvider_1.useAdmin)();
434
420
  (0, react_1.useEffect)(() => {
435
- if (tables.length) {
436
- setSelectedTable(tables[0]);
421
+ if (state.tables.length) {
422
+ setSelectedTable(state.tables[0]);
437
423
  // setField(tables[0].columns.map((elem) => elem.name));
438
- setField(tables[0].columns[0].name);
424
+ setField(state.tables[0].columns[0].name);
439
425
  }
440
- }, [tables]);
426
+ }, [state.tables]);
441
427
  const handleAddFilter = async () => {
442
428
  if (!selectedTable || !field) {
443
429
  return;
@@ -448,7 +434,7 @@ function AddFilterModal({ isOpen, selectedDashboard, client, setIsOpen, ModalCom
448
434
  return;
449
435
  }
450
436
  let responseData;
451
- const url = `https://quill-344421.uc.r.appspot.comdashfilter/${client._id}/`;
437
+ const url = `https://quill-344421.uc.r.appspot.com/dashfilter/${client._id}/`;
452
438
  const body = {
453
439
  name: selectedDashboard,
454
440
  filter: {
@@ -487,7 +473,7 @@ function AddFilterModal({ isOpen, selectedDashboard, client, setIsOpen, ModalCom
487
473
  if (!selectedTable) {
488
474
  return null;
489
475
  }
490
- return ((0, jsx_runtime_1.jsx)(ModalComponent, { isOpen: isOpen, close: () => setIsOpen(false), children: (0, jsx_runtime_1.jsxs)("div", { style: { display: "flex", flexDirection: "column" }, children: [(0, jsx_runtime_1.jsx)(HeaderComponent, { label: "Add filter" }), (0, jsx_runtime_1.jsx)("div", { children: "Label" }), (0, jsx_runtime_1.jsx)(TextInputComponent, { value: name, onChange: (e) => setName(e.target.value) }), (0, jsx_runtime_1.jsx)("div", { children: "Table" }), (0, jsx_runtime_1.jsx)(SelectComponent, { defaultValue: "", value: selectedTable ? selectedTable : "", onChange: (e) => setSelectedTable(e.target.value), options: tables.map((table) => {
476
+ return ((0, jsx_runtime_1.jsx)(ModalComponent, { isOpen: isOpen, close: () => setIsOpen(false), children: (0, jsx_runtime_1.jsxs)("div", { style: { display: "flex", flexDirection: "column" }, children: [(0, jsx_runtime_1.jsx)(HeaderComponent, { label: "Add filter" }), (0, jsx_runtime_1.jsx)("div", { children: "Label" }), (0, jsx_runtime_1.jsx)(TextInputComponent, { value: name, onChange: (e) => setName(e.target.value) }), (0, jsx_runtime_1.jsx)("div", { children: "Table" }), (0, jsx_runtime_1.jsx)(SelectComponent, { defaultValue: "", value: selectedTable ? selectedTable : "", onChange: (e) => setSelectedTable(e.target.value), options: state.tables.map((table) => {
491
477
  return { label: table.name, value: table.name };
492
478
  }) }), (0, jsx_runtime_1.jsx)("div", { children: "Field" }), (0, jsx_runtime_1.jsx)(SelectComponent, { defaultValue: "", value: field ? field : "", options: selectedTable.columns.map((column) => {
493
479
  return { label: column.name, value: column.name };
@@ -495,211 +481,38 @@ function AddFilterModal({ isOpen, selectedDashboard, client, setIsOpen, ModalCom
495
481
  setField(e);
496
482
  } }), (0, jsx_runtime_1.jsx)(ButtonComponent, { label: "Add filter", onClick: handleAddFilter })] }) }));
497
483
  }
498
- function Portal({ publicKey, queryEndpoint, theme = defaultTheme, queryHeaders, withCredentials, environment, organizationId, TextInputComponent, ButtonComponent, SecondaryButtonComponent, ModalComponent, SelectComponent, OrganizationSelectComponent, EnvironmentSelectComponent, UserManagementComponent, HeaderComponent, }) {
499
- return ((0, jsx_runtime_1.jsx)(ContextProvider, { children: (0, jsx_runtime_1.jsx)(Navigation, { theme: theme, publicKey: publicKey, organizationId: organizationId, queryEndpoint: queryEndpoint, queryHeaders: queryHeaders, withCredentials: withCredentials, TextInputComponent: TextInputComponent ||
500
- (({ onChange, value, placeholder }) => ((0, jsx_runtime_1.jsx)("input", { style: {
501
- display: "flex",
502
- flexDirection: "row",
503
- alignItems: "center",
504
- paddingLeft: "12px",
505
- paddingRight: "12px",
506
- fontWeight: "medium",
507
- height: 38,
508
- minWidth: 230,
509
- boxShadow: "0 1px 2px 0 rgba(0,0,0,.05)",
510
- // TODO: TEST
511
- width: "100%",
512
- backgroundColor: theme?.backgroundColor || "white",
513
- color: theme?.primaryTextColor,
514
- borderWidth: "1px",
515
- borderColor: theme?.borderColor || "#E7E7E7",
516
- borderStyle: "solid",
517
- borderRadius: "6px",
518
- }, onChange: onChange, value: value, placeholder: placeholder }))), ButtonComponent: ButtonComponent ||
519
- (({ onClick, label }) => ((0, jsx_runtime_1.jsx)("button", { style: {
520
- height: 36,
521
- background: theme?.primaryButtonColor,
522
- color: theme?.backgroundColor,
523
- display: "flex",
524
- borderRadius: 6,
525
- alignItems: "center",
526
- justifyContent: "center",
527
- outline: "none",
528
- cursor: "pointer",
529
- fontFamily: theme?.fontFamily,
530
- fontWeight: theme?.buttonFontWeight || 600,
531
- border: "none",
532
- fontSize: 14,
533
- paddingLeft: 20,
534
- paddingRight: 20,
535
- }, onClick: onClick, children: label }))), HeaderComponent: HeaderComponent ||
536
- (({ label }) => ((0, jsx_runtime_1.jsx)("h1", { style: {
537
- color: theme?.primaryTextColor,
538
- fontFamily: theme?.fontFamily,
539
- fontWeight: theme?.buttonFontWeight || 600,
540
- fontSize: 24,
541
- }, children: label }))), SecondaryButtonComponent: SecondaryButtonComponent ||
542
- (({ onClick, label }) => ((0, jsx_runtime_1.jsx)("button", { style: {
543
- height: 36,
544
- background: "#F9FAFB",
545
- color: theme?.primaryTextColor,
546
- display: "flex",
547
- borderRadius: 6,
548
- alignItems: "center",
549
- justifyContent: "center",
550
- outline: "none",
551
- cursor: "pointer",
552
- fontFamily: theme?.fontFamily,
553
- fontWeight: theme?.buttonFontWeight || 600,
554
- border: "none",
555
- fontSize: 14,
556
- paddingLeft: 20,
557
- paddingRight: 20,
558
- }, onClick: onClick, children: label }))), ModalComponent: ModalComponent ||
559
- (({ isOpen, close, children }) => {
560
- (0, react_1.useEffect)(() => {
561
- // Prevent scrolling in the background when the modal is open
562
- if (isOpen) {
563
- document.body.style.overflow = "hidden";
564
- }
565
- return () => {
566
- // Re-enable scrolling when the modal is closed/unmounted
567
- document.body.style.overflow = "unset";
568
- };
569
- }, [isOpen]);
570
- if (!isOpen) {
571
- return null;
572
- }
573
- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { style: {
574
- position: "fixed",
575
- top: "0",
576
- right: "0",
577
- bottom: "0",
578
- left: "0",
579
- zIndex: "50",
580
- backgroundColor: "rgba(255, 255, 255, 0.8)",
581
- backdropFilter: "blur(5px)",
582
- }, onClick: close }), (0, jsx_runtime_1.jsx)("div", { style: {
583
- // position: "absolute",
584
- position: "fixed",
585
- left: "50%",
586
- top: "50%",
587
- zIndex: "50",
588
- // width: "100%",
589
- // maxWidth: 1024,
590
- maxHeight: "90vh",
591
- minWidth: 462,
592
- display: "flex",
593
- justifyContent: "center",
594
- alignItems: "center",
595
- transform: "translateX(-50%) translateY(-50%)",
596
- background: "white",
597
- borderRadius: 8,
598
- borderStyle: "solid",
599
- borderWidth: 1,
600
- borderColor: "#e7e7e7",
601
- // overflow: "scroll",
602
- padding: 30,
603
- // zIndex: 1000,
604
- }, children: children })] }));
605
- }), environment: environment, OrganizationSelectComponent: OrganizationSelectComponent, UserManagementComponent: UserManagementComponent, EnvironmentSelectComponent: EnvironmentSelectComponent, SelectComponent: SelectComponent ||
606
- (({ options, onChange, value }) => {
607
- return ((0, jsx_runtime_1.jsxs)("div", { style: { position: "relative" }, children: [(0, jsx_runtime_1.jsx)("select", { style: {
608
- width: "100%",
609
- minWidth: 230,
610
- maxWidth: 230,
611
- outline: "none",
612
- textAlign: "left",
613
- whiteSpace: "nowrap",
614
- overflow: "hidden",
615
- textOverflow: "ellipsis",
616
- borderRadius: 6,
617
- WebkitAppearance: "none",
618
- paddingLeft: 12,
619
- paddingRight: 12,
620
- height: 38,
621
- borderWidth: theme?.borderWidth,
622
- borderColor: theme?.borderColor,
623
- background: theme?.backgroundColor,
624
- color: theme?.primaryTextColor,
625
- boxShadow: "0 1px 2px 0 rgba(0,0,0,.05)",
626
- fontFamily: theme?.fontFamily,
627
- }, value: value || "", onChange: (event) => onChange(event.target.value), children: options.length > 0 &&
628
- options.map((option) => ((0, jsx_runtime_1.jsx)("option", { value: option.value, label: option.label }, option.value))) }), (0, jsx_runtime_1.jsx)(ArrowDownHeadIcon, { style: {
629
- height: "20px",
630
- width: "20px",
631
- flex: "none",
632
- position: "absolute",
633
- right: 8,
634
- top: 9,
635
- color: theme?.secondaryTextColor,
636
- }, "aria-hidden": "true" })] }));
637
- }) }) }));
484
+ exports.AddFilterModal = AddFilterModal;
485
+ function Portal({ publicKey, queryEndpoint, theme = defaultTheme, queryHeaders, withCredentials, environment, organizationId, TextInputComponent, ButtonComponent, SecondaryButtonComponent, ModalComponent, SelectComponent, OrganizationSelectComponent, UserManagementComponent, HeaderComponent, }) {
486
+ return ((0, jsx_runtime_1.jsx)(AdminProvider_1.AdminProvider, { publicKey: publicKey, children: (0, jsx_runtime_1.jsx)(Navigation, { theme: theme, publicKey: publicKey, queryEndpoint: queryEndpoint, queryHeaders: queryHeaders, withCredentials: withCredentials, TextInputComponent: TextInputComponent ||
487
+ primitives_1.TextInputPrimitive, ButtonComponent: ButtonComponent ||
488
+ primitives_1.ButtonPrimitive, HeaderComponent: HeaderComponent ||
489
+ primitives_1.HeaderPrimitive, SecondaryButtonComponent: SecondaryButtonComponent ||
490
+ primitives_1.SecondaryButtonPrimitive, ModalComponent: ModalComponent ||
491
+ primitives_1.ModalPrimitive, environment: environment, OrganizationSelectComponent: OrganizationSelectComponent, UserManagementComponent: UserManagementComponent, SelectComponent: SelectComponent ||
492
+ primitives_1.SelectPrimitive }) }));
638
493
  }
639
494
  exports.default = Portal;
640
- 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" })] }));
641
- function Navigation({ TextInputComponent, ButtonComponent, SecondaryButtonComponent, ModalComponent, SelectComponent, OrganizationSelectComponent, EnvironmentSelectComponent, UserManagementComponent, HeaderComponent, publicKey, organizationId, queryEndpoint, queryHeaders, environment, withCredentials, }) {
642
- const [client, setClient] = (0, react_1.useContext)(ClientContext);
643
- const [environmentContext, setEnvironmentContext] = (0, react_1.useContext)(EnvironmentContext);
644
- const [tables, setTables] = (0, react_1.useContext)(TablesContext);
645
- const [organization, setOrganization] = (0, react_1.useContext)(OrganizationContext);
646
- const [schema, setSchema] = (0, react_1.useContext)(SchemaContext);
647
- const [activeComponent, setActiveComponent] = (0, react_1.useContext)(ActiveComponentContext);
648
- const [reportId, setReportId] = (0, react_1.useContext)(ReportIdContext);
649
- (0, react_1.useEffect)(() => {
650
- let isSubscribed = true;
651
- async function getClient() {
652
- try {
653
- const response1 = await fetch(`https://quill-344421.uc.r.appspot.com/client/${publicKey}/`, {
654
- method: "GET",
655
- headers: {
656
- Authorization: `Bearer `,
657
- },
658
- });
659
- const data1 = await response1.json();
660
- setClient(data1.client);
661
- const response = await fetch(`https://quill-344421.uc.r.appspot.com/schema2/${publicKey}/`, {
662
- method: "GET",
663
- headers: {
664
- Authorization: `Bearer `,
665
- },
666
- });
667
- if (!response.ok) {
668
- throw new Error("Failed to fetch tables data");
669
- }
670
- const data = await response.json();
671
- setTables(data.tables);
672
- setSchema(data.tables);
673
- }
674
- catch (error) {
675
- console.error("ERROR:", error);
676
- }
677
- }
678
- if (isSubscribed) {
679
- getClient();
680
- }
681
- return () => {
682
- isSubscribed = false;
683
- };
684
- }, [publicKey]);
685
- (0, react_1.useEffect)(() => {
686
- setEnvironmentContext(environment);
687
- }, [environment]);
688
- if (!client) {
495
+ function Navigation({ TextInputComponent, ButtonComponent, SecondaryButtonComponent, ModalComponent, SelectComponent, OrganizationSelectComponent, UserManagementComponent, HeaderComponent, publicKey, queryEndpoint, queryHeaders, environment, withCredentials, }) {
496
+ const { state, dispatch } = (0, AdminProvider_1.useAdmin)();
497
+ // MMTODO: Idk if this is needed
498
+ // useEffect(() => {
499
+ // setEnvironmentContext(environment);
500
+ // }, [environment]);
501
+ if (!state.client) {
689
502
  return null;
690
503
  }
691
504
  const renderComponentBasedOnName = () => {
692
- switch (activeComponent) {
505
+ switch (state.activeComponent) {
693
506
  case "Dashboards":
694
- return ((0, jsx_runtime_1.jsx)(Dashboards, { TextInputComponent: TextInputComponent, ButtonComponent: ButtonComponent, SecondaryButtonComponent: SecondaryButtonComponent, ModalComponent: ModalComponent, SelectComponent: SelectComponent, OrganizationSelectComponent: OrganizationSelectComponent, EnvironmentSelectComponent: EnvironmentSelectComponent, HeaderComponent: HeaderComponent, setReportId: setReportId, queryEndpoint: queryEndpoint, organizationId: organizationId, queryHeaders: queryHeaders, withCredentials: withCredentials }));
507
+ return ((0, jsx_runtime_1.jsx)(components_1.DashboardManager, { TextInputComponent: TextInputComponent, ButtonComponent: ButtonComponent, SecondaryButtonComponent: SecondaryButtonComponent, ModalComponent: ModalComponent, SelectComponent: SelectComponent, HeaderComponent: HeaderComponent, setReportId: (id) => dispatch({ type: 'SET_REPORT_ID', payload: id }), queryEndpoint: queryEndpoint, queryHeaders: queryHeaders, withCredentials: withCredentials }));
695
508
  case "SQL editor":
696
- return ((0, jsx_runtime_1.jsx)(QueryEditor, { TextInputComponent: TextInputComponent, ButtonComponent: ButtonComponent, SecondaryButtonComponent: SecondaryButtonComponent, ModalComponent: ModalComponent, SelectComponent: SelectComponent, OrganizationSelectComponent: OrganizationSelectComponent, EnvironmentSelectComponent: EnvironmentSelectComponent, organizationId: organizationId }));
509
+ return ((0, jsx_runtime_1.jsx)(DashboardBuilder_1.default, {}));
697
510
  case "Report":
698
- return ((0, jsx_runtime_1.jsx)(ReportWrapper, { TextInputComponent: TextInputComponent, ButtonComponent: ButtonComponent, SecondaryButtonComponent: SecondaryButtonComponent, ModalComponent: ModalComponent, SelectComponent: SelectComponent, OrganizationSelectComponent: OrganizationSelectComponent, organizationId: organizationId, queryEndpoint: queryEndpoint, queryHeaders: queryHeaders, withCredentials: withCredentials }));
511
+ return ((0, jsx_runtime_1.jsx)(ReportWrapper, { TextInputComponent: TextInputComponent, ButtonComponent: ButtonComponent, SecondaryButtonComponent: SecondaryButtonComponent, ModalComponent: ModalComponent, SelectComponent: SelectComponent, OrganizationSelectComponent: OrganizationSelectComponent, organizationId: state.organizationId, queryEndpoint: queryEndpoint, queryHeaders: queryHeaders, withCredentials: withCredentials }));
699
512
  case "SQL views":
700
- return ((0, jsx_runtime_1.jsx)(Tables, { TextInputComponent: TextInputComponent, ButtonComponent: ButtonComponent, SecondaryButtonComponent: SecondaryButtonComponent, ModalComponent: ModalComponent, SelectComponent: SelectComponent, HeaderComponent: HeaderComponent, queryEndpoint: queryEndpoint, queryHeaders: queryHeaders, EnvironmentSelectComponent: EnvironmentSelectComponent, OrganizationSelectComponent: OrganizationSelectComponent }));
513
+ return ((0, jsx_runtime_1.jsx)(SQLViewManager_1.default, {}));
701
514
  default:
702
- return ((0, jsx_runtime_1.jsx)(Dashboards, { TextInputComponent: TextInputComponent, ButtonComponent: ButtonComponent, SecondaryButtonComponent: SecondaryButtonComponent, OrganizationSelectComponent: OrganizationSelectComponent, EnvironmentSelectComponent: EnvironmentSelectComponent, ModalComponent: ModalComponent, SelectComponent: SelectComponent, HeaderComponent: HeaderComponent, setReportId: setReportId, queryEndpoint: queryEndpoint, organizationId: organizationId, queryHeaders: queryHeaders, withCredentials: withCredentials }));
515
+ return ((0, jsx_runtime_1.jsx)(Dashboards, { TextInputComponent: TextInputComponent, ButtonComponent: ButtonComponent, SecondaryButtonComponent: SecondaryButtonComponent, OrganizationSelectComponent: OrganizationSelectComponent, ModalComponent: ModalComponent, SelectComponent: SelectComponent, HeaderComponent: HeaderComponent, setReportId: (id) => dispatch({ type: 'SET_REPORT_ID', payload: id }), queryEndpoint: queryEndpoint, organizationId: state.organizationId, queryHeaders: queryHeaders, withCredentials: withCredentials }));
703
516
  }
704
517
  };
705
518
  return ((0, jsx_runtime_1.jsxs)("div", { style: {
@@ -734,7 +547,7 @@ function Navigation({ TextInputComponent, ButtonComponent, SecondaryButtonCompon
734
547
  width: 230,
735
548
  }, 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: {
736
549
  color: "#212121",
737
- backgroundColor: activeComponent === "Dashboards" ? "#2121210A" : "transparent",
550
+ backgroundColor: state.activeComponent === "Dashboards" ? "#2121210A" : "transparent",
738
551
  padding: "8px 12px",
739
552
  height: "38px",
740
553
  marginBottom: "4px",
@@ -744,9 +557,11 @@ function Navigation({ TextInputComponent, ButtonComponent, SecondaryButtonCompon
744
557
  transition: "background-color 0.3s",
745
558
  border: "none",
746
559
  outline: "none",
747
- }, onClick: () => setActiveComponent("Dashboards"), children: "Dashboards" }), (0, jsx_runtime_1.jsx)("button", { style: {
560
+ },
561
+ // onClick={() => setActiveComponent("Dashboards")}
562
+ onClick: () => dispatch({ type: 'SET_ACTIVE_COMPONENT', payload: 'Dashboards' }), children: "Dashboards" }), (0, jsx_runtime_1.jsx)("button", { style: {
748
563
  color: "#212121",
749
- backgroundColor: activeComponent === "SQL editor" ? "#2121210A" : "transparent",
564
+ backgroundColor: state.activeComponent === "SQL editor" ? "#2121210A" : "transparent",
750
565
  padding: "8px 12px",
751
566
  height: "38px",
752
567
  marginBottom: "4px",
@@ -756,9 +571,11 @@ function Navigation({ TextInputComponent, ButtonComponent, SecondaryButtonCompon
756
571
  transition: "background-color 0.3s",
757
572
  border: "none",
758
573
  outline: "none",
759
- }, onClick: () => setActiveComponent("SQL editor"), children: "SQL editor" }), (0, jsx_runtime_1.jsx)("button", { style: {
574
+ },
575
+ // onClick={() => setActiveComponent("SQL editor")}
576
+ onClick: () => dispatch({ type: 'SET_ACTIVE_COMPONENT', payload: 'SQL editor' }), children: "SQL editor" }), (0, jsx_runtime_1.jsx)("button", { style: {
760
577
  color: "#212121",
761
- backgroundColor: activeComponent === "SQL views" ? "#2121210A" : "transparent",
578
+ backgroundColor: state.activeComponent === "SQL views" ? "#2121210A" : "transparent",
762
579
  padding: "8px 12px",
763
580
  height: "38px",
764
581
  marginBottom: "4px",
@@ -768,7 +585,9 @@ function Navigation({ TextInputComponent, ButtonComponent, SecondaryButtonCompon
768
585
  transition: "background-color 0.3s",
769
586
  border: "none",
770
587
  outline: "none",
771
- }, onClick: () => setActiveComponent("SQL views"), children: "SQL views" })] }), (0, jsx_runtime_1.jsx)("div", { style: {
588
+ },
589
+ // onClick={() => setActiveComponent("SQL views")}
590
+ onClick: () => dispatch({ type: 'SET_ACTIVE_COMPONENT', payload: 'SQL views' }), children: "SQL views" })] }), (0, jsx_runtime_1.jsx)("div", { style: {
772
591
  display: "flex",
773
592
  flexDirection: "row",
774
593
  minHeight: "50px",
@@ -788,7 +607,7 @@ function Navigation({ TextInputComponent, ButtonComponent, SecondaryButtonCompon
788
607
  , {
789
608
  // organizationId={'2'}
790
609
  // publicKey={client?._id}
791
- organizationId: organizationId, queryEndpoint: queryEndpoint, withCredentials: withCredentials, queryHeaders: queryHeaders, publicKey: publicKey, environment: environment, theme: exports.theme, children: renderComponentBasedOnName() }) })] }));
610
+ organizationId: state.organizationId, queryEndpoint: queryEndpoint, withCredentials: withCredentials, queryHeaders: queryHeaders, publicKey: state.client._id, environment: state.environment, theme: exports.theme, children: renderComponentBasedOnName() }) })] }));
792
611
  }
793
612
  exports.theme = {
794
613
  fontFamily: "Inter; Helvetica",
@@ -800,8 +619,11 @@ exports.theme = {
800
619
  chartTickColor: "#CCCCCC",
801
620
  chartColors: ["#6269E9", "#E14F62"],
802
621
  borderColor: "#E5E7EB",
622
+ labelFontWeight: 500,
623
+ fontSize: 14,
803
624
  borderWidth: 1,
804
625
  primaryButtonColor: "#212121",
626
+ primaryButtonTextColor: "#FFFFFF",
805
627
  };
806
628
  function convertPostgresColumn(column) {
807
629
  let format;
@@ -886,233 +708,10 @@ function classNames(...classes) {
886
708
  return classes.filter(Boolean).join(" ");
887
709
  }
888
710
  exports.classNames = classNames;
889
- function Dashboards({ setReportId, TextInputComponent, ButtonComponent, SecondaryButtonComponent, OrganizationSelectComponent, EnvironmentSelectComponent, ModalComponent, SelectComponent, queryEndpoint, queryHeaders, organizationId, HeaderComponent, withCredentials, }) {
890
- const [organizations] = (0, react_1.useContext)(OrganizationsContext);
891
- const [client] = (0, react_1.useContext)(ClientContext);
892
- const [organization, setOrganization] = (0, react_1.useContext)(OrganizationContext);
893
- const [environment, setEnvironment] = (0, react_1.useContext)(EnvironmentContext);
894
- const [dashboards, setDashboards] = (0, react_1.useState)([]);
895
- const [selectedDashboard, setSelectedDashboard] = (0, react_1.useState)("");
896
- const [selectedEditDashboard, setSelectedEditDashboard] = (0, react_1.useState)("");
897
- const [selectedReorderDashboard, setSelectedReorderDashboard] = (0, react_1.useState)("");
898
- const [editDashboardData, setEditDashboardData] = (0, react_1.useState)(null);
899
- const [addFilterModalIsOpen, setAddFilterModalIsOpen] = (0, react_1.useState)(false);
900
- const [isAddDashboardModalOpen, setIsAddDashboardModalOpen] = (0, react_1.useState)(false);
901
- const [editFilterModalIsOpen, setEditFilterModalIsOpen] = (0, react_1.useState)(false);
902
- const [isReorderDashboardModalOpen, setIsReorderDashboardModalOpen] = (0, react_1.useState)(false);
903
- const [dashboardData, setDashboardData] = (0, react_1.useState)(null);
904
- const [activeComponent, setActiveComponent] = (0, react_1.useContext)(ActiveComponentContext);
905
- const [isEditDashboardModalOpen, setIsEditDashboardModalOpen] = (0, react_1.useState)(false);
906
- const [isOpen, setIsOpen] = (0, react_1.useState)(false);
907
- // const navigate = useNavigate();
908
- // useEffect(() => {
909
- // if (customValue.length && customValue !== id && !userTyping) {
910
- // navigate(`/dashboards/${customValue}`);
911
- // // window.location.reload();
912
- // }
913
- // // } else {
914
- // // navigate("/");
915
- // // }
916
- // }, [customValue, userTyping]);
917
- async function getDashNames() {
918
- const url = `https://quill-344421.uc.r.appspot.com/dashnames/${client._id}/`;
919
- const response2 = await fetch(url, {
920
- method: "GET",
921
- headers: {
922
- Authorization: "Bearer ",
923
- environment: environment,
924
- },
925
- });
926
- // If you need to retrieve the JSON data from the response:
927
- const data = await response2.json();
928
- if (!data.dashboardNames || !data.dashboardNames.length) {
929
- return;
930
- }
931
- const dashNames = data.dashboardNames.map((elem) => {
932
- if (!elem) {
933
- return { name: "null" };
934
- }
935
- return { name: elem };
936
- });
937
- setDashboards(dashNames);
938
- setSelectedDashboard(dashNames[0].name);
939
- }
940
- (0, react_1.useEffect)(() => {
941
- let isSubscribed = true;
942
- if (isSubscribed) {
943
- getDashNames();
944
- }
945
- return () => {
946
- isSubscribed = false;
947
- };
948
- }, [environment]);
949
- // useEffect(() => {
950
- // if (id && id.length) {
951
- // window.location.reload();
952
- // }
953
- // }, [id]);
954
- const handleSetOrganization = (org) => {
955
- setOrganization(null);
956
- setTimeout(() => setOrganization(org), 50);
957
- };
958
- (0, react_1.useEffect)(() => {
959
- async function getDashboardData(dashboard, setData) {
960
- let responseData;
961
- if (queryEndpoint) {
962
- const response = await fetch(queryEndpoint, {
963
- method: "POST",
964
- headers: {
965
- ...queryHeaders,
966
- "Content-Type": "application/json",
967
- },
968
- body: JSON.stringify({
969
- metadata: organizationId
970
- ? {
971
- orgId: organizationId,
972
- task: "config",
973
- name: dashboard,
974
- }
975
- : { task: "config", name: dashboard },
976
- }),
977
- credentials: withCredentials ? "include" : "omit", // If withCredentials is true, set to 'include'. Otherwise, set to 'omit'.
978
- });
979
- responseData = await response.json(); // If the server returns JSON data
980
- }
981
- else {
982
- const url = new URL(`https://quill-344421.uc.r.appspot.com/dashconfig`);
983
- // Setting the search parameters for the URL
984
- url.search = new URLSearchParams({
985
- orgId: organizationId ? organizationId : "",
986
- publicKey: client._id,
987
- name: dashboard,
988
- }).toString();
989
- const response2 = await fetch(url, {
990
- method: "GET",
991
- headers: {
992
- Authorization: "Bearer ",
993
- environment: environment,
994
- },
995
- });
996
- // If you need to retrieve the JSON data from the response:
997
- responseData = await response2.json();
998
- }
999
- setData(responseData);
1000
- }
1001
- if (selectedEditDashboard) {
1002
- getDashboardData(selectedEditDashboard, setEditDashboardData);
1003
- return;
1004
- }
1005
- if (selectedDashboard && client) {
1006
- getDashboardData(selectedDashboard, setDashboardData);
1007
- }
1008
- }, [selectedDashboard, selectedEditDashboard, organizationId, client]);
1009
- return ((0, jsx_runtime_1.jsxs)("div", { style: {
1010
- display: "flex",
1011
- flexDirection: "column",
1012
- paddingTop: "0px",
1013
- }, children: [(0, jsx_runtime_1.jsx)("div", { style: {
1014
- // width: 'calc(100vw - 30px)',
1015
- display: "flex",
1016
- position: "fixed",
1017
- backgroundColor: "white",
1018
- zIndex: 1,
1019
- left: 0,
1020
- right: 0,
1021
- top: 0,
1022
- flexDirection: "row",
1023
- paddingTop: 85,
1024
- alignItems: "center",
1025
- justifyContent: "space-between",
1026
- paddingLeft: "30px",
1027
- paddingRight: "30px",
1028
- borderBottomWidth: 1,
1029
- borderTopWidth: 0,
1030
- borderLeftWidth: 0,
1031
- borderRightWidth: 0,
1032
- borderStyle: "solid",
1033
- borderColor: exports.theme.borderColor,
1034
- paddingBottom: 20,
1035
- boxShadow: "0px 1px 4px 0px rgba(0, 0, 0, 0.07)",
1036
- // paddingRight: '50px',
1037
- // position: 'absolute'
1038
- // // zIndex: 10
1039
- }, children: (0, jsx_runtime_1.jsxs)("div", { style: {
1040
- display: "flex",
1041
- flexDirection: "row",
1042
- alignItems: "flex-end",
1043
- justifyContent: "space-between",
1044
- width: "100%",
1045
- // marginLeft: '25px'
1046
- }, children: [(0, jsx_runtime_1.jsx)("h1", { style: {
1047
- fontSize: "36px",
1048
- paddingTop: "0px",
1049
- fontWeight: "600",
1050
- color: "#384151",
1051
- margin: 0,
1052
- paddingBottom: 4,
1053
- }, children: "Dashboards" }), (0, jsx_runtime_1.jsxs)("div", { style: {
1054
- display: "flex",
1055
- flexDirection: "row",
1056
- alignItems: "center",
1057
- }, 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: {
1058
- display: "flex",
1059
- flexDirection: "row",
1060
- alignItems: "flex-end",
1061
- gap: 16,
1062
- }, 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: {
1063
- fontSize: "14px",
1064
- paddingTop: "0px",
1065
- marginTop: "0px",
1066
- marginBottom: "4px",
1067
- fontWeight: "600",
1068
- color: exports.theme.secondaryTextColor,
1069
- }, children: "Dashboard" }), (0, jsx_runtime_1.jsx)(SelectComponent, { defaultValue: "", options: dashboards.length
1070
- ? dashboards.map((elem) => {
1071
- return { value: elem.name, label: elem.name };
1072
- })
1073
- : [], onChange: (e) => setSelectedDashboard(e), value: selectedDashboard ? selectedDashboard : "" })] }), EnvironmentSelectComponent && (0, jsx_runtime_1.jsx)(EnvironmentSelectComponent, {}), (0, jsx_runtime_1.jsx)("div", { style: {
1074
- minWidth: 238 - 120,
1075
- gap: 12,
1076
- display: "flex",
1077
- flexDirection: "row",
1078
- }, children: (0, jsx_runtime_1.jsx)(SecondaryButtonComponent, { label: "Edit dashboards", onClick: () => setIsEditDashboardModalOpen(true) }) })] }) })] })] }) }), (0, jsx_runtime_1.jsx)("div", { style: { paddingTop: "190px", display: "inline-block" }, children: selectedDashboard && ((0, jsx_runtime_1.jsx)(react_2.Dashboard
1079
- // TODO: CHANGE
1080
- , {
1081
- // TODO: CHANGE
1082
- name: selectedDashboard,
1083
- // name='Customer Report'
1084
- containerStyle: {
1085
- // height: "850px",
1086
- paddingRight: 25,
1087
- // display: "block",
1088
- // width: 'calc(100% - 50px)'
1089
- }, onClickDashboardItem: (elem) => {
1090
- setReportId(elem._id);
1091
- setActiveComponent("Report");
1092
- } })) }), (0, jsx_runtime_1.jsx)(EditDashboardsModal, { clientId: client._id, isOpen: isEditDashboardModalOpen, setIsOpen: setIsEditDashboardModalOpen, ModalComponent: ModalComponent, ButtonComponent: ButtonComponent, SecondaryButtonComponent: SecondaryButtonComponent, TextInputComponent: TextInputComponent, openEditFilterModal: (dashboardName) => {
1093
- setSelectedEditDashboard(dashboardName);
1094
- setEditFilterModalIsOpen(true);
1095
- // setIsEditDashboardModalOpen(false);
1096
- }, openAddDashboardModal: () => {
1097
- setIsAddDashboardModalOpen(true);
1098
- // setIsEditDashboardModalOpen(false);
1099
- }, openEditOrderModal: (dashboardName) => {
1100
- setSelectedReorderDashboard(dashboardName);
1101
- setIsReorderDashboardModalOpen(true);
1102
- }, HeaderComponent: HeaderComponent, setDashboardData: setDashboardData, dashboards: dashboards, getDashNames: getDashNames }), (0, jsx_runtime_1.jsx)(ReorderDashboardModal, { organizationId: organizationId, isOpen: isReorderDashboardModalOpen, setIsOpen: setIsReorderDashboardModalOpen, ModalComponent: ModalComponent, ButtonComponent: ButtonComponent, selectedDashboard: selectedReorderDashboard, organizationId: organizationId }), (0, jsx_runtime_1.jsx)(EditFiltersModal, { selectedDashboard: selectedEditDashboard, dashboardData: editDashboardData, isOpen: editFilterModalIsOpen, setIsOpen: setEditFilterModalIsOpen, openAddFilterModal: () => {
1103
- setAddFilterModalIsOpen(true);
1104
- // setEditFilterModalIsOpen(false);
1105
- }, client: client, ModalComponent: ModalComponent, ButtonComponent: ButtonComponent, SecondaryButtonComponent: SecondaryButtonComponent, TextInputComponent: TextInputComponent, HeaderComponent: HeaderComponent, SelectComponent: SelectComponent, dashNames: dashboards, setSelectedEditDashboard: setSelectedEditDashboard }), (0, jsx_runtime_1.jsx)(AddFilterModal, { selectedDashboard: selectedEditDashboard, isOpen: addFilterModalIsOpen, setIsOpen: setAddFilterModalIsOpen, client: client, ModalComponent: ModalComponent, TextInputComponent: TextInputComponent, SelectComponent: SelectComponent, HeaderComponent: HeaderComponent, ButtonComponent: ButtonComponent, openAddDashboardModal: () => {
1106
- setIsAddDashboardModalOpen(true);
1107
- // setAddFilterModalIsOpen(false);
1108
- } }), (0, jsx_runtime_1.jsx)(AddDashboardModal, { selectedDashboard: selectedDashboard, isOpen: isAddDashboardModalOpen, setIsOpen: setIsAddDashboardModalOpen, client: client, ModalComponent: ModalComponent, TextInputComponent: TextInputComponent, SelectComponent: SelectComponent, HeaderComponent: HeaderComponent, ButtonComponent: ButtonComponent, dashNames: dashboards, openAddFilterModal: () => {
1109
- setAddFilterModalIsOpen(true);
1110
- // setIsAddDashboardModalOpen(false);
1111
- }, organizationId: organizationId, getDashNames: getDashNames })] }));
1112
- }
1113
711
  function AddDashboardModal({ selectedDashboard, isOpen, setIsOpen, client, ModalComponent, TextInputComponent, SelectComponent, HeaderComponent, ButtonComponent, dashNames, getDashNames, organizationId, }) {
712
+ const { state, dispatch } = (0, AdminProvider_1.useAdmin)();
1114
713
  const [selectedDashboardName, setSelectedDashboardName] = (0, react_1.useState)(selectedDashboard.name);
1115
- const [tables] = (0, react_1.useContext)(TablesContext);
714
+ // const [tables] = useContext(TablesContext);
1116
715
  const [selectedTable, setSelectedTable] = (0, react_1.useState)(null);
1117
716
  const [name, setName] = (0, react_1.useState)("");
1118
717
  const [field, setField] = (0, react_1.useState)("");
@@ -1121,12 +720,12 @@ function AddDashboardModal({ selectedDashboard, isOpen, setIsOpen, client, Modal
1121
720
  const [newFilters, setNewFilters] = (0, react_1.useState)([]);
1122
721
  const [newDateFilter, setNewDateFilter] = (0, react_1.useState)(null);
1123
722
  (0, react_1.useEffect)(() => {
1124
- if (tables.length) {
1125
- setSelectedTable(tables[0]);
723
+ if (state.tables.length) {
724
+ setSelectedTable(state.tables[0]);
1126
725
  // setField(tables[0].columns.map((elem) => elem.name));
1127
- setField(tables[0].columns[0].name);
726
+ setField(state.tables[0].columns[0].name);
1128
727
  }
1129
- }, [tables]);
728
+ }, [state.tables]);
1130
729
  const handleDeleteFilter = async (filter) => {
1131
730
  setNewFilters(newFilters.filter((f) => f !== filter));
1132
731
  };
@@ -1271,590 +870,8 @@ function AddDashboardModal({ selectedDashboard, isOpen, setIsOpen, client, Modal
1271
870
  }, children: (0, jsx_runtime_1.jsx)("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", fill: "#4C5462", width: "20", height: "20", children: (0, jsx_runtime_1.jsx)("path", { fillRule: "evenodd", d: "M5.47 5.47a.75.75 0 011.06 0L12 10.94l5.47-5.47a.75.75 0 111.06 1.06L13.06 12l5.47 5.47a.75.75 0 11-1.06 1.06L12 13.06l-5.47 5.47a.75.75 0 01-1.06-1.06L10.94 12 5.47 6.53a.75.75 0 010-1.06z", clipRule: "evenodd" }) }) })] }) })] })] }, filter.field + index));
1272
871
  }), (0, jsx_runtime_1.jsx)(ButtonComponent, { onClick: handleAddFilter, label: "Add new filter +" }), (0, jsx_runtime_1.jsx)(ButtonComponent, { onClick: handleAddDashboardSubmit, label: "Add Dashboard +" })] })] }) }));
1273
872
  }
1274
- function ReorderDashboardModal({ isOpen, setIsOpen, ModalComponent, ButtonComponent, selectedDashboard, organizationId, }) {
1275
- const [client] = (0, react_1.useContext)(ClientContext);
1276
- const [dashboardItems, setDashboardItems] = (0, react_1.useState)([]);
1277
- const [loading, setLoading] = (0, react_1.useState)(false);
1278
- const [chartType, setChartType] = (0, react_1.useState)("metric");
1279
- const [doesDashboardHaveTables, setDoesDashboardHaveTables] = (0, react_1.useState)(false);
1280
- const [doesDashboardHaveCharts, setDoesDashboardHaveCharts] = (0, react_1.useState)(false);
1281
- const [doesDashboardHaveMetrics, setDoesDashboardHaveMetrics] = (0, react_1.useState)(false);
1282
- const [orderArray, setOrderArray] = (0, react_1.useState)([]);
1283
- const [itemMap, setItemMap] = (0, react_1.useState)(null);
1284
- (0, react_1.useEffect)(() => {
1285
- async function getDashboardItems() {
1286
- const { _id, environment } = client;
1287
- setLoading(true);
1288
- const url = new URL("https://quill-344421.uc.r.appspot.com/dashconfig");
1289
- // Add query parameters to the URL
1290
- url.search = new URLSearchParams({
1291
- publicKey: _id,
1292
- orgId: organizationId,
1293
- name: selectedDashboard,
1294
- }).toString();
1295
- const response = await fetch(url, {
1296
- method: "GET",
1297
- headers: {
1298
- environment: environment || undefined,
1299
- },
1300
- });
1301
- const responseData = await response.json();
1302
- let flattened = [];
1303
- for (let key in responseData.sections) {
1304
- flattened = flattened.concat(responseData.sections[key]);
1305
- }
1306
- setDashboardItems(flattened);
1307
- setLoading(false);
1308
- }
1309
- if (selectedDashboard && client) {
1310
- getDashboardItems();
1311
- }
1312
- }, [selectedDashboard, client]);
1313
- (0, react_1.useEffect)(() => {
1314
- const itemMap = new Map();
1315
- dashboardItems.forEach((item) => {
1316
- if (item.chartType === "table") {
1317
- setDoesDashboardHaveTables(true);
1318
- }
1319
- else if (item.chartType === "metric") {
1320
- setDoesDashboardHaveMetrics(true);
1321
- }
1322
- else {
1323
- setDoesDashboardHaveCharts(true);
1324
- }
1325
- itemMap.set(item._id, item);
1326
- });
1327
- setItemMap(itemMap);
1328
- }, [dashboardItems]);
1329
- const closeModal = () => {
1330
- setIsOpen(false);
1331
- };
1332
- return ((0, jsx_runtime_1.jsx)(ModalComponent, { isOpen: isOpen, close: () => setIsOpen(false), children: (0, jsx_runtime_1.jsxs)("div", { style: {
1333
- display: "flex",
1334
- flexDirection: "column",
1335
- position: "relative",
1336
- minWidth: 700,
1337
- maxWidth: 700,
1338
- minHeight: 700,
1339
- // overflowY: "scroll",
1340
- }, children: [loading ? (0, jsx_runtime_1.jsx)("div", { children: "Loading..." }) : null, dashboardItems.length > 0 && itemMap.size > 0 && ((0, jsx_runtime_1.jsx)(ReorderableList, { itemMap: itemMap, initialItems: dashboardItems.filter((elem) => chartType === "chart"
1341
- ? elem.chartType !== "metric" && elem.chartType !== "table"
1342
- : elem.chartType === chartType), ButtonComponent: ButtonComponent, closeModal: closeModal })), (0, jsx_runtime_1.jsxs)("div", { style: {
1343
- height: 80,
1344
- background: "white",
1345
- width: 700,
1346
- position: "absolute",
1347
- top: -20,
1348
- left: 0,
1349
- right: 20,
1350
- paddingTop: 20,
1351
- display: "flex",
1352
- flexDirection: "row",
1353
- alignItems: "center",
1354
- justifyContent: "space-between",
1355
- }, children: [(0, jsx_runtime_1.jsx)("h1", { style: { fontSize: 22, fontWeight: 600 }, children: "Reorder items" }), (0, jsx_runtime_1.jsxs)("div", { style: {
1356
- background: "#f7f7f7",
1357
- borderRadius: 6,
1358
- height: 32,
1359
- display: "flex",
1360
- flexDirection: "row",
1361
- alignItems: "center",
1362
- paddingLeft: 4,
1363
- paddingRight: 4,
1364
- }, children: [doesDashboardHaveMetrics && ((0, jsx_runtime_1.jsx)("button", { style: {
1365
- background: chartType === "metric" ? "white" : undefined,
1366
- color: chartType === "metric" ? "#384151" : "#677389",
1367
- fontWeight: chartType === "metric" ? "600" : "500",
1368
- borderRadius: 4,
1369
- paddingLeft: 6,
1370
- paddingRight: 6,
1371
- fontSize: 16,
1372
- }, onClick: () => setChartType("metric"), children: "Metrics" })), doesDashboardHaveCharts && ((0, jsx_runtime_1.jsx)("button", { style: {
1373
- background: chartType === "chart" ? "white" : undefined,
1374
- color: chartType === "chart" ? "#384151" : "#677389",
1375
- fontWeight: chartType === "chart" ? "600" : "500",
1376
- borderRadius: 4,
1377
- paddingLeft: 6,
1378
- paddingRight: 6,
1379
- fontSize: 16,
1380
- }, onClick: () => setChartType("chart"), children: "Charts" })), doesDashboardHaveTables && ((0, jsx_runtime_1.jsx)("button", { style: {
1381
- background: chartType === "table" ? "white" : undefined,
1382
- color: chartType === "table" ? "#384151" : "#677389",
1383
- fontWeight: chartType === "table" ? "600" : "500",
1384
- borderRadius: 4,
1385
- paddingLeft: 6,
1386
- paddingRight: 6,
1387
- fontSize: 16,
1388
- }, onClick: () => setChartType("table"), children: "Tables" }))] })] })] }) }));
1389
- }
1390
- function EditDashboardsModal({ ModalComponent, TextInputComponent, isOpen, setIsOpen, clientId, ButtonComponent, SecondaryButtonComponent, openEditFilterModal, openEditOrderModal, openAddDashboardModal, HeaderComponent, setDashboardData, dashboards, getDashNames, }) {
1391
- // const [dashboards, setDashboards] = useState([]);
1392
- // useEffect(() => {
1393
- // async function getDashboards(clientId) {
1394
- // const url = `https://quill-344421.uc.r.appspot.com/dashnames/${clientId}/`;
1395
- // const response2 = await fetch(url, {
1396
- // method: "GET",
1397
- // headers: {
1398
- // Authorization: "Bearer ", // Ensure you append your token after 'Bearer ' if needed
1399
- // },
1400
- // });
1401
- // // If you need to retrieve the JSON data from the response:
1402
- // const data = await response2.json();
1403
- // setDashboards(data);
1404
- // }
1405
- // if (clientId) {
1406
- // getDashboards(clientId);
1407
- // }
1408
- // }, [clientId]);
1409
- async function handleDeleteDashboard(dashboardName) {
1410
- const url = `https://quill-344421.uc.r.appspot.com/dashdelete/${clientId}/`;
1411
- const body = {
1412
- name: dashboardName,
1413
- };
1414
- const headers = {
1415
- "Content-Type": "application/json",
1416
- Authorization: `Bearer `,
1417
- };
1418
- try {
1419
- const response = await fetch(url, {
1420
- method: "POST",
1421
- headers: headers,
1422
- body: JSON.stringify(body),
1423
- });
1424
- if (!response.ok) {
1425
- throw new Error(`HTTP error! Status: ${response.status}`);
1426
- }
1427
- const responseData = await response.json();
1428
- if (responseData) {
1429
- getDashNames();
1430
- return;
1431
- }
1432
- }
1433
- catch (e) {
1434
- console.log("error", e);
1435
- }
1436
- }
1437
- return ((0, jsx_runtime_1.jsx)(ModalComponent, { isOpen: isOpen, close: () => setIsOpen(false), children: (0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsxs)("div", { style: {
1438
- display: "flex",
1439
- flexDirection: "column",
1440
- }, children: [(0, jsx_runtime_1.jsx)("h1", { style: {
1441
- fontWeight: "600",
1442
- fontSize: 24,
1443
- paddingBottom: 8,
1444
- color: exports.theme.primaryTextColor,
1445
- }, children: "Dashboards" }), dashboards &&
1446
- dashboards.map((dashboardName, index) => {
1447
- return ((0, jsx_runtime_1.jsxs)("div", { style: {
1448
- display: "flex",
1449
- flexDirection: "row",
1450
- paddingTop: 5,
1451
- width: 400,
1452
- paddingBottom: 5,
1453
- alignItems: "center",
1454
- justifyContent: "space-between",
1455
- }, children: [(0, jsx_runtime_1.jsx)("div", { style: {
1456
- display: "flex",
1457
- flexDirection: "column",
1458
- }, children: (0, jsx_runtime_1.jsx)("div", { style: {
1459
- marginRight: 12,
1460
- fontWeight: "600",
1461
- fontSize: 16,
1462
- color: exports.theme.primaryTextColor,
1463
- }, children: dashboardName.name }) }), (0, jsx_runtime_1.jsx)("div", { style: {
1464
- display: "flex",
1465
- flexDirection: "column",
1466
- }, children: (0, jsx_runtime_1.jsxs)("div", { style: {
1467
- display: "flex",
1468
- flexDirection: "row",
1469
- alignItems: "flex-end",
1470
- }, children: [(0, jsx_runtime_1.jsx)(SecondaryButtonComponent, { onClick: () => openEditFilterModal(dashboardName.name), label: "Edit" }), (0, jsx_runtime_1.jsx)("div", { style: { width: 8 } }), (0, jsx_runtime_1.jsx)(SecondaryButtonComponent, { onClick: () => openEditOrderModal(dashboardName.name), label: "Reorder" }), (0, jsx_runtime_1.jsx)("div", { style: { width: 8 } }), (0, jsx_runtime_1.jsx)(SecondaryButtonComponent, { onClick: () => handleDeleteDashboard(dashboardName.name), label: "Delete" })] }) })] }, dashboardName + index));
1471
- })] }), (0, jsx_runtime_1.jsx)("div", { style: {
1472
- display: "flex",
1473
- flexDirection: "column",
1474
- justifyContent: "center",
1475
- marginTop: 20,
1476
- }, children: (0, jsx_runtime_1.jsx)(ButtonComponent, { onClick: openAddDashboardModal, label: "Create new dashboard" }) })] }) }));
1477
- }
1478
- function DropdownMenu({ items, setSelected, selected, filterKey }) {
1479
- return ((0, jsx_runtime_1.jsx)("select", { onChange: (e) => {
1480
- setSelected(items.find((item) => item.name === e.target.value));
1481
- }, 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))) }));
1482
- }
1483
- exports.DropdownMenu = DropdownMenu;
1484
- function Tables({ TextInputComponent, ButtonComponent, SecondaryButtonComponent, ModalComponent, SelectComponent, queryEndpoint, queryHeaders, withCredentials, HeaderComponent, EnvironmentSelectComponent, OrganizationSelectComponent, }) {
1485
- const [tables, setTables] = (0, react_1.useState)([]);
1486
- const [modalIsOpen, setIsOpen] = (0, react_1.useState)(false);
1487
- const [editModalIsOpen, setEditModalIsOpen] = (0, react_1.useState)(false);
1488
- const [name, setName] = (0, react_1.useState)("");
1489
- const [viewQuery, setViewQuery] = (0, react_1.useState)("");
1490
- const [editViewId, setEditViewId] = (0, react_1.useState)("");
1491
- const [editName, setEditName] = (0, react_1.useState)("");
1492
- const [editViewQuery, setEditViewQuery] = (0, react_1.useState)("");
1493
- const [client] = (0, react_1.useContext)(ClientContext);
1494
- const [tableToBeDeleted, setTableToBeDeleted] = (0, react_1.useState)("");
1495
- const [deleteName, setDeleteName] = (0, react_1.useState)("");
1496
- const [deleteModalIsOpen, setDeleteModalIsOpen] = (0, react_1.useState)(false);
1497
- const closeDeleteModal = () => {
1498
- setDeleteModalIsOpen(false);
1499
- };
1500
- const openModal = () => {
1501
- setIsOpen(true);
1502
- setEditViewQuery("");
1503
- };
1504
- const closeModal = () => {
1505
- setIsOpen(false);
1506
- setName("");
1507
- setViewQuery("");
1508
- };
1509
- const closeEditModal = () => {
1510
- setEditModalIsOpen(false);
1511
- setEditName("");
1512
- setEditViewQuery("");
1513
- };
1514
- const clickTableCell = (table) => {
1515
- setEditModalIsOpen(true);
1516
- setEditName(table.name);
1517
- setEditViewQuery(table.viewQuery);
1518
- setEditViewId(table._id);
1519
- };
1520
- const handleDeleteTable = async () => {
1521
- if (deleteName !== tableToBeDeleted) {
1522
- alert("Table names must match");
1523
- return;
1524
- }
1525
- if (!editViewId) {
1526
- console.log("No view id found");
1527
- return;
1528
- }
1529
- let response;
1530
- if (queryEndpoint) {
1531
- response = await fetch(queryEndpoint, {
1532
- method: "POST",
1533
- headers: {
1534
- "Content-Type": "application/json",
1535
- ...queryHeaders,
1536
- },
1537
- body: JSON.stringify({
1538
- metadata: {
1539
- task: "view",
1540
- id: editViewId,
1541
- deleted: true,
1542
- },
1543
- }),
1544
- credentials: withCredentials ? "include" : "omit", // If withCredentials is true, set to 'include'. Otherwise, set to 'omit'.
1545
- });
1546
- }
1547
- else {
1548
- response = await fetch(`https://quill-344421.uc.r.appspot.com/table/${client._id}/`, {
1549
- method: "POST",
1550
- headers: {
1551
- "Content-Type": "application/json",
1552
- Authorization: `Bearer `,
1553
- },
1554
- body: JSON.stringify({
1555
- id: editViewId,
1556
- deleted: true,
1557
- }),
1558
- });
1559
- }
1560
- const data = await response.json();
1561
- if (data) {
1562
- setDeleteName("");
1563
- setDeleteModalIsOpen(false);
1564
- setEditModalIsOpen(false);
1565
- setEditName("");
1566
- setEditViewQuery("");
1567
- getTables();
1568
- }
1569
- };
1570
- const getTables = async () => {
1571
- const response = await fetch(`https://quill-344421.uc.r.appspot.com/schema2/${client._id}/`, {
1572
- method: "GET",
1573
- headers: { Authorization: `Bearer ` },
1574
- });
1575
- const data = await response.json();
1576
- setTables(data.tables);
1577
- };
1578
- (0, react_1.useEffect)(() => {
1579
- let isSubscribed = true;
1580
- if (isSubscribed && client) {
1581
- getTables();
1582
- }
1583
- return () => {
1584
- isSubscribed = false;
1585
- };
1586
- }, []);
1587
- const handleClickFirstDelete = () => {
1588
- setTableToBeDeleted(editName);
1589
- setDeleteModalIsOpen(true);
1590
- };
1591
- const handleEditTable = async () => {
1592
- if (!editName.length) {
1593
- alert("Please enter a table name.");
1594
- return;
1595
- }
1596
- if (!editViewQuery.length) {
1597
- alert("Please enter a table query.");
1598
- return;
1599
- }
1600
- if (!editViewId) {
1601
- alert("Could not save.");
1602
- return;
1603
- }
1604
- let response;
1605
- if (queryEndpoint) {
1606
- response = await fetch(queryEndpoint, {
1607
- method: "POST",
1608
- headers: {
1609
- "Content-Type": "application/json",
1610
- ...queryHeaders,
1611
- },
1612
- body: JSON.stringify({
1613
- metadata: {
1614
- query: editViewQuery[editViewQuery.length - 1] === ";"
1615
- ? editViewQuery.slice(0, -1)
1616
- : editViewQuery,
1617
- name: editName,
1618
- task: "view",
1619
- id: editViewId,
1620
- },
1621
- }),
1622
- credentials: withCredentials ? "include" : "omit", // If withCredentials is true, set to 'include'. Otherwise, set to 'omit'.
1623
- });
1624
- }
1625
- else {
1626
- response = await fetch(`https://quill-344421.uc.r.appspot.com/table/${client._id}/`, {
1627
- method: "POST",
1628
- headers: {
1629
- "Content-Type": "application/json",
1630
- Authorization: `Bearer `,
1631
- },
1632
- body: JSON.stringify({
1633
- viewQuery: editViewQuery[editViewQuery.length - 1] === ";"
1634
- ? editViewQuery.slice(0, -1)
1635
- : editViewQuery,
1636
- name: editName,
1637
- id: editViewId,
1638
- }),
1639
- });
1640
- }
1641
- const data = await response.json();
1642
- if (data) {
1643
- closeEditModal();
1644
- getTables();
1645
- }
1646
- };
1647
- const handleAddTable = async () => {
1648
- if (!name.length) {
1649
- alert("Please enter a table name.");
1650
- return;
1651
- }
1652
- if (!editViewQuery.length) {
1653
- alert("Please enter a table query.");
1654
- return;
1655
- }
1656
- let response;
1657
- if (queryEndpoint) {
1658
- response = await fetch(queryEndpoint, {
1659
- method: "POST",
1660
- headers: {
1661
- "Content-Type": "application/json",
1662
- ...queryHeaders,
1663
- },
1664
- body: JSON.stringify({
1665
- metadata: {
1666
- query: editViewQuery[editViewQuery.length - 1] === ";"
1667
- ? editViewQuery.slice(0, -1)
1668
- : editViewQuery,
1669
- name: name,
1670
- task: "view",
1671
- },
1672
- }),
1673
- credentials: withCredentials ? "include" : "omit", // If withCredentials is true, set to 'include'. Otherwise, set to 'omit'.
1674
- });
1675
- }
1676
- else {
1677
- response = await fetch(`https://quill-344421.uc.r.appspot.com/table/${client._id}/`, {
1678
- method: "POST",
1679
- headers: {
1680
- "Content-Type": "application/json",
1681
- Authorization: `Bearer `,
1682
- },
1683
- body: JSON.stringify({
1684
- viewQuery: editViewQuery[editViewQuery.length - 1] === ";"
1685
- ? editViewQuery.slice(0, -1)
1686
- : editViewQuery,
1687
- name: name,
1688
- }),
1689
- });
1690
- }
1691
- const data = await response.json();
1692
- if (data) {
1693
- closeModal();
1694
- getTables();
1695
- }
1696
- };
1697
- (0, react_1.useEffect)(() => {
1698
- getTables();
1699
- }, [client]);
1700
- return ((0, jsx_runtime_1.jsxs)("div", { style: { paddingLeft: "50px", paddingRight: "50px" }, children: [(0, jsx_runtime_1.jsx)("div", { style: {
1701
- // width: 'calc(100vw - 30px)',
1702
- display: "flex",
1703
- position: "fixed",
1704
- backgroundColor: "white",
1705
- zIndex: 1,
1706
- left: 0,
1707
- right: 0,
1708
- top: 0,
1709
- flexDirection: "row",
1710
- paddingTop: 85,
1711
- alignItems: "center",
1712
- justifyContent: "space-between",
1713
- paddingLeft: "30px",
1714
- paddingRight: "30px",
1715
- borderBottomWidth: 1,
1716
- borderTopWidth: 0,
1717
- borderLeftWidth: 0,
1718
- borderRightWidth: 0,
1719
- borderStyle: "solid",
1720
- borderColor: exports.theme.borderColor,
1721
- paddingBottom: 20,
1722
- boxShadow: "0px 1px 4px 0px rgba(0, 0, 0, 0.07)",
1723
- // paddingRight: '50px',
1724
- // position: 'absolute'
1725
- // // zIndex: 10
1726
- }, children: (0, jsx_runtime_1.jsxs)("div", { style: {
1727
- display: "flex",
1728
- flexDirection: "row",
1729
- alignItems: "flex-end",
1730
- justifyContent: "space-between",
1731
- width: "100%",
1732
- // marginLeft: '25px'
1733
- }, children: [(0, jsx_runtime_1.jsx)("h1", { style: {
1734
- fontSize: "36px",
1735
- paddingTop: "0px",
1736
- fontWeight: "600",
1737
- color: "#384151",
1738
- margin: 0,
1739
- paddingBottom: 4,
1740
- }, children: "SQL Views" }), (0, jsx_runtime_1.jsx)("div", { style: {
1741
- display: "flex",
1742
- flexDirection: "row",
1743
- alignItems: "center",
1744
- }, children: (0, jsx_runtime_1.jsx)("div", { style: { display: "flex", flexDirection: "column" }, children: (0, jsx_runtime_1.jsxs)("div", { style: {
1745
- display: "flex",
1746
- flexDirection: "row",
1747
- alignItems: "flex-end",
1748
- gap: 16,
1749
- }, children: [OrganizationSelectComponent && (0, jsx_runtime_1.jsx)(OrganizationSelectComponent, {}), EnvironmentSelectComponent && (0, jsx_runtime_1.jsx)(EnvironmentSelectComponent, {}), (0, jsx_runtime_1.jsx)(ButtonComponent, { onClick: openModal, label: "Add view +" })] }) }) })] }) }), (0, jsx_runtime_1.jsx)("div", { style: { height: 220 } }), (0, jsx_runtime_1.jsx)("div", { style: { display: "flex", flexWrap: "wrap" }, children: tables.length
1750
- ? tables.map((table) => ((0, jsx_runtime_1.jsx)(TableCell, { table: table, clickTableCell: clickTableCell })))
1751
- : 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)(HeaderComponent, { label: "Add view" }), (0, jsx_runtime_1.jsx)("h3", { style: {
1752
- fontWeight: 600,
1753
- fontSize: 14,
1754
- marginBottom: 6,
1755
- marginTop: 8,
1756
- color: "#212121",
1757
- }, 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", { style: {
1758
- fontWeight: 600,
1759
- fontSize: 14,
1760
- marginBottom: 6,
1761
- color: "#212121",
1762
- marginTop: 8,
1763
- }, children: "query" }), (0, jsx_runtime_1.jsx)("div", { style: {
1764
- background: exports.theme.backgroundColor,
1765
- // maxHeight: 700,
1766
- width: "800px",
1767
- height: "500px",
1768
- // minWidth: 450,
1769
- // overflowY: "scroll",
1770
- // padding: "20px 30px 20px 20px",
1771
- // marginLeft: 20,
1772
- borderTopLeftRadius: 6,
1773
- borderBottomLeftRadius: 6,
1774
- borderTopRightRadius: 0,
1775
- borderBottomRightRadius: 0,
1776
- overflow: "hidden",
1777
- }, children: (0, jsx_runtime_1.jsx)(react_3.default, { height: "500px", width: "100%", defaultLanguage: "pgsql", defaultValue: "", value: editViewQuery, loading: (0, jsx_runtime_1.jsx)("div", {}), options: {
1778
- wordWrap: "on",
1779
- minimap: {
1780
- enabled: false,
1781
- },
1782
- padding: { top: 16 },
1783
- }, onChange: (query) => setEditViewQuery(query), beforeMount: (monaco) => defineEditorTheme(monaco, exports.theme), onMount: setEditorTheme }) }), (0, jsx_runtime_1.jsx)("div", { style: { height: 20 } }), (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: {
1784
- display: "flex",
1785
- flexDirection: "row",
1786
- alignItems: "center",
1787
- justifyContent: "space-between",
1788
- // width: '100%'
1789
- }, children: [(0, jsx_runtime_1.jsx)("h1", { style: {
1790
- fontSize: "24px",
1791
- paddingTop: "0px",
1792
- marginTop: "0px",
1793
- marginBottom: "0px",
1794
- fontWeight: "bold",
1795
- color: "#384151",
1796
- }, children: "Edit view" }), (0, jsx_runtime_1.jsx)("button", { style: {
1797
- background: "transparent",
1798
- border: "none",
1799
- outline: "none",
1800
- height: 24,
1801
- width: 24,
1802
- cursor: "pointer",
1803
- }, 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: {
1804
- fontWeight: "600",
1805
- fontSize: "14px",
1806
- marginBottom: "6px",
1807
- color: "#212121",
1808
- }, 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: {
1809
- fontWeight: "600",
1810
- fontSize: "14px",
1811
- marginBottom: "6px",
1812
- color: "#212121",
1813
- }, children: "query" }), (0, jsx_runtime_1.jsx)("div", { style: {
1814
- background: exports.theme.backgroundColor,
1815
- // maxHeight: 700,
1816
- width: "520px",
1817
- height: "300px",
1818
- // minWidth: 450,
1819
- // overflowY: "scroll",
1820
- // padding: "20px 30px 20px 20px",
1821
- // marginLeft: 20,
1822
- borderTopLeftRadius: 6,
1823
- borderBottomLeftRadius: 6,
1824
- borderTopRightRadius: 0,
1825
- borderBottomRightRadius: 0,
1826
- overflow: "hidden",
1827
- }, children: (0, jsx_runtime_1.jsx)(react_3.default, { height: "300px", width: "520px", defaultLanguage: "pgsql", defaultValue: "", value: editViewQuery, loading: (0, jsx_runtime_1.jsx)("div", {}), options: {
1828
- wordWrap: "on",
1829
- minimap: {
1830
- enabled: false,
1831
- },
1832
- padding: { top: 16 },
1833
- }, onChange: (query) => setEditViewQuery(query), beforeMount: (monaco) => defineEditorTheme(monaco, exports.theme), onMount: setEditorTheme }) }), (0, jsx_runtime_1.jsxs)("div", { style: {
1834
- display: "flex",
1835
- flexDirection: "row",
1836
- alignItems: "center",
1837
- marginTop: 20,
1838
- gap: 8,
1839
- }, 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: {
1840
- display: "flex",
1841
- flexDirection: "column",
1842
- padding: "6px",
1843
- }, children: [(0, jsx_runtime_1.jsxs)("h1", { style: {
1844
- fontSize: "1.25rem",
1845
- paddingTop: "0px",
1846
- marginTop: "0px",
1847
- marginBottom: "12px",
1848
- fontWeight: "bold",
1849
- color: "#212121",
1850
- }, children: ["Confirm delete \"", tableToBeDeleted, "\" view"] }), (0, jsx_runtime_1.jsx)("h3", { style: {
1851
- fontWeight: "600",
1852
- fontSize: "0.875rem",
1853
- marginBottom: "6px",
1854
- color: "#212121",
1855
- }, 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}` })] }) })] }));
1856
- }
1857
- function TableCell({ table, clickTableCell, key }) {
873
+ exports.AddDashboardModal = AddDashboardModal;
874
+ function TableCell({ table, clickTableCell }) {
1858
875
  const handleClickTableCell = () => {
1859
876
  clickTableCell(table);
1860
877
  };
@@ -1876,163 +893,19 @@ function TableCell({ table, clickTableCell, key }) {
1876
893
  // height: "1.3em",
1877
894
  }, 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))) })) })] }, table.displayName));
1878
895
  }
1879
- function QueryEditor({ TextInputComponent, ButtonComponent, SecondaryButtonComponent, ModalComponent, SelectComponent, OrganizationSelectComponent, EnvironmentSelectComponent, organizationId, }) {
1880
- const [customerId, setCustomerId] = (0, react_1.useState)("");
1881
- const [checked, setChecked] = (0, react_1.useState)(false);
1882
- const [selected, setSelected] = (0, react_1.useState)("");
1883
- const [userTyping, setUserTyping] = (0, react_1.useState)(false);
1884
- const inputRef = (0, react_1.useRef)(null);
1885
- const [organizations, setOrganizations] = (0, react_1.useState)([]);
1886
- const [filteredOptions, setFilteredOptions] = (0, react_1.useState)([]);
1887
- const [sqlPrompt, setSqlPrompt] = (0, react_1.useState)("");
1888
- const [dashboardNames, setDashboardNames] = (0, react_1.useState)([]);
1889
- const [selectedDashboardName, setSelectedDashboardName] = (0, react_1.useState)("");
896
+ exports.TableCell = TableCell;
897
+ const SQLEditorComponent = ({ query, setQuery,
898
+ // handleRunQuery,
899
+ theme,
900
+ // defineEditorTheme,
901
+ // setEditorTheme,
902
+ }) => {
1890
903
  const [isOpen, setIsOpen] = (0, react_1.useState)(false);
1891
- const [organization, setOrganization] = (0, react_1.useContext)(OrganizationContext);
1892
- const [activeQuery, setActiveQuery] = (0, react_1.useContext)(ActiveQueryContext);
1893
- const [client] = (0, react_1.useContext)(ClientContext);
1894
- const [environment, setEnvironment] = (0, react_1.useContext)(EnvironmentContext);
1895
- const [query, setQuery] = (0, react_1.useState)(activeQuery);
1896
904
  const [rows, setRows] = (0, react_1.useState)([]);
1897
905
  const [columns, setColumns] = (0, react_1.useState)([]);
1898
906
  const [fields, setFields] = (0, react_1.useState)([]);
1899
- const [schema] = (0, react_1.useContext)(SchemaContext);
1900
- const [errorMessage, setErrorMessage] = (0, react_1.useState)("");
1901
- const [sqlResponseLoading, setSqlResponseLoading] = (0, react_1.useState)(false);
1902
- const [activeComponent, setActiveComponent] = (0, react_1.useContext)(ActiveComponentContext);
1903
- (0, react_1.useEffect)(() => {
1904
- setQuery(activeQuery);
1905
- }, [activeQuery]);
1906
- (0, react_1.useEffect)(() => {
1907
- let isSubscribed = true;
1908
- async function getCustomers() {
1909
- // If you need to retrieve the JSON data from the response:
1910
- const response2 = await fetch(`https://quill-344421.uc.r.appspot.com/dashnames/${client._id}/`, {
1911
- method: "GET",
1912
- headers: {
1913
- Authorization: `Bearer `,
1914
- environment: environment,
1915
- },
1916
- });
1917
- const response2Data = await response2.json();
1918
- const dashNames = response2Data.dashboardNames.filter((elem) => elem !== null);
1919
- setDashboardNames(dashNames);
1920
- setSelectedDashboardName(dashNames[0]);
1921
- }
1922
- if (isSubscribed) {
1923
- getCustomers();
1924
- }
1925
- return () => {
1926
- isSubscribed = false;
1927
- };
1928
- }, [environment]);
1929
- // const navigate = useNavigate();
1930
- const handleRunQuery = async () => {
1931
- const { _id } = client;
1932
- try {
1933
- const response = await fetch(`https://quill-344421.uc.r.appspot.com/dashquery?orgId=${organizationId || ""}&publicKey=${_id}`, {
1934
- method: "POST",
1935
- headers: {
1936
- Authorization: `Bearer `,
1937
- environment: environment,
1938
- "Content-Type": "application/json", // Important when sending JSON
1939
- },
1940
- body: JSON.stringify({
1941
- query,
1942
- }),
1943
- });
1944
- const responseData = await response.json();
1945
- if (responseData && responseData.errorMessage) {
1946
- setErrorMessage("Failed to run SQL query: " + responseData.errorMessage);
1947
- setRows([]);
1948
- setColumns([]);
1949
- setFields([]);
1950
- return;
1951
- }
1952
- setErrorMessage("");
1953
- setRows(responseData.rows);
1954
- setColumns(responseData.fields.map((elem) => convertPostgresColumn(elem)));
1955
- setFields(responseData.fields);
1956
- }
1957
- catch (e) {
1958
- console.log("ERROR: ", e);
1959
- return;
1960
- }
1961
- };
1962
- const handleAddToDashboard = () => {
1963
- setIsOpen(true);
1964
- };
1965
- const newRows = (0, react_1.useMemo)(() => {
1966
- return JSON.parse(JSON.stringify(rows));
1967
- }, [rows]);
1968
- /* all your useState and useContext calls and your useEffect hooks */
1969
- const handleSetOrganization = (org) => {
1970
- setOrganization(null);
1971
- setTimeout(() => setOrganization(org), 50);
1972
- };
1973
- return ((0, jsx_runtime_1.jsxs)("div", { style: {
1974
- display: "flex",
1975
- flexDirection: "column",
1976
- paddingTop: "70px",
1977
- paddingLeft: "30px",
1978
- paddingRight: "30px",
1979
- }, children: [(0, jsx_runtime_1.jsx)("div", { style: {
1980
- // width: 'calc(100vw - 30px)',
1981
- display: "flex",
1982
- position: "fixed",
1983
- backgroundColor: "white",
1984
- zIndex: 1,
1985
- left: 0,
1986
- right: 0,
1987
- top: 0,
1988
- flexDirection: "row",
1989
- paddingTop: 85,
1990
- alignItems: "center",
1991
- justifyContent: "space-between",
1992
- paddingLeft: "30px",
1993
- paddingRight: "30px",
1994
- borderBottomWidth: 1,
1995
- borderTopWidth: 0,
1996
- borderLeftWidth: 0,
1997
- borderRightWidth: 0,
1998
- borderStyle: "solid",
1999
- borderColor: exports.theme.borderColor,
2000
- paddingBottom: 20,
2001
- boxShadow: "0px 1px 4px 0px rgba(0, 0, 0, 0.07)",
2002
- // paddingRight: '50px',
2003
- // position: 'absolute'
2004
- // // zIndex: 10
2005
- }, children: (0, jsx_runtime_1.jsxs)("div", { style: {
2006
- display: "flex",
2007
- flexDirection: "row",
2008
- alignItems: "flex-end",
2009
- justifyContent: "space-between",
2010
- width: "100%",
2011
- // marginLeft: '25px'
2012
- }, children: [(0, jsx_runtime_1.jsx)("h1", { style: {
2013
- fontSize: "36px",
2014
- paddingTop: "0px",
2015
- fontWeight: "600",
2016
- color: "#384151",
2017
- margin: 0,
2018
- paddingBottom: 4,
2019
- }, children: "SQL Editor" }), (0, jsx_runtime_1.jsx)("div", { style: {
2020
- display: "flex",
2021
- flexDirection: "row",
2022
- alignItems: "center",
2023
- }, children: (0, jsx_runtime_1.jsx)("div", { style: { display: "flex", flexDirection: "column" }, children: (0, jsx_runtime_1.jsxs)("div", { style: {
2024
- display: "flex",
2025
- flexDirection: "row",
2026
- alignItems: "flex-end",
2027
- gap: 16,
2028
- }, children: [OrganizationSelectComponent && (0, jsx_runtime_1.jsx)(OrganizationSelectComponent, {}), EnvironmentSelectComponent && (0, jsx_runtime_1.jsx)(EnvironmentSelectComponent, {})] }) }) })] }) }), (0, jsx_runtime_1.jsx)("div", { style: { height: 120 } }), (0, jsx_runtime_1.jsx)(SQLEditorComponent, { query: query, setQuery: setQuery, handleRunQuery: handleRunQuery, theme: exports.theme, defineEditorTheme: defineEditorTheme, setEditorTheme: setEditorTheme })] }));
2029
- }
2030
- const SQLEditorComponent = ({ query, setQuery, handleRunQuery, theme, defineEditorTheme, setEditorTheme, }) => {
2031
- const [isOpen, setIsOpen] = (0, react_1.useState)(false);
2032
- const [rows, setRows] = (0, react_1.useState)([]);
2033
- const [columns, setColumns] = (0, react_1.useState)([]);
2034
- const [fields, setFields] = (0, react_1.useState)([]);
2035
- const [activeQuery] = (0, react_1.useContext)(ActiveQueryContext);
907
+ // const [activeQuery] = useContext(ActiveQueryContext);
908
+ const { state, dispatch } = (0, AdminProvider_1.useAdmin)();
2036
909
  return ((0, jsx_runtime_1.jsxs)("div", { style: {
2037
910
  background: theme.backgroundColor,
2038
911
  // maxHeight: 700,
@@ -2043,7 +916,7 @@ const SQLEditorComponent = ({ query, setQuery, handleRunQuery, theme, defineEdit
2043
916
  // marginLeft: 20,
2044
917
  borderRadius: 6,
2045
918
  overflow: "hidden",
2046
- }, children: [(0, jsx_runtime_1.jsx)(react_2.SQLEditor, { containerStyle: { height: "calc(100vh - 270px)", width: "100%" }, onChangeQuery: (query) => setQuery(query), onChangeData: (data) => setRows(data), onChangeColumns: (columns) => setColumns(columns), onChangeFields: (fields) => setFields(fields), defaultQuery: activeQuery ? activeQuery : "" }), rows.length > 0 && ((0, jsx_runtime_1.jsx)("button", { style: {
919
+ }, children: [(0, jsx_runtime_1.jsx)(react_2.SQLEditor, { containerStyle: { height: "calc(100vh - 270px)", width: "100%" }, onChangeQuery: (query) => setQuery(query), onChangeData: (data) => setRows(data), onChangeColumns: (columns) => setColumns(columns), onChangeFields: (fields) => setFields(fields), defaultQuery: state.activeQuery ? state.activeQuery : "" }), rows.length > 0 && ((0, jsx_runtime_1.jsx)("button", { style: {
2047
920
  height: 36,
2048
921
  marginLeft: 250,
2049
922
  marginTop: 20,
@@ -2063,6 +936,7 @@ const SQLEditorComponent = ({ query, setQuery, handleRunQuery, theme, defineEdit
2063
936
  paddingRight: 20,
2064
937
  }, 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 })] }));
2065
938
  };
939
+ exports.SQLEditorComponent = SQLEditorComponent;
2066
940
  const SchemaListComponent = ({ schema, theme }) => {
2067
941
  return ((0, jsx_runtime_1.jsx)("div", { style: {
2068
942
  background: theme.backgroundColor,
@@ -2158,6 +1032,7 @@ function defineEditorTheme(monaco, theme) {
2158
1032
  },
2159
1033
  });
2160
1034
  }
1035
+ exports.defineEditorTheme = defineEditorTheme;
2161
1036
  function setEditorTheme(editor, monaco) {
2162
1037
  try {
2163
1038
  monaco.editor.setTheme("onedark");
@@ -2166,19 +1041,7 @@ function setEditorTheme(editor, monaco) {
2166
1041
  console.log("ERROR: ", e);
2167
1042
  }
2168
1043
  }
2169
- const theme = {
2170
- fontFamily: "Inter; Helvetica",
2171
- backgroundColor: "#FFFFFF",
2172
- primaryTextColor: "#364153",
2173
- secondaryTextColor: "#6C727F",
2174
- chartLabelFontFamily: "Inter; Helvetica",
2175
- chartLabelColor: "#666666",
2176
- chartTickColor: "#CCCCCC",
2177
- chartColors: ["#6269E9", "#E14F62"],
2178
- borderColor: "#E5E7EB",
2179
- labelFontWeight: 500,
2180
- fontSize: 14,
2181
- };
1044
+ exports.setEditorTheme = setEditorTheme;
2182
1045
  function isValidDate(d) {
2183
1046
  return d instanceof Date && !isNaN(d);
2184
1047
  }
@@ -2253,11 +1116,9 @@ const FORMAT_OPTIONS = [
2253
1116
  { value: "percent", label: "percent" },
2254
1117
  { value: "string", label: "string" },
2255
1118
  ];
2256
- function Report({ reportId, saveDashboardItem, isOpen, setIsOpen, isEditQueryOpen, setIsEditQueryOpen, SecondaryButtonComponent, ButtonComponent, deleteReport, updateQuery, OrganizationSelectComponent, ModalComponent, }) {
1119
+ function Report({ reportId, saveDashboardItem, isOpen, setIsOpen, isEditQueryOpen, setIsEditQueryOpen, SecondaryButtonComponent, ButtonComponent, deleteReport, updateQuery, OrganizationSelectComponent, ModalComponent, NavigateToDashboardBuilder, }) {
2257
1120
  const { data, loading, error } = (0, react_2.useQuill)(reportId);
2258
- const [client] = (0, react_1.useContext)(ClientContext);
2259
- const [activeQuery, setActiveQuery] = (0, react_1.useContext)(ActiveQueryContext);
2260
- const [activeComponent, setActiveComponent] = (0, react_1.useContext)(ActiveComponentContext);
1121
+ const { state, dispatch } = (0, AdminProvider_1.useAdmin)();
2261
1122
  const downloadCSV = () => {
2262
1123
  // report.rows
2263
1124
  if (!data) {
@@ -2286,7 +1147,8 @@ function Report({ reportId, saveDashboardItem, isOpen, setIsOpen, isEditQueryOpe
2286
1147
  document.body.removeChild(downloadLink);
2287
1148
  };
2288
1149
  const goBack = () => {
2289
- setActiveComponent("Dashboards");
1150
+ // setActiveComponent("Dashboards");
1151
+ dispatch({ type: 'SET_ACTIVE_COMPONENT', payload: 'Dashboards' });
2290
1152
  };
2291
1153
  if (!data || loading) {
2292
1154
  return null;
@@ -2348,7 +1210,7 @@ function Report({ reportId, saveDashboardItem, isOpen, setIsOpen, isEditQueryOpe
2348
1210
  flexDirection: "row",
2349
1211
  alignItems: "flex-end",
2350
1212
  gap: 16,
2351
- }, children: OrganizationSelectComponent && (0, jsx_runtime_1.jsx)(OrganizationSelectComponent, {}) }) })] })] }) }), (0, jsx_runtime_1.jsx)("div", { style: { height: 240 } }), (0, jsx_runtime_1.jsx)(react_2.Chart, { chartId: reportId, colors: exports.theme.chartColors, containerStyle: {
1213
+ }, children: (0, jsx_runtime_1.jsx)(components_1.OrgSelect, { environment: state.environment, setEnvironment: (env) => dispatch({ type: 'SET_ENVIRONMENT', payload: env }), organizations: state.organizations, organizationId: state.organizationId, setOrganizationId: (orgId) => dispatch({ type: 'SET_ORGANIZATION_ID', payload: orgId }), theme: state.theme }) }) })] })] }) }), (0, jsx_runtime_1.jsx)("div", { style: { height: 240 } }), (0, jsx_runtime_1.jsx)(react_2.Chart, { chartId: reportId, colors: exports.theme.chartColors, containerStyle: {
2352
1214
  width: "calc(100vw - 80px)",
2353
1215
  height: data.chartType === "table" ? 600 : 400,
2354
1216
  } }), (0, jsx_runtime_1.jsxs)("div", { style: {
@@ -2357,8 +1219,12 @@ function Report({ reportId, saveDashboardItem, isOpen, setIsOpen, isEditQueryOpe
2357
1219
  gap: 16,
2358
1220
  marginTop: 20,
2359
1221
  }, 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: () => {
2360
- setActiveQuery(data.queryString);
2361
- setActiveComponent("SQL editor");
1222
+ // setActiveQuery(data.queryString);
1223
+ dispatch({ type: 'SET_ACTIVE_QUERY', payload: data.queryString });
1224
+ // setActiveComponent("SQL editor");
1225
+ if (state.navigateToDashboardBuilder) {
1226
+ state.navigateToDashboardBuilder();
1227
+ }
2362
1228
  } }), (0, jsx_runtime_1.jsx)(SecondaryButtonComponent, { label: "Delete", onClick: deleteReport })] }), data.chartType !== "table" && ((0, jsx_runtime_1.jsx)(react_2.Table
2363
1229
  // containerStyle={{ width: "80vw", height: 1100 }}
2364
1230
  , {
@@ -2426,23 +1292,26 @@ function EditQueryModal({ query, report, isOpen, setIsOpen, updateQuery, ModalCo
2426
1292
  }, children: "Save changes" })] }) }) }));
2427
1293
  }
2428
1294
  function EditVisualizationModal({ isOpen, setIsOpen, report, columns, data, fields, query, }) {
2429
- const [tables] = (0, react_1.useContext)(TablesContext);
2430
- const [organization] = (0, react_1.useContext)(OrganizationContext);
1295
+ // const [tables] = useContext(TablesContext);
1296
+ // const [organization] = useContext(OrganizationContext);
2431
1297
  if (!report && !data?.length) {
2432
1298
  return null;
2433
1299
  }
2434
1300
  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 }) }) })] })) }));
2435
1301
  }
2436
1302
  function ReportWrapper({ SecondaryButtonComponent, ButtonComponent, ModalComponent, SelectComponent, OrganizationSelectComponent, organizationId, queryEndpoint, queryHeaders, withCredentials, }) {
2437
- const [organization, setOrganization] = (0, react_1.useContext)(OrganizationContext);
2438
- const [client] = (0, react_1.useContext)(ClientContext);
2439
- const [environment] = (0, react_1.useContext)(EnvironmentContext);
2440
- const [reportId, setReportId] = (0, react_1.useContext)(ReportIdContext);
1303
+ const { state, dispatch } = (0, AdminProvider_1.useAdmin)();
1304
+ // const [organization, setOrganization] = useContext(OrganizationContext);
1305
+ // const [client] = useContext(ClientContext);
1306
+ // const [environment] = useContext(EnvironmentContext);
1307
+ // const [reportId, setReportId] = useContext(ReportIdContext);
2441
1308
  let [isOpen, setIsOpen] = (0, react_1.useState)(false);
2442
1309
  const [isEditQueryOpen, setIsEditQueryOpen] = (0, react_1.useState)(false);
2443
- const [activeComponent, setActiveComponent] = (0, react_1.useContext)(ActiveComponentContext);
1310
+ // const [activeComponent, setActiveComponent] = useContext(
1311
+ // ActiveComponentContext
1312
+ // );
2444
1313
  const updateQuery = async (dashboardItemId, query) => {
2445
- if (!client || !dashboardItemId || !query) {
1314
+ if (!state.client || !dashboardItemId || !query) {
2446
1315
  return;
2447
1316
  }
2448
1317
  let responseData;
@@ -2458,17 +1327,17 @@ function ReportWrapper({ SecondaryButtonComponent, ButtonComponent, ModalCompone
2458
1327
  ? {
2459
1328
  orgId: organizationId,
2460
1329
  task: "edit_query",
2461
- id: reportId,
1330
+ id: state.reportId,
2462
1331
  query,
2463
1332
  }
2464
- : { task: "edit_query", id: reportId, query },
1333
+ : { task: "edit_query", id: state.reportId, query },
2465
1334
  }),
2466
1335
  credentials: withCredentials ? "include" : "omit",
2467
1336
  });
2468
1337
  responseData = await response.json();
2469
1338
  }
2470
1339
  else {
2471
- const url = `https://quill-344421.uc.r.appspot.com/updatequery/${client._id}/${organizationId}/`;
1340
+ const url = `https://quill-344421.uc.r.appspot.com/updatequery/${state.client._id}/${organizationId}/`;
2472
1341
  const requestBody = {
2473
1342
  dashboardItemId,
2474
1343
  query,
@@ -2478,7 +1347,7 @@ function ReportWrapper({ SecondaryButtonComponent, ButtonComponent, ModalCompone
2478
1347
  headers: {
2479
1348
  "Content-Type": "application/json",
2480
1349
  Authorization: "Bearer ",
2481
- environment: environment || undefined,
1350
+ environment: state.environment || undefined,
2482
1351
  },
2483
1352
  body: JSON.stringify(requestBody),
2484
1353
  });
@@ -2500,10 +1369,10 @@ function ReportWrapper({ SecondaryButtonComponent, ButtonComponent, ModalCompone
2500
1369
  }
2501
1370
  };
2502
1371
  const deleteReport = async () => {
2503
- if (!reportId) {
1372
+ if (!state.reportId) {
2504
1373
  return;
2505
1374
  }
2506
- if (!client) {
1375
+ if (!state.client) {
2507
1376
  return;
2508
1377
  }
2509
1378
  let responseData;
@@ -2519,24 +1388,24 @@ function ReportWrapper({ SecondaryButtonComponent, ButtonComponent, ModalCompone
2519
1388
  ? {
2520
1389
  orgId: organizationId,
2521
1390
  task: "delete",
2522
- id: reportId,
1391
+ id: state.reportId,
2523
1392
  }
2524
- : { task: "delete", id: reportId },
1393
+ : { task: "delete", id: state.reportId },
2525
1394
  }),
2526
1395
  credentials: withCredentials ? "include" : "omit", // If withCredentials is true, set to 'include'. Otherwise, set to 'omit'.
2527
1396
  });
2528
1397
  responseData = await response.json(); // If the server returns JSON data
2529
1398
  }
2530
1399
  else {
2531
- const url = `https://quill-344421.uc.r.appspot.com/deletedash/${client._id}/${organizationId}/`;
1400
+ const url = `https://quill-344421.uc.r.appspot.com/deletedash/${state.client._id}/${organizationId}/`;
2532
1401
  const requestBody = {
2533
- dashboardItemId: reportId,
1402
+ dashboardItemId: state.reportId,
2534
1403
  };
2535
1404
  const response = await fetch(url, {
2536
1405
  method: "POST",
2537
1406
  headers: {
2538
1407
  "Content-Type": "application/json",
2539
- environment: environment || undefined,
1408
+ environment: state.environment || undefined,
2540
1409
  },
2541
1410
  body: JSON.stringify(requestBody),
2542
1411
  });
@@ -2544,11 +1413,12 @@ function ReportWrapper({ SecondaryButtonComponent, ButtonComponent, ModalCompone
2544
1413
  responseData = await response.json();
2545
1414
  }
2546
1415
  if (responseData) {
2547
- setActiveComponent("Dashboards");
1416
+ dispatch({ type: 'SET_ACTIVE_COMPONENT', payload: 'Dashboards' });
2548
1417
  }
2549
1418
  };
2550
- return ((0, jsx_runtime_1.jsx)(Report, { reportId: reportId, updateQuery: updateQuery, isOpen: isOpen, setIsOpen: setIsOpen, isEditQueryOpen: isEditQueryOpen, setIsEditQueryOpen: setIsEditQueryOpen, deleteReport: deleteReport, SecondaryButtonComponent: SecondaryButtonComponent, ButtonComponent: ButtonComponent, ModalComponent: ModalComponent, SelectComponent: SelectComponent, OrganizationSelectComponent: OrganizationSelectComponent }));
1419
+ return ((0, jsx_runtime_1.jsx)(Report, { reportId: state.reportId, updateQuery: updateQuery, isOpen: isOpen, setIsOpen: setIsOpen, isEditQueryOpen: isEditQueryOpen, setIsEditQueryOpen: setIsEditQueryOpen, deleteReport: deleteReport, SecondaryButtonComponent: SecondaryButtonComponent, ButtonComponent: ButtonComponent, ModalComponent: ModalComponent, SelectComponent: SelectComponent, OrganizationSelectComponent: OrganizationSelectComponent }));
2551
1420
  }
1421
+ exports.ReportWrapper = ReportWrapper;
2552
1422
  const measuringConfig = {
2553
1423
  droppable: {
2554
1424
  strategy: core_1.MeasuringStrategy.Always,
@@ -2556,7 +1426,7 @@ const measuringConfig = {
2556
1426
  };
2557
1427
  function ReorderableList({ initialItems, itemMap, ButtonComponent, closeModal, }) {
2558
1428
  const [items, setItems] = (0, react_1.useState)([]);
2559
- const [client] = (0, react_1.useContext)(ClientContext);
1429
+ // const [client] = useContext(ClientContext);
2560
1430
  const sensors = (0, core_1.useSensors)((0, core_1.useSensor)(core_1.PointerSensor), (0, core_1.useSensor)(core_1.KeyboardSensor, {
2561
1431
  coordinateGetter: sortable_1.sortableKeyboardCoordinates,
2562
1432
  }), (0, core_1.useSensor)(core_1.TouchSensor, {
@@ -2636,6 +1506,7 @@ function ReorderableList({ initialItems, itemMap, ButtonComponent, closeModal, }
2636
1506
  }
2637
1507
  }
2638
1508
  }
1509
+ exports.ReorderableList = ReorderableList;
2639
1510
  const animateLayoutChanges = (args) => args.isSorting || args.wasDragging ? (0, sortable_1.defaultAnimateLayoutChanges)(args) : true;
2640
1511
  function SortableItem({ id, name }) {
2641
1512
  const { attributes, listeners, setNodeRef, transform, transition } = (0, sortable_1.useSortable)({