@quillsql/react 2.16.2 → 2.16.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -393,7 +393,7 @@ var init_constants = __esm({
393
393
  "use strict";
394
394
  MAX_PIVOT_UNIQUE_VALUES = 250;
395
395
  QUILL_SERVER = typeof process !== "undefined" && process.env ? process.env.QUILL_SERVER_HOST ?? "https://quill-344421.uc.r.appspot.com" : "https://quill-344421.uc.r.appspot.com";
396
- QUILL_QUERY_ENDPOINT = typeof process !== "undefined" && process.env ? process.env.QUILL_QUERY_ENDPOINT ?? "/cloud" : "/cloud";
396
+ QUILL_QUERY_ENDPOINT = typeof process !== "undefined" && process.env ? process.env.QUILL_QUERY_ENDPOINT ?? "/cloud/engine" : "/cloud/engine";
397
397
  ALL_TENANTS = "QUILL_ALL_TENANTS";
398
398
  SINGLE_TENANT = "QUILL_SINGLE_TENANT";
399
399
  SAVED_QUERIES_DASHBOARD = "quill-saved-queries";
@@ -15983,6 +15983,7 @@ async function generatePivotWithSQL({
15983
15983
  dateFilter,
15984
15984
  distinctStrings,
15985
15985
  dashboardName,
15986
+ dashboardFilters,
15986
15987
  tenants,
15987
15988
  additionalProcessing,
15988
15989
  pivotQuery,
@@ -16026,6 +16027,7 @@ async function generatePivotWithSQL({
16026
16027
  metadata: {
16027
16028
  clientId: client.clientId,
16028
16029
  pivot: pivotConfig,
16030
+ reportId: report?.id !== "__quillTempReport" ? report?.id : void 0,
16029
16031
  itemQuery: reportBuilderState ? void 0 : report?.queryString,
16030
16032
  // Don't send itemQuery if reportBuilderState is present
16031
16033
  reportBuilderState,
@@ -16033,6 +16035,11 @@ async function generatePivotWithSQL({
16033
16035
  databaseType,
16034
16036
  // Required when sending reportBuilderState
16035
16037
  dashboardName,
16038
+ filters: !report?.id ? void 0 : dashboardFilters?.map((filter) => ({
16039
+ ...filter,
16040
+ options: void 0
16041
+ })),
16042
+ // Only pass dashboard filters in Dashboard context, not ReportBuilder
16036
16043
  tenants,
16037
16044
  additionalProcessing
16038
16045
  },
@@ -16202,6 +16209,7 @@ async function generatePivotTable({
16202
16209
  eventTracking,
16203
16210
  uniqueValues,
16204
16211
  dashboardName,
16212
+ dashboardFilters,
16205
16213
  tenants,
16206
16214
  additionalProcessing,
16207
16215
  caller,
@@ -16219,6 +16227,7 @@ async function generatePivotTable({
16219
16227
  dateBucket,
16220
16228
  dateFilter,
16221
16229
  dashboardName,
16230
+ dashboardFilters,
16222
16231
  tenants,
16223
16232
  additionalProcessing,
16224
16233
  caller,
@@ -17209,27 +17218,6 @@ var init_astProcessing = __esm({
17209
17218
  if (!tableInfo) {
17210
17219
  throw new Error("Table info not found");
17211
17220
  }
17212
- console.log("[astProcessing] Calling report-builder-unique-values", {
17213
- table: processedName,
17214
- columnCount: tableInfo.columns.length,
17215
- reportBuilderState: {
17216
- tables: [{ name: processedName }],
17217
- columns: tableInfo.columns.map(
17218
- (col) => ({
17219
- field: col.field,
17220
- table: processedName,
17221
- label: col.label,
17222
- format: col.format,
17223
- aggregate: void 0,
17224
- customExpression: void 0
17225
- })
17226
- ),
17227
- filters: [],
17228
- sorts: [],
17229
- groupByColumns: [],
17230
- limit: void 0
17231
- }
17232
- });
17233
17221
  const uniqueValues = await getUniqueStringValuesByColumn({
17234
17222
  columns: tableInfo.columns,
17235
17223
  tableName: processedName,
@@ -17310,12 +17298,15 @@ var init_astProcessing = __esm({
17310
17298
  if (!report) {
17311
17299
  throw new Error("Report not found");
17312
17300
  }
17313
- const resp = astify(
17314
- report.queryString,
17315
- client.databaseType || "postgresql",
17316
- true
17317
- // useNewNodeSql = true
17318
- );
17301
+ const { data: resp } = await quillFetch({
17302
+ client,
17303
+ task: "astify",
17304
+ metadata: {
17305
+ query: report.queryString,
17306
+ useNewNodeSql: true
17307
+ },
17308
+ getToken
17309
+ });
17319
17310
  if (resp.success === false) {
17320
17311
  throw new Error(resp.message || "Couldn't process report query.");
17321
17312
  }
@@ -17656,7 +17647,15 @@ var init_tableProcessing = __esm({
17656
17647
  baseQuery = withMatch[1];
17657
17648
  }
17658
17649
  const dbType = client.databaseType || "postgresql";
17659
- const astResponse = astify(baseQuery, dbType, true);
17650
+ const { data: astResponse } = await quillFetch({
17651
+ client,
17652
+ task: "astify",
17653
+ metadata: {
17654
+ query: baseQuery,
17655
+ useNewNodeSql: true
17656
+ },
17657
+ getToken
17658
+ });
17660
17659
  if (astResponse.success && astResponse.ast) {
17661
17660
  const selectAst = getSelectFromAST(astResponse.ast);
17662
17661
  const tableNames = selectAst.from ? selectAst.from.map((t) => t.as || t.table || t.name).filter(Boolean) : [];
@@ -17812,7 +17811,7 @@ var init_tableProcessing = __esm({
17812
17811
  task: "report-builder-unique-values",
17813
17812
  metadata: {
17814
17813
  reportBuilderState,
17815
- columns: stringColumns.map((col) => col.field),
17814
+ stringColumns: stringColumns.map((col) => col.field),
17816
17815
  clientId: client.clientId,
17817
17816
  databaseType: client.databaseType?.toLowerCase() || "postgresql",
17818
17817
  customFields,
@@ -17933,7 +17932,6 @@ var init_tableProcessing = __esm({
17933
17932
  dashboardName,
17934
17933
  reportBuilderState
17935
17934
  );
17936
- console.log("dateRanges 1", dateRanges);
17937
17935
  if (dateRanges === null) {
17938
17936
  throw new Error("Couldn't fetch date ranges");
17939
17937
  }
@@ -18050,7 +18048,7 @@ var init_tableProcessing = __esm({
18050
18048
  task: "report-builder-unique-values",
18051
18049
  metadata: {
18052
18050
  reportBuilderState,
18053
- columns,
18051
+ stringColumns: columns,
18054
18052
  clientId: client.clientId,
18055
18053
  databaseType: client.databaseType?.toLowerCase() || "postgresql",
18056
18054
  customFields,
@@ -18188,7 +18186,6 @@ var init_tableProcessing = __esm({
18188
18186
  },
18189
18187
  {}
18190
18188
  );
18191
- console.log("what", results);
18192
18189
  return results;
18193
18190
  }
18194
18191
  const distinctValueQuery = generateMinMaxDateRangeQueries(
@@ -18299,15 +18296,23 @@ var init_tableProcessing = __esm({
18299
18296
  let parsedSuccessfully = true;
18300
18297
  let parsingError = "";
18301
18298
  if (!rowCountOnly) {
18302
- const results = astify(
18303
- query,
18304
- client.databaseType || "postgresql",
18305
- true
18306
- // useNewNodeSql = true
18307
- );
18308
- if (!results || results.success == false) {
18299
+ try {
18300
+ const { data: results } = await quillFetch({
18301
+ client,
18302
+ task: "astify",
18303
+ metadata: {
18304
+ query,
18305
+ useNewNodeSql: true
18306
+ },
18307
+ getToken
18308
+ });
18309
+ if (!results || results.success == false) {
18310
+ parsedSuccessfully = false;
18311
+ parsingError = results.message || "";
18312
+ }
18313
+ } catch (e) {
18309
18314
  parsedSuccessfully = false;
18310
- parsingError = results.message || "";
18315
+ parsingError = e.message || "Failed to parse query";
18311
18316
  }
18312
18317
  }
18313
18318
  const fetchResp = await quillFetch({
@@ -19932,6 +19937,7 @@ async function getPivotTable(report, dashboardFilters, dashboardName, getToken,
19932
19937
  dateBucket,
19933
19938
  dateFilter,
19934
19939
  dashboardName,
19940
+ dashboardFilters,
19935
19941
  tenants,
19936
19942
  additionalProcessing,
19937
19943
  getToken
@@ -19960,6 +19966,7 @@ async function getPivotTable(report, dashboardFilters, dashboardName, getToken,
19960
19966
  client,
19961
19967
  uniqueValues: report.distinctStrings,
19962
19968
  dashboardName,
19969
+ dashboardFilters,
19963
19970
  tenants,
19964
19971
  dateFilter,
19965
19972
  additionalProcessing,
@@ -20367,18 +20374,24 @@ async function saveReport({
20367
20374
  tenants
20368
20375
  }) {
20369
20376
  const { publicKey, databaseType } = client;
20370
- const { reportBuilderState, queryString, ...reportWithoutStateAndQuery } = report;
20377
+ const {
20378
+ reportBuilderState,
20379
+ queryString,
20380
+ adminMode,
20381
+ ...reportWithoutStateAndQuery
20382
+ } = report;
20371
20383
  const reportToSave = reportWithoutStateAndQuery;
20372
- const task = reportBuilderState ? "create-report" : "create";
20384
+ const task = reportBuilderState && !adminMode ? "create-report" : "create";
20385
+ const isCreateTask = task === "create";
20373
20386
  const { data } = await quillFetch({
20374
20387
  client,
20375
20388
  task,
20376
20389
  metadata: {
20377
20390
  ...reportToSave,
20378
- // Pass reportBuilderState for create-report, queryString for create
20391
+ // Pass reportBuilderState if present, queryString otherwise
20379
20392
  ...reportBuilderState ? {
20380
20393
  reportBuilderState,
20381
- databaseType: databaseType || "postgresql"
20394
+ databaseType
20382
20395
  } : {
20383
20396
  queryString
20384
20397
  },
@@ -20387,7 +20400,9 @@ async function saveReport({
20387
20400
  dashboardItemId,
20388
20401
  // Remove useNewNodeSql since backend will handle conversion
20389
20402
  clientId: publicKey,
20390
- tenants
20403
+ tenants,
20404
+ // Only include adminMode for 'create' task, not 'create-report'
20405
+ ...isCreateTask && { adminMode }
20391
20406
  },
20392
20407
  getToken
20393
20408
  });
@@ -20664,7 +20679,6 @@ var fetchReportBuilderDataFromAST = async ({
20664
20679
  customFields ?? [],
20665
20680
  dashboardName
20666
20681
  );
20667
- console.log("dateRanges 3", dateRanges);
20668
20682
  if (dateRanges === null) {
20669
20683
  throw new Error("Couldn't fetch date ranges");
20670
20684
  }
@@ -31633,23 +31647,53 @@ function QuillMetricComponent({
31633
31647
  width: "100%"
31634
31648
  }
31635
31649
  }
31636
- ) : !report?.rows?.[0] || report.rows[0][report.xAxisField] === null ? /* @__PURE__ */ jsx43(
31650
+ ) : !report?.rows || report?.rows?.length === 0 || report.rows[0]?.[report.xAxisField] === null || report.rows[0]?.[report.xAxisField] === void 0 ? /* @__PURE__ */ jsx43(
31637
31651
  "div",
31638
31652
  {
31639
31653
  style: {
31640
- display: "flex",
31641
- flex: "1 0 auto",
31642
- // height: '100%',
31643
- margin: "auto",
31644
- justifyContent: "center",
31645
- alignItems: "center",
31646
- fontSize: 13,
31647
- fontFamily: theme?.fontFamily,
31648
- color: theme?.secondaryTextColor,
31649
- maxWidth: "100%",
31650
- width: "100%"
31654
+ padding: 0,
31655
+ height: "100%",
31656
+ width: "100%",
31657
+ boxSizing: "content-box",
31658
+ flex: 1
31651
31659
  },
31652
- children: "No results"
31660
+ children: /* @__PURE__ */ jsx43(
31661
+ "div",
31662
+ {
31663
+ style: {
31664
+ fontFamily: theme?.fontFamily,
31665
+ fontSize: 32,
31666
+ color: theme?.primaryTextColor,
31667
+ fontWeight: "600",
31668
+ textOverflow: "ellipsis",
31669
+ margin: 0,
31670
+ whiteSpace: "nowrap",
31671
+ boxSizing: "content-box",
31672
+ maxWidth: "100%",
31673
+ textAlign: "left",
31674
+ overflow: "hidden",
31675
+ height: "100%",
31676
+ minHeight: "80px",
31677
+ display: "flex",
31678
+ width: "100%",
31679
+ flexDirection: "row",
31680
+ justifyContent: "center",
31681
+ alignItems: "center"
31682
+ },
31683
+ children: /* @__PURE__ */ jsx43(
31684
+ "span",
31685
+ {
31686
+ style: {
31687
+ fontFamily: theme?.fontFamily,
31688
+ fontSize: 13,
31689
+ color: theme?.secondaryTextColor,
31690
+ fontWeight: "normal"
31691
+ },
31692
+ children: "No results"
31693
+ }
31694
+ )
31695
+ }
31696
+ )
31653
31697
  }
31654
31698
  ) : /* @__PURE__ */ jsx43(
31655
31699
  MetricDisplay,
@@ -32882,6 +32926,29 @@ function USMap({
32882
32926
  const hoveredValue = useMemo12(() => {
32883
32927
  return !hoveredState ? void 0 : mappedData[fipsToNames[hoveredState]?.abbreviation ?? ""]?.[measureField] ?? mappedData[fipsToNames[hoveredState]?.name ?? ""]?.[measureField] ?? mappedData[fipsToNames[hoveredState]?.abbreviation?.toLowerCase() ?? ""]?.[measureField] ?? mappedData[fipsToNames[hoveredState]?.name?.toLowerCase() ?? ""]?.[measureField];
32884
32928
  }, [hoveredState, mappedData, measureField]);
32929
+ if (!measureField) {
32930
+ return /* @__PURE__ */ jsx45(
32931
+ "div",
32932
+ {
32933
+ style: {
32934
+ display: "flex",
32935
+ flex: "1 0 auto",
32936
+ marginLeft: "auto",
32937
+ marginRight: "auto",
32938
+ marginTop: "auto",
32939
+ marginBottom: "auto",
32940
+ justifyContent: "center",
32941
+ alignItems: "center",
32942
+ fontSize: 13,
32943
+ color: theme?.secondaryTextColor,
32944
+ fontFamily: theme?.fontFamily,
32945
+ ...containerStyle
32946
+ },
32947
+ className,
32948
+ children: "No results"
32949
+ }
32950
+ );
32951
+ }
32885
32952
  return /* @__PURE__ */ jsxs34(
32886
32953
  "div",
32887
32954
  {
@@ -33050,6 +33117,29 @@ function WorldMap({
33050
33117
  const hoveredValue = useMemo12(() => {
33051
33118
  return !hoveredCountry ? void 0 : mappedData[isoToNames[hoveredCountry]?.abbreviation ?? ""]?.[measureField] ?? mappedData[isoToNames[hoveredCountry]?.name ?? ""]?.[measureField] ?? mappedData[isoToNames[hoveredCountry]?.abbreviation?.toLowerCase() ?? ""]?.[measureField] ?? mappedData[isoToNames[hoveredCountry]?.name?.toLowerCase() ?? ""]?.[measureField];
33052
33119
  }, [hoveredCountry, mappedData, measureField]);
33120
+ if (!measureField) {
33121
+ return /* @__PURE__ */ jsx45(
33122
+ "div",
33123
+ {
33124
+ style: {
33125
+ display: "flex",
33126
+ flex: "1 0 auto",
33127
+ marginLeft: "auto",
33128
+ marginRight: "auto",
33129
+ marginTop: "auto",
33130
+ marginBottom: "auto",
33131
+ justifyContent: "center",
33132
+ alignItems: "center",
33133
+ fontSize: 13,
33134
+ color: theme?.secondaryTextColor,
33135
+ fontFamily: theme?.fontFamily,
33136
+ ...containerStyle
33137
+ },
33138
+ className,
33139
+ children: "No results"
33140
+ }
33141
+ );
33142
+ }
33053
33143
  return /* @__PURE__ */ jsxs34(
33054
33144
  "div",
33055
33145
  {
@@ -35264,7 +35354,7 @@ function Chart({
35264
35354
  index
35265
35355
  )) }),
35266
35356
  loading || !report ? /* @__PURE__ */ jsx48(LoadingComponent, {}) : /* @__PURE__ */ jsxs36(Fragment6, { children: [
35267
- ("table" === report.chartType || "metric" === report.chartType) && /* @__PURE__ */ jsx48(
35357
+ ("table" === report.chartType || "metric" === report.chartType) && /* @__PURE__ */ jsx48(Fragment6, { children: /* @__PURE__ */ jsx48(
35268
35358
  DataLoader,
35269
35359
  {
35270
35360
  item: report,
@@ -35299,13 +35389,17 @@ function Chart({
35299
35389
  error: error2,
35300
35390
  rowCount: rowCount ?? data?.rowCount ?? data?.rows?.length ?? 0,
35301
35391
  rowCountIsLoading,
35302
- onPageChange: (page) => onPageChange(page),
35303
- onSortChange: (sort) => onSortChange(sort),
35392
+ onPageChange: (page) => {
35393
+ onPageChange(page);
35394
+ },
35395
+ onSortChange: (sort) => {
35396
+ onSortChange(sort);
35397
+ },
35304
35398
  hideName: true
35305
35399
  }
35306
35400
  )
35307
35401
  }
35308
- ),
35402
+ ) }),
35309
35403
  report.chartType !== "table" && report.chartType !== "metric" && /* @__PURE__ */ jsx48(
35310
35404
  ChartDataLoader,
35311
35405
  {
@@ -35435,7 +35529,7 @@ var ChartDisplay = ({
35435
35529
  {
35436
35530
  className,
35437
35531
  containerStyle,
35438
- data: config?.rows?.map((row) => {
35532
+ data: !config?.pivot ? config?.rows?.map((row) => {
35439
35533
  return {
35440
35534
  ...row,
35441
35535
  count: (
@@ -35443,7 +35537,7 @@ var ChartDisplay = ({
35443
35537
  parseInt(row[config?.yAxisFields[0]?.field]) / sumByKey(config?.rows, config?.yAxisFields[0]?.field)
35444
35538
  )
35445
35539
  };
35446
- }) || [],
35540
+ }) || [] : config?.rows || [],
35447
35541
  category: config?.yAxisFields?.[0]?.field,
35448
35542
  index: config?.xAxisField,
35449
35543
  colors: chartColors,
@@ -35558,27 +35652,41 @@ var ChartDisplay = ({
35558
35652
  );
35559
35653
  }
35560
35654
  if (config?.chartType?.toLowerCase() === "metric") {
35561
- if (!config?.rows || config?.rows?.length === 0 || // @ts-ignore
35562
- config?.rows[0][config?.xAxisField] === null) {
35655
+ if (!config?.rows || config?.rows?.length === 0 || config?.rows[0]?.[config?.xAxisField] === null || config?.rows[0]?.[config?.xAxisField] === void 0) {
35563
35656
  return /* @__PURE__ */ jsx48(
35564
35657
  "div",
35565
35658
  {
35566
35659
  style: {
35567
- display: "flex",
35568
- flex: "1 0 auto",
35569
- // height: containerStyle?.height || '100%',
35570
- margin: "auto",
35571
- justifyContent: "center",
35572
- alignItems: "center",
35573
- fontSize: 13,
35574
35660
  fontFamily: theme?.fontFamily,
35575
- color: theme?.secondaryTextColor,
35661
+ fontSize: 32,
35662
+ color: theme?.primaryTextColor,
35663
+ fontWeight: "600",
35664
+ textOverflow: "ellipsis",
35665
+ margin: 0,
35666
+ whiteSpace: "nowrap",
35667
+ boxSizing: "content-box",
35576
35668
  maxWidth: "100%",
35669
+ textAlign: "left",
35670
+ overflow: "hidden",
35671
+ height: containerStyle?.height || "100%",
35672
+ display: "flex",
35577
35673
  width: "100%",
35674
+ flexDirection: "row",
35675
+ alignItems: "center",
35578
35676
  ...containerStyle
35579
35677
  },
35580
35678
  className,
35581
- children: "No results"
35679
+ children: /* @__PURE__ */ jsx48(
35680
+ "span",
35681
+ {
35682
+ style: {
35683
+ fontFamily: theme?.fontFamily,
35684
+ fontSize: 13,
35685
+ color: theme?.secondaryTextColor
35686
+ },
35687
+ children: "No results"
35688
+ }
35689
+ )
35582
35690
  }
35583
35691
  );
35584
35692
  }
@@ -38453,7 +38561,7 @@ function Dashboard({
38453
38561
  data: data2,
38454
38562
  rowCount,
38455
38563
  rowCountIsLoading
38456
- }) => /* @__PURE__ */ jsx57(
38564
+ }) => /* @__PURE__ */ jsx57(Fragment10, { children: /* @__PURE__ */ jsx57(
38457
38565
  TableComponent,
38458
38566
  {
38459
38567
  report: data2,
@@ -38478,10 +38586,14 @@ function Dashboard({
38478
38586
  hoverActions,
38479
38587
  rowCount: rowCount ?? data2?.rowCount ?? data2?.rows?.length ?? 0,
38480
38588
  rowCountIsLoading,
38481
- onPageChange: (page) => onPageChange(page),
38482
- onSortChange: (sort) => onSortChange(sort)
38589
+ onPageChange: (page) => {
38590
+ onPageChange(page);
38591
+ },
38592
+ onSortChange: (sort) => {
38593
+ onSortChange(sort);
38594
+ }
38483
38595
  }
38484
- )
38596
+ ) })
38485
38597
  },
38486
38598
  `${name2}${item.id}`
38487
38599
  )) })
@@ -38501,7 +38613,11 @@ function Dashboard({
38501
38613
  children: ({
38502
38614
  isLoading: isLoading2,
38503
38615
  error,
38504
- data: data2
38616
+ onPageChange,
38617
+ onSortChange,
38618
+ data: data2,
38619
+ rowCount,
38620
+ rowCountIsLoading
38505
38621
  }) => item.chartType === "metric" ? /* @__PURE__ */ jsx57(
38506
38622
  MetricComponent,
38507
38623
  {
@@ -38548,7 +38664,14 @@ function Dashboard({
38548
38664
  });
38549
38665
  } : void 0,
38550
38666
  hoverActions,
38551
- rowCount: data2.rowCount ?? data2.rows?.length ?? 0
38667
+ rowCount: rowCount ?? data2.rowCount ?? data2.rows?.length ?? 0,
38668
+ rowCountIsLoading,
38669
+ onPageChange: (page) => {
38670
+ onPageChange(page);
38671
+ },
38672
+ onSortChange: (sort) => {
38673
+ onSortChange(sort);
38674
+ }
38552
38675
  }
38553
38676
  )
38554
38677
  },
@@ -38977,6 +39100,7 @@ import {
38977
39100
  useMemo as useMemo22,
38978
39101
  useCallback as useCallback3
38979
39102
  } from "react";
39103
+ import { flushSync as flushSync2 } from "react-dom";
38980
39104
  import MonacoEditor from "@monaco-editor/react";
38981
39105
 
38982
39106
  // src/ChartBuilder.tsx
@@ -39544,11 +39668,6 @@ var PivotModal = ({
39544
39668
  dashboardName,
39545
39669
  reportBuilderState
39546
39670
  );
39547
- console.log("[PivotModal] Calling report-builder-unique-values", {
39548
- columnCount: smallStringColumns.length,
39549
- hasReportBuilderState: !!reportBuilderState,
39550
- reportBuilderState
39551
- });
39552
39671
  newUniqueValues = await getUniqueValuesByQuery({
39553
39672
  columns: smallStringColumns,
39554
39673
  query: query || "",
@@ -41786,6 +41905,7 @@ function InternalChart({
41786
41905
  // src/ChartBuilder.tsx
41787
41906
  init_paginationProcessing();
41788
41907
  init_tableProcessing();
41908
+ init_dataFetcher();
41789
41909
  init_dates();
41790
41910
 
41791
41911
  // src/components/QuillMultiSelectSectionList.tsx
@@ -42631,15 +42751,19 @@ function ChartBuilderWithModal(props) {
42631
42751
  title: title || "Add to dashboard",
42632
42752
  width: isHorizontalView ? modalWidth : void 0,
42633
42753
  height: isHorizontalView ? modalHeight : void 0,
42634
- children: (props.reportId ? dashboard[props.reportId] ?? props.tempReport : props.tempReport) ? /* @__PURE__ */ jsx65(
42635
- ChartBuilder,
42636
- {
42637
- ...props,
42638
- filtersEnabled: filtersEnabledState,
42639
- onFiltersEnabledChanged: setFiltersEnabledState,
42640
- runQueryOnMount: filtersEnabledState
42641
- }
42642
- ) : /* @__PURE__ */ jsx65("div", { style: { padding: 20 }, children: /* @__PURE__ */ jsx65(QuillLoadingComponent, {}) })
42754
+ children: (() => {
42755
+ const resolvedReport = props.tempReport ?? (props.reportId ? dashboard[props.reportId] : void 0);
42756
+ return resolvedReport ? /* @__PURE__ */ jsx65(
42757
+ ChartBuilder,
42758
+ {
42759
+ ...props,
42760
+ tempReport: resolvedReport,
42761
+ filtersEnabled: filtersEnabledState,
42762
+ onFiltersEnabledChanged: setFiltersEnabledState,
42763
+ runQueryOnMount: filtersEnabledState
42764
+ }
42765
+ ) : /* @__PURE__ */ jsx65("div", { style: { padding: 20 }, children: /* @__PURE__ */ jsx65(QuillLoadingComponent, {}) });
42766
+ })()
42643
42767
  }
42644
42768
  ) });
42645
42769
  }
@@ -42720,7 +42844,7 @@ function ChartBuilder({
42720
42844
  const { tenants, flags } = useContext26(TenantContext);
42721
42845
  const report = useMemo21(() => {
42722
42846
  return reportId && !tempReport ? allReportsById[reportId] : tempReport;
42723
- }, [reportId]);
42847
+ }, [reportId, tempReport, allReportsById]);
42724
42848
  const [windowWidth, setWindowWidth] = useState28(1200);
42725
42849
  const [rows, setRows] = useState28(report?.rows ?? []);
42726
42850
  const [itemQuery, setItemQuery] = useState28(report?.itemQuery);
@@ -42918,7 +43042,7 @@ function ChartBuilder({
42918
43042
  };
42919
43043
  const [currentProcessing, setCurrentProcessing] = useState28(baseProcessing);
42920
43044
  const [customTenantAccess, setCustomTenantAccess] = useState28(
42921
- !!Object.values(report?.flags ?? {}).length
43045
+ report?.flags === null ? false : !!Object.values(report?.flags ?? {}).length
42922
43046
  );
42923
43047
  const [dateFieldOptions, setDateFieldOptions] = useState28([]);
42924
43048
  const [allTables, setAllTables] = useState28([]);
@@ -43631,16 +43755,6 @@ function ChartBuilder({
43631
43755
  fetchRowCount(processing, overrideFilters);
43632
43756
  if (formData.pivot) {
43633
43757
  try {
43634
- console.log(
43635
- "[ChartBuilder] Calling report-builder-unique-values for pivot",
43636
- {
43637
- columns: tableInfo.columns.filter(
43638
- (column) => column.field === formData.pivot?.columnField
43639
- ).map((c) => c.field),
43640
- hasReportBuilderState: !!reportBuilderState,
43641
- reportBuilderState
43642
- }
43643
- );
43644
43758
  const uniqueValues = await getUniqueValuesByQuery({
43645
43759
  reportBuilderState,
43646
43760
  columns: tableInfo.columns.filter(
@@ -44028,9 +44142,46 @@ function ChartBuilder({
44028
44142
  event.preventDefault();
44029
44143
  };
44030
44144
  const deleteChart = async () => {
44031
- if (onDelete && onDelete()) {
44032
- setIsOpen(false);
44033
- setIsSubmitting(false);
44145
+ if (!client || !reportId) {
44146
+ console.error("Cannot delete: missing client or reportId");
44147
+ return;
44148
+ }
44149
+ try {
44150
+ const { status, error } = await quillFetch({
44151
+ client,
44152
+ task: "delete",
44153
+ metadata: {
44154
+ dashboardItemId: reportId,
44155
+ tenants
44156
+ },
44157
+ getToken
44158
+ });
44159
+ if (status !== "success") {
44160
+ throw new Error(`Error deleting report: ${error}`);
44161
+ } else {
44162
+ if (onDelete) {
44163
+ onDelete();
44164
+ }
44165
+ reloadDashboard(destinationDashboard, true, {
44166
+ report: { id: reportId },
44167
+ action: "delete"
44168
+ });
44169
+ setIsOpen(false);
44170
+ setIsSubmitting(false);
44171
+ }
44172
+ } catch (err) {
44173
+ console.error("Error deleting chart:", err);
44174
+ eventTracking?.logError?.({
44175
+ type: "bug",
44176
+ severity: "high",
44177
+ message: "Error deleting chart",
44178
+ errorMessage: err.message,
44179
+ errorStack: err.stack,
44180
+ errorData: {
44181
+ caller: "ChartBuilder",
44182
+ function: "deleteChart"
44183
+ }
44184
+ });
44034
44185
  }
44035
44186
  };
44036
44187
  const editChart = async () => {
@@ -44069,14 +44220,17 @@ function ChartBuilder({
44069
44220
  includeCustomFields: includeCustomFields || containsCustomFields,
44070
44221
  template: tenants ? void 0 : report && !isAdmin && formData.template ? false : formData.template,
44071
44222
  adminMode: isAdmin,
44072
- flags: containsCustomFields && customTenantAccess ? currentTenantAsFormFlags : formFlags ? Object.fromEntries(
44073
- Object.entries(formFlags).filter(([, value]) => value.length > 0).map(([key, value]) => {
44074
- return [
44075
- key,
44076
- Object.keys(allTenantMap).length > 1 && allTenantMap[key]?.length === value.length ? ALL_TENANTS : value
44077
- ];
44078
- })
44079
- ) : void 0,
44223
+ reportBuilderState,
44224
+ ...isAdmin && {
44225
+ reportFlags: !customTenantAccess && !containsCustomFields ? null : containsCustomFields && customTenantAccess ? currentTenantAsFormFlags : formFlags ? Object.fromEntries(
44226
+ Object.entries(formFlags).filter(([, value]) => value.length > 0).map(([key, value]) => {
44227
+ return [
44228
+ key,
44229
+ Object.keys(allTenantMap).length > 1 && allTenantMap[key]?.length === value.length ? ALL_TENANTS : value
44230
+ ];
44231
+ })
44232
+ ) : void 0
44233
+ },
44080
44234
  referenceLines: formData.referenceLines.map((line) => {
44081
44235
  return {
44082
44236
  label: line.label,
@@ -45445,7 +45599,7 @@ function ChartBuilder({
45445
45599
  right: 16
45446
45600
  },
45447
45601
  children: [
45448
- !hideDeleteButton && !isHorizontalView && report && /* @__PURE__ */ jsx65(
45602
+ !hideDeleteButton && report && /* @__PURE__ */ jsx65(
45449
45603
  SecondaryButtonComponent,
45450
45604
  {
45451
45605
  onClick: deleteChart,
@@ -46201,6 +46355,7 @@ function SQLEditor({
46201
46355
  CheckboxComponent = QuillChartBuilderCheckboxComponent,
46202
46356
  defaultQuery,
46203
46357
  destinationDashboard,
46358
+ destinationSection,
46204
46359
  onChangeQuery,
46205
46360
  onChangeData,
46206
46361
  onChangeColumns,
@@ -46210,12 +46365,16 @@ function SQLEditor({
46210
46365
  onCloseChartBuilder,
46211
46366
  isChartBuilderEnabled = false,
46212
46367
  isAdminEnabled = false,
46368
+ chartBuilderOptions,
46213
46369
  chartBuilderTitle,
46214
46370
  runQueryOnMount = false,
46215
46371
  onAddToDashboardComplete,
46372
+ onSubmitCreateReport,
46373
+ onSubmitEditReport,
46216
46374
  onSaveQueryComplete,
46217
46375
  addToDashboardButtonLabel = "Add to dashboard",
46218
46376
  report = void 0,
46377
+ reportId = void 0,
46219
46378
  organizationName = void 0,
46220
46379
  isChartBuilderHorizontalView = true,
46221
46380
  containerStyle = { height: "100vh" },
@@ -46226,7 +46385,7 @@ function SQLEditor({
46226
46385
  const [sqlPrompt, setSqlPrompt] = useState30("");
46227
46386
  const [client] = useContext28(ClientContext);
46228
46387
  const [theme] = useContext28(ThemeContext);
46229
- const { tenants } = useContext28(TenantContext);
46388
+ const { tenants, flags } = useContext28(TenantContext);
46230
46389
  const { dashboards } = useDashboards();
46231
46390
  const {
46232
46391
  data,
@@ -46235,6 +46394,7 @@ function SQLEditor({
46235
46394
  } = useDashboardInternal(destinationDashboard);
46236
46395
  const { getToken, quillFetchWithToken } = useContext28(FetchContext);
46237
46396
  const { eventTracking } = useContext28(EventTrackingContext);
46397
+ const { allReportsById } = useAllReports();
46238
46398
  const destinationDashboardConfig = useMemo22(() => {
46239
46399
  return dashboards?.find((d) => d.name === destinationDashboard);
46240
46400
  }, [dashboards, destinationDashboard]);
@@ -46302,6 +46462,46 @@ function SQLEditor({
46302
46462
  reload();
46303
46463
  }
46304
46464
  }, [data, dashboardIsLoading]);
46465
+ useEffect24(() => {
46466
+ const loadReport = async () => {
46467
+ let reportToLoad;
46468
+ if (!client) {
46469
+ return;
46470
+ }
46471
+ try {
46472
+ if (!reportId) {
46473
+ throw new Error("Report ID is required");
46474
+ }
46475
+ reportToLoad = allReportsById[reportId];
46476
+ if (!reportToLoad) {
46477
+ throw new Error("Report not found");
46478
+ }
46479
+ setQuery(reportToLoad.queryString || "");
46480
+ setTempReport(reportToLoad);
46481
+ if (reportToLoad.rows && reportToLoad.rows.length > 0) {
46482
+ setRows(reportToLoad.rows);
46483
+ setDisplayTable(true);
46484
+ }
46485
+ } catch (err) {
46486
+ console.error(err);
46487
+ eventTracking?.logError?.({
46488
+ type: "bug",
46489
+ severity: "high",
46490
+ message: "Error loading report",
46491
+ errorMessage: err.message,
46492
+ errorStack: err.stack,
46493
+ errorData: {
46494
+ caller: "SQLEditor",
46495
+ function: "loadReport"
46496
+ }
46497
+ });
46498
+ setErrorMessage("Error when loading report");
46499
+ }
46500
+ };
46501
+ if (reportId && client) {
46502
+ loadReport();
46503
+ }
46504
+ }, [allReportsById[reportId || ""], client]);
46305
46505
  const dynamicHeight = tableRef.current ? tableRef.current.clientHeight : cachedHeight;
46306
46506
  const rowsPerPage = Math.max(
46307
46507
  DEFAULT_ROWS_PER_PAGE,
@@ -47084,7 +47284,7 @@ function SQLEditor({
47084
47284
  {
47085
47285
  onClick: async () => {
47086
47286
  onSaveChanges && onSaveChanges();
47087
- setTempReport({
47287
+ const updatedReport = {
47088
47288
  ...tempReport,
47089
47289
  id: TEMP_REPORT_ID,
47090
47290
  rows,
@@ -47094,6 +47294,9 @@ function SQLEditor({
47094
47294
  queryString: query ?? "",
47095
47295
  dashboardName: report?.dashboardName ?? destinationDashboard
47096
47296
  // flags: flagsToAdd,
47297
+ };
47298
+ flushSync2(() => {
47299
+ setTempReport(updatedReport);
47097
47300
  });
47098
47301
  setIsChartBuilderOpen(true);
47099
47302
  },
@@ -47120,13 +47323,38 @@ function SQLEditor({
47120
47323
  isHorizontalView: isChartBuilderHorizontalView,
47121
47324
  isOpen: isChartBuilderOpen,
47122
47325
  setIsOpen: setIsChartBuilderOpen,
47123
- onAddToDashboardComplete,
47326
+ onAddToDashboardComplete: reportId || report?.id ? (data2) => {
47327
+ if (onSubmitEditReport) {
47328
+ onSubmitEditReport(data2);
47329
+ } else if (onAddToDashboardComplete) {
47330
+ onAddToDashboardComplete(data2);
47331
+ }
47332
+ if (!isAdminEnabled && destinationDashboard) {
47333
+ reload(destinationDashboard, false, {
47334
+ report: data2,
47335
+ action: "upsert"
47336
+ });
47337
+ }
47338
+ } : (data2) => {
47339
+ if (onSubmitCreateReport) {
47340
+ onSubmitCreateReport(data2);
47341
+ } else if (onAddToDashboardComplete) {
47342
+ onAddToDashboardComplete(data2);
47343
+ }
47344
+ if (!isAdminEnabled && destinationDashboard) {
47345
+ reload(destinationDashboard, false, {
47346
+ report: data2,
47347
+ action: "upsert"
47348
+ });
47349
+ }
47350
+ },
47124
47351
  destinationDashboard,
47352
+ destinationSection,
47125
47353
  isAdmin: isAdminEnabled,
47126
47354
  title: chartBuilderTitle,
47127
47355
  buttonLabel: addToDashboardButtonLabel,
47128
47356
  tempReport,
47129
- reportId: report?.id,
47357
+ reportId: reportId || report?.id,
47130
47358
  organizationName,
47131
47359
  CardComponent,
47132
47360
  TableComponent,
@@ -47151,6 +47379,8 @@ function SQLEditor({
47151
47379
  CheckboxComponent,
47152
47380
  hideDateRangeFilter: true,
47153
47381
  hideDeleteButton: true,
47382
+ showTableFormatOptions: chartBuilderOptions?.showTableFormatOptions,
47383
+ showDashboardFilterFields: chartBuilderOptions?.showDashboardFilterFields,
47154
47384
  onClickChartElement,
47155
47385
  isEditingMode: true
47156
47386
  }
@@ -47170,7 +47400,7 @@ function SQLEditor({
47170
47400
  isAdmin: false,
47171
47401
  title: "Save query",
47172
47402
  buttonLabel: "Save query",
47173
- tempReport,
47403
+ tempReport: { ...tempReport, dashboardName: SAVED_QUERIES_DASHBOARD },
47174
47404
  reportId: report?.id,
47175
47405
  organizationName,
47176
47406
  CardComponent,
@@ -51503,7 +51733,10 @@ var SaveReport = ({
51503
51733
  chartBuilderTitle,
51504
51734
  onSubmitEditReport = () => void 0,
51505
51735
  onSubmitCreateReport = () => void 0,
51736
+ onDiscardChanges = () => void 0,
51506
51737
  destinationSection,
51738
+ showTableFormatOptions,
51739
+ showDashboardFilterFields,
51507
51740
  SelectComponent = QuillSelectComponent,
51508
51741
  TextInputComponent = QuillTextInput,
51509
51742
  ButtonComponent = MemoizedButton,
@@ -51536,6 +51769,9 @@ var SaveReport = ({
51536
51769
  ),
51537
51770
  submitButtonLabel
51538
51771
  }) => {
51772
+ const { reload } = useDashboardInternal(
51773
+ reportBuilder.destinationDashboard ?? null
51774
+ );
51539
51775
  return /* @__PURE__ */ jsxs59("div", { children: [
51540
51776
  SaveTrigger,
51541
51777
  /* @__PURE__ */ jsx79(
@@ -51549,7 +51785,24 @@ var SaveReport = ({
51549
51785
  isHorizontalView: true,
51550
51786
  isOpen,
51551
51787
  setIsOpen,
51552
- onAddToDashboardComplete: reportBuilder.reportId ? onSubmitEditReport : onSubmitCreateReport,
51788
+ onAddToDashboardComplete: reportBuilder.reportId ? (data) => {
51789
+ onSubmitEditReport(data);
51790
+ if (!isAdminEnabled && reportBuilder.destinationDashboard) {
51791
+ reload(reportBuilder.destinationDashboard, false, {
51792
+ report: data,
51793
+ action: "upsert"
51794
+ });
51795
+ }
51796
+ } : (data) => {
51797
+ onSubmitCreateReport(data);
51798
+ if (!isAdminEnabled && reportBuilder.destinationDashboard) {
51799
+ reload(reportBuilder.destinationDashboard, false, {
51800
+ report: data,
51801
+ action: "upsert"
51802
+ });
51803
+ }
51804
+ },
51805
+ onDiscardChanges,
51553
51806
  destinationDashboard: reportBuilder.destinationDashboard,
51554
51807
  destinationSection,
51555
51808
  initialUniqueValues: reportBuilder.columnUniqueValues,
@@ -51578,6 +51831,8 @@ var SaveReport = ({
51578
51831
  FormContainer: ChartBuilderFormContainer,
51579
51832
  hideDateRangeFilter: true,
51580
51833
  hideDeleteButton: true,
51834
+ showTableFormatOptions,
51835
+ showDashboardFilterFields,
51581
51836
  buttonLabel: submitButtonLabel ?? (!!reportBuilder.reportId ? "Save changes" : "Add to dashboard"),
51582
51837
  onClickChartElement,
51583
51838
  isEditingMode: true
@@ -51674,6 +51929,7 @@ function ReportBuilder({
51674
51929
  containerStyle,
51675
51930
  className,
51676
51931
  pivotRecommendationsEnabled = true,
51932
+ chartBuilderOptions,
51677
51933
  reportId,
51678
51934
  hideCopySQL = true,
51679
51935
  isChartBuilderHorizontalView = true,
@@ -52130,6 +52386,9 @@ function ReportBuilder({
52130
52386
  ErrorMessageComponent,
52131
52387
  PivotRowContainer,
52132
52388
  PivotColumnContainer,
52389
+ showTableFormatOptions: chartBuilderOptions?.showTableFormatOptions,
52390
+ showDashboardFilterFields: chartBuilderOptions?.showDashboardFilterFields,
52391
+ onDiscardChanges,
52133
52392
  onClickChartElement,
52134
52393
  submitButtonLabel
52135
52394
  }
@@ -52150,7 +52409,7 @@ function ReportBuilder({
52150
52409
  isAdmin: false,
52151
52410
  title: "Save query",
52152
52411
  buttonLabel: "Save query",
52153
- tempReport,
52412
+ tempReport: { ...tempReport, dashboardName: SAVED_QUERIES_DASHBOARD },
52154
52413
  reportId,
52155
52414
  organizationName,
52156
52415
  CardComponent,
@@ -52204,7 +52463,10 @@ function ChartEditor({
52204
52463
  chartBuilderTitle = "Edit chart",
52205
52464
  chartBuilderButtonLabel,
52206
52465
  onAddToDashboardComplete,
52466
+ onSubmitEditReport,
52467
+ onDiscardChanges,
52207
52468
  destinationDashboard,
52469
+ destinationSection,
52208
52470
  organizationName,
52209
52471
  isHorizontalView = true,
52210
52472
  onDelete,
@@ -52232,6 +52494,9 @@ function ChartEditor({
52232
52494
  ErrorComponent = QuillChartErrorWithAction,
52233
52495
  hideDeleteButton = false,
52234
52496
  hideSubmitButton = false,
52497
+ showTableFormatOptions,
52498
+ showDashboardFilterFields,
52499
+ chartBuilderOptions,
52235
52500
  onClickChartElement,
52236
52501
  onClickChartError
52237
52502
  }) {
@@ -52320,7 +52585,12 @@ function ChartEditor({
52320
52585
  ModalComponent,
52321
52586
  {
52322
52587
  isOpen,
52323
- setIsOpen,
52588
+ setIsOpen: (value) => {
52589
+ if (!value) {
52590
+ setChartBuilderKey(chartBuilderKey + 1);
52591
+ }
52592
+ setIsOpen(value);
52593
+ },
52324
52594
  title: chartBuilderTitle || "Add to dashboard",
52325
52595
  width: isHorizontalView ? modalWidth : void 0,
52326
52596
  height: isHorizontalView ? modalHeight : void 0,
@@ -52333,8 +52603,15 @@ function ChartEditor({
52333
52603
  isComparison: dateFilter?.comparisonRange,
52334
52604
  setIsOpen,
52335
52605
  showDashboardDropdown: isAdmin,
52336
- onAddToDashboardComplete,
52606
+ onAddToDashboardComplete: (data) => {
52607
+ if (onSubmitEditReport) {
52608
+ onSubmitEditReport(data);
52609
+ } else if (onAddToDashboardComplete) {
52610
+ onAddToDashboardComplete(data);
52611
+ }
52612
+ },
52337
52613
  destinationDashboard,
52614
+ destinationSection,
52338
52615
  dateRange,
52339
52616
  SelectComponent,
52340
52617
  TextInputComponent,
@@ -52360,13 +52637,18 @@ function ChartEditor({
52360
52637
  onClickChartError,
52361
52638
  onDelete,
52362
52639
  onDiscardChanges: () => {
52640
+ if (onDiscardChanges) {
52641
+ onDiscardChanges();
52642
+ }
52363
52643
  setChartBuilderKey(chartBuilderKey + 1);
52364
52644
  },
52365
52645
  title: chartBuilderTitle,
52366
52646
  buttonLabel: chartBuilderButtonLabel,
52367
52647
  organizationName,
52368
52648
  hideSubmitButton,
52369
- hideDeleteButton,
52649
+ hideDeleteButton: chartBuilderOptions?.showDeleteButton !== void 0 ? !chartBuilderOptions.showDeleteButton : hideDeleteButton,
52650
+ showTableFormatOptions: chartBuilderOptions?.showTableFormatOptions ?? showTableFormatOptions,
52651
+ showDashboardFilterFields: chartBuilderOptions?.showDashboardFilterFields ?? showDashboardFilterFields,
52370
52652
  filtersEnabled,
52371
52653
  onFiltersEnabledChanged: (value) => {
52372
52654
  setFiltersEnabled(value);