@quillsql/react 2.11.16 → 2.11.17

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 (203) hide show
  1. package/dist/cjs/Chart.d.ts +117 -42
  2. package/dist/cjs/Chart.d.ts.map +1 -1
  3. package/dist/cjs/Chart.js +44 -18
  4. package/dist/cjs/ChartBuilder.d.ts +194 -30
  5. package/dist/cjs/ChartBuilder.d.ts.map +1 -1
  6. package/dist/cjs/ChartBuilder.js +122 -62
  7. package/dist/cjs/ChartEditor.d.ts +114 -18
  8. package/dist/cjs/ChartEditor.d.ts.map +1 -1
  9. package/dist/cjs/ChartEditor.js +47 -15
  10. package/dist/cjs/Dashboard.d.ts +148 -91
  11. package/dist/cjs/Dashboard.d.ts.map +1 -1
  12. package/dist/cjs/Dashboard.js +46 -152
  13. package/dist/cjs/DateRangePicker/QuillDateRangePicker.d.ts +21 -1
  14. package/dist/cjs/DateRangePicker/QuillDateRangePicker.d.ts.map +1 -1
  15. package/dist/cjs/DateRangePicker/QuillDateRangePicker.js +5 -2
  16. package/dist/cjs/DateRangePicker/dateRangePickerUtils.js +1 -1
  17. package/dist/cjs/QuillProvider.d.ts +105 -2
  18. package/dist/cjs/QuillProvider.d.ts.map +1 -1
  19. package/dist/cjs/QuillProvider.js +59 -0
  20. package/dist/cjs/ReportBuilder.d.ts +188 -42
  21. package/dist/cjs/ReportBuilder.d.ts.map +1 -1
  22. package/dist/cjs/ReportBuilder.js +466 -394
  23. package/dist/cjs/SQLEditor.d.ts +158 -23
  24. package/dist/cjs/SQLEditor.d.ts.map +1 -1
  25. package/dist/cjs/SQLEditor.js +35 -30
  26. package/dist/cjs/Table.d.ts +119 -15
  27. package/dist/cjs/Table.d.ts.map +1 -1
  28. package/dist/cjs/Table.js +37 -6
  29. package/dist/cjs/TableChart.d.ts.map +1 -1
  30. package/dist/cjs/TableChart.js +0 -194
  31. package/dist/cjs/{BarList.d.ts → components/Chart/BarList.d.ts} +1 -1
  32. package/dist/cjs/components/Chart/BarList.d.ts.map +1 -0
  33. package/dist/cjs/{BarList.js → components/Chart/BarList.js} +1 -1
  34. package/dist/cjs/components/Chart/LineChart.d.ts +2 -3
  35. package/dist/cjs/components/Chart/LineChart.d.ts.map +1 -1
  36. package/dist/cjs/components/Chart/LineChart.js +3 -3
  37. package/dist/cjs/components/Chart/PieChart.d.ts.map +1 -0
  38. package/dist/cjs/{PieChart.js → components/Chart/PieChart.js} +1 -1
  39. package/dist/cjs/components/Dashboard/ChartComponent.d.ts +2 -1
  40. package/dist/cjs/components/Dashboard/ChartComponent.d.ts.map +1 -1
  41. package/dist/cjs/components/Dashboard/ChartComponent.js +6 -7
  42. package/dist/cjs/components/Dashboard/DashboardFilter.d.ts +22 -0
  43. package/dist/cjs/components/Dashboard/DashboardFilter.d.ts.map +1 -0
  44. package/dist/cjs/components/Dashboard/DashboardFilter.js +75 -0
  45. package/dist/cjs/components/Dashboard/DataLoader.d.ts +1 -1
  46. package/dist/cjs/components/Dashboard/DataLoader.d.ts.map +1 -1
  47. package/dist/cjs/components/Dashboard/DataLoader.js +1 -1
  48. package/dist/cjs/components/Dashboard/MetricComponent.d.ts +2 -12
  49. package/dist/cjs/components/Dashboard/MetricComponent.d.ts.map +1 -1
  50. package/dist/cjs/components/Dashboard/MetricComponent.js +39 -17
  51. package/dist/cjs/components/Dashboard/TableComponent.d.ts +2 -1
  52. package/dist/cjs/components/Dashboard/TableComponent.d.ts.map +1 -1
  53. package/dist/cjs/components/Dashboard/TableComponent.js +6 -9
  54. package/dist/cjs/components/QuillSelect.d.ts +4 -1
  55. package/dist/cjs/components/QuillSelect.d.ts.map +1 -1
  56. package/dist/cjs/components/QuillSelect.js +13 -8
  57. package/dist/cjs/components/QuillTable.d.ts +16 -2
  58. package/dist/cjs/components/QuillTable.d.ts.map +1 -1
  59. package/dist/cjs/components/QuillTable.js +4 -4
  60. package/dist/cjs/components/ReportBuilder/AddColumnPopover.d.ts +9 -3
  61. package/dist/cjs/components/ReportBuilder/AddColumnPopover.d.ts.map +1 -1
  62. package/dist/cjs/components/ReportBuilder/AddColumnPopover.js +8 -6
  63. package/dist/cjs/components/ReportBuilder/AddLimitPopover.d.ts +13 -1
  64. package/dist/cjs/components/ReportBuilder/AddLimitPopover.d.ts.map +1 -1
  65. package/dist/cjs/components/ReportBuilder/AddLimitPopover.js +4 -14
  66. package/dist/cjs/components/ReportBuilder/AddSortPopover.d.ts +21 -1
  67. package/dist/cjs/components/ReportBuilder/AddSortPopover.d.ts.map +1 -1
  68. package/dist/cjs/components/ReportBuilder/AddSortPopover.js +15 -17
  69. package/dist/cjs/components/ReportBuilder/bigDateMap.js +1 -1
  70. package/dist/cjs/components/ReportBuilder/convert.d.ts +2 -1
  71. package/dist/cjs/components/ReportBuilder/convert.d.ts.map +1 -1
  72. package/dist/cjs/components/ReportBuilder/convert.js +40 -20
  73. package/dist/cjs/components/ReportBuilder/pivot.d.ts +2 -1
  74. package/dist/cjs/components/ReportBuilder/pivot.d.ts.map +1 -1
  75. package/dist/cjs/components/ReportBuilder/ui.d.ts +83 -18
  76. package/dist/cjs/components/ReportBuilder/ui.d.ts.map +1 -1
  77. package/dist/cjs/components/ReportBuilder/ui.js +52 -100
  78. package/dist/cjs/components/ReportBuilder/util.d.ts +2 -1
  79. package/dist/cjs/components/ReportBuilder/util.d.ts.map +1 -1
  80. package/dist/cjs/components/ReportBuilder/util.js +16 -9
  81. package/dist/cjs/components/UiComponents.d.ts +86 -86
  82. package/dist/cjs/components/UiComponents.d.ts.map +1 -1
  83. package/dist/cjs/components/UiComponents.js +118 -103
  84. package/dist/cjs/hooks/index.d.ts +1 -0
  85. package/dist/cjs/hooks/index.d.ts.map +1 -1
  86. package/dist/cjs/hooks/index.js +3 -1
  87. package/dist/cjs/hooks/useTheme.d.ts +7 -0
  88. package/dist/cjs/hooks/useTheme.d.ts.map +1 -0
  89. package/dist/cjs/hooks/useTheme.js +12 -0
  90. package/dist/cjs/index.d.ts +10 -2
  91. package/dist/cjs/index.d.ts.map +1 -1
  92. package/dist/cjs/internals/ReportBuilder/PivotList.d.ts.map +1 -1
  93. package/dist/cjs/internals/ReportBuilder/PivotList.js +10 -10
  94. package/dist/cjs/internals/ReportBuilder/PivotModal.d.ts +29 -14
  95. package/dist/cjs/internals/ReportBuilder/PivotModal.d.ts.map +1 -1
  96. package/dist/cjs/internals/ReportBuilder/PivotModal.js +73 -49
  97. package/dist/cjs/utils/dataFetcher.d.ts.map +1 -1
  98. package/dist/cjs/utils/dataFetcher.js +2 -0
  99. package/dist/esm/Chart.d.ts +117 -42
  100. package/dist/esm/Chart.d.ts.map +1 -1
  101. package/dist/esm/Chart.js +45 -19
  102. package/dist/esm/ChartBuilder.d.ts +194 -30
  103. package/dist/esm/ChartBuilder.d.ts.map +1 -1
  104. package/dist/esm/ChartBuilder.js +122 -62
  105. package/dist/esm/ChartEditor.d.ts +114 -18
  106. package/dist/esm/ChartEditor.d.ts.map +1 -1
  107. package/dist/esm/ChartEditor.js +51 -19
  108. package/dist/esm/Dashboard.d.ts +148 -91
  109. package/dist/esm/Dashboard.d.ts.map +1 -1
  110. package/dist/esm/Dashboard.js +49 -153
  111. package/dist/esm/DateRangePicker/QuillDateRangePicker.d.ts +21 -1
  112. package/dist/esm/DateRangePicker/QuillDateRangePicker.d.ts.map +1 -1
  113. package/dist/esm/DateRangePicker/QuillDateRangePicker.js +6 -3
  114. package/dist/esm/DateRangePicker/dateRangePickerUtils.js +1 -1
  115. package/dist/esm/QuillProvider.d.ts +105 -2
  116. package/dist/esm/QuillProvider.d.ts.map +1 -1
  117. package/dist/esm/QuillProvider.js +59 -0
  118. package/dist/esm/ReportBuilder.d.ts +188 -42
  119. package/dist/esm/ReportBuilder.d.ts.map +1 -1
  120. package/dist/esm/ReportBuilder.js +468 -396
  121. package/dist/esm/SQLEditor.d.ts +158 -23
  122. package/dist/esm/SQLEditor.d.ts.map +1 -1
  123. package/dist/esm/SQLEditor.js +35 -30
  124. package/dist/esm/Table.d.ts +119 -15
  125. package/dist/esm/Table.d.ts.map +1 -1
  126. package/dist/esm/Table.js +38 -7
  127. package/dist/esm/TableChart.d.ts.map +1 -1
  128. package/dist/esm/TableChart.js +0 -194
  129. package/dist/esm/{BarList.d.ts → components/Chart/BarList.d.ts} +1 -1
  130. package/dist/esm/components/Chart/BarList.d.ts.map +1 -0
  131. package/dist/esm/{BarList.js → components/Chart/BarList.js} +1 -1
  132. package/dist/esm/components/Chart/LineChart.d.ts +2 -3
  133. package/dist/esm/components/Chart/LineChart.d.ts.map +1 -1
  134. package/dist/esm/components/Chart/LineChart.js +3 -3
  135. package/dist/esm/components/Chart/PieChart.d.ts.map +1 -0
  136. package/dist/esm/{PieChart.js → components/Chart/PieChart.js} +1 -1
  137. package/dist/esm/components/Dashboard/ChartComponent.d.ts +2 -1
  138. package/dist/esm/components/Dashboard/ChartComponent.d.ts.map +1 -1
  139. package/dist/esm/components/Dashboard/ChartComponent.js +5 -6
  140. package/dist/esm/components/Dashboard/DashboardFilter.d.ts +22 -0
  141. package/dist/esm/components/Dashboard/DashboardFilter.d.ts.map +1 -0
  142. package/dist/esm/components/Dashboard/DashboardFilter.js +71 -0
  143. package/dist/esm/components/Dashboard/DataLoader.d.ts +1 -1
  144. package/dist/esm/components/Dashboard/DataLoader.d.ts.map +1 -1
  145. package/dist/esm/components/Dashboard/DataLoader.js +1 -1
  146. package/dist/esm/components/Dashboard/MetricComponent.d.ts +2 -12
  147. package/dist/esm/components/Dashboard/MetricComponent.d.ts.map +1 -1
  148. package/dist/esm/components/Dashboard/MetricComponent.js +39 -17
  149. package/dist/esm/components/Dashboard/TableComponent.d.ts +2 -1
  150. package/dist/esm/components/Dashboard/TableComponent.d.ts.map +1 -1
  151. package/dist/esm/components/Dashboard/TableComponent.js +6 -9
  152. package/dist/esm/components/QuillSelect.d.ts +4 -1
  153. package/dist/esm/components/QuillSelect.d.ts.map +1 -1
  154. package/dist/esm/components/QuillSelect.js +14 -9
  155. package/dist/esm/components/QuillTable.d.ts +16 -2
  156. package/dist/esm/components/QuillTable.d.ts.map +1 -1
  157. package/dist/esm/components/QuillTable.js +4 -4
  158. package/dist/esm/components/ReportBuilder/AddColumnPopover.d.ts +9 -3
  159. package/dist/esm/components/ReportBuilder/AddColumnPopover.d.ts.map +1 -1
  160. package/dist/esm/components/ReportBuilder/AddColumnPopover.js +8 -6
  161. package/dist/esm/components/ReportBuilder/AddLimitPopover.d.ts +13 -1
  162. package/dist/esm/components/ReportBuilder/AddLimitPopover.d.ts.map +1 -1
  163. package/dist/esm/components/ReportBuilder/AddLimitPopover.js +4 -14
  164. package/dist/esm/components/ReportBuilder/AddSortPopover.d.ts +21 -1
  165. package/dist/esm/components/ReportBuilder/AddSortPopover.d.ts.map +1 -1
  166. package/dist/esm/components/ReportBuilder/AddSortPopover.js +17 -19
  167. package/dist/esm/components/ReportBuilder/bigDateMap.js +1 -1
  168. package/dist/esm/components/ReportBuilder/convert.d.ts +2 -1
  169. package/dist/esm/components/ReportBuilder/convert.d.ts.map +1 -1
  170. package/dist/esm/components/ReportBuilder/convert.js +33 -13
  171. package/dist/esm/components/ReportBuilder/pivot.d.ts +2 -1
  172. package/dist/esm/components/ReportBuilder/pivot.d.ts.map +1 -1
  173. package/dist/esm/components/ReportBuilder/ui.d.ts +83 -18
  174. package/dist/esm/components/ReportBuilder/ui.d.ts.map +1 -1
  175. package/dist/esm/components/ReportBuilder/ui.js +50 -98
  176. package/dist/esm/components/ReportBuilder/util.d.ts +2 -1
  177. package/dist/esm/components/ReportBuilder/util.d.ts.map +1 -1
  178. package/dist/esm/components/ReportBuilder/util.js +14 -8
  179. package/dist/esm/components/UiComponents.d.ts +86 -86
  180. package/dist/esm/components/UiComponents.d.ts.map +1 -1
  181. package/dist/esm/components/UiComponents.js +111 -101
  182. package/dist/esm/hooks/index.d.ts +1 -0
  183. package/dist/esm/hooks/index.d.ts.map +1 -1
  184. package/dist/esm/hooks/index.js +1 -0
  185. package/dist/esm/hooks/useTheme.d.ts +7 -0
  186. package/dist/esm/hooks/useTheme.d.ts.map +1 -0
  187. package/dist/esm/hooks/useTheme.js +10 -0
  188. package/dist/esm/index.d.ts +10 -2
  189. package/dist/esm/index.d.ts.map +1 -1
  190. package/dist/esm/internals/ReportBuilder/PivotList.d.ts.map +1 -1
  191. package/dist/esm/internals/ReportBuilder/PivotList.js +10 -10
  192. package/dist/esm/internals/ReportBuilder/PivotModal.d.ts +29 -14
  193. package/dist/esm/internals/ReportBuilder/PivotModal.d.ts.map +1 -1
  194. package/dist/esm/internals/ReportBuilder/PivotModal.js +73 -49
  195. package/dist/esm/utils/dataFetcher.d.ts.map +1 -1
  196. package/dist/esm/utils/dataFetcher.js +2 -0
  197. package/package.json +1 -1
  198. package/dist/cjs/BarList.d.ts.map +0 -1
  199. package/dist/cjs/PieChart.d.ts.map +0 -1
  200. package/dist/esm/BarList.d.ts.map +0 -1
  201. package/dist/esm/PieChart.d.ts.map +0 -1
  202. /package/dist/cjs/{PieChart.d.ts → components/Chart/PieChart.d.ts} +0 -0
  203. /package/dist/esm/{PieChart.d.ts → components/Chart/PieChart.d.ts} +0 -0
@@ -11,6 +11,8 @@ const date_fns_1 = require("date-fns");
11
11
  const valueFormatter_1 = require("../../utils/valueFormatter");
12
12
  const ChartBuilder_1 = require("../../ChartBuilder");
13
13
  const textProcessing_1 = require("../../utils/textProcessing");
14
+ const util_1 = require("../../components/ReportBuilder/util");
15
+ const ast_1 = require("../../components/ReportBuilder/ast");
14
16
  const QuillHover = () => {
15
17
  return ((0, jsx_runtime_1.jsx)("style", { children: `
16
18
  .quill-hover {
@@ -73,7 +75,7 @@ const PivotModal = ({ pivotRowField, setPivotRowField, pivotColumnField, setPivo
73
75
  return (columns || []).reduce((map, col) => {
74
76
  // only use columns shown in the report builder's table
75
77
  // also filter out id
76
- if (col.field !== 'id' && !col.field.endsWith('_id')) {
78
+ if (col.field !== 'id') {
77
79
  map[col.field] = col.fieldType || col.format;
78
80
  }
79
81
  return map;
@@ -193,7 +195,7 @@ const PivotModal = ({ pivotRowField, setPivotRowField, pivotColumnField, setPivo
193
195
  return pts;
194
196
  }, [createdPivots, data]);
195
197
  const samplePivotTable = (0, react_1.useMemo)(() => {
196
- if (!pivotAggregation || !pivotRowField) {
198
+ if (!pivotAggregation) {
197
199
  return null;
198
200
  }
199
201
  const pivot = {
@@ -229,10 +231,7 @@ const PivotModal = ({ pivotRowField, setPivotRowField, pivotColumnField, setPivo
229
231
  position: 'absolute',
230
232
  top: -2,
231
233
  right: -2,
232
- } })) }), (0, jsx_runtime_1.jsx)(PopoverComponent, { onClose: () => {
233
- setShowUpdatePivot(false);
234
- setPopUpTitle('Add Pivot');
235
- }, style: rightAlign ? { right: 0 } : {}, parentRef: parentRef, showTrigger: showTrigger, label: triggerButtonText, isOpen: isOpen, setIsOpen: setIsOpen, onClick: () => {
234
+ } })) }), showTrigger && ((0, jsx_runtime_1.jsx)(SecondaryButtonComponent, { onClick: () => {
236
235
  if (columns.length === 0) {
237
236
  setIsOpen(false);
238
237
  }
@@ -243,15 +242,19 @@ const PivotModal = ({ pivotRowField, setPivotRowField, pivotColumnField, setPivo
243
242
  if (!isOpen && recommendedPivots.length === 0) {
244
243
  refreshPivots();
245
244
  }
245
+ setIsOpen(!isOpen);
246
246
  setShowUpdatePivot(false);
247
- }, children: (0, jsx_runtime_1.jsx)("div", { children: showUpdatePivot ? ((0, jsx_runtime_1.jsxs)("div", { className: "ref-in-use", ref: editModalRef, style: {
247
+ }, label: triggerButtonText })), (0, jsx_runtime_1.jsx)(PopoverComponent, { isOpen: isOpen, setIsOpen: (isOpen) => {
248
+ if (!isOpen) {
249
+ setShowUpdatePivot(false);
250
+ setPopUpTitle('Add Pivot');
251
+ }
252
+ setIsOpen(isOpen);
253
+ }, popoverChildren: (0, jsx_runtime_1.jsx)("div", { children: showUpdatePivot ? ((0, jsx_runtime_1.jsxs)("div", { className: "ref-in-use", ref: editModalRef, style: {
248
254
  backgroundColor: 'rgb(255, 255, 255)',
249
255
  display: 'flex',
250
256
  flexDirection: 'column',
251
- }, children: [(0, jsx_runtime_1.jsx)(HeaderComponent, { children: popUpTitle }), (0, jsx_runtime_1.jsx)("div", { style: { height: 12 } }), (0, jsx_runtime_1.jsx)("div", { style: { width: divWidth }, children: samplePivotTable && ((0, jsx_runtime_1.jsx)("div", { style: {
252
- marginBottom: 20,
253
- minHeight: 160,
254
- }, children: (0, jsx_runtime_1.jsx)(PivotList_1.PivotCard, { pivotTable: samplePivotTable, theme: theme, index: 0, onSelectPivot: () => { }, selectedPivotIndex: -1, onEditPivot: () => { }, ButtonComponent: ButtonComponent, showEdit: false, clickable: false, minHeight: 140, LabelComponent: LabelComponent, TextComponent: TextComponent, HeaderComponent: HeaderComponent }) })) }), (0, jsx_runtime_1.jsxs)("div", { style: {
257
+ }, children: [(0, jsx_runtime_1.jsx)(HeaderComponent, { label: popUpTitle }), (0, jsx_runtime_1.jsx)("div", { style: { height: 12 } }), (0, jsx_runtime_1.jsxs)("div", { style: {
255
258
  display: 'flex',
256
259
  flexDirection: 'column',
257
260
  gap: 10,
@@ -262,49 +265,55 @@ const PivotModal = ({ pivotRowField, setPivotRowField, pivotColumnField, setPivo
262
265
  flexDirection: 'row',
263
266
  gap: 20,
264
267
  marginBottom: 5,
265
- }, children: [(0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)(LabelComponent, { children: "Row Field" }), (0, jsx_runtime_1.jsx)(SelectComponent, { id: "pivot-row-field", value: pivotRowField, onChange: (e) => {
266
- setPivotRowField(e === '' ? undefined : e);
268
+ }, children: [(0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)(LabelComponent, { label: "Row Field" }), (0, jsx_runtime_1.jsx)(SelectComponent, { id: "pivot-row-field", value: pivotRowField, onChange: (e) => {
269
+ setPivotRowField(e.target.value === ''
270
+ ? undefined
271
+ : e.target.value);
267
272
  }, options: [
268
273
  ...columnSelectOptions.filter((option) => {
269
274
  const format = columns.find((col) => col.field === option.value)?.format;
270
275
  return (format === 'string' ||
271
- ChartBuilder_1.dateFormatOptions.includes(format));
276
+ ChartBuilder_1.dateFormatOptions.includes(format) ||
277
+ (0, util_1.isIdColumn)(option.value));
272
278
  }),
273
- ], theme: theme })] }), (0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)(LabelComponent, { children: "Column Field" }), (0, jsx_runtime_1.jsx)(SelectComponent, { id: "pivot-row-field", value: pivotColumnField, onChange: (e) => {
274
- setPivotColumnField(e === '' ? undefined : e);
279
+ ] })] }), (0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)(LabelComponent, { label: "Column Field" }), (0, jsx_runtime_1.jsx)(SelectComponent, { id: "pivot-row-field", value: pivotColumnField, onChange: (e) => {
280
+ setPivotColumnField(e.target.value === ''
281
+ ? undefined
282
+ : e.target.value);
275
283
  }, options: [
276
284
  ...columnSelectOptions.filter((option) => {
277
- return (columns.find((col) => col.field === option.value)
278
- ?.format === 'string');
285
+ return (columns.find((col) => col.field === option.value)?.format === 'string');
279
286
  }),
280
- ], theme: theme })] })] }), (0, jsx_runtime_1.jsxs)("div", { style: {
287
+ ] })] })] }), (0, jsx_runtime_1.jsxs)("div", { style: {
281
288
  display: 'flex',
282
289
  flexDirection: 'row',
283
290
  gap: 20,
284
291
  marginBottom: 20,
285
- }, children: [(0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)(LabelComponent, { children: "Value Field" }), (0, jsx_runtime_1.jsx)(SelectComponent, { id: "pivot-row-field", value: pivotValueField, onChange: (e) => {
286
- setPivotValueField(e === '' ? undefined : e);
292
+ }, children: [(0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)(LabelComponent, { label: "Value Field" }), (0, jsx_runtime_1.jsx)(SelectComponent, { id: "pivot-row-field", value: pivotValueField, onChange: (e) => {
293
+ setPivotValueField(e.target.value === ''
294
+ ? undefined
295
+ : e.target.value);
287
296
  }, options: [
288
297
  ...columnSelectOptions.filter((option) => {
289
- return (option.value === '' ||
290
- ChartBuilder_1.numberFormatOptions.includes(columns.find((col) => col.field === option.value)?.format));
298
+ return ((option.value === '' ||
299
+ ChartBuilder_1.numberFormatOptions.includes(columns.find((col) => col.field === option.value)?.format)) &&
300
+ !(0, util_1.isIdColumn)(option.value));
291
301
  }),
292
- ], theme: theme })] }), (0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)(LabelComponent, { children: "Aggregation Type" }), (0, jsx_runtime_1.jsx)(SelectComponent, { id: "pivot-row-field", value: pivotAggregation, theme: theme, onChange: (e) => {
293
- if (e !== 'count' &&
302
+ ] })] }), (0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)(LabelComponent, { label: "Aggregation Type" }), (0, jsx_runtime_1.jsx)(SelectComponent, { id: "pivot-row-field", value: pivotAggregation, onChange: (e) => {
303
+ if (e.target.value !== 'count' &&
294
304
  pivotValueField &&
295
305
  !ChartBuilder_1.numberFormatOptions.includes(columns.find((col) => col.field === pivotValueField)?.format)) {
296
306
  setPivotValueField(null);
297
307
  }
298
- setPivotAggregation(e === '' ? undefined : e);
308
+ setPivotAggregation(e.target.value === ''
309
+ ? undefined
310
+ : e.target.value);
299
311
  }, options: [
300
312
  ...['sum', 'average', 'count', 'max', 'min'].map((option) => {
301
313
  return { label: option, value: option };
302
314
  }),
303
315
  ] })] })] })] }), (0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)(ButtonComponent, { id: "custom-button", onClick: () => {
304
316
  const errors = [];
305
- if (!pivotRowField) {
306
- errors.push('Row field cannot be empty');
307
- }
308
317
  if (!pivotValueField && pivotAggregation !== 'count') {
309
318
  errors.push("Value field cannot be empty when aggregation is not 'count'");
310
319
  }
@@ -547,7 +556,7 @@ const fixBigQueryData = (data = []) => {
547
556
  function generatePivotTable(pivot, data, dateRange, isComparison, rowLimit = -1, compRange = null) {
548
557
  // If there is no rowField, aggregate on the valueField
549
558
  if (!pivot.rowField) {
550
- return valueFieldAggregation(data, pivot.valueField, pivot.aggregationType);
559
+ return valueFieldAggregation(data, pivot.valueField, pivot.aggregationType, isComparison);
551
560
  }
552
561
  // Handle edge-case for BigQuery objects.
553
562
  data = fixBigQueryData(data);
@@ -767,15 +776,6 @@ function generatePivotTable(pivot, data, dateRange, isComparison, rowLimit = -1,
767
776
  }
768
777
  break;
769
778
  case 'average':
770
- value = filteredData.length
771
- ? filteredData.reduce((sum, item) => sum + parseFloat(item[key] ?? 0), 0) / filteredData.length
772
- : 0;
773
- if (isComparison) {
774
- comparisonValue = comparisonFilteredData.length
775
- ? comparisonFilteredData.reduce((sum, item) => sum + parseFloat(item[key] ?? 0), 0) / comparisonFilteredData.length
776
- : 0;
777
- }
778
- break;
779
779
  case 'avg':
780
780
  value = filteredData.length
781
781
  ? filteredData.reduce((sum, item) => sum + parseFloat(item[key] ?? 0), 0) / filteredData.length
@@ -879,12 +879,18 @@ function generatePivotTable(pivot, data, dateRange, isComparison, rowLimit = -1,
879
879
  if (pivot.rowFieldType === 'date') {
880
880
  return new Date(a[pivot.rowField]) - new Date(b[pivot.rowField]);
881
881
  }
882
+ else if ((0, ast_1.isNumericColumnType)(pivot.rowFieldType)) {
883
+ return a[pivot.rowField] - b[pivot.rowField];
884
+ }
882
885
  return a[pivot.rowField].localeCompare(b[pivot.rowField]);
883
886
  }
884
887
  else {
885
888
  if (pivot.rowFieldType === 'date') {
886
889
  return new Date(b[pivot.rowField]) - new Date(a[pivot.rowField]);
887
890
  }
891
+ else if ((0, ast_1.isNumericColumnType)(pivot.rowFieldType)) {
892
+ return a[pivot.rowField] - b[pivot.rowField];
893
+ }
888
894
  return b[pivot.rowField].localeCompare(a[pivot.rowField]);
889
895
  }
890
896
  });
@@ -892,30 +898,45 @@ function generatePivotTable(pivot, data, dateRange, isComparison, rowLimit = -1,
892
898
  return { rows: pivotRows, columns };
893
899
  }
894
900
  exports.generatePivotTable = generatePivotTable;
895
- function valueFieldAggregation(data, valueField, aggregationType) {
896
- let value;
901
+ function valueFieldAggregation(data, valueField, aggregationType, isComparison) {
902
+ let value = 0;
903
+ let comparisonValue = 0;
897
904
  switch (aggregationType) {
898
905
  case 'sum':
899
906
  value = data.reduce((sum, item) => sum + parseFloat(item[valueField] ?? 0), 0);
907
+ if (isComparison) {
908
+ comparisonValue = data.reduce((sum, item) => sum + parseFloat(item[`comparison_${valueField}`] ?? 0), 0);
909
+ }
900
910
  break;
901
911
  case 'count':
902
- value = data.length;
912
+ value = data.reduce((count, item) => count + (item[valueField] ? 1 : 0), 0);
913
+ if (isComparison) {
914
+ comparisonValue = data.reduce((count, item) => count + (item[`comparison_${valueField}`] ? 1 : 0), 0);
915
+ }
903
916
  break;
904
917
  case 'avg':
905
- value = data.length
906
- ? data.reduce((sum, item) => sum + parseFloat(item[valueField] ?? 0), 0) / data.length
907
- : 0;
908
- break;
909
918
  case 'average':
910
- value = data.length
911
- ? data.reduce((sum, item) => sum + parseFloat(item[valueField] ?? 0), 0) / data.length
912
- : 0;
919
+ const count = data.reduce((count, item) => count + (item[valueField] ? 1 : 0), 0);
920
+ value =
921
+ data.reduce((sum, item) => sum + parseFloat(item[valueField] ?? 0), 0) /
922
+ (count === 0 ? 1 : count);
923
+ if (isComparison) {
924
+ const comparisonCount = data.reduce((count, item) => count + (item[`comparison_${valueField}`] ? 1 : 0), 0);
925
+ comparisonValue =
926
+ data.reduce((sum, item) => sum + parseFloat(item[`comparison_${valueField}`] ?? 0), 0) / (comparisonCount === 0 ? 1 : comparisonCount);
927
+ }
913
928
  break;
914
929
  case 'max':
915
930
  value = data.reduce((max, item) => Math.max(max, parseFloat(item[valueField] ?? 0)), -Infinity);
931
+ if (isComparison) {
932
+ comparisonValue = data.reduce((max, item) => Math.max(max, parseFloat(item[`comparison_${valueField}`] ?? 0)), -Infinity);
933
+ }
916
934
  break;
917
935
  case 'min':
918
936
  value = data.reduce((min, item) => Math.min(min, parseFloat(item[valueField] ?? 0)), Infinity);
937
+ if (isComparison) {
938
+ comparisonValue = data.reduce((min, item) => Math.min(min, parseFloat(item[`comparison_${valueField}`] ?? 0)), Infinity);
939
+ }
919
940
  break;
920
941
  // Implement other aggregation types as needed
921
942
  default:
@@ -923,6 +944,9 @@ function valueFieldAggregation(data, valueField, aggregationType) {
923
944
  }
924
945
  const row = {};
925
946
  row[valueField] = value;
947
+ if (isComparison) {
948
+ row[`comparison_${valueField}`] = comparisonValue;
949
+ }
926
950
  return {
927
951
  rows: [row],
928
952
  columns: [{ label: (0, textProcessing_1.snakeCaseToTitleCase)(valueField), field: valueField }],
@@ -1 +1 @@
1
- {"version":3,"file":"dataFetcher.d.ts","sourceRoot":"","sources":["../../../src/utils/dataFetcher.tsx"],"names":[],"mappings":"AAEA,wBAAsB,OAAO,CAC3B,MAAM,EAAE,GAAG,EACX,kBAAkB,EAAE,MAAM,EAC1B,MAAM,EAAE,kBAAkB,EAC1B,iBAAiB,EAAE,GAAG,EACtB,gBAAgB,EAAE,GAAG,EACrB,MAAM,SAAS,gBA8DhB;AAED,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,GAAG,EACX,kBAAkB,EAAE,MAAM,EAC1B,gBAAgB,EAAE,GAAG,EACrB,MAAM,SAAS,gBA+BhB"}
1
+ {"version":3,"file":"dataFetcher.d.ts","sourceRoot":"","sources":["../../../src/utils/dataFetcher.tsx"],"names":[],"mappings":"AAEA,wBAAsB,OAAO,CAC3B,MAAM,EAAE,GAAG,EACX,kBAAkB,EAAE,MAAM,EAC1B,MAAM,EAAE,kBAAkB,EAC1B,iBAAiB,EAAE,GAAG,EACtB,gBAAgB,EAAE,GAAG,EACrB,MAAM,SAAS,gBAgEhB;AAED,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,GAAG,EACX,kBAAkB,EAAE,MAAM,EAC1B,gBAAgB,EAAE,GAAG,EACrB,MAAM,SAAS,gBA+BhB"}
@@ -23,6 +23,7 @@ async function getData(client, cloudQueryEndpoint, noCred, hostedRequestBody, cl
23
23
  let result;
24
24
  if (responseJson.data?.data) {
25
25
  result = {
26
+ fields: responseJson?.data.queries?.queryResults[0]?.fields,
26
27
  ...responseJson.data.data,
27
28
  rows: responseJson?.data.queries?.queryResults[0]?.rows,
28
29
  compareRows: responseJson?.data.queries?.queryResults[1]?.rows,
@@ -30,6 +31,7 @@ async function getData(client, cloudQueryEndpoint, noCred, hostedRequestBody, cl
30
31
  }
31
32
  else {
32
33
  result = {
34
+ fields: responseJson?.queries?.queryResults[0]?.fields,
33
35
  ...responseJson.data,
34
36
  rows: responseJson?.queries?.queryResults[0]?.rows,
35
37
  compareRows: responseJson?.queries?.queryResults[1]?.rows,
@@ -1,46 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { QuillTheme } from './QuillProvider';
3
- interface BaseChartProps {
4
- colors?: string[];
5
- containerStyle?: React.CSSProperties;
6
- dateFilter?: any;
7
- theme?: any;
8
- isDateFilter?: boolean;
9
- isAnimationActive?: boolean;
10
- hideXAxis?: boolean;
11
- hideYAxis?: boolean;
12
- hideCartesianGrid?: boolean;
13
- dashedComparison?: boolean;
14
- dateRangeFilterDisabled?: boolean;
15
- singlePointStyle?: 'dot' | 'line';
16
- mapColorsToFields?: (_dashboardItem: DashboardItem, _theme: QuillTheme) => ColorMapType;
17
- }
18
- interface WithChartId extends BaseChartProps {
19
- chartId: string;
20
- }
21
- export type FieldFormat = 'whole_number' | 'one_decimal_place' | 'two_decimal_places' | 'dollar_amount' | 'dollar_cents' | 'MMM_yyyy' | 'MMM_dd_yyyy' | 'MMM_dd-MMM_dd' | 'MMM_dd_hh:mm_ap_pm' | 'hh_ap_pm' | 'percent' | 'string';
22
- interface YAxisField {
23
- label: string;
24
- field: string;
25
- chartType: string;
26
- format: FieldFormat;
27
- }
28
- export interface DashboardItem {
29
- id: string;
30
- name: string;
31
- chartType: string;
32
- xAxisField: string;
33
- xAxisLabel: string;
34
- xAxisFormat: FieldFormat;
35
- yAxisFields: YAxisField[];
36
- rows: any[];
37
- columns: any[];
38
- pivot: any;
39
- }
40
- interface WithConfig extends BaseChartProps {
41
- config: DashboardItem | any;
42
- }
43
- type ChartProps = WithChartId | WithConfig;
3
+ import { type DashboardItem } from './Dashboard';
44
4
  export declare function didFiltersChange(dashboardItem: any, filters: any): boolean;
45
5
  export type ColorMapType = {
46
6
  [key: string]: {
@@ -52,6 +12,121 @@ export type ColorMapType = {
52
12
  comparisonGradientStop?: string;
53
13
  };
54
14
  };
55
- declare const Chart: (data: ChartProps) => import("react/jsx-runtime").JSX.Element;
15
+ /**
16
+ * Props for the Quill Chart component.
17
+ */
18
+ export interface ChartProps {
19
+ /**
20
+ * A dashboard item to render, if any.
21
+ *
22
+ * When config is passed, the chart will not refetch the given dashboard item
23
+ * and will instead simply render the item it was given.
24
+ *
25
+ * A `config` must be passed if `chartId` is not present.
26
+ */
27
+ config?: DashboardItem | any;
28
+ /**
29
+ * A dashboard item to render, if any.
30
+ *
31
+ * When a chartId is passed, the chart will first fetch the data necessary to
32
+ * render this chart, and then it will render the dashboard item that it
33
+ * receives from the server.
34
+ *
35
+ * A `chartId` must be passed if `config` is not present.
36
+ */
37
+ chartId?: string;
38
+ /**
39
+ * A list of color strings used to color the chart.
40
+ *
41
+ * For example, a pie chart would use the colors for each section and a bar
42
+ * chart would use the colors for each bar.
43
+ */
44
+ colors?: string[];
45
+ /**
46
+ * Applies the given date filter to this chart, if any.
47
+ */
48
+ dateFilter?: any;
49
+ /**
50
+ * Whether this chart has a date filter.
51
+ */
52
+ isDateFilter?: boolean;
53
+ /**
54
+ * Whether to show animations on render complete.
55
+ */
56
+ isAnimationActive?: boolean;
57
+ /**
58
+ * Whether to hide the x axis.
59
+ */
60
+ hideXAxis?: boolean;
61
+ /**
62
+ * Whether to hide the y axis.
63
+ */
64
+ hideYAxis?: boolean;
65
+ /**
66
+ * Whether to hide the cartesian grid lines.
67
+ */
68
+ hideCartesianGrid?: boolean;
69
+ /**
70
+ * Whether the date range filter has been disabled.
71
+ */
72
+ hideDateRangeFilter?: boolean;
73
+ /**
74
+ * Whether the comparison range shows as dashed for date comparison line
75
+ * charts (as opposed to the default solid line).
76
+ */
77
+ comparisonLineStyle?: 'solid' | 'dashed';
78
+ /**
79
+ * An optional function that takes a dashboard item and theme and returns a
80
+ * map of keys used in that dashboard item to the colors they should use.
81
+ *
82
+ * The color values support RGB hexcodes and CSS color literals.
83
+ *
84
+ * @example
85
+ * ```js
86
+ * let mapColorsToFields = (item, theme) => {
87
+ * return {
88
+ * // all the queries with yAxis of 'amount' get colored this way:
89
+ * amount: {
90
+ * primary: 'red',
91
+ * comparison: 'gray',
92
+ * primaryGradientStart: 'red',
93
+ * primaryGradientStop: 'lightred',
94
+ * comparisonGradientStart: '#EFEFEF',
95
+ * comparisonGradientStop: '#EFEFEF00',
96
+ * },
97
+ * total: {
98
+ * primary: 'red'
99
+ * },
100
+ * };
101
+ * }
102
+ * ```
103
+ */
104
+ mapColorsToFields?: (dashboardItem: DashboardItem, theme: QuillTheme) => ColorMapType;
105
+ /**
106
+ * Styles the top-level container of the Chart.
107
+ */
108
+ containerStyle?: React.CSSProperties;
109
+ }
110
+ /**
111
+ * ### Quill Chart
112
+ *
113
+ * A simple component that displays the given data in one of many chart types.
114
+ *
115
+ * @example
116
+ * ```js
117
+ * // Usage with chart id (will auto-fetch data)
118
+ * <Chart chartId="12345" />
119
+ * ```
120
+ *
121
+ * @example
122
+ * ```js
123
+ * // Usage with a dashboard item (will not auto-fetch data)
124
+ * <Chart config={dashboardItem} />
125
+ * ```
126
+ *
127
+ * ### Chart API
128
+ * @see https://docs.quillsql.com/components/chart
129
+ */
130
+ declare const Chart: (props: ChartProps) => import("react/jsx-runtime").JSX.Element;
56
131
  export default Chart;
57
132
  //# sourceMappingURL=Chart.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Chart.d.ts","sourceRoot":"","sources":["../../src/Chart.tsx"],"names":[],"mappings":";AAYA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAgB7C,UAAU,cAAc;IACtB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,cAAc,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;IACrC,UAAU,CAAC,EAAE,GAAG,CAAC;IACjB,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,gBAAgB,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;IAClC,iBAAiB,CAAC,EAAE,CAClB,cAAc,EAAE,aAAa,EAC7B,MAAM,EAAE,UAAU,KACf,YAAY,CAAC;CACnB;AAED,UAAU,WAAY,SAAQ,cAAc;IAC1C,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,MAAM,WAAW,GACnB,cAAc,GACd,mBAAmB,GACnB,oBAAoB,GACpB,eAAe,GACf,cAAc,GACd,UAAU,GACV,aAAa,GACb,eAAe,GACf,oBAAoB,GACpB,UAAU,GACV,SAAS,GACT,QAAQ,CAAC;AAEb,UAAU,UAAU;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,WAAW,CAAC;CACrB;AAED,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,WAAW,CAAC;IACzB,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,OAAO,EAAE,GAAG,EAAE,CAAC;IACf,KAAK,EAAE,GAAG,CAAC;CACZ;AAED,UAAU,UAAW,SAAQ,cAAc;IACzC,MAAM,EAAE,aAAa,GAAG,GAAG,CAAC;CAC7B;AAED,KAAK,UAAU,GAAG,WAAW,GAAG,UAAU,CAAC;AA+D3C,wBAAgB,gBAAgB,CAAC,aAAa,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,WAQhE;AAED,MAAM,MAAM,YAAY,GAAG;IACzB,CAAC,GAAG,EAAE,MAAM,GAAG;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,oBAAoB,CAAC,EAAE,MAAM,CAAC;QAC9B,mBAAmB,CAAC,EAAE,MAAM,CAAC;QAC7B,uBAAuB,CAAC,EAAE,MAAM,CAAC;QACjC,sBAAsB,CAAC,EAAE,MAAM,CAAC;KACjC,CAAC;CACH,CAAC;AAaF,QAAA,MAAM,KAAK,SAAU,UAAU,4CAqC9B,CAAC;AAkiBF,eAAe,KAAK,CAAC"}
1
+ {"version":3,"file":"Chart.d.ts","sourceRoot":"","sources":["../../src/Chart.tsx"],"names":[],"mappings":";AAWA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAgB7C,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAiGjD,wBAAgB,gBAAgB,CAAC,aAAa,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,WAQhE;AAED,MAAM,MAAM,YAAY,GAAG;IACzB,CAAC,GAAG,EAAE,MAAM,GAAG;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,oBAAoB,CAAC,EAAE,MAAM,CAAC;QAC9B,mBAAmB,CAAC,EAAE,MAAM,CAAC;QAC7B,uBAAuB,CAAC,EAAE,MAAM,CAAC;QACjC,sBAAsB,CAAC,EAAE,MAAM,CAAC;KACjC,CAAC;CACH,CAAC;AAeF;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB;;;;;;;OAOG;IACH,MAAM,CAAC,EAAE,aAAa,GAAG,GAAG,CAAC;IAE7B;;;;;;;;OAQG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;;;OAKG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAElB;;OAEG;IACH,UAAU,CAAC,EAAE,GAAG,CAAC;IAEjB;;OAEG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IAEvB;;OAEG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAE5B;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB;;OAEG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAE5B;;OAEG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAE9B;;;OAGG;IACH,mBAAmB,CAAC,EAAE,OAAO,GAAG,QAAQ,CAAC;IAEzC;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,iBAAiB,CAAC,EAAE,CAClB,aAAa,EAAE,aAAa,EAC5B,KAAK,EAAE,UAAU,KACd,YAAY,CAAC;IAElB;;OAEG;IACH,cAAc,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;CACtC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,QAAA,MAAM,KAAK,UAAW,UAAU,4CAqC/B,CAAC;AA+hBF,eAAe,KAAK,CAAC"}
package/dist/esm/Chart.js CHANGED
@@ -1,9 +1,10 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /* eslint-disable no-unused-vars */
2
3
  import { useState, useEffect, useContext, useMemo } from 'react';
3
4
  import { differenceInHours } from 'date-fns';
4
- import BarList from './BarList';
5
- import PieChart from './PieChart';
6
- import { ClientContext, DashboardContext, ThemeContext, DashboardFiltersContext, } from './Context';
5
+ import BarList from './components/Chart/BarList';
6
+ import PieChart from './components/Chart/PieChart';
7
+ import { ClientContext, DashboardContext, DashboardFiltersContext, } from './Context';
7
8
  import QuillTable from './components/QuillTable';
8
9
  import { getData } from './utils/dataFetcher';
9
10
  import { generatePivotTable, generatePivotTableYAxis, } from './internals/ReportBuilder/PivotModal';
@@ -16,6 +17,7 @@ import ChartError from './components/Chart/ChartError';
16
17
  import { COMPARISON_OPTIONS } from './DateRangePicker/dateRangePickerUtils';
17
18
  import { quillFormat } from './utils/valueFormatter';
18
19
  import { downloadCSV } from './utils/csv';
20
+ import useTheme from './hooks/useTheme';
19
21
  // @ts-ignore
20
22
  function sumByKey(arr, key) {
21
23
  // @ts-ignore
@@ -76,11 +78,33 @@ function fallbackMapColorsToFields(_dashboardItem, _theme) {
76
78
  // By default, if the key is not in the map we use the colors array.
77
79
  return {};
78
80
  }
79
- const Chart = (data) => {
81
+ /**
82
+ * ### Quill Chart
83
+ *
84
+ * A simple component that displays the given data in one of many chart types.
85
+ *
86
+ * @example
87
+ * ```js
88
+ * // Usage with chart id (will auto-fetch data)
89
+ * <Chart chartId="12345" />
90
+ * ```
91
+ *
92
+ * @example
93
+ * ```js
94
+ * // Usage with a dashboard item (will not auto-fetch data)
95
+ * <Chart config={dashboardItem} />
96
+ * ```
97
+ *
98
+ * ### Chart API
99
+ * @see https://docs.quillsql.com/components/chart
100
+ */
101
+ const Chart = (props) => {
102
+ // Cast the props to the internal version so we can use the inherited types.
103
+ let data = props;
80
104
  if ('config' in data) {
81
105
  return (_jsx(ChartDisplay, { ...data, error: data.config.rows ? undefined : 'No rows found', loading: Boolean(!data.config), isComparison: Boolean(data?.config?.compareRows?.length) }));
82
106
  }
83
- const [theme] = useContext(ThemeContext);
107
+ const theme = useTheme();
84
108
  const chartColors = useMemo(() => {
85
109
  return data.colors?.length
86
110
  ? data.colors
@@ -88,9 +112,9 @@ const Chart = (data) => {
88
112
  ? theme.chartColors
89
113
  : ['#4E80EE', '#E14F62', '#55B5A6', '#E9A23B', '#6466E9', '#55B685'];
90
114
  }, [data.colors]);
91
- return (_jsx(ChartUpdater, { chartId: data.chartId, containerStyle: data.containerStyle, colors: chartColors, theme: theme, isAnimationActive: data.isAnimationActive, hideXAxis: data.hideXAxis, hideYAxis: data.hideYAxis, hideCartesianGrid: data.hideCartesianGrid, dashedComparison: data.dashedComparison, dateRangeFilterDisabled: data.dateRangeFilterDisabled, singlePointStyle: data.singlePointStyle ?? 'dot', mapColorsToFields: data.mapColorsToFields ?? fallbackMapColorsToFields }));
115
+ return (_jsx(ChartUpdater, { chartId: data.chartId, containerStyle: data.containerStyle, colors: chartColors, isAnimationActive: data.isAnimationActive, hideXAxis: data.hideXAxis, hideYAxis: data.hideYAxis, hideCartesianGrid: data.hideCartesianGrid, hideDateRangeFilter: data.hideDateRangeFilter, comparisonLineStyle: data.comparisonLineStyle, mapColorsToFields: data.mapColorsToFields ?? fallbackMapColorsToFields }));
92
116
  };
93
- const ChartUpdater = ({ colors, chartId, containerStyle, theme, isAnimationActive, hideXAxis, hideYAxis, hideCartesianGrid, dashedComparison, dateRangeFilterDisabled, singlePointStyle, mapColorsToFields, }) => {
117
+ const ChartUpdater = ({ colors, chartId, containerStyle, isAnimationActive, hideXAxis, hideYAxis, hideCartesianGrid, comparisonLineStyle, hideDateRangeFilter, mapColorsToFields, }) => {
94
118
  const { dispatch, dashboard } = useContext(DashboardContext);
95
119
  const { dashboardFilters } = useContext(DashboardFiltersContext);
96
120
  const [initialLoad, setInitialLoad] = useState(true);
@@ -99,6 +123,7 @@ const ChartUpdater = ({ colors, chartId, containerStyle, theme, isAnimationActiv
99
123
  const [isComparison, setIsComparison] = useState(false);
100
124
  const [colorMap, setColorMap] = useState({});
101
125
  const [client, _] = useContext(ClientContext);
126
+ const theme = useTheme();
102
127
  useEffect(() => {
103
128
  async function getChartOptions() {
104
129
  setLoading(true);
@@ -108,7 +133,7 @@ const ChartUpdater = ({ colors, chartId, containerStyle, theme, isAnimationActiv
108
133
  }
109
134
  try {
110
135
  // Remove extra fields on each filter so we don't confuse the backend.
111
- const allowDateRange = !dateRangeFilterDisabled;
136
+ const allowDateRange = !hideDateRangeFilter;
112
137
  const minimalFilters = Object.values(dashboardFilters).length
113
138
  ? Object.values(dashboardFilters)
114
139
  .filter((f) => allowDateRange || f.filterType !== 'date_range')
@@ -166,11 +191,11 @@ const ChartUpdater = ({ colors, chartId, containerStyle, theme, isAnimationActiv
166
191
  setInitialLoad(false);
167
192
  getChartOptions();
168
193
  }, [dashboardFilters, client, chartId]);
169
- return (_jsx(ChartDisplay, { config: dashboard[chartId], colors: colors, containerStyle: containerStyle, hideXAxis: hideXAxis, hideYAxis: hideYAxis, hideCartesianGrid: hideCartesianGrid, dashedComparison: dashedComparison, singlePointStyle: singlePointStyle, isAnimationActive: isAnimationActive, isComparison: isComparison, loading: loading || initialLoad, error: error, colorMap: colorMap }));
194
+ return (_jsx(ChartDisplay, { config: dashboard[chartId], colors: colors, containerStyle: containerStyle, hideXAxis: hideXAxis, hideYAxis: hideYAxis, hideCartesianGrid: hideCartesianGrid, comparisonLineStyle: comparisonLineStyle, isAnimationActive: isAnimationActive, isComparison: isComparison, loading: loading || initialLoad, error: error, colorMap: colorMap }));
170
195
  };
171
- const ChartDisplay = ({ config, colors, containerStyle, hideXAxis, hideYAxis, hideCartesianGrid, dashedComparison, isAnimationActive, loading = false, error = undefined, isComparison = false, singlePointStyle = 'dot', colorMap, }) => {
196
+ const ChartDisplay = ({ config, colors, containerStyle, hideXAxis, hideYAxis, hideCartesianGrid, comparisonLineStyle, isAnimationActive, loading = false, error = undefined, isComparison = false, colorMap, }) => {
172
197
  const { dashboardFilters } = useContext(DashboardFiltersContext);
173
- const [theme] = useContext(ThemeContext);
198
+ const theme = useTheme();
174
199
  const chartColors = useMemo(() => {
175
200
  return colors?.length
176
201
  ? colors
@@ -298,13 +323,14 @@ const ChartDisplay = ({ config, colors, containerStyle, hideXAxis, hideYAxis, hi
298
323
  return (_jsx(BarChart, { colors: chartColors, theme: theme, isStacked: isPivot && yAxisFields.length > (dateFilter?.comparison ? 2 : 1), yAxisFields: yAxisFields, data: barChartData, xAxisField: config.xAxisField, xAxisLabel: config.xAxisLabel, xAxisFormat: config.xAxisFormat, containerStyle: containerStyle, comparison: dateFilter?.comparison, isAnimationActive: isAnimationActive, hideXAxis: hideXAxis, hideYAxis: hideYAxis, hideCartesianGrid: hideCartesianGrid, colorMap: colorMap }));
299
324
  }
300
325
  if (chartTypes.includes('metric')) {
301
- const data = config; // THIS SHOULD ACCOUNT FOR PIVOT TABLES IN THE FUTURE
302
- const isComparison = data.rows?.length > 0 &&
303
- Object.keys(data.rows[0]).includes(`comparison_${data.xAxisField}`);
326
+ const data = config;
327
+ const rows = pivotTable?.rows ?? data.rows ?? [];
328
+ const isComparison = rows?.length > 0 &&
329
+ Object.keys(rows[0]).includes(`comparison_${data.xAxisField}`);
304
330
  const primaryMetricLabel = data?.filtersApplied?.date_range?.preset?.label;
305
331
  const comparisonKey = data?.filtersApplied?.date_range?.comparisonRange?.value;
306
332
  const comparisonLabel = COMPARISON_OPTIONS.find((opt) => opt.value === comparisonKey)?.text;
307
- if (data.rows?.length === 0 || data.rows[0][data.xAxisField] === null) {
333
+ if (rows?.length === 0 || rows[0][data.xAxisField] === null) {
308
334
  return (_jsx("div", { style: {
309
335
  display: 'flex',
310
336
  flex: '1 0 auto',
@@ -342,7 +368,7 @@ const ChartDisplay = ({ config, colors, containerStyle, hideXAxis, hideYAxis, hi
342
368
  marginRight: 'auto',
343
369
  }, children: [_jsx("span", { children: data.rows?.length > 0 &&
344
370
  valueFormatter({
345
- value: data.rows[0][data.xAxisField] ?? 0,
371
+ value: rows[0][data.xAxisField] ?? 0,
346
372
  field: data.xAxisField,
347
373
  fields: [
348
374
  {
@@ -371,9 +397,9 @@ const ChartDisplay = ({ config, colors, containerStyle, hideXAxis, hideYAxis, hi
371
397
  fontWeight: '500',
372
398
  fontFamily: theme?.fontFamily,
373
399
  color: theme?.secondaryTextColor,
374
- }, children: data.rows?.length > 0 &&
400
+ }, children: rows?.length > 0 &&
375
401
  valueFormatter({
376
- value: data.rows[0][`comparison_${data.xAxisField}`] ?? 0,
402
+ value: rows[0][`comparison_${data.xAxisField}`] ?? 0,
377
403
  field: data.xAxisField,
378
404
  fields: [
379
405
  {
@@ -407,6 +433,6 @@ const ChartDisplay = ({ config, colors, containerStyle, hideXAxis, hideYAxis, hi
407
433
  { [xAxis]: endDate, [yAxis]: '0' },
408
434
  ];
409
435
  }
410
- return (_jsx(LineChart, { colors: chartColors, colorMap: colorMap, yAxisFields: yAxisFields, data: lineChartData, xAxisField: config.xAxisField, xAxisLabel: config.xAxisLabel, xAxisFormat: config.xAxisFormat, containerStyle: containerStyle, theme: theme, comparison: dateFilter?.comparison, isAnimationActive: isAnimationActive, hideXAxis: hideXAxis, hideYAxis: hideYAxis, hideCartesianGrid: hideCartesianGrid, dashedComparison: dashedComparison, singlePointStyle: singlePointStyle }));
436
+ return (_jsx(LineChart, { colors: chartColors, colorMap: colorMap, yAxisFields: yAxisFields, data: lineChartData, xAxisField: config.xAxisField, xAxisLabel: config.xAxisLabel, xAxisFormat: config.xAxisFormat, containerStyle: containerStyle, theme: theme, comparison: dateFilter?.comparison, isAnimationActive: isAnimationActive, hideXAxis: hideXAxis, hideYAxis: hideYAxis, hideCartesianGrid: hideCartesianGrid, comparisonLineStyle: comparisonLineStyle ?? 'solid' }));
411
437
  };
412
438
  export default Chart;