@quillsql/react 2.13.47 → 2.13.49

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 (298) hide show
  1. package/dist/cjs/Chart.d.ts +2 -2
  2. package/dist/cjs/Chart.d.ts.map +1 -1
  3. package/dist/cjs/Chart.js +56 -49
  4. package/dist/cjs/ChartBuilder.d.ts +3 -2
  5. package/dist/cjs/ChartBuilder.d.ts.map +1 -1
  6. package/dist/cjs/ChartBuilder.js +172 -138
  7. package/dist/cjs/ChartEditor.d.ts +2 -2
  8. package/dist/cjs/ChartEditor.d.ts.map +1 -1
  9. package/dist/cjs/ChartEditor.js +5 -2
  10. package/dist/cjs/Context.d.ts +121 -41
  11. package/dist/cjs/Context.d.ts.map +1 -1
  12. package/dist/cjs/Context.js +449 -261
  13. package/dist/cjs/Dashboard.d.ts.map +1 -1
  14. package/dist/cjs/Dashboard.js +26 -25
  15. package/dist/cjs/DateRangePicker/QuillDateRangePicker.js +0 -3
  16. package/dist/cjs/DateRangePicker/dateRangePickerUtils.d.ts +24 -10
  17. package/dist/cjs/DateRangePicker/dateRangePickerUtils.d.ts.map +1 -1
  18. package/dist/cjs/DateRangePicker/dateRangePickerUtils.js +472 -96
  19. package/dist/cjs/QuillProvider.d.ts +3 -1
  20. package/dist/cjs/QuillProvider.d.ts.map +1 -1
  21. package/dist/cjs/QuillProvider.js +2 -2
  22. package/dist/cjs/ReportBuilder.d.ts.map +1 -1
  23. package/dist/cjs/ReportBuilder.js +25 -14
  24. package/dist/cjs/SQLEditor.d.ts +1 -1
  25. package/dist/cjs/SQLEditor.d.ts.map +1 -1
  26. package/dist/cjs/SQLEditor.js +51 -16
  27. package/dist/cjs/Table.d.ts.map +1 -1
  28. package/dist/cjs/Table.js +85 -14
  29. package/dist/cjs/assets/ExclamationFilledIcon.d.ts.map +1 -1
  30. package/dist/cjs/components/Chart/BarChart.d.ts.map +1 -1
  31. package/dist/cjs/components/Chart/BarChart.js +2 -1
  32. package/dist/cjs/components/Chart/CustomReferenceLine.d.ts +1 -1
  33. package/dist/cjs/components/Chart/CustomReferenceLine.d.ts.map +1 -1
  34. package/dist/cjs/components/Chart/CustomReferenceLine.js +7 -6
  35. package/dist/cjs/components/Chart/GaugeChart.d.ts +1 -1
  36. package/dist/cjs/components/Chart/GaugeChart.d.ts.map +1 -1
  37. package/dist/cjs/components/Chart/GaugeChart.js +63 -36
  38. package/dist/cjs/components/Chart/InternalChart.d.ts.map +1 -1
  39. package/dist/cjs/components/Chart/InternalChart.js +30 -33
  40. package/dist/cjs/components/Chart/LineChart.d.ts.map +1 -1
  41. package/dist/cjs/components/Chart/LineChart.js +3 -1
  42. package/dist/cjs/components/Chart/MapChart.d.ts +3 -3
  43. package/dist/cjs/components/Chart/MapChart.d.ts.map +1 -1
  44. package/dist/cjs/components/Chart/MapChart.js +62 -34
  45. package/dist/cjs/components/Chart/PieChart.d.ts +3 -1
  46. package/dist/cjs/components/Chart/PieChart.d.ts.map +1 -1
  47. package/dist/cjs/components/Chart/PieChart.js +80 -39
  48. package/dist/cjs/components/Dashboard/DashboardFilter.d.ts.map +1 -1
  49. package/dist/cjs/components/Dashboard/DashboardFilter.js +4 -20
  50. package/dist/cjs/components/Dashboard/DashboardTemplate.d.ts.map +1 -1
  51. package/dist/cjs/components/Dashboard/DashboardTemplate.js +2 -1
  52. package/dist/cjs/components/Dashboard/DataLoader.d.ts +4 -4
  53. package/dist/cjs/components/Dashboard/DataLoader.d.ts.map +1 -1
  54. package/dist/cjs/components/Dashboard/DataLoader.js +101 -65
  55. package/dist/cjs/components/Dashboard/MetricComponent.d.ts.map +1 -1
  56. package/dist/cjs/components/Dashboard/MetricComponent.js +2 -2
  57. package/dist/cjs/components/Dashboard/util.d.ts +1 -1
  58. package/dist/cjs/components/Dashboard/util.d.ts.map +1 -1
  59. package/dist/cjs/components/Dashboard/util.js +7 -6
  60. package/dist/cjs/components/QuillMultiSelectSectionList.d.ts.map +1 -1
  61. package/dist/cjs/components/QuillMultiSelectSectionList.js +32 -22
  62. package/dist/cjs/components/QuillMultiSelectWithCombo.d.ts.map +1 -1
  63. package/dist/cjs/components/QuillMultiSelectWithCombo.js +186 -159
  64. package/dist/cjs/components/QuillSelect.d.ts.map +1 -1
  65. package/dist/cjs/components/QuillSelect.js +83 -75
  66. package/dist/cjs/components/QuillSelectWithCombo.d.ts.map +1 -1
  67. package/dist/cjs/components/QuillSelectWithCombo.js +18 -11
  68. package/dist/cjs/components/QuillTable.d.ts.map +1 -1
  69. package/dist/cjs/components/QuillTable.js +59 -61
  70. package/dist/cjs/components/ReportBuilder/FilterStack.d.ts +2 -1
  71. package/dist/cjs/components/ReportBuilder/FilterStack.d.ts.map +1 -1
  72. package/dist/cjs/components/ReportBuilder/FilterStack.js +3 -4
  73. package/dist/cjs/components/ReportBuilder/ui.d.ts +2 -2
  74. package/dist/cjs/components/ReportBuilder/ui.d.ts.map +1 -1
  75. package/dist/cjs/components/ReportBuilder/ui.js +4 -7
  76. package/dist/cjs/components/UiComponents.d.ts +1 -1
  77. package/dist/cjs/hooks/useAskQuill.d.ts.map +1 -1
  78. package/dist/cjs/hooks/useAskQuill.js +5 -1
  79. package/dist/cjs/hooks/useDashboard.d.ts +2 -2
  80. package/dist/cjs/hooks/useDashboard.d.ts.map +1 -1
  81. package/dist/cjs/hooks/useDashboard.js +160 -69
  82. package/dist/cjs/hooks/useExport.d.ts.map +1 -1
  83. package/dist/cjs/hooks/useExport.js +29 -15
  84. package/dist/cjs/hooks/useOnClickOutside.d.ts.map +1 -1
  85. package/dist/cjs/hooks/useQuill.d.ts +1 -0
  86. package/dist/cjs/hooks/useQuill.d.ts.map +1 -1
  87. package/dist/cjs/hooks/useQuill.js +22 -12
  88. package/dist/cjs/hooks/useReport.d.ts +2 -2
  89. package/dist/cjs/hooks/useReport.d.ts.map +1 -1
  90. package/dist/cjs/hooks/useReport.js +3 -4
  91. package/dist/cjs/hooks/useVirtualTables.d.ts.map +1 -1
  92. package/dist/cjs/hooks/useVirtualTables.js +16 -22
  93. package/dist/cjs/index.d.ts +2 -2
  94. package/dist/cjs/index.d.ts.map +1 -1
  95. package/dist/cjs/index.js +2 -1
  96. package/dist/cjs/internals/ReportBuilder/PivotModal.d.ts +2 -1
  97. package/dist/cjs/internals/ReportBuilder/PivotModal.d.ts.map +1 -1
  98. package/dist/cjs/internals/ReportBuilder/PivotModal.js +19 -7
  99. package/dist/cjs/models/Client.d.ts +0 -1
  100. package/dist/cjs/models/Client.d.ts.map +1 -1
  101. package/dist/cjs/models/Data.d.ts +20 -0
  102. package/dist/cjs/models/Data.d.ts.map +1 -0
  103. package/dist/cjs/models/Data.js +2 -0
  104. package/dist/cjs/models/Filter.d.ts +42 -4
  105. package/dist/cjs/models/Filter.d.ts.map +1 -1
  106. package/dist/cjs/models/Pivot.d.ts.map +1 -1
  107. package/dist/cjs/utils/astProcessing.d.ts +3 -2
  108. package/dist/cjs/utils/astProcessing.d.ts.map +1 -1
  109. package/dist/cjs/utils/astProcessing.js +28 -37
  110. package/dist/cjs/utils/client.d.ts +3 -2
  111. package/dist/cjs/utils/client.d.ts.map +1 -1
  112. package/dist/cjs/utils/client.js +38 -39
  113. package/dist/cjs/utils/columnProcessing.d.ts.map +1 -1
  114. package/dist/cjs/utils/columnProcessing.js +14 -3
  115. package/dist/cjs/utils/constants.d.ts +1 -0
  116. package/dist/cjs/utils/constants.d.ts.map +1 -1
  117. package/dist/cjs/utils/constants.js +2 -1
  118. package/dist/cjs/utils/dashboard.d.ts +3 -2
  119. package/dist/cjs/utils/dashboard.d.ts.map +1 -1
  120. package/dist/cjs/utils/dashboard.js +30 -12
  121. package/dist/cjs/utils/dataFetcher.d.ts +8 -5
  122. package/dist/cjs/utils/dataFetcher.d.ts.map +1 -1
  123. package/dist/cjs/utils/dataFetcher.js +189 -65
  124. package/dist/cjs/utils/filterProcessing.d.ts +2 -1
  125. package/dist/cjs/utils/filterProcessing.d.ts.map +1 -1
  126. package/dist/cjs/utils/filterProcessing.js +24 -38
  127. package/dist/cjs/utils/getDomain.d.ts.map +1 -1
  128. package/dist/cjs/utils/paginationProcessing.d.ts +1 -0
  129. package/dist/cjs/utils/paginationProcessing.d.ts.map +1 -1
  130. package/dist/cjs/utils/paginationProcessing.js +6 -1
  131. package/dist/cjs/utils/pivotConstructor.d.ts +2 -1
  132. package/dist/cjs/utils/pivotConstructor.d.ts.map +1 -1
  133. package/dist/cjs/utils/pivotConstructor.js +15 -9
  134. package/dist/cjs/utils/pivotProcessing.d.ts.map +1 -1
  135. package/dist/cjs/utils/pivotProcessing.js +3 -5
  136. package/dist/cjs/utils/queryConstructor.js +1 -1
  137. package/dist/cjs/utils/report.d.ts +10 -7
  138. package/dist/cjs/utils/report.d.ts.map +1 -1
  139. package/dist/cjs/utils/report.js +52 -60
  140. package/dist/cjs/utils/schema.d.ts +4 -3
  141. package/dist/cjs/utils/schema.d.ts.map +1 -1
  142. package/dist/cjs/utils/schema.js +30 -44
  143. package/dist/cjs/utils/tableProcessing.d.ts +16 -10
  144. package/dist/cjs/utils/tableProcessing.d.ts.map +1 -1
  145. package/dist/cjs/utils/tableProcessing.js +92 -90
  146. package/dist/cjs/utils/textProcessing.d.ts.map +1 -1
  147. package/dist/cjs/utils/textProcessing.js +2 -1
  148. package/dist/cjs/utils/ui.d.ts.map +1 -1
  149. package/dist/esm/Chart.d.ts +2 -2
  150. package/dist/esm/Chart.d.ts.map +1 -1
  151. package/dist/esm/Chart.js +60 -53
  152. package/dist/esm/ChartBuilder.d.ts +3 -2
  153. package/dist/esm/ChartBuilder.d.ts.map +1 -1
  154. package/dist/esm/ChartBuilder.js +173 -139
  155. package/dist/esm/ChartEditor.d.ts +2 -2
  156. package/dist/esm/ChartEditor.d.ts.map +1 -1
  157. package/dist/esm/ChartEditor.js +6 -3
  158. package/dist/esm/Context.d.ts +121 -41
  159. package/dist/esm/Context.d.ts.map +1 -1
  160. package/dist/esm/Context.js +450 -262
  161. package/dist/esm/Dashboard.d.ts.map +1 -1
  162. package/dist/esm/Dashboard.js +28 -27
  163. package/dist/esm/DateRangePicker/QuillDateRangePicker.js +0 -3
  164. package/dist/esm/DateRangePicker/dateRangePickerUtils.d.ts +24 -10
  165. package/dist/esm/DateRangePicker/dateRangePickerUtils.d.ts.map +1 -1
  166. package/dist/esm/DateRangePicker/dateRangePickerUtils.js +471 -95
  167. package/dist/esm/QuillProvider.d.ts +3 -1
  168. package/dist/esm/QuillProvider.d.ts.map +1 -1
  169. package/dist/esm/QuillProvider.js +2 -2
  170. package/dist/esm/ReportBuilder.d.ts.map +1 -1
  171. package/dist/esm/ReportBuilder.js +28 -17
  172. package/dist/esm/SQLEditor.d.ts +1 -1
  173. package/dist/esm/SQLEditor.d.ts.map +1 -1
  174. package/dist/esm/SQLEditor.js +54 -19
  175. package/dist/esm/Table.d.ts.map +1 -1
  176. package/dist/esm/Table.js +88 -17
  177. package/dist/esm/assets/ExclamationFilledIcon.d.ts.map +1 -1
  178. package/dist/esm/components/Chart/BarChart.d.ts.map +1 -1
  179. package/dist/esm/components/Chart/BarChart.js +2 -1
  180. package/dist/esm/components/Chart/CustomReferenceLine.d.ts +1 -1
  181. package/dist/esm/components/Chart/CustomReferenceLine.d.ts.map +1 -1
  182. package/dist/esm/components/Chart/CustomReferenceLine.js +8 -7
  183. package/dist/esm/components/Chart/GaugeChart.d.ts +1 -1
  184. package/dist/esm/components/Chart/GaugeChart.d.ts.map +1 -1
  185. package/dist/esm/components/Chart/GaugeChart.js +65 -38
  186. package/dist/esm/components/Chart/InternalChart.d.ts.map +1 -1
  187. package/dist/esm/components/Chart/InternalChart.js +32 -35
  188. package/dist/esm/components/Chart/LineChart.d.ts.map +1 -1
  189. package/dist/esm/components/Chart/LineChart.js +3 -1
  190. package/dist/esm/components/Chart/MapChart.d.ts +3 -3
  191. package/dist/esm/components/Chart/MapChart.d.ts.map +1 -1
  192. package/dist/esm/components/Chart/MapChart.js +67 -39
  193. package/dist/esm/components/Chart/PieChart.d.ts +3 -1
  194. package/dist/esm/components/Chart/PieChart.d.ts.map +1 -1
  195. package/dist/esm/components/Chart/PieChart.js +80 -39
  196. package/dist/esm/components/Dashboard/DashboardFilter.d.ts.map +1 -1
  197. package/dist/esm/components/Dashboard/DashboardFilter.js +5 -21
  198. package/dist/esm/components/Dashboard/DashboardSection.js +2 -2
  199. package/dist/esm/components/Dashboard/DashboardTemplate.d.ts.map +1 -1
  200. package/dist/esm/components/Dashboard/DashboardTemplate.js +3 -2
  201. package/dist/esm/components/Dashboard/DataLoader.d.ts +4 -4
  202. package/dist/esm/components/Dashboard/DataLoader.d.ts.map +1 -1
  203. package/dist/esm/components/Dashboard/DataLoader.js +102 -66
  204. package/dist/esm/components/Dashboard/MetricComponent.d.ts.map +1 -1
  205. package/dist/esm/components/Dashboard/MetricComponent.js +2 -2
  206. package/dist/esm/components/Dashboard/util.d.ts +1 -1
  207. package/dist/esm/components/Dashboard/util.d.ts.map +1 -1
  208. package/dist/esm/components/Dashboard/util.js +8 -7
  209. package/dist/esm/components/QuillMultiSelectSectionList.d.ts.map +1 -1
  210. package/dist/esm/components/QuillMultiSelectSectionList.js +32 -22
  211. package/dist/esm/components/QuillMultiSelectWithCombo.d.ts.map +1 -1
  212. package/dist/esm/components/QuillMultiSelectWithCombo.js +187 -160
  213. package/dist/esm/components/QuillSelect.d.ts.map +1 -1
  214. package/dist/esm/components/QuillSelect.js +85 -77
  215. package/dist/esm/components/QuillSelectWithCombo.d.ts.map +1 -1
  216. package/dist/esm/components/QuillSelectWithCombo.js +18 -11
  217. package/dist/esm/components/QuillTable.d.ts.map +1 -1
  218. package/dist/esm/components/QuillTable.js +59 -61
  219. package/dist/esm/components/ReportBuilder/FilterStack.d.ts +2 -1
  220. package/dist/esm/components/ReportBuilder/FilterStack.d.ts.map +1 -1
  221. package/dist/esm/components/ReportBuilder/FilterStack.js +3 -4
  222. package/dist/esm/components/ReportBuilder/ui.d.ts +2 -2
  223. package/dist/esm/components/ReportBuilder/ui.d.ts.map +1 -1
  224. package/dist/esm/components/ReportBuilder/ui.js +4 -7
  225. package/dist/esm/components/UiComponents.d.ts +1 -1
  226. package/dist/esm/hooks/useAskQuill.d.ts.map +1 -1
  227. package/dist/esm/hooks/useAskQuill.js +6 -2
  228. package/dist/esm/hooks/useDashboard.d.ts +2 -2
  229. package/dist/esm/hooks/useDashboard.d.ts.map +1 -1
  230. package/dist/esm/hooks/useDashboard.js +162 -71
  231. package/dist/esm/hooks/useExport.d.ts.map +1 -1
  232. package/dist/esm/hooks/useExport.js +31 -17
  233. package/dist/esm/hooks/useOnClickOutside.d.ts.map +1 -1
  234. package/dist/esm/hooks/useQuill.d.ts +1 -0
  235. package/dist/esm/hooks/useQuill.d.ts.map +1 -1
  236. package/dist/esm/hooks/useQuill.js +23 -13
  237. package/dist/esm/hooks/useReport.d.ts +2 -2
  238. package/dist/esm/hooks/useReport.d.ts.map +1 -1
  239. package/dist/esm/hooks/useReport.js +4 -5
  240. package/dist/esm/hooks/useVirtualTables.d.ts.map +1 -1
  241. package/dist/esm/hooks/useVirtualTables.js +17 -23
  242. package/dist/esm/index.d.ts +2 -2
  243. package/dist/esm/index.d.ts.map +1 -1
  244. package/dist/esm/index.js +1 -1
  245. package/dist/esm/internals/ReportBuilder/PivotModal.d.ts +2 -1
  246. package/dist/esm/internals/ReportBuilder/PivotModal.d.ts.map +1 -1
  247. package/dist/esm/internals/ReportBuilder/PivotModal.js +20 -8
  248. package/dist/esm/models/Client.d.ts +0 -1
  249. package/dist/esm/models/Client.d.ts.map +1 -1
  250. package/dist/esm/models/Data.d.ts +20 -0
  251. package/dist/esm/models/Data.d.ts.map +1 -0
  252. package/dist/esm/models/Data.js +1 -0
  253. package/dist/esm/models/Filter.d.ts +42 -4
  254. package/dist/esm/models/Filter.d.ts.map +1 -1
  255. package/dist/esm/models/Pivot.d.ts.map +1 -1
  256. package/dist/esm/utils/astProcessing.d.ts +3 -2
  257. package/dist/esm/utils/astProcessing.d.ts.map +1 -1
  258. package/dist/esm/utils/astProcessing.js +28 -37
  259. package/dist/esm/utils/client.d.ts +3 -2
  260. package/dist/esm/utils/client.d.ts.map +1 -1
  261. package/dist/esm/utils/client.js +38 -39
  262. package/dist/esm/utils/columnProcessing.d.ts.map +1 -1
  263. package/dist/esm/utils/columnProcessing.js +14 -3
  264. package/dist/esm/utils/constants.d.ts +1 -0
  265. package/dist/esm/utils/constants.d.ts.map +1 -1
  266. package/dist/esm/utils/constants.js +1 -0
  267. package/dist/esm/utils/dashboard.d.ts +3 -2
  268. package/dist/esm/utils/dashboard.d.ts.map +1 -1
  269. package/dist/esm/utils/dashboard.js +31 -13
  270. package/dist/esm/utils/dataFetcher.d.ts +8 -5
  271. package/dist/esm/utils/dataFetcher.d.ts.map +1 -1
  272. package/dist/esm/utils/dataFetcher.js +187 -65
  273. package/dist/esm/utils/filterProcessing.d.ts +2 -1
  274. package/dist/esm/utils/filterProcessing.d.ts.map +1 -1
  275. package/dist/esm/utils/filterProcessing.js +25 -39
  276. package/dist/esm/utils/getDomain.d.ts.map +1 -1
  277. package/dist/esm/utils/paginationProcessing.d.ts +1 -0
  278. package/dist/esm/utils/paginationProcessing.d.ts.map +1 -1
  279. package/dist/esm/utils/paginationProcessing.js +5 -0
  280. package/dist/esm/utils/pivotConstructor.d.ts +2 -1
  281. package/dist/esm/utils/pivotConstructor.d.ts.map +1 -1
  282. package/dist/esm/utils/pivotConstructor.js +16 -10
  283. package/dist/esm/utils/pivotProcessing.d.ts.map +1 -1
  284. package/dist/esm/utils/pivotProcessing.js +5 -7
  285. package/dist/esm/utils/queryConstructor.js +1 -1
  286. package/dist/esm/utils/report.d.ts +10 -7
  287. package/dist/esm/utils/report.d.ts.map +1 -1
  288. package/dist/esm/utils/report.js +53 -61
  289. package/dist/esm/utils/schema.d.ts +4 -3
  290. package/dist/esm/utils/schema.d.ts.map +1 -1
  291. package/dist/esm/utils/schema.js +30 -44
  292. package/dist/esm/utils/tableProcessing.d.ts +16 -10
  293. package/dist/esm/utils/tableProcessing.d.ts.map +1 -1
  294. package/dist/esm/utils/tableProcessing.js +94 -92
  295. package/dist/esm/utils/textProcessing.d.ts.map +1 -1
  296. package/dist/esm/utils/textProcessing.js +2 -1
  297. package/dist/esm/utils/ui.d.ts.map +1 -1
  298. package/package.json +2 -1
@@ -1,14 +1,14 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useState, createContext, useEffect, useReducer, useRef, useMemo, } from 'react';
3
- import { getSchemaInfo } from './utils/schema';
4
- import { fetchClient } from './utils/client';
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import equal from 'fast-deep-equal';
3
+ import { createContext, useEffect, useMemo, useReducer, useRef, useState, } from 'react';
4
+ import { convertPresetOptionsToSelectableList, defaultOptionsV2, } from './DateRangePicker/dateRangePickerUtils';
5
5
  import { InternalFilterType, } from './models/Filter';
6
+ import { fetchClient } from './utils/client';
6
7
  import { getDashboard as requestGetDashboard } from './utils/dashboard';
7
- import equal from 'fast-deep-equal';
8
- import { defaultOptionsV2, PRIMARY_RANGE, } from './DateRangePicker/dateRangePickerUtils';
9
- import { processReportResponse } from './utils/report';
8
+ import { quillFetch, parseFetchResponse } from './utils/dataFetcher';
10
9
  import { createDefaultDateFilter, mergeCustomFilters, } from './utils/filterProcessing';
11
- import { getData } from './utils/dataFetcher';
10
+ import { processReportResponse } from './utils/report';
11
+ import { getSchemaInfo } from './utils/schema';
12
12
  const dummySetter = () => { };
13
13
  export const SchemaDataContext = createContext([
14
14
  {
@@ -176,6 +176,8 @@ const reportsReducer = (state = {}, action) => {
176
176
  ...action.data,
177
177
  },
178
178
  };
179
+ case 'CLEAR_REPORTS':
180
+ return {};
179
181
  default:
180
182
  return state;
181
183
  }
@@ -185,6 +187,24 @@ export const ReportsContext = createContext({
185
187
  reportsDispatch: dummySetter,
186
188
  fetchIndividualReport: async () => { },
187
189
  });
190
+ const customReportFiltersReducer = (state, action) => {
191
+ switch (action.type) {
192
+ case 'ADD_CUSTOM_REPORT_FILTERS':
193
+ if (!action.data) {
194
+ const newState = { ...state };
195
+ delete newState[action.reportId];
196
+ return newState;
197
+ }
198
+ return {
199
+ ...state,
200
+ [action.reportId]: action.data,
201
+ };
202
+ case 'DELETE_CUSTOM_REPORT_FILTERS':
203
+ return Object.fromEntries(Object.entries(state).filter(([key]) => key !== action.reportId));
204
+ default:
205
+ return state;
206
+ }
207
+ };
188
208
  const reportFiltersReducer = (state = {}, action) => {
189
209
  switch (action.type) {
190
210
  case 'ADD_REPORT_FILTERS':
@@ -224,10 +244,30 @@ const reportFiltersReducer = (state = {}, action) => {
224
244
  };
225
245
  export const ReportFiltersContext = createContext({
226
246
  reportFilters: {},
247
+ customReportFilters: {},
227
248
  reportFiltersDispatch: dummySetter,
249
+ customReportFiltersDispatch: dummySetter,
228
250
  loadFiltersForReport: async () => { },
229
251
  abortLoadingFilters: () => { },
230
252
  });
253
+ const customDashboardFiltersReducer = (state, action) => {
254
+ switch (action.type) {
255
+ case 'ADD_CUSTOM_DASHBOARD_FILTERS':
256
+ if (!action.data) {
257
+ const newState = { ...state };
258
+ delete newState[action.dashboardName];
259
+ return newState;
260
+ }
261
+ return {
262
+ ...state,
263
+ [action.dashboardName]: action.data,
264
+ };
265
+ case 'DELETE_CUSTOM_DASHBOARD_FILTERS':
266
+ return Object.fromEntries(Object.entries(state).filter(([key]) => key !== action.dashboardName));
267
+ default:
268
+ return state;
269
+ }
270
+ };
231
271
  const dashboardFiltersReducer = (state, action) => {
232
272
  switch (action.type) {
233
273
  case 'SET_INITIAL_DASHBOARD_FILTERS':
@@ -267,12 +307,18 @@ const dashboardFiltersReducer = (state, action) => {
267
307
  };
268
308
  export const DashboardFiltersContext = createContext({
269
309
  dashboardFilters: {},
310
+ dashboardCustomFilters: {},
270
311
  dispatch: dummySetter,
312
+ customFilterDispatch: dummySetter,
271
313
  loadFiltersForDashboard: async () => { },
272
314
  });
273
315
  export const TenantContext = createContext({});
316
+ export const FetchContext = createContext({
317
+ getToken: async () => '',
318
+ quillFetchWithToken: async () => ({ data: null }),
319
+ });
274
320
  // TODO: track errors per dashboard in the same way as loading state
275
- export const ContextProvider = ({ children, initialTheme, publicKey, queryEndpoint, queryHeaders, withCredentials, tenants, flags, }) => {
321
+ export const ContextProvider = ({ children, initialTheme, publicKey, queryEndpoint, queryHeaders, withCredentials, tenants, flags, isAdmin, getAuthorizationToken = async () => '', }) => {
276
322
  // get client from session storage
277
323
  const [client, setClient] = useState(typeof window !== 'undefined' && sessionStorage
278
324
  ? JSON.parse(sessionStorage.getItem('quill-client') ?? 'null')
@@ -314,6 +360,8 @@ export const ContextProvider = ({ children, initialTheme, publicKey, queryEndpoi
314
360
  const [dashboard, dispatch] = useReducer(dashboardReducer, {});
315
361
  const [dashboardConfig, dashboardConfigDispatch] = useReducer(dashboardConfigReducer, {});
316
362
  const [dashboardFilters, dashboardFiltersDispatch] = useReducer(dashboardFiltersReducer, {});
363
+ const [dashboardCustomFilters, customFilterDispatch] = useReducer(customDashboardFiltersReducer, {});
364
+ const [customReportFilters, customReportFiltersDispatch] = useReducer(customReportFiltersReducer, {});
317
365
  const filterOptionsAbortControllers = useRef(new Set());
318
366
  const [reportFilters, reportFiltersDispatch] = useReducer(reportFiltersReducer, {});
319
367
  const reportFilterOptionsAbortControllers = useRef({});
@@ -321,6 +369,8 @@ export const ContextProvider = ({ children, initialTheme, publicKey, queryEndpoi
321
369
  const reportsAbortControllers = useRef({});
322
370
  const fetchSchemaAbortController = useRef(null);
323
371
  const fetchSchemaProcessId = useRef(0);
372
+ const currentTenant = useRef(null);
373
+ const currentPublicKey = useRef(null);
324
374
  // SETS INITIAL THEME
325
375
  useEffect(() => {
326
376
  if (!theme) {
@@ -348,7 +398,7 @@ export const ContextProvider = ({ children, initialTheme, publicKey, queryEndpoi
348
398
  // id: reportId,
349
399
  // });
350
400
  }
351
- async function loadFiltersForReport(reportId, initiator, filters, updatedFilterLabel, customFilters, filterMap, dashboardName) {
401
+ async function loadFiltersForReport(reportId, initiator, filters, updatedFilterLabel, customFilters, dashboardName) {
352
402
  // Abort all previous fetch requests
353
403
  reportFilterOptionsAbortControllers.current[reportId]?.requests.forEach((controller) => controller.abort());
354
404
  reportFilterOptionsAbortControllers.current[reportId] = {
@@ -393,56 +443,54 @@ export const ContextProvider = ({ children, initialTheme, publicKey, queryEndpoi
393
443
  const filterOptionsAbortController = new AbortController();
394
444
  reportFilterOptionsAbortControllers.current[reportId]?.requests.add(filterOptionsAbortController);
395
445
  try {
396
- const response = await fetch(`${queryEndpoint}?filterOptions`, {
397
- method: 'POST',
398
- headers: {
399
- ...queryHeaders,
400
- 'Content-Type': 'application/json',
446
+ const result = await quillFetch({
447
+ client: {
448
+ clientId: publicKey,
449
+ queryEndpoint,
450
+ queryHeaders,
451
+ withCredentials: !!withCredentials,
452
+ },
453
+ task: 'filter-options',
454
+ metadata: {
455
+ clientId: publicKey,
456
+ publicKey: publicKey,
457
+ reportId: dashboardName ? undefined : reportId,
458
+ name: dashboardName,
459
+ useNewNodeSql: true,
460
+ filter: {
461
+ ...filter,
462
+ query: undefined,
463
+ options: undefined,
464
+ },
465
+ appliedFilters: filters
466
+ .filter((f) => f.label !== filter.label)
467
+ .map((f) => ({
468
+ ...f,
469
+ query: undefined,
470
+ options: undefined,
471
+ })),
472
+ customFilters: customFilters?.filter((f) => f.filterType !== InternalFilterType.DateCustomFilter &&
473
+ f.filterType !== InternalFilterType.DateFilter &&
474
+ f.filterType !== InternalFilterType.DateComparisonFilter),
475
+ tenants,
401
476
  },
402
- body: JSON.stringify({
403
- metadata: {
404
- clientId: populatedClient?.publicKey,
405
- publicKey: populatedClient?.publicKey,
406
- reportId: dashboardName ? undefined : reportId,
407
- name: dashboardName,
408
- task: 'filter-options',
409
- useNewNodeSql: true,
477
+ abortSignal: filterOptionsAbortController?.signal,
478
+ getToken: getAuthorizationToken,
479
+ });
480
+ const filterOptions = result.data?.filters[0]?.options ?? [];
481
+ if (!filterOptionsAbortController.signal.aborted) {
482
+ reportFiltersDispatch({
483
+ type: 'UPDATE_REPORT_FILTER',
484
+ id: reportId,
485
+ data: {
410
486
  filter: {
411
487
  ...filter,
412
- options: undefined,
488
+ options: filterOptions,
413
489
  },
414
- appliedFilters: filters
415
- .filter((f) => f.label !== filter.label)
416
- .map((f) => ({
417
- ...f,
418
- query: undefined,
419
- options: undefined,
420
- })),
421
- customFilters: customFilters?.filter((f) => f.filterType !== InternalFilterType.DateCustomFilter &&
422
- f.filterType !== InternalFilterType.DateFilter &&
423
- f.filterType !== InternalFilterType.DateComparisonFilter),
424
- tenants,
490
+ loading: false,
425
491
  },
426
- }),
427
- signal: filterOptionsAbortController?.signal,
428
- credentials: withCredentials ? 'include' : 'omit',
429
- });
430
- return response.json().then((result) => {
431
- const filterOptions = result.data?.filters[0]?.options ?? [];
432
- if (reportFilters[reportId]?.[filter.label]) {
433
- reportFiltersDispatch({
434
- type: 'UPDATE_REPORT_FILTER',
435
- id: reportId,
436
- data: {
437
- filter: {
438
- ...filter,
439
- options: filterOptions,
440
- },
441
- loading: false,
442
- },
443
- });
444
- }
445
- });
492
+ });
493
+ }
446
494
  }
447
495
  catch (error) {
448
496
  if (error instanceof Error && error.name === 'AbortError') {
@@ -465,7 +513,7 @@ export const ContextProvider = ({ children, initialTheme, publicKey, queryEndpoi
465
513
  delete reportFilterOptionsAbortControllers.current[reportId];
466
514
  }
467
515
  }
468
- async function fetchIndividualReport({ reportId, initiator, fetchRows = true, dashboardFilters, customFilters, additionalProcessing, dateBucket, reportAbortController, customFields, propogateChanges, }) {
516
+ async function fetchIndividualReport({ reportId, initiator, fetchRows = true, dashboardFilters, customFilters, additionalProcessing, dateBucket, reportAbortController, customFields, propagateChanges, }) {
469
517
  if (!populatedClient) {
470
518
  return;
471
519
  }
@@ -473,7 +521,8 @@ export const ContextProvider = ({ children, initialTheme, publicKey, queryEndpoi
473
521
  const currentRequest = reportsAbortControllers.current[reportId];
474
522
  if (currentRequest) {
475
523
  // Chart requests override useQuill and useExport requests
476
- if (initiator === 'Chart') {
524
+ if (initiator === 'Chart' ||
525
+ (currentRequest.initiator !== 'Chart' && initiator === 'Table')) {
477
526
  currentRequest.request.abort();
478
527
  }
479
528
  else {
@@ -486,55 +535,33 @@ export const ContextProvider = ({ children, initialTheme, publicKey, queryEndpoi
486
535
  request: abortController,
487
536
  };
488
537
  try {
489
- const hostedBody = {
538
+ const resp = await quillFetch({
539
+ client: {
540
+ clientId: publicKey,
541
+ queryEndpoint,
542
+ queryHeaders,
543
+ withCredentials: !!withCredentials,
544
+ },
545
+ task: fetchRows ? 'report' : 'report-info',
490
546
  metadata: {
491
547
  reportId,
492
- dashboardItemId: reportId,
493
548
  clientId: populatedClient.publicKey,
494
- task: 'report',
495
- databaseType: populatedClient.databaseType,
496
- filters: filters.map((filter) => ({ ...filter, options: undefined })),
497
- additionalProcessing,
498
549
  useNewNodeSql: true,
499
- getDefaultDashboardFilters: !filters.length,
550
+ filters: filters?.map((f) => ({ ...f, options: undefined })),
551
+ additionalProcessing,
552
+ dateBucket,
553
+ databaseType: populatedClient.databaseType,
500
554
  tenants,
501
555
  flags,
502
556
  customFields,
503
557
  },
504
- };
505
- const cloudBody = {
506
- id: reportId,
507
- filters: filters,
508
- useNewNodeSql: true,
509
- };
510
- const resp = fetchRows
511
- ? await getData(populatedClient, 'itempost', 'omit', hostedBody, cloudBody, 'POST', 'fetch-data', abortController.signal)
512
- : await fetch(`${queryEndpoint}`, {
513
- method: 'POST',
514
- headers: {
515
- 'Content-Type': 'application/json',
516
- ...queryHeaders,
517
- },
518
- body: JSON.stringify({
519
- metadata: {
520
- task: fetchRows ? 'report' : 'report-info',
521
- reportId,
522
- clientId: populatedClient.publicKey,
523
- useNewNodeSql: true,
524
- filters: filters?.map((f) => ({ ...f, options: undefined })),
525
- getDefaultDashboardFilters: !filters.length,
526
- additionalProcessing,
527
- dateBucket,
528
- databaseType: populatedClient.databaseType,
529
- tenants,
530
- flags,
531
- customFields,
532
- },
533
- }),
534
- signal: abortController.signal,
535
- credentials: withCredentials ? 'include' : 'omit',
536
- });
537
- const results = fetchRows ? resp : await resp.json();
558
+ abortSignal: abortController.signal,
559
+ getToken: getAuthorizationToken,
560
+ urlParameters: `caller=fetchReport&task=report`,
561
+ });
562
+ const results = fetchRows
563
+ ? await parseFetchResponse(populatedClient, 'report', resp, getAuthorizationToken)
564
+ : resp;
538
565
  if (results.error) {
539
566
  console.error('Error fetching report:', results.error);
540
567
  return;
@@ -548,6 +575,7 @@ export const ContextProvider = ({ children, initialTheme, publicKey, queryEndpoi
548
575
  dateBucket,
549
576
  additionalProcessing,
550
577
  customFields,
578
+ getToken: getAuthorizationToken,
551
579
  });
552
580
  reportsDispatch({
553
581
  type: 'ADD_REPORT',
@@ -559,7 +587,7 @@ export const ContextProvider = ({ children, initialTheme, publicKey, queryEndpoi
559
587
  },
560
588
  });
561
589
  // If the report matches the active dashboard, update the dashboard state
562
- if (propogateChanges) {
590
+ if (propagateChanges) {
563
591
  if (dashboard[report.dashboardName]) {
564
592
  dispatch({
565
593
  type: 'UPDATE_DASHBOARD_ITEM',
@@ -577,7 +605,26 @@ export const ContextProvider = ({ children, initialTheme, publicKey, queryEndpoi
577
605
  const returnedFilters = !fetchRows
578
606
  ? results.data.filters
579
607
  : results.filters;
580
- const dateFilterTemplate = returnedFilters.find((f) => f.filterType === 'date_range');
608
+ let dateFilterTemplate = returnedFilters.find((f) => f.filterType === 'date_range');
609
+ if (dateFilterTemplate) {
610
+ dateFilterTemplate = {
611
+ ...dateFilterTemplate,
612
+ presetOptions: dateFilterTemplate?.presetOptions?.map((preset) => ({
613
+ ...preset,
614
+ loopStart: preset.loopStart
615
+ ? new Date(preset.loopStart)
616
+ : undefined,
617
+ loopEnd: preset.loopEnd ? new Date(preset.loopEnd) : undefined,
618
+ })),
619
+ defaultPresetRanges: dateFilterTemplate?.defaultPresetRanges?.map((preset) => ({
620
+ ...preset,
621
+ loopStart: preset.loopStart
622
+ ? new Date(preset.loopStart)
623
+ : undefined,
624
+ loopEnd: preset.loopEnd ? new Date(preset.loopEnd) : undefined,
625
+ })),
626
+ };
627
+ }
581
628
  const dateFilter = dateFilterTemplate
582
629
  ? createDefaultDateFilter(dateFilterTemplate, [report], report.dashboardName)
583
630
  : undefined;
@@ -586,14 +633,6 @@ export const ContextProvider = ({ children, initialTheme, publicKey, queryEndpoi
586
633
  ...(dateFilter ? [dateFilter] : []),
587
634
  ...stringFilters,
588
635
  ];
589
- reportFiltersDispatch({
590
- type: 'ADD_REPORT_FILTERS',
591
- id: reportId,
592
- data: allFilters.map((filter) => ({
593
- filter,
594
- loading: filter.filterType !== 'date_range',
595
- })),
596
- });
597
636
  loadFiltersForReport(reportId, initiator, allFilters, undefined, customFilters);
598
637
  }
599
638
  }
@@ -653,64 +692,63 @@ export const ContextProvider = ({ children, initialTheme, publicKey, queryEndpoi
653
692
  const filterOptionsAbortController = new AbortController();
654
693
  filterOptionsAbortControllers.current.add(filterOptionsAbortController);
655
694
  try {
656
- const response = await fetch(`${queryEndpoint}?filterOptions`, {
657
- method: 'POST',
658
- headers: {
659
- ...queryHeaders,
660
- 'Content-Type': 'application/json',
695
+ const result = await quillFetch({
696
+ client: {
697
+ clientId: publicKey,
698
+ queryEndpoint,
699
+ queryHeaders,
700
+ withCredentials: !!withCredentials,
661
701
  },
662
- body: JSON.stringify({
663
- metadata: {
664
- clientId: populatedClient?.publicKey,
665
- publicKey: populatedClient?.publicKey,
666
- name: dashboardName,
667
- task: 'filter-options',
668
- useNewNodeSql: true,
669
- filter: {
670
- ...filter,
671
- options: undefined,
672
- },
673
- appliedFilters: filters
674
- .filter((f) => f.label !== filter.label)
675
- .map((f) => ({
676
- ...f,
677
- query: undefined,
678
- options: undefined,
679
- })),
680
- customFilters,
681
- tenants: tenants,
702
+ task: 'filter-options',
703
+ metadata: {
704
+ clientId: publicKey,
705
+ publicKey,
706
+ name: dashboardName,
707
+ useNewNodeSql: true,
708
+ filter: {
709
+ ...filter,
710
+ query: undefined,
711
+ options: undefined,
682
712
  },
683
- }),
684
- signal: filterOptionsAbortController?.signal,
685
- credentials: withCredentials ? 'include' : 'omit',
713
+ appliedFilters: filters
714
+ .filter((f) => f.label !== filter.label)
715
+ .map((f) => ({
716
+ ...f,
717
+ query: undefined,
718
+ options: undefined,
719
+ })),
720
+ customFilters,
721
+ tenants,
722
+ },
723
+ abortSignal: filterOptionsAbortController?.signal,
724
+ getToken: getAuthorizationToken,
686
725
  });
687
- return response.json().then((result) => {
688
- const filterOptions = result.data?.filters[0]?.options ?? [];
689
- dashboardFiltersDispatch({
690
- type: 'UPDATE_DASHBOARD_FILTER',
691
- dashboardName,
692
- filterName: filter.label,
693
- data: {
694
- filter: {
695
- ...filter,
696
- options: filterOptions,
697
- },
698
- loading: false,
726
+ const filterOptions = result.data?.filters[0]?.options ?? [];
727
+ dashboardFiltersDispatch({
728
+ type: 'UPDATE_DASHBOARD_FILTER',
729
+ dashboardName,
730
+ filterName: filter.label,
731
+ data: {
732
+ filter: {
733
+ ...filter,
734
+ options: filterOptions,
699
735
  },
700
- });
701
- // Should we be updating the filters for all attached reports when the dashboard filters change?
702
- // reportFiltersDispatch({
703
- // type: 'UPDATE_REPORT_FILTER',
704
- // id: filter.label,
705
- // data: {
706
- // filter: {
707
- // ...filter,
708
- // options: filterOptions,
709
- // },
710
- // loading: false,
711
- // },
712
- // });
736
+ loading: false,
737
+ },
738
+ });
739
+ // Should we be updating the filters for all attached reports when the dashboard filters change?
740
+ reportFiltersDispatch({
741
+ type: 'UPDATE_REPORT_FILTER',
742
+ id: filter.label,
743
+ data: {
744
+ filter: {
745
+ ...filter,
746
+ options: filterOptions,
747
+ },
748
+ loading: false,
749
+ },
713
750
  });
751
+ return null;
714
752
  }
715
753
  catch (error) {
716
754
  if (error instanceof Error && error.name === 'AbortError') {
@@ -733,6 +771,8 @@ export const ContextProvider = ({ children, initialTheme, publicKey, queryEndpoi
733
771
  }));
734
772
  }
735
773
  async function loadDashboard(dashboardName, fetchFromServer = false, reportAction) {
774
+ if (!client)
775
+ return;
736
776
  let curDashboardConfig = dashboardConfig[dashboardName]?.config;
737
777
  if (!fetchFromServer && curDashboardConfig?.sections) {
738
778
  if (reportAction?.action === 'delete') {
@@ -750,7 +790,6 @@ export const ContextProvider = ({ children, initialTheme, publicKey, queryEndpoi
750
790
  });
751
791
  dispatch({
752
792
  type: 'REMOVE_DASHBOARD_ITEM',
753
- dashboard: dashboardName,
754
793
  id: reportAction.report.id,
755
794
  });
756
795
  }
@@ -767,12 +806,75 @@ export const ContextProvider = ({ children, initialTheme, publicKey, queryEndpoi
767
806
  },
768
807
  });
769
808
  }
809
+ let newSectionOrder = curDashboardConfig.sectionOrder;
810
+ if (newSectionOrder) {
811
+ newSectionOrder = newSectionOrder.map((section) => {
812
+ if (section.section === report.section &&
813
+ !section.reportOrder.includes(report.id)) {
814
+ section.reportOrder.push(report.id);
815
+ }
816
+ else if (section.section !== report.section &&
817
+ section.reportOrder.includes(report.id)) {
818
+ section.reportOrder = section.reportOrder.filter((id) => id !== report.id);
819
+ }
820
+ return section;
821
+ });
822
+ const newSections = newSectionOrder.reduce((acc, section) => {
823
+ acc[section.section] = section.reportOrder
824
+ .map((id, index) => {
825
+ if (id === report.id) {
826
+ return { ...report, id: id, order: index };
827
+ }
828
+ return dashboard?.[dashboardName]?.[id]
829
+ ? { ...dashboard[dashboardName][id], id: id, order: index }
830
+ : null;
831
+ })
832
+ .filter((r) => r);
833
+ return acc;
834
+ }, {});
835
+ dashboardConfigDispatch({
836
+ type: 'UPDATE_DASHBOARD',
837
+ id: dashboardName,
838
+ data: {
839
+ config: {
840
+ ...curDashboardConfig,
841
+ sections: newSections,
842
+ sectionOrder: newSectionOrder?.map((section) => ({
843
+ ...section,
844
+ _id: section._id ?? 'temp_section_id_' + Date.now().toString(),
845
+ })) ?? [],
846
+ },
847
+ loading: false,
848
+ },
849
+ });
850
+ if ((curDashboardConfig.sectionOrder?.find((section) => section.reportOrder?.includes(report?.id ?? ''))?.section ?? '') !== report.section) {
851
+ const body = {
852
+ task: 'set-section-order',
853
+ clientId: client?.clientId,
854
+ dashboardName,
855
+ sectionOrder: newSectionOrder,
856
+ };
857
+ try {
858
+ await quillFetch({
859
+ client,
860
+ task: 'set-section-order',
861
+ metadata: body,
862
+ getToken: getAuthorizationToken,
863
+ });
864
+ }
865
+ catch (e) {
866
+ console.error(e);
867
+ }
868
+ }
869
+ }
870
+ }
871
+ if (reportAction?.action !== 'upsert') {
872
+ dashboardConfigDispatch({
873
+ type: 'UPDATE_DASHBOARD',
874
+ id: dashboardName,
875
+ data: { config: curDashboardConfig, loading: false },
876
+ });
770
877
  }
771
- dashboardConfigDispatch({
772
- type: 'UPDATE_DASHBOARD',
773
- id: dashboardName,
774
- data: { config: curDashboardConfig, loading: false },
775
- });
776
878
  return curDashboardConfig;
777
879
  }
778
880
  if (!fetchFromServer &&
@@ -796,7 +898,7 @@ export const ContextProvider = ({ children, initialTheme, publicKey, queryEndpoi
796
898
  id: dashboardName,
797
899
  data: true,
798
900
  });
799
- const resp = await requestGetDashboard(dashboardName, populatedClient, tenants, flags);
901
+ const resp = await requestGetDashboard(dashboardName, populatedClient, getAuthorizationToken, tenants, flags);
800
902
  // if dashboard has changed
801
903
  if (!equal(resp, curDashboardConfig)) {
802
904
  dashboardConfigDispatch({
@@ -844,6 +946,7 @@ export const ContextProvider = ({ children, initialTheme, publicKey, queryEndpoi
844
946
  tenants,
845
947
  caller,
846
948
  abortSignal: fetchSchemaAbortController.current.signal,
949
+ getToken: getAuthorizationToken,
847
950
  });
848
951
  if (currentProcessId === fetchSchemaProcessId.current) {
849
952
  setSchemaData({
@@ -877,74 +980,112 @@ export const ContextProvider = ({ children, initialTheme, publicKey, queryEndpoi
877
980
  fetchDashboardsAbortController.current = new AbortController();
878
981
  dashboardConfigDispatch({ type: 'CLEAR_DASHBOARDS' });
879
982
  try {
880
- const response = await fetch(`${queryEndpoint}?dashboards`, {
881
- method: 'POST',
882
- headers: {
883
- ...queryHeaders,
884
- 'Content-Type': 'application/json',
983
+ const result = await quillFetch({
984
+ client: {
985
+ clientId: publicKey,
986
+ queryEndpoint,
987
+ queryHeaders,
988
+ withCredentials: !!withCredentials,
885
989
  },
886
- body: JSON.stringify({
887
- metadata: {
888
- clientId: publicKey,
889
- publicKey: publicKey,
890
- task: 'dashboards',
891
- getSections: true,
892
- },
893
- }),
894
- credentials: withCredentials ? 'include' : 'omit',
895
- signal: fetchDashboardsAbortController.current.signal,
990
+ task: 'dashboards',
991
+ metadata: {
992
+ clientId: publicKey,
993
+ // getSections: true, // skip fetching reports since 'dashboard' always does anyway
994
+ },
995
+ abortSignal: fetchDashboardsAbortController.current.signal,
996
+ getToken: getAuthorizationToken,
896
997
  });
897
- const result = await response.json();
898
998
  dashboardConfigDispatch({
899
999
  type: 'SET_DASHBOARD_DATA',
900
1000
  data: result.data.dashboards.map((dashboard) => ({
901
1001
  ...dashboard,
1002
+ dateFilter: dashboard.dateFilter
1003
+ ? {
1004
+ ...dashboard.dateFilter,
1005
+ presetOptions: dashboard.dateFilter.presetOptions?.map((preset) => ({
1006
+ ...preset,
1007
+ loopStart: preset.loopStart
1008
+ ? new Date(preset.loopStart)
1009
+ : undefined,
1010
+ loopEnd: preset.loopEnd
1011
+ ? new Date(preset.loopEnd)
1012
+ : undefined,
1013
+ })),
1014
+ defaultPresetRanges: dashboard.dateFilter.defaultPresetRanges?.map((preset) => ({
1015
+ ...preset,
1016
+ loopStart: preset.loopStart
1017
+ ? new Date(preset.loopStart)
1018
+ : undefined,
1019
+ loopEnd: preset.loopEnd
1020
+ ? new Date(preset.loopEnd)
1021
+ : undefined,
1022
+ })),
1023
+ }
1024
+ : undefined,
902
1025
  createdAt: new Date(dashboard.createdAt),
903
1026
  })),
904
1027
  });
905
1028
  dashboardFiltersDispatch({
906
1029
  type: 'SET_INITIAL_DASHBOARD_FILTERS',
907
1030
  data: result.data.dashboards.reduce((acc, dashboard) => {
908
- let presetsOptions = defaultOptionsV2;
909
- if (dashboard.dateFilter?.presetRanges) {
910
- presetsOptions = dashboard.dateFilter.presetRanges.map((elem) => {
911
- if (!elem.isStatic) {
912
- return {
913
- label: elem.label,
914
- value: elem.value,
915
- startDate: (PRIMARY_RANGE[elem.value] ??
916
- PRIMARY_RANGE['LAST_30_DAYS']).startDate,
917
- endDate: (PRIMARY_RANGE[elem.value] ??
918
- PRIMARY_RANGE['LAST_30_DAYS']).endDate,
919
- };
920
- }
921
- return {
922
- label: elem.label,
923
- value: elem.value,
924
- startDate: new Date(elem.startDate),
925
- endDate: new Date(elem.endDate),
926
- };
927
- });
1031
+ let presetOptions = defaultOptionsV2;
1032
+ if (dashboard.dateFilter?.presetOptions ||
1033
+ dashboard.dateFilter?.defaultPresetRanges) {
1034
+ presetOptions = convertPresetOptionsToSelectableList((dashboard.dateFilter.presetOptions ?? []).map((preset) => ({
1035
+ ...preset,
1036
+ loopStart: preset.loopStart
1037
+ ? new Date(preset.loopStart)
1038
+ : undefined,
1039
+ loopEnd: preset.loopEnd
1040
+ ? new Date(preset.loopEnd)
1041
+ : undefined,
1042
+ })), (dashboard.dateFilter.defaultPresetRanges ?? []).map((preset) => ({
1043
+ ...preset,
1044
+ loopStart: preset.loopStart
1045
+ ? new Date(preset.loopStart)
1046
+ : undefined,
1047
+ loopEnd: preset.loopEnd
1048
+ ? new Date(preset.loopEnd)
1049
+ : undefined,
1050
+ })));
928
1051
  }
929
- acc[dashboard.name] = dashboard.filters.reduce((acc, filter) => {
930
- acc[filter.label] = {
931
- filter: { ...filter, options: undefined },
932
- loading: true,
933
- };
934
- return acc;
935
- }, {});
1052
+ acc[dashboard.name] = {};
936
1053
  if (dashboard.dateFilter) {
937
1054
  dashboard.dateFilter = {
938
1055
  ...dashboard.dateFilter,
939
- startDate: presetsOptions.find((elem) => elem.value === dashboard.dateFilter.primaryRange?.value)?.startDate,
940
- endDate: presetsOptions.find((elem) => elem.value === dashboard.dateFilter.primaryRange?.value)?.endDate,
1056
+ startDate: presetOptions.find((elem) => elem.value === dashboard.dateFilter.primaryRange?.value)?.startDate,
1057
+ endDate: presetOptions.find((elem) => elem.value === dashboard.dateFilter.primaryRange?.value)?.endDate,
941
1058
  filterType: 'date_range',
1059
+ presetOptions: dashboard.dateFilter.presetOptions?.map((preset) => ({
1060
+ ...preset,
1061
+ loopStart: preset.loopStart
1062
+ ? new Date(preset.loopStart)
1063
+ : undefined,
1064
+ loopEnd: preset.loopEnd
1065
+ ? new Date(preset.loopEnd)
1066
+ : undefined,
1067
+ })),
1068
+ defaultPresetRanges: dashboard.dateFilter.defaultPresetRanges?.map((preset) => ({
1069
+ ...preset,
1070
+ loopStart: preset.loopStart
1071
+ ? new Date(preset.loopStart)
1072
+ : undefined,
1073
+ loopEnd: preset.loopEnd
1074
+ ? new Date(preset.loopEnd)
1075
+ : undefined,
1076
+ })),
942
1077
  };
943
1078
  acc[dashboard.name][dashboard.dateFilter.label] = {
944
1079
  filter: dashboard.dateFilter,
945
1080
  loading: true,
946
1081
  };
947
1082
  }
1083
+ dashboard.filters.forEach((filter) => {
1084
+ acc[dashboard.name][filter.label] = {
1085
+ filter: { ...filter, options: undefined },
1086
+ loading: true,
1087
+ };
1088
+ });
948
1089
  return acc;
949
1090
  }, {}),
950
1091
  });
@@ -963,6 +1104,33 @@ export const ContextProvider = ({ children, initialTheme, publicKey, queryEndpoi
963
1104
  }
964
1105
  }
965
1106
  }
1107
+ async function quillFetchWithToken({ client, task, method = 'POST', metadata, abortSignal, credentials = 'omit', urlParameters, includeFlags = false, includeTenants = false, adminMode, }) {
1108
+ try {
1109
+ const result = await quillFetch({
1110
+ client,
1111
+ task,
1112
+ method,
1113
+ metadata: {
1114
+ flags: includeFlags ? flags : undefined,
1115
+ tenants: includeTenants ? tenants : undefined,
1116
+ adminMode,
1117
+ ...metadata,
1118
+ },
1119
+ abortSignal,
1120
+ credentials,
1121
+ urlParameters,
1122
+ getToken: getAuthorizationToken,
1123
+ });
1124
+ return result;
1125
+ }
1126
+ catch (e) {
1127
+ if (e instanceof Error && e.name === 'AbortError') {
1128
+ throw e;
1129
+ }
1130
+ console.error('Failed to fetch:', e);
1131
+ return { error: 'Failed to fetch data' };
1132
+ }
1133
+ }
966
1134
  useEffect(() => {
967
1135
  async function updateClientAndSchema(publicKey) {
968
1136
  if (populatedClient?.clientId === publicKey &&
@@ -970,8 +1138,8 @@ export const ContextProvider = ({ children, initialTheme, publicKey, queryEndpoi
970
1138
  return;
971
1139
  setIsClientLoading(true);
972
1140
  setSchemaData({ ...schemaData, isSchemaLoading: true });
973
- const newClient = await fetchClient(publicKey, queryEndpoint, withCredentials, queryHeaders);
974
- if (!newClient.allTenantTypes?.every((t) => t.defaultId)) {
1141
+ const newClient = await fetchClient(publicKey, queryEndpoint, withCredentials, getAuthorizationToken, queryHeaders, isAdmin);
1142
+ if (!newClient.allTenantTypes?.every((t) => t.defaultId || t.scope === 'database')) {
975
1143
  console.error('Default organization not found. Please select a default organization for ', newClient.allTenantTypes?.find((t) => !t.defaultId));
976
1144
  }
977
1145
  setClient({
@@ -986,69 +1154,89 @@ export const ContextProvider = ({ children, initialTheme, publicKey, queryEndpoi
986
1154
  featureFlags: newClient.featureFlags,
987
1155
  domainName: newClient.domainName,
988
1156
  allTenantTypes: newClient.allTenantTypes,
989
- // @ts-ignore
990
- maintenanceMode: newClient?.maintenanceMode || false,
991
1157
  });
992
1158
  setIsClientLoading(false);
993
1159
  }
994
1160
  updateClientAndSchema(publicKey);
995
1161
  }, [publicKey]);
996
1162
  useEffect(() => {
997
- if (populatedClient) {
998
- fetchSchema({ client: populatedClient, tenants, caller: 'context' });
999
- }
1000
- if (typeof window !== 'undefined' && sessionStorage) {
1001
- sessionStorage.setItem('quill-client', JSON.stringify({
1002
- ...populatedClient,
1003
- allTenantTypes: undefined,
1004
- }));
1163
+ if (populatedClient?.publicKey &&
1164
+ currentPublicKey.current !== populatedClient?.publicKey) {
1165
+ // CLEAR ALL DASHBOARD DATA AND REPORTS AND THEIR FILTERS
1166
+ dispatch({ type: 'CLEAR_DASHBOARDS' });
1167
+ dashboardFiltersDispatch({ type: 'CLEAR_DASHBOARD_FILTERS' });
1168
+ reportFiltersDispatch({ type: 'CLEAR_REPORT_FILTERS' });
1169
+ reportsDispatch({ type: 'CLEAR_REPORTS' });
1170
+ // TODO: this is yet another unfortunate hack where the answer is to unify the admin and react state
1171
+ // currently, we fetch the dashboards twice if both the client and default org change
1172
+ // because if we didn't, we would fetch 0 times if the client changed but the org didn't
1173
+ if (isAdmin) {
1174
+ setIsDashboardsLoading(true);
1175
+ fetchDashboards(populatedClient?.publicKey);
1176
+ }
1177
+ else {
1178
+ setIsDashboardsLoading(false);
1179
+ }
1180
+ if (typeof window !== 'undefined' && sessionStorage) {
1181
+ sessionStorage.setItem('quill-client', JSON.stringify({
1182
+ ...populatedClient,
1183
+ allTenantTypes: undefined,
1184
+ }));
1185
+ }
1186
+ currentPublicKey.current = publicKey;
1005
1187
  }
1006
- }, [populatedClient?.publicKey, tenants]);
1007
- // FIXME: fetchDashboards needs to rerun every time the tenant changes so that we filter reports on their flags
1188
+ }, [populatedClient?.publicKey]);
1008
1189
  useEffect(() => {
1009
- // Clear context
1010
- setIsDashboardsLoading(true);
1011
- // TODO: this is yet another unfortunate hack where the answer is to unify the admin and react state
1012
- // currently, we fetch the dashboards twice if both the client and default org change
1013
- // because if we didn't, we would fetch 0 times if the client changed but the org didn't
1014
- fetchDashboards(publicKey);
1015
- dashboardFiltersDispatch({ type: 'CLEAR_DASHBOARD_FILTERS' });
1016
- reportFiltersDispatch({ type: 'CLEAR_REPORT_FILTERS' });
1017
- dispatch({ type: 'CLEAR_DASHBOARDS', dashboard: null });
1018
- }, [publicKey]);
1190
+ if (populatedClient?.currentTenants &&
1191
+ !equal(currentTenant.current, populatedClient?.currentTenants)) {
1192
+ dispatch({ type: 'CLEAR_DASHBOARDS' });
1193
+ dashboardFiltersDispatch({ type: 'CLEAR_DASHBOARD_FILTERS' });
1194
+ reportFiltersDispatch({ type: 'CLEAR_REPORT_FILTERS' });
1195
+ reportsDispatch({ type: 'CLEAR_REPORTS' });
1196
+ if (populatedClient) {
1197
+ fetchSchema({
1198
+ client: populatedClient,
1199
+ tenants: populatedClient.currentTenants,
1200
+ caller: 'context',
1201
+ });
1202
+ }
1203
+ currentTenant.current = populatedClient?.currentTenants ?? null;
1204
+ }
1205
+ }, [populatedClient?.currentTenants]);
1019
1206
  if (!theme) {
1020
1207
  return null;
1021
1208
  }
1022
1209
  if (!tenants) {
1023
1210
  throw new Error('Quill Error: QuillProvider prop organizationId is deprecated. Please use QuillProvider tenants prop instead');
1024
1211
  }
1025
- if (populatedClient?.maintenanceMode) {
1026
- return (_jsxs("div", { children: [_jsx("h1", { children: "Dashboard is currently in maintenance mode" }), _jsx("p", { children: "Please check back later or contact your administrator for more information." })] }));
1027
- }
1028
1212
  return (_jsx(ClientContext.Provider, { value: [
1029
1213
  isClientLoading || !populatedClient ? null : populatedClient,
1030
1214
  isClientLoading,
1031
1215
  setClient,
1032
- ], children: _jsx(ThemeContext.Provider, { value: [theme, setTheme], children: _jsx(SchemaDataContext.Provider, { value: [schemaData, setSchemaData], children: _jsx(DashboardContext.Provider, { value: [dashboard, dispatch], children: _jsx(DashboardConfigContext.Provider, { value: {
1033
- dashboardConfig: isDashboardsLoading ? {} : dashboardConfig,
1034
- isLoading: isDashboardsLoading,
1035
- dashboardConfigDispatch,
1036
- loadDashboard,
1037
- }, children: _jsx(DashboardFiltersContext.Provider, { value: {
1038
- dashboardFilters,
1039
- dispatch: dashboardFiltersDispatch,
1040
- loadFiltersForDashboard,
1041
- }, children: _jsx(ReportFiltersContext.Provider, { value: {
1042
- reportFilters,
1043
- reportFiltersDispatch,
1044
- loadFiltersForReport,
1045
- abortLoadingFilters,
1046
- }, children: _jsx(ReportsContext.Provider, { value: {
1047
- reports,
1048
- reportsDispatch,
1049
- fetchIndividualReport,
1050
- }, children: _jsx(TenantContext.Provider, { value: {
1051
- tenants: populatedClient?.currentFlags ?? tenants,
1052
- flags: populatedClient?.currentFlags ?? flags,
1053
- }, children: children }) }) }) }) }) }) }) }) }));
1216
+ ], children: _jsx(ThemeContext.Provider, { value: [theme, setTheme], children: _jsx(FetchContext.Provider, { value: { getToken: getAuthorizationToken, quillFetchWithToken }, children: _jsx(SchemaDataContext.Provider, { value: [schemaData, setSchemaData], children: _jsx(DashboardContext.Provider, { value: [dashboard, dispatch], children: _jsx(DashboardConfigContext.Provider, { value: {
1217
+ dashboardConfig: isDashboardsLoading ? {} : dashboardConfig,
1218
+ isLoading: isDashboardsLoading,
1219
+ dashboardConfigDispatch,
1220
+ loadDashboard,
1221
+ }, children: _jsx(DashboardFiltersContext.Provider, { value: {
1222
+ dashboardFilters,
1223
+ dashboardCustomFilters,
1224
+ customFilterDispatch,
1225
+ dispatch: dashboardFiltersDispatch,
1226
+ loadFiltersForDashboard,
1227
+ }, children: _jsx(ReportFiltersContext.Provider, { value: {
1228
+ reportFilters,
1229
+ customReportFilters,
1230
+ reportFiltersDispatch,
1231
+ customReportFiltersDispatch,
1232
+ loadFiltersForReport,
1233
+ abortLoadingFilters,
1234
+ }, children: _jsx(ReportsContext.Provider, { value: {
1235
+ reports,
1236
+ reportsDispatch,
1237
+ fetchIndividualReport,
1238
+ }, children: _jsx(TenantContext.Provider, { value: {
1239
+ tenants: populatedClient?.currentTenants ?? tenants,
1240
+ flags: populatedClient?.currentFlags ?? flags,
1241
+ }, children: children }) }) }) }) }) }) }) }) }) }));
1054
1242
  };