@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.cjs CHANGED
@@ -379,7 +379,7 @@ var init_constants = __esm({
379
379
  "use strict";
380
380
  MAX_PIVOT_UNIQUE_VALUES = 250;
381
381
  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";
382
- QUILL_QUERY_ENDPOINT = typeof process !== "undefined" && process.env ? process.env.QUILL_QUERY_ENDPOINT ?? "/cloud" : "/cloud";
382
+ QUILL_QUERY_ENDPOINT = typeof process !== "undefined" && process.env ? process.env.QUILL_QUERY_ENDPOINT ?? "/cloud/engine" : "/cloud/engine";
383
383
  ALL_TENANTS = "QUILL_ALL_TENANTS";
384
384
  SINGLE_TENANT = "QUILL_SINGLE_TENANT";
385
385
  SAVED_QUERIES_DASHBOARD = "quill-saved-queries";
@@ -15946,6 +15946,7 @@ async function generatePivotWithSQL({
15946
15946
  dateFilter,
15947
15947
  distinctStrings,
15948
15948
  dashboardName,
15949
+ dashboardFilters,
15949
15950
  tenants,
15950
15951
  additionalProcessing,
15951
15952
  pivotQuery,
@@ -15989,6 +15990,7 @@ async function generatePivotWithSQL({
15989
15990
  metadata: {
15990
15991
  clientId: client.clientId,
15991
15992
  pivot: pivotConfig,
15993
+ reportId: report?.id !== "__quillTempReport" ? report?.id : void 0,
15992
15994
  itemQuery: reportBuilderState ? void 0 : report?.queryString,
15993
15995
  // Don't send itemQuery if reportBuilderState is present
15994
15996
  reportBuilderState,
@@ -15996,6 +15998,11 @@ async function generatePivotWithSQL({
15996
15998
  databaseType,
15997
15999
  // Required when sending reportBuilderState
15998
16000
  dashboardName,
16001
+ filters: !report?.id ? void 0 : dashboardFilters?.map((filter) => ({
16002
+ ...filter,
16003
+ options: void 0
16004
+ })),
16005
+ // Only pass dashboard filters in Dashboard context, not ReportBuilder
15999
16006
  tenants,
16000
16007
  additionalProcessing
16001
16008
  },
@@ -16165,6 +16172,7 @@ async function generatePivotTable({
16165
16172
  eventTracking,
16166
16173
  uniqueValues,
16167
16174
  dashboardName,
16175
+ dashboardFilters,
16168
16176
  tenants,
16169
16177
  additionalProcessing,
16170
16178
  caller,
@@ -16182,6 +16190,7 @@ async function generatePivotTable({
16182
16190
  dateBucket,
16183
16191
  dateFilter,
16184
16192
  dashboardName,
16193
+ dashboardFilters,
16185
16194
  tenants,
16186
16195
  additionalProcessing,
16187
16196
  caller,
@@ -17173,27 +17182,6 @@ var init_astProcessing = __esm({
17173
17182
  if (!tableInfo) {
17174
17183
  throw new Error("Table info not found");
17175
17184
  }
17176
- console.log("[astProcessing] Calling report-builder-unique-values", {
17177
- table: processedName,
17178
- columnCount: tableInfo.columns.length,
17179
- reportBuilderState: {
17180
- tables: [{ name: processedName }],
17181
- columns: tableInfo.columns.map(
17182
- (col) => ({
17183
- field: col.field,
17184
- table: processedName,
17185
- label: col.label,
17186
- format: col.format,
17187
- aggregate: void 0,
17188
- customExpression: void 0
17189
- })
17190
- ),
17191
- filters: [],
17192
- sorts: [],
17193
- groupByColumns: [],
17194
- limit: void 0
17195
- }
17196
- });
17197
17185
  const uniqueValues = await getUniqueStringValuesByColumn({
17198
17186
  columns: tableInfo.columns,
17199
17187
  tableName: processedName,
@@ -17274,12 +17262,15 @@ var init_astProcessing = __esm({
17274
17262
  if (!report) {
17275
17263
  throw new Error("Report not found");
17276
17264
  }
17277
- const resp = astify(
17278
- report.queryString,
17279
- client.databaseType || "postgresql",
17280
- true
17281
- // useNewNodeSql = true
17282
- );
17265
+ const { data: resp } = await quillFetch({
17266
+ client,
17267
+ task: "astify",
17268
+ metadata: {
17269
+ query: report.queryString,
17270
+ useNewNodeSql: true
17271
+ },
17272
+ getToken
17273
+ });
17283
17274
  if (resp.success === false) {
17284
17275
  throw new Error(resp.message || "Couldn't process report query.");
17285
17276
  }
@@ -17620,7 +17611,15 @@ var init_tableProcessing = __esm({
17620
17611
  baseQuery = withMatch[1];
17621
17612
  }
17622
17613
  const dbType = client.databaseType || "postgresql";
17623
- const astResponse = astify(baseQuery, dbType, true);
17614
+ const { data: astResponse } = await quillFetch({
17615
+ client,
17616
+ task: "astify",
17617
+ metadata: {
17618
+ query: baseQuery,
17619
+ useNewNodeSql: true
17620
+ },
17621
+ getToken
17622
+ });
17624
17623
  if (astResponse.success && astResponse.ast) {
17625
17624
  const selectAst = getSelectFromAST(astResponse.ast);
17626
17625
  const tableNames = selectAst.from ? selectAst.from.map((t) => t.as || t.table || t.name).filter(Boolean) : [];
@@ -17776,7 +17775,7 @@ var init_tableProcessing = __esm({
17776
17775
  task: "report-builder-unique-values",
17777
17776
  metadata: {
17778
17777
  reportBuilderState,
17779
- columns: stringColumns.map((col) => col.field),
17778
+ stringColumns: stringColumns.map((col) => col.field),
17780
17779
  clientId: client.clientId,
17781
17780
  databaseType: client.databaseType?.toLowerCase() || "postgresql",
17782
17781
  customFields,
@@ -17897,7 +17896,6 @@ var init_tableProcessing = __esm({
17897
17896
  dashboardName,
17898
17897
  reportBuilderState
17899
17898
  );
17900
- console.log("dateRanges 1", dateRanges);
17901
17899
  if (dateRanges === null) {
17902
17900
  throw new Error("Couldn't fetch date ranges");
17903
17901
  }
@@ -18014,7 +18012,7 @@ var init_tableProcessing = __esm({
18014
18012
  task: "report-builder-unique-values",
18015
18013
  metadata: {
18016
18014
  reportBuilderState,
18017
- columns,
18015
+ stringColumns: columns,
18018
18016
  clientId: client.clientId,
18019
18017
  databaseType: client.databaseType?.toLowerCase() || "postgresql",
18020
18018
  customFields,
@@ -18152,7 +18150,6 @@ var init_tableProcessing = __esm({
18152
18150
  },
18153
18151
  {}
18154
18152
  );
18155
- console.log("what", results);
18156
18153
  return results;
18157
18154
  }
18158
18155
  const distinctValueQuery = generateMinMaxDateRangeQueries(
@@ -18263,15 +18260,23 @@ var init_tableProcessing = __esm({
18263
18260
  let parsedSuccessfully = true;
18264
18261
  let parsingError = "";
18265
18262
  if (!rowCountOnly) {
18266
- const results = astify(
18267
- query,
18268
- client.databaseType || "postgresql",
18269
- true
18270
- // useNewNodeSql = true
18271
- );
18272
- if (!results || results.success == false) {
18263
+ try {
18264
+ const { data: results } = await quillFetch({
18265
+ client,
18266
+ task: "astify",
18267
+ metadata: {
18268
+ query,
18269
+ useNewNodeSql: true
18270
+ },
18271
+ getToken
18272
+ });
18273
+ if (!results || results.success == false) {
18274
+ parsedSuccessfully = false;
18275
+ parsingError = results.message || "";
18276
+ }
18277
+ } catch (e) {
18273
18278
  parsedSuccessfully = false;
18274
- parsingError = results.message || "";
18279
+ parsingError = e.message || "Failed to parse query";
18275
18280
  }
18276
18281
  }
18277
18282
  const fetchResp = await quillFetch({
@@ -19924,6 +19929,7 @@ async function getPivotTable(report, dashboardFilters, dashboardName, getToken,
19924
19929
  dateBucket,
19925
19930
  dateFilter,
19926
19931
  dashboardName,
19932
+ dashboardFilters,
19927
19933
  tenants,
19928
19934
  additionalProcessing,
19929
19935
  getToken
@@ -19952,6 +19958,7 @@ async function getPivotTable(report, dashboardFilters, dashboardName, getToken,
19952
19958
  client,
19953
19959
  uniqueValues: report.distinctStrings,
19954
19960
  dashboardName,
19961
+ dashboardFilters,
19955
19962
  tenants,
19956
19963
  dateFilter,
19957
19964
  additionalProcessing,
@@ -20359,18 +20366,24 @@ async function saveReport({
20359
20366
  tenants
20360
20367
  }) {
20361
20368
  const { publicKey, databaseType } = client;
20362
- const { reportBuilderState, queryString, ...reportWithoutStateAndQuery } = report;
20369
+ const {
20370
+ reportBuilderState,
20371
+ queryString,
20372
+ adminMode,
20373
+ ...reportWithoutStateAndQuery
20374
+ } = report;
20363
20375
  const reportToSave = reportWithoutStateAndQuery;
20364
- const task = reportBuilderState ? "create-report" : "create";
20376
+ const task = reportBuilderState && !adminMode ? "create-report" : "create";
20377
+ const isCreateTask = task === "create";
20365
20378
  const { data } = await quillFetch({
20366
20379
  client,
20367
20380
  task,
20368
20381
  metadata: {
20369
20382
  ...reportToSave,
20370
- // Pass reportBuilderState for create-report, queryString for create
20383
+ // Pass reportBuilderState if present, queryString otherwise
20371
20384
  ...reportBuilderState ? {
20372
20385
  reportBuilderState,
20373
- databaseType: databaseType || "postgresql"
20386
+ databaseType
20374
20387
  } : {
20375
20388
  queryString
20376
20389
  },
@@ -20379,7 +20392,9 @@ async function saveReport({
20379
20392
  dashboardItemId,
20380
20393
  // Remove useNewNodeSql since backend will handle conversion
20381
20394
  clientId: publicKey,
20382
- tenants
20395
+ tenants,
20396
+ // Only include adminMode for 'create' task, not 'create-report'
20397
+ ...isCreateTask && { adminMode }
20383
20398
  },
20384
20399
  getToken
20385
20400
  });
@@ -20656,7 +20671,6 @@ var fetchReportBuilderDataFromAST = async ({
20656
20671
  customFields ?? [],
20657
20672
  dashboardName
20658
20673
  );
20659
- console.log("dateRanges 3", dateRanges);
20660
20674
  if (dateRanges === null) {
20661
20675
  throw new Error("Couldn't fetch date ranges");
20662
20676
  }
@@ -31558,23 +31572,53 @@ function QuillMetricComponent({
31558
31572
  width: "100%"
31559
31573
  }
31560
31574
  }
31561
- ) : !report?.rows?.[0] || report.rows[0][report.xAxisField] === null ? /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
31575
+ ) : !report?.rows || report?.rows?.length === 0 || report.rows[0]?.[report.xAxisField] === null || report.rows[0]?.[report.xAxisField] === void 0 ? /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
31562
31576
  "div",
31563
31577
  {
31564
31578
  style: {
31565
- display: "flex",
31566
- flex: "1 0 auto",
31567
- // height: '100%',
31568
- margin: "auto",
31569
- justifyContent: "center",
31570
- alignItems: "center",
31571
- fontSize: 13,
31572
- fontFamily: theme?.fontFamily,
31573
- color: theme?.secondaryTextColor,
31574
- maxWidth: "100%",
31575
- width: "100%"
31579
+ padding: 0,
31580
+ height: "100%",
31581
+ width: "100%",
31582
+ boxSizing: "content-box",
31583
+ flex: 1
31576
31584
  },
31577
- children: "No results"
31585
+ children: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
31586
+ "div",
31587
+ {
31588
+ style: {
31589
+ fontFamily: theme?.fontFamily,
31590
+ fontSize: 32,
31591
+ color: theme?.primaryTextColor,
31592
+ fontWeight: "600",
31593
+ textOverflow: "ellipsis",
31594
+ margin: 0,
31595
+ whiteSpace: "nowrap",
31596
+ boxSizing: "content-box",
31597
+ maxWidth: "100%",
31598
+ textAlign: "left",
31599
+ overflow: "hidden",
31600
+ height: "100%",
31601
+ minHeight: "80px",
31602
+ display: "flex",
31603
+ width: "100%",
31604
+ flexDirection: "row",
31605
+ justifyContent: "center",
31606
+ alignItems: "center"
31607
+ },
31608
+ children: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
31609
+ "span",
31610
+ {
31611
+ style: {
31612
+ fontFamily: theme?.fontFamily,
31613
+ fontSize: 13,
31614
+ color: theme?.secondaryTextColor,
31615
+ fontWeight: "normal"
31616
+ },
31617
+ children: "No results"
31618
+ }
31619
+ )
31620
+ }
31621
+ )
31578
31622
  }
31579
31623
  ) : /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
31580
31624
  MetricDisplay,
@@ -32802,6 +32846,29 @@ function USMap({
32802
32846
  const hoveredValue = (0, import_react26.useMemo)(() => {
32803
32847
  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];
32804
32848
  }, [hoveredState, mappedData, measureField]);
32849
+ if (!measureField) {
32850
+ return /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
32851
+ "div",
32852
+ {
32853
+ style: {
32854
+ display: "flex",
32855
+ flex: "1 0 auto",
32856
+ marginLeft: "auto",
32857
+ marginRight: "auto",
32858
+ marginTop: "auto",
32859
+ marginBottom: "auto",
32860
+ justifyContent: "center",
32861
+ alignItems: "center",
32862
+ fontSize: 13,
32863
+ color: theme?.secondaryTextColor,
32864
+ fontFamily: theme?.fontFamily,
32865
+ ...containerStyle
32866
+ },
32867
+ className,
32868
+ children: "No results"
32869
+ }
32870
+ );
32871
+ }
32805
32872
  return /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)(
32806
32873
  "div",
32807
32874
  {
@@ -32970,6 +33037,29 @@ function WorldMap({
32970
33037
  const hoveredValue = (0, import_react26.useMemo)(() => {
32971
33038
  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];
32972
33039
  }, [hoveredCountry, mappedData, measureField]);
33040
+ if (!measureField) {
33041
+ return /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
33042
+ "div",
33043
+ {
33044
+ style: {
33045
+ display: "flex",
33046
+ flex: "1 0 auto",
33047
+ marginLeft: "auto",
33048
+ marginRight: "auto",
33049
+ marginTop: "auto",
33050
+ marginBottom: "auto",
33051
+ justifyContent: "center",
33052
+ alignItems: "center",
33053
+ fontSize: 13,
33054
+ color: theme?.secondaryTextColor,
33055
+ fontFamily: theme?.fontFamily,
33056
+ ...containerStyle
33057
+ },
33058
+ className,
33059
+ children: "No results"
33060
+ }
33061
+ );
33062
+ }
32973
33063
  return /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)(
32974
33064
  "div",
32975
33065
  {
@@ -35184,7 +35274,7 @@ function Chart({
35184
35274
  index
35185
35275
  )) }),
35186
35276
  loading || !report ? /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(LoadingComponent, {}) : /* @__PURE__ */ (0, import_jsx_runtime48.jsxs)(import_jsx_runtime48.Fragment, { children: [
35187
- ("table" === report.chartType || "metric" === report.chartType) && /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
35277
+ ("table" === report.chartType || "metric" === report.chartType) && /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(import_jsx_runtime48.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
35188
35278
  DataLoader,
35189
35279
  {
35190
35280
  item: report,
@@ -35219,13 +35309,17 @@ function Chart({
35219
35309
  error: error2,
35220
35310
  rowCount: rowCount ?? data?.rowCount ?? data?.rows?.length ?? 0,
35221
35311
  rowCountIsLoading,
35222
- onPageChange: (page) => onPageChange(page),
35223
- onSortChange: (sort) => onSortChange(sort),
35312
+ onPageChange: (page) => {
35313
+ onPageChange(page);
35314
+ },
35315
+ onSortChange: (sort) => {
35316
+ onSortChange(sort);
35317
+ },
35224
35318
  hideName: true
35225
35319
  }
35226
35320
  )
35227
35321
  }
35228
- ),
35322
+ ) }),
35229
35323
  report.chartType !== "table" && report.chartType !== "metric" && /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
35230
35324
  ChartDataLoader,
35231
35325
  {
@@ -35355,7 +35449,7 @@ var ChartDisplay = ({
35355
35449
  {
35356
35450
  className,
35357
35451
  containerStyle,
35358
- data: config?.rows?.map((row) => {
35452
+ data: !config?.pivot ? config?.rows?.map((row) => {
35359
35453
  return {
35360
35454
  ...row,
35361
35455
  count: (
@@ -35363,7 +35457,7 @@ var ChartDisplay = ({
35363
35457
  parseInt(row[config?.yAxisFields[0]?.field]) / sumByKey(config?.rows, config?.yAxisFields[0]?.field)
35364
35458
  )
35365
35459
  };
35366
- }) || [],
35460
+ }) || [] : config?.rows || [],
35367
35461
  category: config?.yAxisFields?.[0]?.field,
35368
35462
  index: config?.xAxisField,
35369
35463
  colors: chartColors,
@@ -35478,27 +35572,41 @@ var ChartDisplay = ({
35478
35572
  );
35479
35573
  }
35480
35574
  if (config?.chartType?.toLowerCase() === "metric") {
35481
- if (!config?.rows || config?.rows?.length === 0 || // @ts-ignore
35482
- config?.rows[0][config?.xAxisField] === null) {
35575
+ if (!config?.rows || config?.rows?.length === 0 || config?.rows[0]?.[config?.xAxisField] === null || config?.rows[0]?.[config?.xAxisField] === void 0) {
35483
35576
  return /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
35484
35577
  "div",
35485
35578
  {
35486
35579
  style: {
35487
- display: "flex",
35488
- flex: "1 0 auto",
35489
- // height: containerStyle?.height || '100%',
35490
- margin: "auto",
35491
- justifyContent: "center",
35492
- alignItems: "center",
35493
- fontSize: 13,
35494
35580
  fontFamily: theme?.fontFamily,
35495
- color: theme?.secondaryTextColor,
35581
+ fontSize: 32,
35582
+ color: theme?.primaryTextColor,
35583
+ fontWeight: "600",
35584
+ textOverflow: "ellipsis",
35585
+ margin: 0,
35586
+ whiteSpace: "nowrap",
35587
+ boxSizing: "content-box",
35496
35588
  maxWidth: "100%",
35589
+ textAlign: "left",
35590
+ overflow: "hidden",
35591
+ height: containerStyle?.height || "100%",
35592
+ display: "flex",
35497
35593
  width: "100%",
35594
+ flexDirection: "row",
35595
+ alignItems: "center",
35498
35596
  ...containerStyle
35499
35597
  },
35500
35598
  className,
35501
- children: "No results"
35599
+ children: /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
35600
+ "span",
35601
+ {
35602
+ style: {
35603
+ fontFamily: theme?.fontFamily,
35604
+ fontSize: 13,
35605
+ color: theme?.secondaryTextColor
35606
+ },
35607
+ children: "No results"
35608
+ }
35609
+ )
35502
35610
  }
35503
35611
  );
35504
35612
  }
@@ -38366,7 +38474,7 @@ function Dashboard({
38366
38474
  data: data2,
38367
38475
  rowCount,
38368
38476
  rowCountIsLoading
38369
- }) => /* @__PURE__ */ (0, import_jsx_runtime57.jsx)(
38477
+ }) => /* @__PURE__ */ (0, import_jsx_runtime57.jsx)(import_jsx_runtime57.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime57.jsx)(
38370
38478
  TableComponent,
38371
38479
  {
38372
38480
  report: data2,
@@ -38391,10 +38499,14 @@ function Dashboard({
38391
38499
  hoverActions,
38392
38500
  rowCount: rowCount ?? data2?.rowCount ?? data2?.rows?.length ?? 0,
38393
38501
  rowCountIsLoading,
38394
- onPageChange: (page) => onPageChange(page),
38395
- onSortChange: (sort) => onSortChange(sort)
38502
+ onPageChange: (page) => {
38503
+ onPageChange(page);
38504
+ },
38505
+ onSortChange: (sort) => {
38506
+ onSortChange(sort);
38507
+ }
38396
38508
  }
38397
- )
38509
+ ) })
38398
38510
  },
38399
38511
  `${name2}${item.id}`
38400
38512
  )) })
@@ -38414,7 +38526,11 @@ function Dashboard({
38414
38526
  children: ({
38415
38527
  isLoading: isLoading2,
38416
38528
  error,
38417
- data: data2
38529
+ onPageChange,
38530
+ onSortChange,
38531
+ data: data2,
38532
+ rowCount,
38533
+ rowCountIsLoading
38418
38534
  }) => item.chartType === "metric" ? /* @__PURE__ */ (0, import_jsx_runtime57.jsx)(
38419
38535
  MetricComponent,
38420
38536
  {
@@ -38461,7 +38577,14 @@ function Dashboard({
38461
38577
  });
38462
38578
  } : void 0,
38463
38579
  hoverActions,
38464
- rowCount: data2.rowCount ?? data2.rows?.length ?? 0
38580
+ rowCount: rowCount ?? data2.rowCount ?? data2.rows?.length ?? 0,
38581
+ rowCountIsLoading,
38582
+ onPageChange: (page) => {
38583
+ onPageChange(page);
38584
+ },
38585
+ onSortChange: (sort) => {
38586
+ onSortChange(sort);
38587
+ }
38465
38588
  }
38466
38589
  )
38467
38590
  },
@@ -38878,6 +39001,7 @@ var Table_default = Table;
38878
39001
 
38879
39002
  // src/SQLEditor.tsx
38880
39003
  var import_react45 = require("react");
39004
+ var import_react_dom5 = require("react-dom");
38881
39005
  var import_react46 = __toESM(require("@monaco-editor/react"), 1);
38882
39006
 
38883
39007
  // src/ChartBuilder.tsx
@@ -39411,11 +39535,6 @@ var PivotModal = ({
39411
39535
  dashboardName,
39412
39536
  reportBuilderState
39413
39537
  );
39414
- console.log("[PivotModal] Calling report-builder-unique-values", {
39415
- columnCount: smallStringColumns.length,
39416
- hasReportBuilderState: !!reportBuilderState,
39417
- reportBuilderState
39418
- });
39419
39538
  newUniqueValues = await getUniqueValuesByQuery({
39420
39539
  columns: smallStringColumns,
39421
39540
  query: query || "",
@@ -41646,6 +41765,7 @@ function InternalChart({
41646
41765
  // src/ChartBuilder.tsx
41647
41766
  init_paginationProcessing();
41648
41767
  init_tableProcessing();
41768
+ init_dataFetcher();
41649
41769
  init_dates();
41650
41770
 
41651
41771
  // src/components/QuillMultiSelectSectionList.tsx
@@ -42486,15 +42606,19 @@ function ChartBuilderWithModal(props) {
42486
42606
  title: title || "Add to dashboard",
42487
42607
  width: isHorizontalView ? modalWidth : void 0,
42488
42608
  height: isHorizontalView ? modalHeight : void 0,
42489
- children: (props.reportId ? dashboard[props.reportId] ?? props.tempReport : props.tempReport) ? /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(
42490
- ChartBuilder,
42491
- {
42492
- ...props,
42493
- filtersEnabled: filtersEnabledState,
42494
- onFiltersEnabledChanged: setFiltersEnabledState,
42495
- runQueryOnMount: filtersEnabledState
42496
- }
42497
- ) : /* @__PURE__ */ (0, import_jsx_runtime65.jsx)("div", { style: { padding: 20 }, children: /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(QuillLoadingComponent, {}) })
42609
+ children: (() => {
42610
+ const resolvedReport = props.tempReport ?? (props.reportId ? dashboard[props.reportId] : void 0);
42611
+ return resolvedReport ? /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(
42612
+ ChartBuilder,
42613
+ {
42614
+ ...props,
42615
+ tempReport: resolvedReport,
42616
+ filtersEnabled: filtersEnabledState,
42617
+ onFiltersEnabledChanged: setFiltersEnabledState,
42618
+ runQueryOnMount: filtersEnabledState
42619
+ }
42620
+ ) : /* @__PURE__ */ (0, import_jsx_runtime65.jsx)("div", { style: { padding: 20 }, children: /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(QuillLoadingComponent, {}) });
42621
+ })()
42498
42622
  }
42499
42623
  ) });
42500
42624
  }
@@ -42575,7 +42699,7 @@ function ChartBuilder({
42575
42699
  const { tenants, flags } = (0, import_react43.useContext)(TenantContext);
42576
42700
  const report = (0, import_react43.useMemo)(() => {
42577
42701
  return reportId && !tempReport ? allReportsById[reportId] : tempReport;
42578
- }, [reportId]);
42702
+ }, [reportId, tempReport, allReportsById]);
42579
42703
  const [windowWidth, setWindowWidth] = (0, import_react43.useState)(1200);
42580
42704
  const [rows, setRows] = (0, import_react43.useState)(report?.rows ?? []);
42581
42705
  const [itemQuery, setItemQuery] = (0, import_react43.useState)(report?.itemQuery);
@@ -42773,7 +42897,7 @@ function ChartBuilder({
42773
42897
  };
42774
42898
  const [currentProcessing, setCurrentProcessing] = (0, import_react43.useState)(baseProcessing);
42775
42899
  const [customTenantAccess, setCustomTenantAccess] = (0, import_react43.useState)(
42776
- !!Object.values(report?.flags ?? {}).length
42900
+ report?.flags === null ? false : !!Object.values(report?.flags ?? {}).length
42777
42901
  );
42778
42902
  const [dateFieldOptions, setDateFieldOptions] = (0, import_react43.useState)([]);
42779
42903
  const [allTables, setAllTables] = (0, import_react43.useState)([]);
@@ -43486,16 +43610,6 @@ function ChartBuilder({
43486
43610
  fetchRowCount(processing, overrideFilters);
43487
43611
  if (formData.pivot) {
43488
43612
  try {
43489
- console.log(
43490
- "[ChartBuilder] Calling report-builder-unique-values for pivot",
43491
- {
43492
- columns: tableInfo.columns.filter(
43493
- (column) => column.field === formData.pivot?.columnField
43494
- ).map((c) => c.field),
43495
- hasReportBuilderState: !!reportBuilderState,
43496
- reportBuilderState
43497
- }
43498
- );
43499
43613
  const uniqueValues = await getUniqueValuesByQuery({
43500
43614
  reportBuilderState,
43501
43615
  columns: tableInfo.columns.filter(
@@ -43883,9 +43997,46 @@ function ChartBuilder({
43883
43997
  event.preventDefault();
43884
43998
  };
43885
43999
  const deleteChart = async () => {
43886
- if (onDelete && onDelete()) {
43887
- setIsOpen(false);
43888
- setIsSubmitting(false);
44000
+ if (!client || !reportId) {
44001
+ console.error("Cannot delete: missing client or reportId");
44002
+ return;
44003
+ }
44004
+ try {
44005
+ const { status, error } = await quillFetch({
44006
+ client,
44007
+ task: "delete",
44008
+ metadata: {
44009
+ dashboardItemId: reportId,
44010
+ tenants
44011
+ },
44012
+ getToken
44013
+ });
44014
+ if (status !== "success") {
44015
+ throw new Error(`Error deleting report: ${error}`);
44016
+ } else {
44017
+ if (onDelete) {
44018
+ onDelete();
44019
+ }
44020
+ reloadDashboard(destinationDashboard, true, {
44021
+ report: { id: reportId },
44022
+ action: "delete"
44023
+ });
44024
+ setIsOpen(false);
44025
+ setIsSubmitting(false);
44026
+ }
44027
+ } catch (err) {
44028
+ console.error("Error deleting chart:", err);
44029
+ eventTracking?.logError?.({
44030
+ type: "bug",
44031
+ severity: "high",
44032
+ message: "Error deleting chart",
44033
+ errorMessage: err.message,
44034
+ errorStack: err.stack,
44035
+ errorData: {
44036
+ caller: "ChartBuilder",
44037
+ function: "deleteChart"
44038
+ }
44039
+ });
43889
44040
  }
43890
44041
  };
43891
44042
  const editChart = async () => {
@@ -43924,14 +44075,17 @@ function ChartBuilder({
43924
44075
  includeCustomFields: includeCustomFields || containsCustomFields,
43925
44076
  template: tenants ? void 0 : report && !isAdmin && formData.template ? false : formData.template,
43926
44077
  adminMode: isAdmin,
43927
- flags: containsCustomFields && customTenantAccess ? currentTenantAsFormFlags : formFlags ? Object.fromEntries(
43928
- Object.entries(formFlags).filter(([, value]) => value.length > 0).map(([key, value]) => {
43929
- return [
43930
- key,
43931
- Object.keys(allTenantMap).length > 1 && allTenantMap[key]?.length === value.length ? ALL_TENANTS : value
43932
- ];
43933
- })
43934
- ) : void 0,
44078
+ reportBuilderState,
44079
+ ...isAdmin && {
44080
+ reportFlags: !customTenantAccess && !containsCustomFields ? null : containsCustomFields && customTenantAccess ? currentTenantAsFormFlags : formFlags ? Object.fromEntries(
44081
+ Object.entries(formFlags).filter(([, value]) => value.length > 0).map(([key, value]) => {
44082
+ return [
44083
+ key,
44084
+ Object.keys(allTenantMap).length > 1 && allTenantMap[key]?.length === value.length ? ALL_TENANTS : value
44085
+ ];
44086
+ })
44087
+ ) : void 0
44088
+ },
43935
44089
  referenceLines: formData.referenceLines.map((line) => {
43936
44090
  return {
43937
44091
  label: line.label,
@@ -45300,7 +45454,7 @@ function ChartBuilder({
45300
45454
  right: 16
45301
45455
  },
45302
45456
  children: [
45303
- !hideDeleteButton && !isHorizontalView && report && /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(
45457
+ !hideDeleteButton && report && /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(
45304
45458
  SecondaryButtonComponent,
45305
45459
  {
45306
45460
  onClick: deleteChart,
@@ -46056,6 +46210,7 @@ function SQLEditor({
46056
46210
  CheckboxComponent = QuillChartBuilderCheckboxComponent,
46057
46211
  defaultQuery,
46058
46212
  destinationDashboard,
46213
+ destinationSection,
46059
46214
  onChangeQuery,
46060
46215
  onChangeData,
46061
46216
  onChangeColumns,
@@ -46065,12 +46220,16 @@ function SQLEditor({
46065
46220
  onCloseChartBuilder,
46066
46221
  isChartBuilderEnabled = false,
46067
46222
  isAdminEnabled = false,
46223
+ chartBuilderOptions,
46068
46224
  chartBuilderTitle,
46069
46225
  runQueryOnMount = false,
46070
46226
  onAddToDashboardComplete,
46227
+ onSubmitCreateReport,
46228
+ onSubmitEditReport,
46071
46229
  onSaveQueryComplete,
46072
46230
  addToDashboardButtonLabel = "Add to dashboard",
46073
46231
  report = void 0,
46232
+ reportId = void 0,
46074
46233
  organizationName = void 0,
46075
46234
  isChartBuilderHorizontalView = true,
46076
46235
  containerStyle = { height: "100vh" },
@@ -46081,7 +46240,7 @@ function SQLEditor({
46081
46240
  const [sqlPrompt, setSqlPrompt] = (0, import_react45.useState)("");
46082
46241
  const [client] = (0, import_react45.useContext)(ClientContext);
46083
46242
  const [theme] = (0, import_react45.useContext)(ThemeContext);
46084
- const { tenants } = (0, import_react45.useContext)(TenantContext);
46243
+ const { tenants, flags } = (0, import_react45.useContext)(TenantContext);
46085
46244
  const { dashboards } = useDashboards();
46086
46245
  const {
46087
46246
  data,
@@ -46090,6 +46249,7 @@ function SQLEditor({
46090
46249
  } = useDashboardInternal(destinationDashboard);
46091
46250
  const { getToken, quillFetchWithToken } = (0, import_react45.useContext)(FetchContext);
46092
46251
  const { eventTracking } = (0, import_react45.useContext)(EventTrackingContext);
46252
+ const { allReportsById } = useAllReports();
46093
46253
  const destinationDashboardConfig = (0, import_react45.useMemo)(() => {
46094
46254
  return dashboards?.find((d) => d.name === destinationDashboard);
46095
46255
  }, [dashboards, destinationDashboard]);
@@ -46157,6 +46317,46 @@ function SQLEditor({
46157
46317
  reload();
46158
46318
  }
46159
46319
  }, [data, dashboardIsLoading]);
46320
+ (0, import_react45.useEffect)(() => {
46321
+ const loadReport = async () => {
46322
+ let reportToLoad;
46323
+ if (!client) {
46324
+ return;
46325
+ }
46326
+ try {
46327
+ if (!reportId) {
46328
+ throw new Error("Report ID is required");
46329
+ }
46330
+ reportToLoad = allReportsById[reportId];
46331
+ if (!reportToLoad) {
46332
+ throw new Error("Report not found");
46333
+ }
46334
+ setQuery(reportToLoad.queryString || "");
46335
+ setTempReport(reportToLoad);
46336
+ if (reportToLoad.rows && reportToLoad.rows.length > 0) {
46337
+ setRows(reportToLoad.rows);
46338
+ setDisplayTable(true);
46339
+ }
46340
+ } catch (err) {
46341
+ console.error(err);
46342
+ eventTracking?.logError?.({
46343
+ type: "bug",
46344
+ severity: "high",
46345
+ message: "Error loading report",
46346
+ errorMessage: err.message,
46347
+ errorStack: err.stack,
46348
+ errorData: {
46349
+ caller: "SQLEditor",
46350
+ function: "loadReport"
46351
+ }
46352
+ });
46353
+ setErrorMessage("Error when loading report");
46354
+ }
46355
+ };
46356
+ if (reportId && client) {
46357
+ loadReport();
46358
+ }
46359
+ }, [allReportsById[reportId || ""], client]);
46160
46360
  const dynamicHeight = tableRef.current ? tableRef.current.clientHeight : cachedHeight;
46161
46361
  const rowsPerPage = Math.max(
46162
46362
  DEFAULT_ROWS_PER_PAGE,
@@ -46939,7 +47139,7 @@ function SQLEditor({
46939
47139
  {
46940
47140
  onClick: async () => {
46941
47141
  onSaveChanges && onSaveChanges();
46942
- setTempReport({
47142
+ const updatedReport = {
46943
47143
  ...tempReport,
46944
47144
  id: TEMP_REPORT_ID,
46945
47145
  rows,
@@ -46949,6 +47149,9 @@ function SQLEditor({
46949
47149
  queryString: query ?? "",
46950
47150
  dashboardName: report?.dashboardName ?? destinationDashboard
46951
47151
  // flags: flagsToAdd,
47152
+ };
47153
+ (0, import_react_dom5.flushSync)(() => {
47154
+ setTempReport(updatedReport);
46952
47155
  });
46953
47156
  setIsChartBuilderOpen(true);
46954
47157
  },
@@ -46975,13 +47178,38 @@ function SQLEditor({
46975
47178
  isHorizontalView: isChartBuilderHorizontalView,
46976
47179
  isOpen: isChartBuilderOpen,
46977
47180
  setIsOpen: setIsChartBuilderOpen,
46978
- onAddToDashboardComplete,
47181
+ onAddToDashboardComplete: reportId || report?.id ? (data2) => {
47182
+ if (onSubmitEditReport) {
47183
+ onSubmitEditReport(data2);
47184
+ } else if (onAddToDashboardComplete) {
47185
+ onAddToDashboardComplete(data2);
47186
+ }
47187
+ if (!isAdminEnabled && destinationDashboard) {
47188
+ reload(destinationDashboard, false, {
47189
+ report: data2,
47190
+ action: "upsert"
47191
+ });
47192
+ }
47193
+ } : (data2) => {
47194
+ if (onSubmitCreateReport) {
47195
+ onSubmitCreateReport(data2);
47196
+ } else if (onAddToDashboardComplete) {
47197
+ onAddToDashboardComplete(data2);
47198
+ }
47199
+ if (!isAdminEnabled && destinationDashboard) {
47200
+ reload(destinationDashboard, false, {
47201
+ report: data2,
47202
+ action: "upsert"
47203
+ });
47204
+ }
47205
+ },
46979
47206
  destinationDashboard,
47207
+ destinationSection,
46980
47208
  isAdmin: isAdminEnabled,
46981
47209
  title: chartBuilderTitle,
46982
47210
  buttonLabel: addToDashboardButtonLabel,
46983
47211
  tempReport,
46984
- reportId: report?.id,
47212
+ reportId: reportId || report?.id,
46985
47213
  organizationName,
46986
47214
  CardComponent,
46987
47215
  TableComponent,
@@ -47006,6 +47234,8 @@ function SQLEditor({
47006
47234
  CheckboxComponent,
47007
47235
  hideDateRangeFilter: true,
47008
47236
  hideDeleteButton: true,
47237
+ showTableFormatOptions: chartBuilderOptions?.showTableFormatOptions,
47238
+ showDashboardFilterFields: chartBuilderOptions?.showDashboardFilterFields,
47009
47239
  onClickChartElement,
47010
47240
  isEditingMode: true
47011
47241
  }
@@ -47025,7 +47255,7 @@ function SQLEditor({
47025
47255
  isAdmin: false,
47026
47256
  title: "Save query",
47027
47257
  buttonLabel: "Save query",
47028
- tempReport,
47258
+ tempReport: { ...tempReport, dashboardName: SAVED_QUERIES_DASHBOARD },
47029
47259
  reportId: report?.id,
47030
47260
  organizationName,
47031
47261
  CardComponent,
@@ -51328,7 +51558,10 @@ var SaveReport = ({
51328
51558
  chartBuilderTitle,
51329
51559
  onSubmitEditReport = () => void 0,
51330
51560
  onSubmitCreateReport = () => void 0,
51561
+ onDiscardChanges = () => void 0,
51331
51562
  destinationSection,
51563
+ showTableFormatOptions,
51564
+ showDashboardFilterFields,
51332
51565
  SelectComponent = QuillSelectComponent,
51333
51566
  TextInputComponent = QuillTextInput,
51334
51567
  ButtonComponent = MemoizedButton,
@@ -51361,6 +51594,9 @@ var SaveReport = ({
51361
51594
  ),
51362
51595
  submitButtonLabel
51363
51596
  }) => {
51597
+ const { reload } = useDashboardInternal(
51598
+ reportBuilder.destinationDashboard ?? null
51599
+ );
51364
51600
  return /* @__PURE__ */ (0, import_jsx_runtime79.jsxs)("div", { children: [
51365
51601
  SaveTrigger,
51366
51602
  /* @__PURE__ */ (0, import_jsx_runtime79.jsx)(
@@ -51374,7 +51610,24 @@ var SaveReport = ({
51374
51610
  isHorizontalView: true,
51375
51611
  isOpen,
51376
51612
  setIsOpen,
51377
- onAddToDashboardComplete: reportBuilder.reportId ? onSubmitEditReport : onSubmitCreateReport,
51613
+ onAddToDashboardComplete: reportBuilder.reportId ? (data) => {
51614
+ onSubmitEditReport(data);
51615
+ if (!isAdminEnabled && reportBuilder.destinationDashboard) {
51616
+ reload(reportBuilder.destinationDashboard, false, {
51617
+ report: data,
51618
+ action: "upsert"
51619
+ });
51620
+ }
51621
+ } : (data) => {
51622
+ onSubmitCreateReport(data);
51623
+ if (!isAdminEnabled && reportBuilder.destinationDashboard) {
51624
+ reload(reportBuilder.destinationDashboard, false, {
51625
+ report: data,
51626
+ action: "upsert"
51627
+ });
51628
+ }
51629
+ },
51630
+ onDiscardChanges,
51378
51631
  destinationDashboard: reportBuilder.destinationDashboard,
51379
51632
  destinationSection,
51380
51633
  initialUniqueValues: reportBuilder.columnUniqueValues,
@@ -51403,6 +51656,8 @@ var SaveReport = ({
51403
51656
  FormContainer: ChartBuilderFormContainer,
51404
51657
  hideDateRangeFilter: true,
51405
51658
  hideDeleteButton: true,
51659
+ showTableFormatOptions,
51660
+ showDashboardFilterFields,
51406
51661
  buttonLabel: submitButtonLabel ?? (!!reportBuilder.reportId ? "Save changes" : "Add to dashboard"),
51407
51662
  onClickChartElement,
51408
51663
  isEditingMode: true
@@ -51499,6 +51754,7 @@ function ReportBuilder({
51499
51754
  containerStyle,
51500
51755
  className,
51501
51756
  pivotRecommendationsEnabled = true,
51757
+ chartBuilderOptions,
51502
51758
  reportId,
51503
51759
  hideCopySQL = true,
51504
51760
  isChartBuilderHorizontalView = true,
@@ -51955,6 +52211,9 @@ function ReportBuilder({
51955
52211
  ErrorMessageComponent,
51956
52212
  PivotRowContainer,
51957
52213
  PivotColumnContainer,
52214
+ showTableFormatOptions: chartBuilderOptions?.showTableFormatOptions,
52215
+ showDashboardFilterFields: chartBuilderOptions?.showDashboardFilterFields,
52216
+ onDiscardChanges,
51958
52217
  onClickChartElement,
51959
52218
  submitButtonLabel
51960
52219
  }
@@ -51975,7 +52234,7 @@ function ReportBuilder({
51975
52234
  isAdmin: false,
51976
52235
  title: "Save query",
51977
52236
  buttonLabel: "Save query",
51978
- tempReport,
52237
+ tempReport: { ...tempReport, dashboardName: SAVED_QUERIES_DASHBOARD },
51979
52238
  reportId,
51980
52239
  organizationName,
51981
52240
  CardComponent,
@@ -52023,7 +52282,10 @@ function ChartEditor({
52023
52282
  chartBuilderTitle = "Edit chart",
52024
52283
  chartBuilderButtonLabel,
52025
52284
  onAddToDashboardComplete,
52285
+ onSubmitEditReport,
52286
+ onDiscardChanges,
52026
52287
  destinationDashboard,
52288
+ destinationSection,
52027
52289
  organizationName,
52028
52290
  isHorizontalView = true,
52029
52291
  onDelete,
@@ -52051,6 +52313,9 @@ function ChartEditor({
52051
52313
  ErrorComponent = QuillChartErrorWithAction,
52052
52314
  hideDeleteButton = false,
52053
52315
  hideSubmitButton = false,
52316
+ showTableFormatOptions,
52317
+ showDashboardFilterFields,
52318
+ chartBuilderOptions,
52054
52319
  onClickChartElement,
52055
52320
  onClickChartError
52056
52321
  }) {
@@ -52139,7 +52404,12 @@ function ChartEditor({
52139
52404
  ModalComponent,
52140
52405
  {
52141
52406
  isOpen,
52142
- setIsOpen,
52407
+ setIsOpen: (value) => {
52408
+ if (!value) {
52409
+ setChartBuilderKey(chartBuilderKey + 1);
52410
+ }
52411
+ setIsOpen(value);
52412
+ },
52143
52413
  title: chartBuilderTitle || "Add to dashboard",
52144
52414
  width: isHorizontalView ? modalWidth : void 0,
52145
52415
  height: isHorizontalView ? modalHeight : void 0,
@@ -52152,8 +52422,15 @@ function ChartEditor({
52152
52422
  isComparison: dateFilter?.comparisonRange,
52153
52423
  setIsOpen,
52154
52424
  showDashboardDropdown: isAdmin,
52155
- onAddToDashboardComplete,
52425
+ onAddToDashboardComplete: (data) => {
52426
+ if (onSubmitEditReport) {
52427
+ onSubmitEditReport(data);
52428
+ } else if (onAddToDashboardComplete) {
52429
+ onAddToDashboardComplete(data);
52430
+ }
52431
+ },
52156
52432
  destinationDashboard,
52433
+ destinationSection,
52157
52434
  dateRange,
52158
52435
  SelectComponent,
52159
52436
  TextInputComponent,
@@ -52179,13 +52456,18 @@ function ChartEditor({
52179
52456
  onClickChartError,
52180
52457
  onDelete,
52181
52458
  onDiscardChanges: () => {
52459
+ if (onDiscardChanges) {
52460
+ onDiscardChanges();
52461
+ }
52182
52462
  setChartBuilderKey(chartBuilderKey + 1);
52183
52463
  },
52184
52464
  title: chartBuilderTitle,
52185
52465
  buttonLabel: chartBuilderButtonLabel,
52186
52466
  organizationName,
52187
52467
  hideSubmitButton,
52188
- hideDeleteButton,
52468
+ hideDeleteButton: chartBuilderOptions?.showDeleteButton !== void 0 ? !chartBuilderOptions.showDeleteButton : hideDeleteButton,
52469
+ showTableFormatOptions: chartBuilderOptions?.showTableFormatOptions ?? showTableFormatOptions,
52470
+ showDashboardFilterFields: chartBuilderOptions?.showDashboardFilterFields ?? showDashboardFilterFields,
52189
52471
  filtersEnabled,
52190
52472
  onFiltersEnabledChanged: (value) => {
52191
52473
  setFiltersEnabled(value);