@quillsql/react 2.16.48 → 2.16.50

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
@@ -37,6 +37,89 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
37
37
  mod
38
38
  ));
39
39
 
40
+ // src/utils/textProcessing.ts
41
+ function capitalize(text) {
42
+ return text.charAt(0).toUpperCase() + text.slice(1);
43
+ }
44
+ function matchCasing(text, template) {
45
+ if (!text || !template) {
46
+ return text ?? "";
47
+ }
48
+ const isTitleCase = (str) => /^[A-Z][a-z]*([A-Z][a-z]*)*$/.test(str);
49
+ const isCamelCase = (str) => /^[a-z]+([A-Z][a-z]*)*$/.test(str);
50
+ const isSnakeCase = (str) => /^[a-z0-9]+(_[a-z0-9]+)*$/.test(str);
51
+ const isAllLowerCase = (str) => /^[a-z]+$/.test(str);
52
+ const isAllUpperCase = (str) => /^[A-Z]+$/.test(str);
53
+ const isCapitalized = (str) => /^[A-Z][a-z]*$/.test(str);
54
+ const isScreamingSnakeCase = (str) => /^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$/.test(str);
55
+ const toTitleCase = (str) => str.toLowerCase().replace(/\b\w/g, (char) => char.toUpperCase());
56
+ const toCamelCase = (str) => str.replace(/_./g, (match) => match.charAt(1).toUpperCase()).toLowerCase();
57
+ const toSnakeCase = (str) => str.replace(/[A-Z]/g, (match) => `_${match.toLowerCase()}`);
58
+ const toLowerCase = (str) => str.toLowerCase();
59
+ const toUpperCase = (str) => str.toUpperCase();
60
+ const toCapitalized = (str) => str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
61
+ const toScreamingSnakeCase = (str) => str.replace(/([A-Z])/g, "_$1").replace(/^_/, "").toUpperCase();
62
+ if (isTitleCase(template)) {
63
+ return toTitleCase(text);
64
+ } else if (isCamelCase(template)) {
65
+ return toCamelCase(text);
66
+ } else if (isSnakeCase(template)) {
67
+ return toSnakeCase(text);
68
+ } else if (isAllLowerCase(template)) {
69
+ return toLowerCase(text);
70
+ } else if (isAllUpperCase(template)) {
71
+ return toUpperCase(text);
72
+ } else if (isCapitalized(template)) {
73
+ return toCapitalized(text);
74
+ } else if (isScreamingSnakeCase(template)) {
75
+ return toScreamingSnakeCase(text);
76
+ } else {
77
+ return text;
78
+ }
79
+ }
80
+ function snakeCaseToTitleCase(str) {
81
+ if (!str) {
82
+ return str;
83
+ }
84
+ return str.toString().split(/_| /).map(
85
+ (word) => word === "id" ? "ID" : word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()
86
+ ).join(" ");
87
+ }
88
+ function snakeAndCamelCaseToTitleCase(str) {
89
+ if (!str || typeof str !== "string") {
90
+ return str;
91
+ }
92
+ if (str.includes("_")) {
93
+ return str.split(/_| /).map((word) => word === "id" ? "ID" : capitalize(word)).join(" ");
94
+ } else {
95
+ const text = str.replace(/([a-z])([A-Z])/g, "$1 $2");
96
+ const newText = text.split(" ").map((word) => word === "Id" || word === "id" ? "ID" : capitalize(word)).join(" ");
97
+ return newText;
98
+ }
99
+ }
100
+ function formatIdentifierLabel(str) {
101
+ if (!str || typeof str !== "string") {
102
+ return str;
103
+ }
104
+ const hasUnderscore = str.includes("_");
105
+ const hasCamelCaseBoundary = /[a-z0-9][A-Z]/.test(str);
106
+ if (hasUnderscore || hasCamelCaseBoundary) {
107
+ return snakeAndCamelCaseToTitleCase(str);
108
+ }
109
+ return str;
110
+ }
111
+ function removeDoubleQuotes(str) {
112
+ if (!str) {
113
+ return str;
114
+ }
115
+ return str.replace(/"/g, "");
116
+ }
117
+ var init_textProcessing = __esm({
118
+ "src/utils/textProcessing.ts"() {
119
+ "use strict";
120
+ }
121
+ });
122
+
40
123
  // src/utils/valueFormatter.ts
41
124
  import {
42
125
  endOfWeek,
@@ -73,6 +156,7 @@ var DATE_FORMAT_TYPES, NUMBER_FORMAT_TYPES, valueFormatter, quillFormat, quillAu
73
156
  var init_valueFormatter = __esm({
74
157
  "src/utils/valueFormatter.ts"() {
75
158
  "use strict";
159
+ init_textProcessing();
76
160
  DATE_FORMAT_TYPES = [
77
161
  "yyyy",
78
162
  "MMM_yyyy",
@@ -235,7 +319,7 @@ var init_valueFormatter = __esm({
235
319
  if (typeof value === "object") {
236
320
  return JSON.stringify(value);
237
321
  }
238
- return value.toString();
322
+ return formatIdentifierLabel(value.toString());
239
323
  };
240
324
  formatterDollar = new Intl.NumberFormat("en-US", {
241
325
  style: "currency",
@@ -508,78 +592,6 @@ var init_ast = __esm({
508
592
  }
509
593
  });
510
594
 
511
- // src/utils/textProcessing.ts
512
- function capitalize(text) {
513
- return text.charAt(0).toUpperCase() + text.slice(1);
514
- }
515
- function matchCasing(text, template) {
516
- if (!text || !template) {
517
- return text ?? "";
518
- }
519
- const isTitleCase = (str) => /^[A-Z][a-z]*([A-Z][a-z]*)*$/.test(str);
520
- const isCamelCase = (str) => /^[a-z]+([A-Z][a-z]*)*$/.test(str);
521
- const isSnakeCase = (str) => /^[a-z0-9]+(_[a-z0-9]+)*$/.test(str);
522
- const isAllLowerCase = (str) => /^[a-z]+$/.test(str);
523
- const isAllUpperCase = (str) => /^[A-Z]+$/.test(str);
524
- const isCapitalized = (str) => /^[A-Z][a-z]*$/.test(str);
525
- const isScreamingSnakeCase = (str) => /^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$/.test(str);
526
- const toTitleCase = (str) => str.toLowerCase().replace(/\b\w/g, (char) => char.toUpperCase());
527
- const toCamelCase = (str) => str.replace(/_./g, (match) => match.charAt(1).toUpperCase()).toLowerCase();
528
- const toSnakeCase = (str) => str.replace(/[A-Z]/g, (match) => `_${match.toLowerCase()}`);
529
- const toLowerCase = (str) => str.toLowerCase();
530
- const toUpperCase = (str) => str.toUpperCase();
531
- const toCapitalized = (str) => str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
532
- const toScreamingSnakeCase = (str) => str.replace(/([A-Z])/g, "_$1").replace(/^_/, "").toUpperCase();
533
- if (isTitleCase(template)) {
534
- return toTitleCase(text);
535
- } else if (isCamelCase(template)) {
536
- return toCamelCase(text);
537
- } else if (isSnakeCase(template)) {
538
- return toSnakeCase(text);
539
- } else if (isAllLowerCase(template)) {
540
- return toLowerCase(text);
541
- } else if (isAllUpperCase(template)) {
542
- return toUpperCase(text);
543
- } else if (isCapitalized(template)) {
544
- return toCapitalized(text);
545
- } else if (isScreamingSnakeCase(template)) {
546
- return toScreamingSnakeCase(text);
547
- } else {
548
- return text;
549
- }
550
- }
551
- function snakeCaseToTitleCase(str) {
552
- if (!str) {
553
- return str;
554
- }
555
- return str.toString().split(/_| /).map(
556
- (word) => word === "id" ? "ID" : word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()
557
- ).join(" ");
558
- }
559
- function snakeAndCamelCaseToTitleCase(str) {
560
- if (!str || typeof str !== "string") {
561
- return str;
562
- }
563
- if (str.includes("_")) {
564
- return str.split(/_| /).map((word) => word === "id" ? "ID" : capitalize(word)).join(" ");
565
- } else {
566
- const text = str.replace(/([a-z])([A-Z])/g, "$1 $2");
567
- const newText = text.split(" ").map((word) => word === "Id" || word === "id" ? "ID" : capitalize(word)).join(" ");
568
- return newText;
569
- }
570
- }
571
- function removeDoubleQuotes(str) {
572
- if (!str) {
573
- return str;
574
- }
575
- return str.replace(/"/g, "");
576
- }
577
- var init_textProcessing = __esm({
578
- "src/utils/textProcessing.ts"() {
579
- "use strict";
580
- }
581
- });
582
-
583
595
  // src/components/ReportBuilder/bigDateMap.ts
584
596
  function cleanDateFieldName(fieldName) {
585
597
  if (!fieldName) return void 0;
@@ -15133,6 +15145,63 @@ function getDateString(value, dateRange, dateBucket, databaseType) {
15133
15145
  function isDateField(fieldType) {
15134
15146
  return fieldType === "date" || fieldType === "datetime" || fieldType === "timestamp" || fieldType === "timestamptz" || fieldType === "yyyy" || fieldType === "MMM_yyyy" || fieldType === "MMM_dd" || fieldType === "MMM_dd_yyyy" || fieldType === "MMM_dd_hh:mm_ap_pm" || fieldType === "hh_ap_pm";
15135
15147
  }
15148
+ function getExclusiveDateBucketRange(startInput, bucket) {
15149
+ const parsed = startInput instanceof Date ? startInput : new Date(startInput);
15150
+ if (Number.isNaN(parsed.getTime())) {
15151
+ throw new Error(`Invalid bucket start date: ${String(startInput)}`);
15152
+ }
15153
+ let start;
15154
+ let endExclusive;
15155
+ switch (bucket) {
15156
+ case "day": {
15157
+ start = new Date(
15158
+ Date.UTC(
15159
+ parsed.getUTCFullYear(),
15160
+ parsed.getUTCMonth(),
15161
+ parsed.getUTCDate()
15162
+ )
15163
+ );
15164
+ endExclusive = new Date(start);
15165
+ endExclusive.setUTCDate(endExclusive.getUTCDate() + 1);
15166
+ break;
15167
+ }
15168
+ case "week": {
15169
+ const day = parsed.getUTCDay();
15170
+ start = new Date(
15171
+ Date.UTC(
15172
+ parsed.getUTCFullYear(),
15173
+ parsed.getUTCMonth(),
15174
+ parsed.getUTCDate() - (day + 6) % 7
15175
+ )
15176
+ );
15177
+ endExclusive = new Date(start);
15178
+ endExclusive.setUTCDate(endExclusive.getUTCDate() + 7);
15179
+ break;
15180
+ }
15181
+ case "month": {
15182
+ start = new Date(
15183
+ Date.UTC(parsed.getUTCFullYear(), parsed.getUTCMonth(), 1)
15184
+ );
15185
+ endExclusive = new Date(
15186
+ Date.UTC(parsed.getUTCFullYear(), parsed.getUTCMonth() + 1, 1)
15187
+ );
15188
+ break;
15189
+ }
15190
+ case "year": {
15191
+ start = new Date(Date.UTC(parsed.getUTCFullYear(), 0, 1));
15192
+ endExclusive = new Date(Date.UTC(parsed.getUTCFullYear() + 1, 0, 1));
15193
+ break;
15194
+ }
15195
+ default: {
15196
+ const _exhaustive = bucket;
15197
+ throw new Error(`Unsupported date bucket: ${String(_exhaustive)}`);
15198
+ }
15199
+ }
15200
+ return {
15201
+ start: start.toISOString(),
15202
+ endExclusive: endExclusive.toISOString()
15203
+ };
15204
+ }
15136
15205
  var init_dates = __esm({
15137
15206
  "src/utils/dates.ts"() {
15138
15207
  "use strict";
@@ -17252,7 +17321,7 @@ async function generatePivotWithSQL({
17252
17321
  client,
17253
17322
  task: "pivot-template",
17254
17323
  metadata: {
17255
- clientId: client.clientId,
17324
+ clientId: client.id,
17256
17325
  pivot: pivotConfig,
17257
17326
  reportId: report?.id !== "__quillTempReport" ? report?.id : void 0,
17258
17327
  itemQuery: reportBuilderState ? void 0 : report?.queryString,
@@ -19077,7 +19146,7 @@ var init_tableProcessing = __esm({
19077
19146
  metadata: {
19078
19147
  reportBuilderState,
19079
19148
  stringColumns: stringColumns.map((col) => col.field),
19080
- clientId: client.clientId,
19149
+ clientId: client.id,
19081
19150
  databaseType: client.databaseType?.toLowerCase() || "postgresql",
19082
19151
  customFields,
19083
19152
  filters: void 0,
@@ -19268,7 +19337,7 @@ var init_tableProcessing = __esm({
19268
19337
  metadata: {
19269
19338
  reportBuilderState,
19270
19339
  columns: stringNames,
19271
- clientId: client.publicKey,
19340
+ clientId: client.id,
19272
19341
  databaseType: client.databaseType,
19273
19342
  customFieldsByTable: customFields,
19274
19343
  useNewNodeSql: true,
@@ -19283,7 +19352,7 @@ var init_tableProcessing = __esm({
19283
19352
  task: "query",
19284
19353
  metadata: {
19285
19354
  query: countQuery,
19286
- clientId: client.publicKey,
19355
+ clientId: client.id,
19287
19356
  databaseType: client.databaseType,
19288
19357
  customFieldsByTable: customFields,
19289
19358
  useNewNodeSql: true,
@@ -19343,7 +19412,7 @@ var init_tableProcessing = __esm({
19343
19412
  metadata: {
19344
19413
  reportBuilderState,
19345
19414
  stringColumns: columns,
19346
- clientId: client.clientId,
19415
+ clientId: client.id,
19347
19416
  databaseType: client.databaseType?.toLowerCase() || "postgresql",
19348
19417
  customFields,
19349
19418
  filters,
@@ -19393,7 +19462,7 @@ var init_tableProcessing = __esm({
19393
19462
  task: "query",
19394
19463
  metadata: {
19395
19464
  query,
19396
- clientId: client.publicKey,
19465
+ clientId: client.id,
19397
19466
  databaseType: client.databaseType,
19398
19467
  customFieldsByTable: customFields,
19399
19468
  useNewNodeSql: true,
@@ -19505,7 +19574,7 @@ var init_tableProcessing = __esm({
19505
19574
  task: "query",
19506
19575
  metadata: {
19507
19576
  query,
19508
- clientId: client.publicKey,
19577
+ clientId: client.id,
19509
19578
  databaseType: client.databaseType,
19510
19579
  customFieldsByTable: customFields,
19511
19580
  useNewNodeSql: true,
@@ -19634,7 +19703,7 @@ var init_tableProcessing = __esm({
19634
19703
  metadata: {
19635
19704
  query,
19636
19705
  filterMap,
19637
- clientId: client.publicKey,
19706
+ clientId: client.id,
19638
19707
  databaseType: client?.databaseType,
19639
19708
  customFieldsByTable: customFields,
19640
19709
  additionalProcessing: processing,
@@ -19669,7 +19738,7 @@ var init_tableProcessing = __esm({
19669
19738
  task: "log-broken-query",
19670
19739
  metadata: {
19671
19740
  query,
19672
- clientId: client.clientId,
19741
+ clientId: client.id,
19673
19742
  error: parsingError
19674
19743
  },
19675
19744
  getToken
@@ -19780,7 +19849,7 @@ var init_tableProcessing = __esm({
19780
19849
  metadata: {
19781
19850
  dashboardItemId: reportId,
19782
19851
  filters: minimalFilters,
19783
- clientId: client?.publicKey,
19852
+ clientId: client?.id,
19784
19853
  databaseType: client?.databaseType,
19785
19854
  additionalProcessing: updatedProcessing,
19786
19855
  forcePagination: true,
@@ -19853,7 +19922,7 @@ var init_tableProcessing = __esm({
19853
19922
  rowCountOnly,
19854
19923
  customFields,
19855
19924
  tenants,
19856
- clientId: client.clientId,
19925
+ clientId: client.id,
19857
19926
  databaseType: client.databaseType?.toLowerCase() || "postgresql",
19858
19927
  dashboardName,
19859
19928
  ...reportId ? {
@@ -20024,7 +20093,7 @@ async function testSqlViewState(client, referencedTables, getToken) {
20024
20093
  task: "test-view",
20025
20094
  metadata: {
20026
20095
  tables: [table],
20027
- clientId: client.clientId
20096
+ clientId: client.id
20028
20097
  },
20029
20098
  getToken
20030
20099
  });
@@ -20033,7 +20102,7 @@ async function testSqlViewState(client, referencedTables, getToken) {
20033
20102
  metadata: {
20034
20103
  table,
20035
20104
  task: "set-broken-view",
20036
- clientId: client.clientId
20105
+ clientId: client.id
20037
20106
  }
20038
20107
  };
20039
20108
  quillFetch({
@@ -20143,7 +20212,7 @@ async function* quillStream({
20143
20212
  body: JSON.stringify({
20144
20213
  metadata: {
20145
20214
  task,
20146
- clientId: client.clientId,
20215
+ clientId: client.id,
20147
20216
  ...metadata
20148
20217
  }
20149
20218
  }),
@@ -20372,7 +20441,7 @@ async function getData(client, cloudQueryEndpoint, noCred, hostedRequestBody, cl
20372
20441
  body: method === "POST" ? JSON.stringify({
20373
20442
  ...cloudRequestBody,
20374
20443
  ...{
20375
- publicKey: client?.publicKey
20444
+ publicKey: client?.id
20376
20445
  }
20377
20446
  }) : null,
20378
20447
  signal: abortSignal
@@ -20401,7 +20470,7 @@ async function fetchSqlQuery(ast, client, getToken, formData) {
20401
20470
  client,
20402
20471
  task: "sqlify",
20403
20472
  metadata: {
20404
- clientId: client.clientId,
20473
+ clientId: client.id,
20405
20474
  useNewNodeSql: true,
20406
20475
  ast: { ...ast, where }
20407
20476
  },
@@ -20422,7 +20491,7 @@ async function fetchSqlQueryFromState(reportBuilderState, client, getToken, data
20422
20491
  client,
20423
20492
  task: "sqlify",
20424
20493
  metadata: {
20425
- clientId: client.clientId,
20494
+ clientId: client.id,
20426
20495
  useNewNodeSql: true,
20427
20496
  ast
20428
20497
  },
@@ -20439,7 +20508,7 @@ async function fetchQueryDateRangesFromState(reportBuilderState, columns, client
20439
20508
  client,
20440
20509
  task: "report-builder-date-ranges",
20441
20510
  metadata: {
20442
- clientId: client.clientId,
20511
+ clientId: client.id,
20443
20512
  reportBuilderState,
20444
20513
  dateColumns: columns,
20445
20514
  databaseType: databaseType || "postgresql",
@@ -20557,7 +20626,7 @@ var init_dataFetcher = __esm({
20557
20626
  body: JSON.stringify({
20558
20627
  metadata: {
20559
20628
  task,
20560
- clientId: client.clientId,
20629
+ clientId: client.id ?? client.clientId,
20561
20630
  ...metadata
20562
20631
  }
20563
20632
  }),
@@ -21037,7 +21106,7 @@ import {
21037
21106
  useEffect as useEffect19,
21038
21107
  useState as useState26,
21039
21108
  useMemo as useMemo19,
21040
- useRef as useRef15
21109
+ useRef as useRef16
21041
21110
  } from "react";
21042
21111
 
21043
21112
  // src/Chart.tsx
@@ -21046,7 +21115,7 @@ import {
21046
21115
  useEffect as useEffect16,
21047
21116
  useContext as useContext17,
21048
21117
  useMemo as useMemo16,
21049
- useRef as useRef13
21118
+ useRef as useRef14
21050
21119
  } from "react";
21051
21120
 
21052
21121
  // src/utils/csv.ts
@@ -21528,7 +21597,7 @@ async function getDashboard(dashboardName, client, getToken, tenants, flags) {
21528
21597
  task: "dashboard",
21529
21598
  metadata: {
21530
21599
  name: dashboardName,
21531
- clientId: client.publicKey,
21600
+ clientId: client.id,
21532
21601
  databaseType: client.databaseType,
21533
21602
  useNewNodeSql: true,
21534
21603
  tenants,
@@ -21903,7 +21972,7 @@ function createPivotTemplateMetadata({
21903
21972
  reportId,
21904
21973
  dashboardItemId: reportId,
21905
21974
  ...draftSessionId ? { draftSessionId: String(draftSessionId).trim() } : {},
21906
- clientId: client.publicKey,
21975
+ clientId: client.id,
21907
21976
  databaseType: client.databaseType,
21908
21977
  filters: removeFilterOptions(filters),
21909
21978
  additionalProcessing: normalizedAdditionalProcessing,
@@ -22220,7 +22289,7 @@ async function fetchReportRows({
22220
22289
  task: "report",
22221
22290
  metadata: {
22222
22291
  reportId,
22223
- clientId: client.publicKey,
22292
+ clientId: client.id,
22224
22293
  databaseType: client.databaseType,
22225
22294
  filters: filters.map((filter) => ({ ...filter, options: void 0 })),
22226
22295
  useNewNodeSql: true,
@@ -22290,7 +22359,7 @@ async function fetchReport({
22290
22359
  reportId,
22291
22360
  dashboardItemId: reportId,
22292
22361
  ...draftSessionId ? { draftSessionId: String(draftSessionId).trim() } : {},
22293
- clientId: client.publicKey,
22362
+ clientId: client.id,
22294
22363
  databaseType: client.databaseType,
22295
22364
  filters: filters.map((filter) => ({ ...filter, options: void 0 })),
22296
22365
  customFields,
@@ -22427,7 +22496,7 @@ async function fetchReportName({
22427
22496
  task: "report-name",
22428
22497
  metadata: {
22429
22498
  reportId,
22430
- clientId: client.publicKey,
22499
+ clientId: client.id,
22431
22500
  databaseType: client.databaseType,
22432
22501
  tenants
22433
22502
  },
@@ -22451,7 +22520,7 @@ async function fetchReportRowCount(reportId, client, getToken, tenants, flags, u
22451
22520
  metadata: {
22452
22521
  reportId,
22453
22522
  dashboardItemId: reportId,
22454
- clientId: client.publicKey,
22523
+ clientId: client.id,
22455
22524
  databaseType: client.databaseType,
22456
22525
  filters: filters.map((filter) => ({ ...filter, options: void 0 })),
22457
22526
  customFields,
@@ -22481,7 +22550,7 @@ async function saveReport({
22481
22550
  tenants,
22482
22551
  draftSessionId
22483
22552
  }) {
22484
- const { publicKey, databaseType } = client;
22553
+ const { id, databaseType } = client;
22485
22554
  const {
22486
22555
  reportBuilderState,
22487
22556
  queryString,
@@ -22521,7 +22590,7 @@ async function saveReport({
22521
22590
  ...dashboardItemId ? { reportId: dashboardItemId } : {},
22522
22591
  ...draftSessionId ? { draftSessionId: String(draftSessionId).trim() } : {},
22523
22592
  // Remove useNewNodeSql since backend will handle conversion
22524
- clientId: publicKey,
22593
+ clientId: id,
22525
22594
  tenants,
22526
22595
  // Only include adminMode for 'create' task, not 'create-report'
22527
22596
  ...isCreateTask && { adminMode },
@@ -23335,7 +23404,6 @@ var getSchemaInfo = async ({
23335
23404
  getToken,
23336
23405
  eventTracking
23337
23406
  }) => {
23338
- const { publicKey } = client;
23339
23407
  let customFieldsByTableUnique = null;
23340
23408
  if (client.featureFlags?.customFieldsEnabled && tenants && tenants[0] !== "QUILL_ALL_TENANTS" && tenants.length === 1 && (typeof tenants[0] !== "object" || tenants[0].tenantIds?.[0] !== "QUILL_ALL_TENANTS" && tenants[0].tenantIds?.length === 1)) {
23341
23409
  try {
@@ -23354,13 +23422,13 @@ var getSchemaInfo = async ({
23354
23422
  client,
23355
23423
  task: "schema",
23356
23424
  metadata: {
23357
- clientId: publicKey,
23425
+ clientId: client.id,
23358
23426
  removeCustomerField: true,
23359
23427
  removeCustomFieldRef: true,
23360
23428
  tableIds,
23361
23429
  customFieldsByTable: customFieldsByTableUnique,
23362
23430
  useNewCustomFields: true,
23363
- gatherSchemaData: "665610862cf7a3000be66453" === publicKey ? true : false,
23431
+ gatherSchemaData: "665610862cf7a3000be66453" === client.id ? true : false,
23364
23432
  // TODO: this should be a feature flag on the client
23365
23433
  tenants
23366
23434
  },
@@ -24477,7 +24545,7 @@ var CacheCab = class {
24477
24545
  task: "report",
24478
24546
  metadata: {
24479
24547
  reportId,
24480
- clientId: client.publicKey,
24548
+ clientId: client.id,
24481
24549
  databaseType: client.databaseType,
24482
24550
  filters: adjusted,
24483
24551
  additionalProcessing: { page: { rowsPerPage: 1e3, rowsPerRequest: 1e5 } },
@@ -24616,7 +24684,7 @@ var CacheCab = class {
24616
24684
  );
24617
24685
  const keyParts = [
24618
24686
  reportId,
24619
- client.publicKey,
24687
+ client.id,
24620
24688
  client.databaseType,
24621
24689
  hashString(stableStringify(canonicalizeForKey(tenants ?? null))),
24622
24690
  hashString(stableStringify(canonicalizeForKey(flags ?? null))),
@@ -25254,12 +25322,11 @@ var ContextProvider = ({
25254
25322
  typeof window !== "undefined" && sessionStorage ? JSON.parse(sessionStorage.getItem("quill-client") ?? "null") : null
25255
25323
  );
25256
25324
  const populatedClient = useMemo(() => {
25257
- if (!client || client.clientId !== publicKey) return null;
25325
+ if (!client || client.id !== publicKey) return null;
25258
25326
  return {
25259
25327
  ...client,
25260
- publicKey,
25261
- _id: publicKey,
25262
25328
  id: publicKey,
25329
+ clientId: publicKey,
25263
25330
  queryHeaders,
25264
25331
  queryEndpoint,
25265
25332
  streamEndpoint,
@@ -25422,7 +25489,7 @@ var ContextProvider = ({
25422
25489
  try {
25423
25490
  const result = await quillFetch({
25424
25491
  client: {
25425
- clientId: publicKey,
25492
+ id: publicKey,
25426
25493
  queryEndpoint,
25427
25494
  queryHeaders,
25428
25495
  withCredentials: !!withCredentials
@@ -25544,7 +25611,7 @@ var ContextProvider = ({
25544
25611
  try {
25545
25612
  const resp = await quillFetch({
25546
25613
  client: {
25547
- clientId: publicKey,
25614
+ id: publicKey,
25548
25615
  queryEndpoint,
25549
25616
  queryHeaders,
25550
25617
  withCredentials: !!withCredentials
@@ -25552,7 +25619,7 @@ var ContextProvider = ({
25552
25619
  task: fetchRows ? "report" : "report-info",
25553
25620
  metadata: {
25554
25621
  reportId,
25555
- clientId: populatedClient.publicKey,
25622
+ clientId: populatedClient.id,
25556
25623
  useNewNodeSql: true,
25557
25624
  filters: filters?.map((f) => ({ ...f, options: void 0 })),
25558
25625
  additionalProcessing,
@@ -25735,7 +25802,7 @@ var ContextProvider = ({
25735
25802
  try {
25736
25803
  const result = await quillFetch({
25737
25804
  client: {
25738
- clientId: publicKey,
25805
+ id: publicKey,
25739
25806
  queryEndpoint,
25740
25807
  queryHeaders,
25741
25808
  withCredentials: !!withCredentials
@@ -25955,7 +26022,7 @@ var ContextProvider = ({
25955
26022
  });
25956
26023
  return curDashboardConfig;
25957
26024
  }
25958
- if (!populatedClient || !populatedClient.publicKey) {
26025
+ if (!populatedClient || !populatedClient.id) {
25959
26026
  return curDashboardConfig;
25960
26027
  }
25961
26028
  if (dashboardName === null || dashboardName === void 0)
@@ -26109,7 +26176,7 @@ var ContextProvider = ({
26109
26176
  try {
26110
26177
  const result = await quillFetch({
26111
26178
  client: {
26112
- clientId: publicKey2,
26179
+ id: publicKey2,
26113
26180
  queryEndpoint,
26114
26181
  queryHeaders,
26115
26182
  withCredentials: !!withCredentials
@@ -26652,8 +26719,7 @@ var ContextProvider = ({
26652
26719
  withCredentials: withCredentials ?? false,
26653
26720
  databaseType: envClient.databaseType,
26654
26721
  name: envClient.name,
26655
- clientId: publicKey2,
26656
- publicKey: publicKey2,
26722
+ id: publicKey2,
26657
26723
  featureFlags: envClient.featureFlags,
26658
26724
  clerkOrgId: envClient.clerkOrgId,
26659
26725
  allTenantTypes: hydratedTenantTypes
@@ -26725,16 +26791,16 @@ var ContextProvider = ({
26725
26791
  }, [publicKey]);
26726
26792
  useEffect(() => {
26727
26793
  if (!hasHandledInitialPopulatedClient.current) {
26728
- if (!populatedClient?.publicKey && !populatedClient?.currentTenants) {
26794
+ if (!populatedClient?.id && !populatedClient?.currentTenants) {
26729
26795
  return;
26730
26796
  }
26731
26797
  hasHandledInitialPopulatedClient.current = true;
26732
- currentPublicKey.current = populatedClient?.publicKey ?? null;
26798
+ currentPublicKey.current = populatedClient?.id ?? null;
26733
26799
  currentTenant.current = populatedClient?.currentTenants ?? null;
26734
26800
  return;
26735
26801
  }
26736
26802
  let publicKeyChanged = false;
26737
- if (populatedClient?.publicKey && currentPublicKey.current !== populatedClient?.publicKey) {
26803
+ if (populatedClient?.id && currentPublicKey.current !== populatedClient?.id) {
26738
26804
  publicKeyChanged = true;
26739
26805
  dispatch({ type: "CLEAR_DASHBOARDS" });
26740
26806
  dashboardFiltersDispatch({ type: "CLEAR_DASHBOARD_FILTERS" });
@@ -26743,7 +26809,7 @@ var ContextProvider = ({
26743
26809
  backfilledDashboards.current.clear();
26744
26810
  if (isAdmin) {
26745
26811
  setIsDashboardsLoading(true);
26746
- fetchDashboards(populatedClient?.publicKey);
26812
+ fetchDashboards(populatedClient?.id);
26747
26813
  } else {
26748
26814
  setIsDashboardsLoading(false);
26749
26815
  }
@@ -26775,17 +26841,17 @@ var ContextProvider = ({
26775
26841
  })
26776
26842
  );
26777
26843
  }
26778
- if (populatedClient?.currentTenants && populatedClient?.publicKey) {
26844
+ if (populatedClient?.currentTenants && populatedClient?.id) {
26779
26845
  const tenant = typeof populatedClient?.currentTenants[0] === "object" ? populatedClient?.currentTenants[0]?.tenantField : void 0;
26780
26846
  const tenantIds = tenant && typeof populatedClient?.currentTenants[0] === "object" ? populatedClient?.currentTenants[0]?.tenantIds : populatedClient?.currentTenants;
26781
26847
  eventTracking?.setUser?.({
26782
- clientId: populatedClient.publicKey,
26848
+ clientId: populatedClient.id,
26783
26849
  clerkOrgId: populatedClient.clerkOrgId,
26784
26850
  tenant,
26785
26851
  tenantIds
26786
26852
  });
26787
26853
  }
26788
- }, [populatedClient?.currentTenants, populatedClient?.publicKey]);
26854
+ }, [populatedClient?.currentTenants, populatedClient?.id]);
26789
26855
  if (!theme) {
26790
26856
  return null;
26791
26857
  }
@@ -27100,7 +27166,7 @@ var useDashboardInternal = (dashboardName, customFilters) => {
27100
27166
  });
27101
27167
  const body = {
27102
27168
  task: "set-section-order",
27103
- clientId: client.clientId,
27169
+ clientId: client.id,
27104
27170
  dashboardName,
27105
27171
  sectionOrder
27106
27172
  };
@@ -27328,7 +27394,7 @@ var useDashboards = () => {
27328
27394
  dateFilter,
27329
27395
  name: name2.trim(),
27330
27396
  task: "edit-dashboard",
27331
- clientId: clientId ?? client.clientId,
27397
+ clientId: clientId ?? client.id,
27332
27398
  tenantKeys: dashboardOwners
27333
27399
  };
27334
27400
  try {
@@ -27403,7 +27469,7 @@ var useDashboards = () => {
27403
27469
  initialCacheDateRange,
27404
27470
  name: name2.trim(),
27405
27471
  task: "edit-dashboard",
27406
- clientId: clientId ?? client.clientId,
27472
+ clientId: clientId ?? client.id,
27407
27473
  tenantKeys
27408
27474
  };
27409
27475
  try {
@@ -27581,7 +27647,7 @@ var useDashboards = () => {
27581
27647
  client,
27582
27648
  task: "delete-dashboard",
27583
27649
  metadata: {
27584
- clientId: client.clientId,
27650
+ clientId: client.id,
27585
27651
  databaseType: client.databaseType,
27586
27652
  name: name2
27587
27653
  }
@@ -28426,7 +28492,7 @@ async function getExportData(client, dashboardFilters, reportId, getToken, event
28426
28492
  metadata: {
28427
28493
  reportId,
28428
28494
  dashboardItemId: reportId,
28429
- clientId: client.publicKey,
28495
+ clientId: client.id,
28430
28496
  databaseType: client?.databaseType,
28431
28497
  filters: minimalFilters,
28432
28498
  useNewNodeSql: true,
@@ -29199,6 +29265,69 @@ function linspace(start, end, num) {
29199
29265
  }
29200
29266
  return result;
29201
29267
  }
29268
+ function stableColorIndex(field) {
29269
+ let hash = 0;
29270
+ for (const character of field.replace("comparison_", "")) {
29271
+ hash = Math.imul(hash, 31) + character.charCodeAt(0) >>> 0;
29272
+ }
29273
+ return hash;
29274
+ }
29275
+ function assignStableSeriesColors(fields, colors, knownFields = fields) {
29276
+ const normalize2 = (values) => [
29277
+ ...new Set(
29278
+ values.filter((field) => typeof field === "string").map((field) => field.replace("comparison_", ""))
29279
+ )
29280
+ ];
29281
+ const uniqueFields = normalize2(fields);
29282
+ const universe = normalize2([...knownFields, ...fields]);
29283
+ const result = /* @__PURE__ */ new Map();
29284
+ if (universe.length === 0) {
29285
+ return result;
29286
+ }
29287
+ if (!colors.length) {
29288
+ for (const field of uniqueFields) {
29289
+ result.set(field, "gray");
29290
+ }
29291
+ return result;
29292
+ }
29293
+ const palette = colors.length >= universe.length ? colors : generateArrayFromColor(colors, universe.length);
29294
+ const ordered = [...universe].sort((a, b) => {
29295
+ const diff = stableColorIndex(a) - stableColorIndex(b);
29296
+ return diff !== 0 ? diff : a.localeCompare(b);
29297
+ });
29298
+ const usedIndices = /* @__PURE__ */ new Set();
29299
+ const deferred = [];
29300
+ const assigned = /* @__PURE__ */ new Map();
29301
+ for (const field of ordered) {
29302
+ const preferred = stableColorIndex(field) % palette.length;
29303
+ if (!usedIndices.has(preferred)) {
29304
+ usedIndices.add(preferred);
29305
+ assigned.set(field, palette[preferred]);
29306
+ } else {
29307
+ deferred.push(field);
29308
+ }
29309
+ }
29310
+ for (const field of deferred) {
29311
+ const preferred = stableColorIndex(field) % palette.length;
29312
+ let found = false;
29313
+ for (let offset = 1; offset < palette.length; offset++) {
29314
+ const idx = (preferred + offset) % palette.length;
29315
+ if (!usedIndices.has(idx)) {
29316
+ usedIndices.add(idx);
29317
+ assigned.set(field, palette[idx]);
29318
+ found = true;
29319
+ break;
29320
+ }
29321
+ }
29322
+ if (!found) {
29323
+ assigned.set(field, palette[preferred]);
29324
+ }
29325
+ }
29326
+ for (const field of uniqueFields) {
29327
+ result.set(field, assigned.get(field));
29328
+ }
29329
+ return result;
29330
+ }
29202
29331
  function selectColor(element, colors, index) {
29203
29332
  if (!element?.field) return "gray";
29204
29333
  const isComparison = element.field.includes("comparison_");
@@ -31494,15 +31623,19 @@ var QuillPortal = ({
31494
31623
  };
31495
31624
 
31496
31625
  // src/components/Chart/CustomLegend.tsx
31626
+ init_textProcessing();
31497
31627
  import { jsx as jsx27, jsxs as jsxs19 } from "react/jsx-runtime";
31498
31628
  var getLegendLabel = (entry) => {
31499
31629
  const label = entry?.payload?.name ?? entry?.value ?? entry?.dataKey ?? "";
31500
- return typeof label === "string" ? label : String(label ?? "");
31630
+ return snakeAndCamelCaseToTitleCase(
31631
+ typeof label === "string" ? label : String(label ?? "")
31632
+ );
31501
31633
  };
31502
31634
  var LegendItem = ({
31503
31635
  entry,
31504
31636
  index,
31505
- theme
31637
+ theme,
31638
+ onClick
31506
31639
  }) => /* @__PURE__ */ jsx27(
31507
31640
  "div",
31508
31641
  {
@@ -31511,30 +31644,37 @@ var LegendItem = ({
31511
31644
  alignItems: "baseline",
31512
31645
  marginRight: "1rem"
31513
31646
  },
31514
- children: /* @__PURE__ */ jsxs19("div", { style: { display: "flex", flexDirection: "row", alignItems: "center" }, children: [
31515
- /* @__PURE__ */ jsx27(
31516
- "svg",
31517
- {
31518
- style: { marginRight: "0.5rem" },
31519
- width: "16",
31520
- height: "16",
31521
- viewBox: "0 0 16 16",
31522
- children: /* @__PURE__ */ jsx27("rect", { width: "16", height: "16", rx: "3", fill: entry?.color })
31523
- }
31524
- ),
31525
- /* @__PURE__ */ jsx27(
31526
- "span",
31527
- {
31528
- style: {
31529
- color: theme?.secondaryTextColor,
31530
- fontFamily: theme?.fontFamily,
31531
- fontSize: theme?.fontSizeMedium || "14px",
31532
- whiteSpace: "nowrap"
31533
- },
31534
- children: getLegendLabel(entry)
31535
- }
31536
- )
31537
- ] })
31647
+ onClick: () => onClick ? onClick(entry) : void 0,
31648
+ children: /* @__PURE__ */ jsxs19(
31649
+ "div",
31650
+ {
31651
+ style: { display: "flex", flexDirection: "row", alignItems: "center" },
31652
+ children: [
31653
+ /* @__PURE__ */ jsx27(
31654
+ "svg",
31655
+ {
31656
+ style: { marginRight: "0.5rem" },
31657
+ width: "16",
31658
+ height: "16",
31659
+ viewBox: "0 0 16 16",
31660
+ children: /* @__PURE__ */ jsx27("rect", { width: "16", height: "16", rx: "3", fill: entry?.color })
31661
+ }
31662
+ ),
31663
+ /* @__PURE__ */ jsx27(
31664
+ "span",
31665
+ {
31666
+ style: {
31667
+ color: theme?.secondaryTextColor,
31668
+ fontFamily: theme?.fontFamily,
31669
+ fontSize: theme?.fontSizeMedium || "14px",
31670
+ whiteSpace: "nowrap"
31671
+ },
31672
+ children: getLegendLabel(entry)
31673
+ }
31674
+ )
31675
+ ]
31676
+ }
31677
+ )
31538
31678
  },
31539
31679
  `legend-${index}`
31540
31680
  );
@@ -31548,7 +31688,8 @@ var getOuterWidth = (element) => {
31548
31688
  };
31549
31689
  var RenderLegend = ({
31550
31690
  payload,
31551
- limit
31691
+ limit,
31692
+ onClickLegendElement
31552
31693
  }) => {
31553
31694
  const [theme] = useContext5(ThemeContext);
31554
31695
  const [isOpen, setIsOpen] = useState9(false);
@@ -31561,7 +31702,10 @@ var RenderLegend = ({
31561
31702
  const safePayload = payload ?? [];
31562
31703
  const maxItems = limit ?? safePayload.length;
31563
31704
  const measuredLimit = visibleCount ?? maxItems;
31564
- const visiblePayload = safePayload.slice(0, Math.min(maxItems, measuredLimit));
31705
+ const visiblePayload = safePayload.slice(
31706
+ 0,
31707
+ Math.min(maxItems, measuredLimit)
31708
+ );
31565
31709
  const handleOpen = () => setIsOpen(true);
31566
31710
  const handleClose = () => setIsOpen(false);
31567
31711
  useLayoutEffect2(() => {
@@ -31622,7 +31766,6 @@ var RenderLegend = ({
31622
31766
  visibility: "hidden",
31623
31767
  height: 0,
31624
31768
  overflow: "hidden",
31625
- pointerEvents: "none",
31626
31769
  display: "flex",
31627
31770
  alignItems: "center",
31628
31771
  flexWrap: "nowrap",
@@ -31646,7 +31789,15 @@ var RenderLegend = ({
31646
31789
  ref: (element) => {
31647
31790
  itemRefs.current[index] = element;
31648
31791
  },
31649
- children: /* @__PURE__ */ jsx27(LegendItem, { entry, index, theme })
31792
+ children: /* @__PURE__ */ jsx27(
31793
+ LegendItem,
31794
+ {
31795
+ entry,
31796
+ index,
31797
+ theme,
31798
+ onClick: onClickLegendElement
31799
+ }
31800
+ )
31650
31801
  },
31651
31802
  `legend-measure-${index}`
31652
31803
  ))
@@ -31687,7 +31838,8 @@ var RenderLegend = ({
31687
31838
  {
31688
31839
  entry,
31689
31840
  index,
31690
- theme
31841
+ theme,
31842
+ onClick: onClickLegendElement
31691
31843
  },
31692
31844
  `legend-${index}`
31693
31845
  ))
@@ -31734,7 +31886,8 @@ var RenderLegend = ({
31734
31886
  {
31735
31887
  entry,
31736
31888
  index,
31737
- theme
31889
+ theme,
31890
+ onClick: onClickLegendElement
31738
31891
  },
31739
31892
  `legend-popover-${index}`
31740
31893
  ))
@@ -32006,6 +32159,7 @@ var PieChartWrapper = React4.forwardRef(
32006
32159
  containerStyle,
32007
32160
  theme,
32008
32161
  onClickChartElement,
32162
+ onClickLegendElement,
32009
32163
  yAxisFields,
32010
32164
  showLegend = false,
32011
32165
  ...other
@@ -32102,7 +32256,13 @@ var PieChartWrapper = React4.forwardRef(
32102
32256
  paddingBottom: 20,
32103
32257
  fontFamily: theme?.fontFamily
32104
32258
  },
32105
- content: /* @__PURE__ */ jsx28(RenderLegend, { limit: 5 })
32259
+ content: /* @__PURE__ */ jsx28(
32260
+ RenderLegend,
32261
+ {
32262
+ limit: 5,
32263
+ onClickLegendElement
32264
+ }
32265
+ )
32106
32266
  }
32107
32267
  ),
32108
32268
  /* @__PURE__ */ jsx28(
@@ -32745,6 +32905,7 @@ import {
32745
32905
  } from "recharts";
32746
32906
 
32747
32907
  // src/utils/axisFormatter.ts
32908
+ init_textProcessing();
32748
32909
  import { endOfWeek as endOfWeek2, format as format5, getWeek as getWeek2, isValid as isValid5, startOfWeek as startOfWeek5 } from "date-fns";
32749
32910
  import { utcToZonedTime as utcToZonedTime4 } from "date-fns-tz";
32750
32911
  var axisFormatter = ({ value, field, fields }) => {
@@ -32796,7 +32957,7 @@ var formatString2 = (value) => {
32796
32957
  if (typeof value === "object") {
32797
32958
  return JSON.stringify(value);
32798
32959
  }
32799
- return value.toString();
32960
+ return formatIdentifierLabel(value.toString());
32800
32961
  };
32801
32962
  var formatterDecimal2 = new Intl.NumberFormat("en-US", {
32802
32963
  style: "decimal",
@@ -33003,6 +33164,7 @@ function ChartTooltipRow2({
33003
33164
  }
33004
33165
 
33005
33166
  // src/components/Chart/ChartTooltipGroup.tsx
33167
+ init_textProcessing();
33006
33168
  import { jsx as jsx32, jsxs as jsxs23 } from "react/jsx-runtime";
33007
33169
  function ChartTooltipGroup({
33008
33170
  name: name2,
@@ -33037,7 +33199,7 @@ function ChartTooltipGroup({
33037
33199
  paddingBottom: 2,
33038
33200
  textTransform: "capitalize"
33039
33201
  },
33040
- children: name2.replaceAll("_", " ").toLowerCase()
33202
+ children: formatIdentifierLabel(name2)
33041
33203
  }
33042
33204
  ),
33043
33205
  items.map(({ color, value, name: name3 }, idx) => /* @__PURE__ */ jsx32(
@@ -33058,6 +33220,7 @@ function ChartTooltipGroup({
33058
33220
 
33059
33221
  // src/components/Chart/ChartTooltip.tsx
33060
33222
  init_dates();
33223
+ init_textProcessing();
33061
33224
  import { jsx as jsx33, jsxs as jsxs24 } from "react/jsx-runtime";
33062
33225
  var ChartTooltipPrimary = (props) => /* @__PURE__ */ jsxs24(ChartTooltipFrame2, { theme: props.theme, children: [
33063
33226
  /* @__PURE__ */ jsx33(
@@ -33092,7 +33255,7 @@ var ChartTooltipPrimary = (props) => /* @__PURE__ */ jsxs24(ChartTooltipFrame2,
33092
33255
  paddingTop: 2,
33093
33256
  paddingBottom: 2
33094
33257
  },
33095
- children: !isNaN(new Date(props.label)) && props.dateFormatter ? props.dateFormatter(props.label) : !isNaN(new Date(props.label)) ? format6(new Date(props.label), "MMM yyyy") : props.label
33258
+ children: !isNaN(new Date(props.label)) && props.dateFormatter ? props.dateFormatter(props.label) : !isNaN(new Date(props.label)) ? format6(new Date(props.label), "MMM yyyy") : formatIdentifierLabel(props.label)
33096
33259
  }
33097
33260
  )
33098
33261
  }
@@ -33175,7 +33338,7 @@ function reformatComparisonPayload(props, primaryLabel, comparisonLabel) {
33175
33338
  return columnsByKey;
33176
33339
  }
33177
33340
  function getTooltipLabel(props, altTooltipLabel, isDateXAxis) {
33178
- return props.payload.length <= 2 && altTooltipLabel && isDateXAxis ? !isNaN(new Date(altTooltipLabel)) && props.dateFormatter ? props.dateFormatter(altTooltipLabel) : !isNaN(new Date(altTooltipLabel)) ? format6(new Date(altTooltipLabel), "MMM yyyy") : altTooltipLabel : !isNaN(new Date(props.label)) && props.dateFormatter ? props.dateFormatter(props.label) : !isNaN(new Date(props.label)) ? format6(new Date(props.label), "MMM yyyy") : props.label;
33341
+ return props.payload.length <= 2 && altTooltipLabel && isDateXAxis ? !isNaN(new Date(altTooltipLabel)) && props.dateFormatter ? props.dateFormatter(altTooltipLabel) : !isNaN(new Date(altTooltipLabel)) ? format6(new Date(altTooltipLabel), "MMM yyyy") : formatIdentifierLabel(altTooltipLabel) : !isNaN(new Date(props.label)) && props.dateFormatter ? props.dateFormatter(props.label) : !isNaN(new Date(props.label)) ? format6(new Date(props.label), "MMM yyyy") : formatIdentifierLabel(props.label);
33179
33342
  }
33180
33343
  function ChartTooltipComparison(props) {
33181
33344
  const isDateXAxis = isDateFormat2(props.xAxisFormat);
@@ -33431,6 +33594,7 @@ function CustomReferenceLine({
33431
33594
 
33432
33595
  // src/components/Chart/LineChart.tsx
33433
33596
  init_columnProcessing();
33597
+ init_textProcessing();
33434
33598
  import { jsx as jsx35, jsxs as jsxs26 } from "react/jsx-runtime";
33435
33599
  function createLineForEmptyChart(yAxisFields, dateFilter, xAxisField, xAxisFormat) {
33436
33600
  let lineChartData = [];
@@ -33467,6 +33631,8 @@ function LineChart({
33467
33631
  cartesianGridLineColor,
33468
33632
  onClickChartElement = () => {
33469
33633
  },
33634
+ onClickLegendElement = () => {
33635
+ },
33470
33636
  dateFilter,
33471
33637
  referenceLines,
33472
33638
  showLegend = false
@@ -33563,7 +33729,7 @@ function LineChart({
33563
33729
  paddingBottom: 20,
33564
33730
  fontFamily: theme?.fontFamily
33565
33731
  },
33566
- content: /* @__PURE__ */ jsx35(RenderLegend, {})
33732
+ content: /* @__PURE__ */ jsx35(RenderLegend, { onClickLegendElement })
33567
33733
  }
33568
33734
  ),
33569
33735
  /* @__PURE__ */ jsx35(
@@ -33651,7 +33817,9 @@ function LineChart({
33651
33817
  color: p.color || "black",
33652
33818
  chartType: "line",
33653
33819
  dataKey: p.dataKey?.toLocaleString() || "",
33654
- name: name2 || p.name?.toString() || "",
33820
+ name: snakeAndCamelCaseToTitleCase(
33821
+ name2 || p.name?.toString() || ""
33822
+ ),
33655
33823
  payload: p.payload || {},
33656
33824
  type: p.type || "none",
33657
33825
  unit: "string",
@@ -33744,6 +33912,7 @@ function LineChart({
33744
33912
  Area,
33745
33913
  {
33746
33914
  type: "linear",
33915
+ name: elem.label || elem.field,
33747
33916
  dataKey: elem.field,
33748
33917
  stroke: getCustomColor(index, elem.field) ?? selectColor(elem, colors, index - numComparisons),
33749
33918
  fill: `url(#${uniqueId})`,
@@ -33774,6 +33943,7 @@ import {
33774
33943
  Tooltip as Tooltip3
33775
33944
  } from "recharts";
33776
33945
  import { useMemo as useMemo6 } from "react";
33946
+ init_textProcessing();
33777
33947
  import { jsx as jsx36, jsxs as jsxs27 } from "react/jsx-runtime";
33778
33948
  function RadarChart({
33779
33949
  colors,
@@ -33789,6 +33959,8 @@ function RadarChart({
33789
33959
  isAnimationActive = true,
33790
33960
  onClickChartElement = () => {
33791
33961
  },
33962
+ onClickLegendElement = () => {
33963
+ },
33792
33964
  dateFilter,
33793
33965
  showLegend = false
33794
33966
  }) {
@@ -33882,7 +34054,7 @@ function RadarChart({
33882
34054
  paddingBottom: 20,
33883
34055
  fontFamily: theme?.fontFamily
33884
34056
  },
33885
- content: /* @__PURE__ */ jsx36(RenderLegend, {})
34057
+ content: /* @__PURE__ */ jsx36(RenderLegend, { onClickLegendElement })
33886
34058
  }
33887
34059
  ),
33888
34060
  /* @__PURE__ */ jsx36(
@@ -33917,7 +34089,9 @@ function RadarChart({
33917
34089
  color: p.color || "black",
33918
34090
  chartType: "radar",
33919
34091
  dataKey: p.dataKey?.toLocaleString() || "",
33920
- name: name2 || p.name?.toString() || "",
34092
+ name: snakeAndCamelCaseToTitleCase(
34093
+ name2 || p.name?.toString() || ""
34094
+ ),
33921
34095
  payload: p.payload || {},
33922
34096
  type: p.type || "none",
33923
34097
  unit: "string",
@@ -34034,6 +34208,10 @@ var CustomBar = memo((props) => {
34034
34208
  width: rawWidth,
34035
34209
  height: rawHeight,
34036
34210
  fill,
34211
+ fillOpacity,
34212
+ stroke,
34213
+ strokeWidth,
34214
+ style,
34037
34215
  yAxisFields = [],
34038
34216
  dataKey,
34039
34217
  payload = {},
@@ -34091,18 +34269,43 @@ var CustomBar = memo((props) => {
34091
34269
  rawY,
34092
34270
  radius
34093
34271
  ]);
34094
- return /* @__PURE__ */ jsx37("path", { d: path, fill });
34272
+ return /* @__PURE__ */ jsx37(
34273
+ "path",
34274
+ {
34275
+ d: path,
34276
+ fill,
34277
+ fillOpacity,
34278
+ stroke,
34279
+ strokeWidth,
34280
+ style
34281
+ }
34282
+ );
34095
34283
  });
34096
34284
  CustomBar.displayName = "CustomBar";
34097
34285
  var CustomBar_default = CustomBar;
34098
34286
 
34099
34287
  // src/components/Chart/BarChart.tsx
34100
34288
  init_columnProcessing();
34101
- import { useMemo as useMemo8 } from "react";
34289
+ init_textProcessing();
34290
+ import { useMemo as useMemo8, useRef as useRef6 } from "react";
34102
34291
  import { Fragment as Fragment3, jsx as jsx38, jsxs as jsxs28 } from "react/jsx-runtime";
34103
34292
  var CATEGORY_AXIS_WIDTH = 120;
34104
34293
  var VALUE_AXIS_WIDTH = 44;
34105
34294
  var STACKED_DOMAIN_HEADROOM = 1.05;
34295
+ function rowValueFromPivotRow(row, xAxisField, fallbackLabel) {
34296
+ const rawDate = row?.__quillRawDate;
34297
+ if (rawDate != null && rawDate !== "") {
34298
+ return String(rawDate);
34299
+ }
34300
+ const category = row?.[xAxisField];
34301
+ if (category != null && category !== "") {
34302
+ return String(category);
34303
+ }
34304
+ if (fallbackLabel != null && fallbackLabel !== "") {
34305
+ return String(fallbackLabel);
34306
+ }
34307
+ return null;
34308
+ }
34106
34309
  function getStackedDomain(data, fields, comparison) {
34107
34310
  const fieldsArray = fields.filter((field) => comparison || !field.field.startsWith("comparison_")).map((field) => field.field);
34108
34311
  if (fieldsArray.length === 0 || data.length === 0) {
@@ -34124,14 +34327,16 @@ function getStackedDomain(data, fields, comparison) {
34124
34327
  }
34125
34328
  return [0, maxStack * STACKED_DOMAIN_HEADROOM];
34126
34329
  }
34127
- var createCustomBar = (yAxisFields, theme, layout) => {
34330
+ var createCustomBar = (yAxisFields, theme, layout, active = false) => {
34128
34331
  return (props) => /* @__PURE__ */ jsx38(
34129
34332
  CustomBar_default,
34130
34333
  {
34131
34334
  ...props,
34132
34335
  yAxisFields,
34133
34336
  theme,
34134
- layout
34337
+ layout,
34338
+ stroke: active ? theme?.primaryTextColor ?? "#111827" : props.stroke,
34339
+ strokeWidth: active ? 1.5 : props.strokeWidth
34135
34340
  }
34136
34341
  );
34137
34342
  };
@@ -34152,6 +34357,7 @@ function BarChart({
34152
34357
  hideYAxis = false,
34153
34358
  hideCartesianGrid = false,
34154
34359
  onClickChartElement,
34360
+ onClickLegendElement,
34155
34361
  dateFilter,
34156
34362
  referenceLines,
34157
34363
  showLegend = false,
@@ -34181,6 +34387,21 @@ function BarChart({
34181
34387
  () => stackedMode ? getStackedDomain(data, yAxisFields, comparison) : getDomain(data, yAxisFields, referenceLines),
34182
34388
  [stackedMode, data, yAxisFields, referenceLines, comparison]
34183
34389
  );
34390
+ const knownSeriesFieldsRef = useRef6([]);
34391
+ const knownColorsKeyRef = useRef6("");
34392
+ const seriesColorByField = useMemo8(() => {
34393
+ const visibleFields = yAxisFields.filter((field) => comparison || !field.field.startsWith("comparison_")).map((field) => field.field);
34394
+ const colorsKey = colors.join("\0");
34395
+ if (knownColorsKeyRef.current !== colorsKey) {
34396
+ knownSeriesFieldsRef.current = [];
34397
+ knownColorsKeyRef.current = colorsKey;
34398
+ }
34399
+ const knownFields = [
34400
+ .../* @__PURE__ */ new Set([...knownSeriesFieldsRef.current, ...visibleFields])
34401
+ ];
34402
+ knownSeriesFieldsRef.current = knownFields;
34403
+ return assignStableSeriesColors(visibleFields, colors, knownFields);
34404
+ }, [yAxisFields, colors, comparison]);
34184
34405
  const allowDecimals = useMemo8(
34185
34406
  () => getAllowDecimals(data, yAxisFields, referenceLines),
34186
34407
  [data, yAxisFields, referenceLines]
@@ -34204,6 +34425,16 @@ function BarChart({
34204
34425
  return void 0;
34205
34426
  return createCustomBar(sortYAxisFields([...yAxisFields]), theme, layout);
34206
34427
  }, [isStacked, yAxisFields, theme, layout]);
34428
+ const customActiveBarShape = useMemo8(() => {
34429
+ if (!theme?.barChartCornerRadius && !theme?.barChartCornerRadiusRatio)
34430
+ return void 0;
34431
+ return createCustomBar(
34432
+ sortYAxisFields([...yAxisFields]),
34433
+ theme,
34434
+ layout,
34435
+ true
34436
+ );
34437
+ }, [isStacked, yAxisFields, theme, layout]);
34207
34438
  if (!data || data.length === 0) {
34208
34439
  return /* @__PURE__ */ jsx38(
34209
34440
  "div",
@@ -34245,9 +34476,28 @@ function BarChart({
34245
34476
  {
34246
34477
  data: data ?? [],
34247
34478
  layout,
34248
- onClick: (event) => onClickChartElement ? onClickChartElement(
34249
- event?.activePayload ? event.activePayload[0].payload : void 0
34250
- ) : void 0,
34479
+ onClick: (event) => {
34480
+ if (!onClickChartElement || event?.activeLabel === void 0 || event?.activeTooltipIndex === void 0) {
34481
+ return;
34482
+ }
34483
+ const index = Number(event.activeTooltipIndex);
34484
+ const row = event.activePayload?.[0]?.payload ?? data[index] ?? {};
34485
+ onClickChartElement({
34486
+ ...row,
34487
+ interactionType: "bucket",
34488
+ activeLabel: event.activeLabel,
34489
+ rowValue: rowValueFromPivotRow(row, xAxisField, event.activeLabel),
34490
+ columnValue: void 0,
34491
+ activeDataKey: void 0,
34492
+ activeValue: void 0,
34493
+ activePayload: event.activePayload ?? [],
34494
+ category: event.activeLabel,
34495
+ series: void 0,
34496
+ value: void 0,
34497
+ row,
34498
+ index
34499
+ });
34500
+ },
34251
34501
  children: [
34252
34502
  !hideCartesianGrid && /* @__PURE__ */ jsx38(
34253
34503
  CartesianGrid2,
@@ -34267,7 +34517,7 @@ function BarChart({
34267
34517
  wrapperStyle: {
34268
34518
  paddingBottom: 20
34269
34519
  },
34270
- content: /* @__PURE__ */ jsx38(RenderLegend, {})
34520
+ content: /* @__PURE__ */ jsx38(RenderLegend, { onClickLegendElement })
34271
34521
  }
34272
34522
  ),
34273
34523
  isHorizontalBars ? /* @__PURE__ */ jsxs28(Fragment3, { children: [
@@ -34346,11 +34596,13 @@ function BarChart({
34346
34596
  {
34347
34597
  wrapperStyle: { outline: "none", zIndex: 2 },
34348
34598
  isAnimationActive: false,
34349
- cursor: { fill: "#d1d5db", opacity: "0.15" },
34599
+ cursor: false,
34600
+ shared: false,
34350
34601
  content: ({ active, payload, label }) => {
34351
34602
  if (!payload || payload.length === 0) {
34352
34603
  return null;
34353
34604
  }
34605
+ const activeLabel = label ?? payload[0]?.payload?.[xAxisField] ?? "";
34354
34606
  const payloadItems = payload.map((p) => {
34355
34607
  const rawName = yAxisFields?.find(
34356
34608
  (f) => f.field === p.name?.toString()
@@ -34361,7 +34613,9 @@ function BarChart({
34361
34613
  color: p.color || "black",
34362
34614
  chartType: "line",
34363
34615
  dataKey: p.dataKey?.toLocaleString() || "",
34364
- name: name2 || p.name?.toString() || "",
34616
+ name: snakeAndCamelCaseToTitleCase(
34617
+ name2 || p.name?.toString() || ""
34618
+ ),
34365
34619
  payload: p.payload || {},
34366
34620
  type: p.type || "none",
34367
34621
  unit: "string",
@@ -34374,7 +34628,7 @@ function BarChart({
34374
34628
  theme,
34375
34629
  active,
34376
34630
  payload: payloadItems,
34377
- label,
34631
+ label: `${activeLabel}`,
34378
34632
  dateFormatter: (value) => valueFormatter({
34379
34633
  value,
34380
34634
  field: xAxisField,
@@ -34406,21 +34660,55 @@ function BarChart({
34406
34660
  return /* @__PURE__ */ jsx38(
34407
34661
  Bar,
34408
34662
  {
34663
+ name: elem.label || elem.field,
34409
34664
  dataKey: elem.field,
34410
34665
  stackId: stackedMode ? "same_id" : isStacked ? elem.field.replace("comparison_", "") : void 0,
34411
34666
  type: "linear",
34412
34667
  fill: getCustomColor(elem.field) ?? selectColor(
34413
34668
  elem,
34414
- colors.length >= yAxisFields.length / (comparison ? 2 : 1) ? colors : generateArrayFromColor(
34415
- colors.slice(0, 2),
34416
- yAxisFields.length
34417
- ),
34418
- yAxisFields.findIndex(
34419
- (field) => field.field === elem.field?.replace("comparison_", "")
34420
- )
34669
+ [
34670
+ seriesColorByField.get(
34671
+ elem.field.replace("comparison_", "")
34672
+ ) ?? colors[0] ?? "gray"
34673
+ ],
34674
+ 0
34421
34675
  ),
34422
34676
  isAnimationActive,
34423
- shape: customBarShape
34677
+ shape: customBarShape,
34678
+ activeBar: customActiveBarShape ?? {
34679
+ fillOpacity: 1,
34680
+ stroke: theme?.primaryTextColor ?? "#111827",
34681
+ strokeWidth: 1.5
34682
+ },
34683
+ style: {
34684
+ cursor: onClickChartElement ? "pointer" : void 0
34685
+ },
34686
+ onClick: (bar, index, event) => {
34687
+ event?.stopPropagation();
34688
+ const payload = bar.payload ?? data[index] ?? {};
34689
+ onClickChartElement?.({
34690
+ ...payload,
34691
+ interactionType: "bar",
34692
+ activeLabel: payload[xAxisField],
34693
+ rowValue: rowValueFromPivotRow(payload, xAxisField),
34694
+ columnValue: elem.field,
34695
+ activeDataKey: elem.field,
34696
+ activeValue: payload[elem.field] ?? bar.value,
34697
+ activePayload: [
34698
+ {
34699
+ dataKey: elem.field,
34700
+ name: elem.label || elem.field,
34701
+ payload,
34702
+ value: payload[elem.field] ?? bar.value
34703
+ }
34704
+ ],
34705
+ category: payload[xAxisField],
34706
+ series: elem.field,
34707
+ value: payload[elem.field] ?? bar.value,
34708
+ row: payload,
34709
+ index
34710
+ });
34711
+ }
34424
34712
  },
34425
34713
  elem.field
34426
34714
  );
@@ -34578,7 +34866,7 @@ import { useMemo as useMemo12 } from "react";
34578
34866
  import {
34579
34867
  useContext as useContext9,
34580
34868
  useEffect as useEffect10,
34581
- useRef as useRef7,
34869
+ useRef as useRef8,
34582
34870
  useState as useState12
34583
34871
  } from "react";
34584
34872
  import {
@@ -34601,7 +34889,7 @@ import {
34601
34889
  import {
34602
34890
  useContext as useContext8,
34603
34891
  useMemo as useMemo9,
34604
- useRef as useRef6,
34892
+ useRef as useRef7,
34605
34893
  useState as useState11,
34606
34894
  useEffect as useEffect9
34607
34895
  } from "react";
@@ -34620,8 +34908,8 @@ function QuillSelectComponent({
34620
34908
  }) {
34621
34909
  const [theme] = useContext8(ThemeContext);
34622
34910
  const [showModal, setShowModal] = useState11(false);
34623
- const modalRef = useRef6(null);
34624
- const buttonRef = useRef6(null);
34911
+ const modalRef = useRef7(null);
34912
+ const buttonRef = useRef7(null);
34625
34913
  useOnClickOutside_default(
34626
34914
  modalRef,
34627
34915
  (event) => {
@@ -34646,7 +34934,7 @@ function QuillSelectComponent({
34646
34934
  }, [sortedItems]);
34647
34935
  const [popoverPosition, setPopoverPosition] = useState11(void 0);
34648
34936
  const [z, setZ] = useState11(10);
34649
- const scrollableParentRef = useRef6(document.body);
34937
+ const scrollableParentRef = useRef7(document.body);
34650
34938
  const updatePosition = () => {
34651
34939
  if (buttonRef.current) {
34652
34940
  requestAnimationFrame(() => {
@@ -34971,8 +35259,8 @@ function QuillDateRangePicker({
34971
35259
  );
34972
35260
  const [localPreset, setLocalPreset] = useState12(preset);
34973
35261
  const [showModal, setShowModal] = useState12(false);
34974
- const buttonRef = useRef7(null);
34975
- const modalRef = useRef7(null);
35262
+ const buttonRef = useRef8(null);
35263
+ const modalRef = useRef8(null);
34976
35264
  useEffect10(() => {
34977
35265
  setLocalEndDate(dateRange.endDate);
34978
35266
  setLocalStartDate(dateRange.startDate);
@@ -35488,7 +35776,7 @@ import React7, {
35488
35776
  useContext as useContext10,
35489
35777
  useEffect as useEffect11,
35490
35778
  useMemo as useMemo10,
35491
- useRef as useRef8,
35779
+ useRef as useRef9,
35492
35780
  useState as useState13
35493
35781
  } from "react";
35494
35782
  import { createPortal as createPortal3 } from "react-dom";
@@ -35508,15 +35796,15 @@ function QuillMultiSelectComponentWithCombo({
35508
35796
  const [theme] = useContext10(ThemeContext);
35509
35797
  const [selectedOptions, setSelectedOptions] = useState13([]);
35510
35798
  const [showModal, setShowModal] = useState13(false);
35511
- const modalRef = useRef8(null);
35512
- const buttonRef = useRef8(null);
35513
- const debounceTimeoutId = useRef8(null);
35799
+ const modalRef = useRef9(null);
35800
+ const buttonRef = useRef9(null);
35801
+ const debounceTimeoutId = useRef9(null);
35514
35802
  const [searchQuery, setSearchQuery] = React7.useState("");
35515
35803
  const [exceedsLimit, setExceedsLimit] = useState13(false);
35516
35804
  const [popoverPosition, setPopoverPosition] = useState13(void 0);
35517
35805
  const [z, setZ] = useState13(10);
35518
- const scrollableParentRef = useRef8(document.body);
35519
- const selectAllRef = useRef8(null);
35806
+ const scrollableParentRef = useRef9(document.body);
35807
+ const selectAllRef = useRef9(null);
35520
35808
  let CheckboxState;
35521
35809
  ((CheckboxState2) => {
35522
35810
  CheckboxState2[CheckboxState2["SELECTED"] = 0] = "SELECTED";
@@ -36153,7 +36441,7 @@ var ListboxTextInput = ({
36153
36441
  import React8, {
36154
36442
  useContext as useContext11,
36155
36443
  useMemo as useMemo11,
36156
- useRef as useRef9,
36444
+ useRef as useRef10,
36157
36445
  useState as useState14
36158
36446
  } from "react";
36159
36447
  import { jsx as jsx43, jsxs as jsxs33 } from "react/jsx-runtime";
@@ -36170,8 +36458,8 @@ function QuillSelectComponentWithCombo({
36170
36458
  }) {
36171
36459
  const [theme] = useContext11(ThemeContext);
36172
36460
  const [showModal, setShowModal] = useState14(false);
36173
- const modalRef = useRef9(null);
36174
- const buttonRef = useRef9(null);
36461
+ const modalRef = useRef10(null);
36462
+ const buttonRef = useRef10(null);
36175
36463
  const [searchQuery, setSearchQuery] = React8.useState("");
36176
36464
  const filteredItems = React8.useMemo(() => {
36177
36465
  if (searchQuery === "") {
@@ -37128,7 +37416,7 @@ var MetricDisplay = ({
37128
37416
  };
37129
37417
 
37130
37418
  // src/components/Dashboard/DataLoader.tsx
37131
- import { useContext as useContext13, useEffect as useEffect12, useMemo as useMemo13, useRef as useRef10, useState as useState15 } from "react";
37419
+ import { useContext as useContext13, useEffect as useEffect12, useMemo as useMemo13, useRef as useRef11, useState as useState15 } from "react";
37132
37420
  init_paginationProcessing();
37133
37421
  init_tableProcessing();
37134
37422
  import equal2 from "fast-deep-equal";
@@ -37268,17 +37556,17 @@ function DataLoader({
37268
37556
  reportFilters,
37269
37557
  dashboardFilters
37270
37558
  ]);
37271
- const previousFilters = useRef10(filters);
37272
- const previousUserFilters = useRef10(userFilters);
37273
- const previousTenants = useRef10(tenants);
37274
- const previousCustomFields = useRef10(schemaData.customFields);
37559
+ const previousFilters = useRef11(filters);
37560
+ const previousUserFilters = useRef11(userFilters);
37561
+ const previousTenants = useRef11(tenants);
37562
+ const previousCustomFields = useRef11(schemaData.customFields);
37275
37563
  const [rowCountIsLoading, setRowCountIsLoading] = useState15(false);
37276
- const rowsRequestId = useRef10(0);
37277
- const rowsAbortController = useRef10(null);
37278
- const rowCountRequestId = useRef10(0);
37279
- const rowCountAbortController = useRef10(null);
37280
- const updateTableRowsRequestId = useRef10(0);
37281
- const updateTableRowsAbortController = useRef10(null);
37564
+ const rowsRequestId = useRef11(0);
37565
+ const rowsAbortController = useRef11(null);
37566
+ const rowCountRequestId = useRef11(0);
37567
+ const rowCountAbortController = useRef11(null);
37568
+ const updateTableRowsRequestId = useRef11(0);
37569
+ const updateTableRowsAbortController = useRef11(null);
37282
37570
  const fetchRowCount = async (processing) => {
37283
37571
  if (!client || !filters) {
37284
37572
  if (!rowCountAbortController.current) return;
@@ -37678,13 +37966,13 @@ var ChartDataLoader = ({
37678
37966
  const [error, setError] = useState15(void 0);
37679
37967
  const [client] = useContext13(ClientContext);
37680
37968
  const [schemaData] = useContext13(SchemaDataContext);
37681
- const previousFilters = useRef10(filters);
37682
- const previousUserFilters = useRef10(userFilters);
37683
- const previousDateBucket = useRef10(dateBucket);
37684
- const previousTenants = useRef10(tenants);
37685
- const previousCustomFields = useRef10(schemaData.customFields);
37686
- const fetchReportAbortController = useRef10(null);
37687
- const rowsRequestId = useRef10(0);
37969
+ const previousFilters = useRef11(filters);
37970
+ const previousUserFilters = useRef11(userFilters);
37971
+ const previousDateBucket = useRef11(dateBucket);
37972
+ const previousTenants = useRef11(tenants);
37973
+ const previousCustomFields = useRef11(schemaData.customFields);
37974
+ const fetchReportAbortController = useRef11(null);
37975
+ const rowsRequestId = useRef11(0);
37688
37976
  const chartReport = useMemo13(() => {
37689
37977
  const report = dashboardName ? dashboard[item.id] : reports[item.id];
37690
37978
  if (!report) {
@@ -37959,7 +38247,7 @@ var useReportInternal = (reportId) => {
37959
38247
  import equal3 from "fast-deep-equal";
37960
38248
 
37961
38249
  // src/components/Chart/MapChart.tsx
37962
- import { useEffect as useEffect13, useMemo as useMemo15, useRef as useRef11, useState as useState17 } from "react";
38250
+ import { useEffect as useEffect13, useMemo as useMemo15, useRef as useRef12, useState as useState17 } from "react";
37963
38251
  init_valueFormatter();
37964
38252
  import usStates10m from "us-atlas/states-10m.json";
37965
38253
  import worldCountries50m from "world-atlas/countries-50m.json";
@@ -38573,7 +38861,7 @@ function USMap({
38573
38861
  containerStyle
38574
38862
  }) {
38575
38863
  const simpleMaps = useSimpleMapsModule();
38576
- const containerRef = useRef11(null);
38864
+ const containerRef = useRef12(null);
38577
38865
  const [hoveredState, setHoveredState] = useState17(
38578
38866
  void 0
38579
38867
  );
@@ -38769,7 +39057,7 @@ function WorldMap({
38769
39057
  containerStyle
38770
39058
  }) {
38771
39059
  const simpleMaps = useSimpleMapsModule();
38772
- const containerRef = useRef11(null);
39060
+ const containerRef = useRef12(null);
38773
39061
  const [hoveredCountry, setHoveredCountry] = useState17(
38774
39062
  void 0
38775
39063
  );
@@ -39020,7 +39308,7 @@ function MapLayout({
39020
39308
  }
39021
39309
 
39022
39310
  // src/components/Chart/GaugeChart.tsx
39023
- import { useEffect as useEffect14, useRef as useRef12, useState as useState18 } from "react";
39311
+ import { useEffect as useEffect14, useRef as useRef13, useState as useState18 } from "react";
39024
39312
  import { jsx as jsx48 } from "react/jsx-runtime";
39025
39313
  function GaugeChart({
39026
39314
  data,
@@ -39052,15 +39340,15 @@ function D3Gauge({
39052
39340
  colors,
39053
39341
  isAnimationActive
39054
39342
  }) {
39055
- const containerRef = useRef12(null);
39056
- const svgRef = useRef12(null);
39057
- const gaugeGroupRef = useRef12(null);
39058
- const needleRef = useRef12(null);
39059
- const needleOutlineRef = useRef12(null);
39060
- const textRef = useRef12(null);
39061
- const animationFrameRef = useRef12(null);
39062
- const previousPercentageRef = useRef12(0);
39063
- const firstMountRef = useRef12(true);
39343
+ const containerRef = useRef13(null);
39344
+ const svgRef = useRef13(null);
39345
+ const gaugeGroupRef = useRef13(null);
39346
+ const needleRef = useRef13(null);
39347
+ const needleOutlineRef = useRef13(null);
39348
+ const textRef = useRef13(null);
39349
+ const animationFrameRef = useRef13(null);
39350
+ const previousPercentageRef = useRef13(0);
39351
+ const firstMountRef = useRef13(true);
39064
39352
  const startAngle = -(3 * Math.PI) / 4;
39065
39353
  const totalAngle = 3 * Math.PI / 2;
39066
39354
  const [arc, setArc] = useState18(null);
@@ -39597,7 +39885,7 @@ function Chart({
39597
39885
  filters,
39598
39886
  dashboardCustomFilters[allReportsById[reportId]?.dashboardName ?? ""]
39599
39887
  ]);
39600
- const previousFilters = useRef13(void 0);
39888
+ const previousFilters = useRef14(void 0);
39601
39889
  if (!equal3(previousFilters.current, filters)) {
39602
39890
  previousFilters.current = filters;
39603
39891
  }
@@ -40014,6 +40302,7 @@ var ChartDisplay = ({
40014
40302
  onPageChange,
40015
40303
  onSortChange,
40016
40304
  onClickChartElement,
40305
+ onClickLegendElement,
40017
40306
  overrideTheme,
40018
40307
  referenceLines,
40019
40308
  showLegend,
@@ -40098,6 +40387,7 @@ var ChartDisplay = ({
40098
40387
  theme: overrideTheme ?? theme,
40099
40388
  colorMap,
40100
40389
  onClickChartElement,
40390
+ onClickLegendElement,
40101
40391
  yAxisFields: config?.yAxisFields,
40102
40392
  showLegend: resolvedShowLegend
40103
40393
  }
@@ -40174,6 +40464,7 @@ var ChartDisplay = ({
40174
40464
  hideCartesianGrid,
40175
40465
  colorMap,
40176
40466
  onClickChartElement,
40467
+ onClickLegendElement,
40177
40468
  dateFilter: !hideDateRangeFilter ? dateFilter : void 0,
40178
40469
  referenceLines,
40179
40470
  showLegend: resolvedShowLegend
@@ -40201,6 +40492,7 @@ var ChartDisplay = ({
40201
40492
  hideCartesianGrid,
40202
40493
  colorMap,
40203
40494
  onClickChartElement,
40495
+ onClickLegendElement,
40204
40496
  dateFilter: !hideDateRangeFilter ? dateFilter : void 0,
40205
40497
  referenceLines,
40206
40498
  showLegend: resolvedShowLegend,
@@ -40357,6 +40649,7 @@ var ChartDisplay = ({
40357
40649
  className,
40358
40650
  isAnimationActive,
40359
40651
  onClickChartElement,
40652
+ onClickLegendElement,
40360
40653
  dateFilter: !hideDateRangeFilter ? dateFilter : void 0,
40361
40654
  showLegend: resolvedShowLegend
40362
40655
  }
@@ -40387,6 +40680,7 @@ var ChartDisplay = ({
40387
40680
  comparisonLineStyle: comparisonLineStyle ?? "solid",
40388
40681
  cartesianGridLineColor,
40389
40682
  onClickChartElement,
40683
+ onClickLegendElement,
40390
40684
  dateFilter: !hideDateRangeFilter ? dateFilter : void 0,
40391
40685
  referenceLines,
40392
40686
  showLegend: resolvedShowLegend
@@ -40650,7 +40944,7 @@ import {
40650
40944
  useContext as useContext20,
40651
40945
  useEffect as useEffect17,
40652
40946
  useMemo as useMemo17,
40653
- useRef as useRef14,
40947
+ useRef as useRef15,
40654
40948
  useState as useState22
40655
40949
  } from "react";
40656
40950
  init_util();
@@ -41149,7 +41443,7 @@ var FilterPopoverWrapper = ({
41149
41443
  const [isOpen, setIsOpen] = useState22(false);
41150
41444
  const [uniqueValues, setUniqueValues] = useState22(void 0);
41151
41445
  const [uniqueValuesIsLoading, setUniqueValuesIsLoading] = useState22(false);
41152
- const prevFiltersRef = useRef14("");
41446
+ const prevFiltersRef = useRef15("");
41153
41447
  const columnInternals = useMemo17(() => {
41154
41448
  if (!tables) {
41155
41449
  return null;
@@ -42408,7 +42702,7 @@ function DashboardLegacy({
42408
42702
  });
42409
42703
  return map;
42410
42704
  }, [data?.sections, data?.sectionOrder]);
42411
- const mounted = useRef15(false);
42705
+ const mounted = useRef16(false);
42412
42706
  useEffect19(() => {
42413
42707
  if (!mounted.current) {
42414
42708
  mounted.current = true;
@@ -42450,16 +42744,16 @@ function DashboardLegacy({
42450
42744
  ) : defaultOptionsV2;
42451
42745
  }, [populatedDashboardFilters]);
42452
42746
  const [filterValues, setFilterValues] = useState26({});
42453
- const prevNameRef = useRef15(name2);
42454
- const prevFlagsRef = useRef15(flags);
42455
- const prevClientRef = useRef15(client?.publicKey ?? "");
42456
- const addFilterPopoverButtonRef = useRef15(null);
42457
- const viewFiltersPopoverButtonRef = useRef15(null);
42458
- const previousFilters = useRef15(filters);
42747
+ const prevNameRef = useRef16(name2);
42748
+ const prevFlagsRef = useRef16(flags);
42749
+ const prevClientRef = useRef16(client?.id ?? "");
42750
+ const addFilterPopoverButtonRef = useRef16(null);
42751
+ const viewFiltersPopoverButtonRef = useRef16(null);
42752
+ const previousFilters = useRef16(filters);
42459
42753
  if (!equal4(previousFilters.current, filters)) {
42460
42754
  previousFilters.current = filters;
42461
42755
  }
42462
- const isInitialLoadOfDashboardRef = useRef15(false);
42756
+ const isInitialLoadOfDashboardRef = useRef16(false);
42463
42757
  const referencedTables = useMemo19(() => {
42464
42758
  const sections = data?.sections || {};
42465
42759
  const tables2 = Object.values(sections).flatMap(
@@ -42487,7 +42781,7 @@ function DashboardLegacy({
42487
42781
  prevFlagsRef.current = flags;
42488
42782
  });
42489
42783
  }, [name2, isClientLoading]);
42490
- const tenantMounted = useRef15(false);
42784
+ const tenantMounted = useRef16(false);
42491
42785
  useEffect19(() => {
42492
42786
  if (!tenantMounted.current) {
42493
42787
  tenantMounted.current = true;
@@ -42508,15 +42802,15 @@ function DashboardLegacy({
42508
42802
  });
42509
42803
  }, [flags]);
42510
42804
  useEffect19(() => {
42511
- if (prevClientRef.current === client?.publicKey) {
42805
+ if (prevClientRef.current === client?.id) {
42512
42806
  return;
42513
42807
  }
42514
- const isInitialKeySet = !prevClientRef.current && client?.publicKey;
42808
+ const isInitialKeySet = !prevClientRef.current && client?.id;
42515
42809
  if (isInitialKeySet && Object.values(data?.sections ?? {}).flat().length) {
42516
- prevClientRef.current = client?.publicKey ?? "";
42810
+ prevClientRef.current = client?.id ?? "";
42517
42811
  return;
42518
42812
  }
42519
- prevClientRef.current = client?.publicKey ?? "";
42813
+ prevClientRef.current = client?.id ?? "";
42520
42814
  if (isClientLoading) {
42521
42815
  return;
42522
42816
  }
@@ -42528,7 +42822,7 @@ function DashboardLegacy({
42528
42822
  prevFlagsRef.current = flags;
42529
42823
  isInitialLoadOfDashboardRef.current = false;
42530
42824
  });
42531
- }, [client?.publicKey]);
42825
+ }, [client?.id]);
42532
42826
  useEffect19(() => {
42533
42827
  setFilterValues(
42534
42828
  Object.values(populatedDashboardFilters ?? {}).reduce((acc, f) => {
@@ -43511,6 +43805,7 @@ function StaticChart(props) {
43511
43805
  const {
43512
43806
  reportId,
43513
43807
  onClickChartElement,
43808
+ onClickLegendElement,
43514
43809
  containerStyle,
43515
43810
  showLegend,
43516
43811
  className
@@ -43563,6 +43858,7 @@ function StaticChart(props) {
43563
43858
  reportId,
43564
43859
  config,
43565
43860
  onClickChartElement,
43861
+ onClickLegendElement,
43566
43862
  loading,
43567
43863
  className,
43568
43864
  containerStyle: safeContainerStyle,
@@ -44514,7 +44810,7 @@ import {
44514
44810
  useState as useState33,
44515
44811
  useContext as useContext30,
44516
44812
  useEffect as useEffect25,
44517
- useRef as useRef20,
44813
+ useRef as useRef21,
44518
44814
  useMemo as useMemo27,
44519
44815
  useCallback as useCallback4
44520
44816
  } from "react";
@@ -44523,7 +44819,7 @@ import MonacoEditor from "@monaco-editor/react";
44523
44819
  // src/ChartBuilder.tsx
44524
44820
  import {
44525
44821
  useEffect as useEffect23,
44526
- useRef as useRef19,
44822
+ useRef as useRef20,
44527
44823
  useState as useState31,
44528
44824
  useContext as useContext28,
44529
44825
  useMemo as useMemo26,
@@ -44553,7 +44849,7 @@ import {
44553
44849
  useMemo as useMemo23,
44554
44850
  useState as useState28,
44555
44851
  useEffect as useEffect21,
44556
- useRef as useRef16
44852
+ useRef as useRef17
44557
44853
  } from "react";
44558
44854
 
44559
44855
  // src/internals/ReportBuilder/PivotList.tsx
@@ -45028,8 +45324,8 @@ var PivotModal = ({
45028
45324
  const [schemaData] = useContext25(SchemaDataContext);
45029
45325
  const { tenants } = useContext25(TenantContext);
45030
45326
  const { eventTracking } = useContext25(EventTrackingContext);
45031
- const rowFieldRef = useRef16(null);
45032
- const colFieldRef = useRef16(null);
45327
+ const rowFieldRef = useRef17(null);
45328
+ const colFieldRef = useRef17(null);
45033
45329
  const [pivotCardWidth, setPivotCardWidth] = useState28(420);
45034
45330
  const [samplePivotTable, setSamplePivotTable] = useState28(null);
45035
45331
  const [hasNoRecommendedPivots, sethasNoRecommendedPivots] = useState28(false);
@@ -45038,7 +45334,7 @@ var PivotModal = ({
45038
45334
  const [allowedRowFields, setAllowedRowFields] = useState28([]);
45039
45335
  const [allowedValueFields, setAllowedValueFields] = useState28([]);
45040
45336
  const [uniqueValues, setUniqueValues] = useState28(initialUniqueValues);
45041
- const buttonRef = useRef16(null);
45337
+ const buttonRef = useRef17(null);
45042
45338
  const [dateRanges, setDateRanges] = useState28({});
45043
45339
  const [pivotError, setPivotError] = useState28("");
45044
45340
  const [limitInput, setLimitInput] = useState28(
@@ -45057,7 +45353,7 @@ var PivotModal = ({
45057
45353
  const [popoverPosition, setPopoverPosition] = useState28(
45058
45354
  "bottom"
45059
45355
  );
45060
- const popoverRef = useRef16(null);
45356
+ const popoverRef = useRef17(null);
45061
45357
  const columnsToShow = useMemo23(() => {
45062
45358
  return (columns || []).reduce((map, col) => {
45063
45359
  map[col.field] = col.format;
@@ -45386,7 +45682,7 @@ var PivotModal = ({
45386
45682
  };
45387
45683
  fetchPivotTables();
45388
45684
  }, [selectedPivotIndex, data, dateRange, createdPivots]);
45389
- const previousUniqueValuesRef = useRef16();
45685
+ const previousUniqueValuesRef = useRef17();
45390
45686
  useEffect21(() => {
45391
45687
  if (!uniqueValuesIsLoading && !equal5(uniqueValues, previousUniqueValuesRef.current)) {
45392
45688
  previousUniqueValuesRef.current = uniqueValues;
@@ -46798,7 +47094,7 @@ import {
46798
47094
  useEffect as useEffect22,
46799
47095
  useContext as useContext26,
46800
47096
  useMemo as useMemo24,
46801
- useRef as useRef17,
47097
+ useRef as useRef18,
46802
47098
  useLayoutEffect as useLayoutEffect3
46803
47099
  } from "react";
46804
47100
  import { differenceInHours as differenceInHours2 } from "date-fns";
@@ -46920,7 +47216,7 @@ function InternalChart({
46920
47216
  const { dashboardConfig } = useContext26(DashboardConfigContext);
46921
47217
  const { eventTracking } = useContext26(EventTrackingContext);
46922
47218
  const [filtersPopoverOpen, setFiltersPopoverOpen] = useState29(false);
46923
- const filtersButtonRef = useRef17(null);
47219
+ const filtersButtonRef = useRef18(null);
46924
47220
  const currentReportFilters = useMemo24(() => {
46925
47221
  const dashFilters = dashboardConfig[report?.dashboardName ?? ""]?.config.filters;
46926
47222
  if (!dashFilters)
@@ -46949,8 +47245,8 @@ function InternalChart({
46949
47245
  ) : defaultOptionsV2;
46950
47246
  }, [reportDateFilter]);
46951
47247
  const [filterValues, setFilterValues] = useState29({});
46952
- const multiselectDebounceRef = useRef17({});
46953
- const latestMultiselectValueRef = useRef17({});
47248
+ const multiselectDebounceRef = useRef18({});
47249
+ const latestMultiselectValueRef = useRef18({});
46954
47250
  const [lockedFilters, setLockedFilters] = useState29(
46955
47251
  {}
46956
47252
  );
@@ -47112,7 +47408,7 @@ function InternalChart({
47112
47408
  onDashboardFilterChange(filter.label, filterValue);
47113
47409
  };
47114
47410
  const [filtersExpanded, setFiltersExpanded] = useState29(false);
47115
- const filtersContainerRef = useRef17(null);
47411
+ const filtersContainerRef = useRef18(null);
47116
47412
  const [visibleFilters, setVisibleFilters] = useState29([]);
47117
47413
  const filtersOverflowing = useMemo24(() => {
47118
47414
  return visibleFilters.some((visible) => visible);
@@ -47378,7 +47674,7 @@ init_dates();
47378
47674
  import React16, {
47379
47675
  useContext as useContext27,
47380
47676
  useMemo as useMemo25,
47381
- useRef as useRef18,
47677
+ useRef as useRef19,
47382
47678
  useState as useState30
47383
47679
  } from "react";
47384
47680
  import { Fragment as Fragment12, jsx as jsx68, jsxs as jsxs49 } from "react/jsx-runtime";
@@ -47398,9 +47694,9 @@ function QuillMultiSelectSectionList({
47398
47694
  }) {
47399
47695
  const [theme] = useContext27(ThemeContext);
47400
47696
  const [showModal, setShowModal] = useState30(false);
47401
- const modalRef = useRef18(null);
47402
- const buttonRef = useRef18(null);
47403
- const debounceTimeoutId = useRef18(null);
47697
+ const modalRef = useRef19(null);
47698
+ const buttonRef = useRef19(null);
47699
+ const debounceTimeoutId = useRef19(null);
47404
47700
  const [searchQuery, setSearchQuery] = React16.useState("");
47405
47701
  useOnClickOutside_default(
47406
47702
  modalRef,
@@ -48187,7 +48483,7 @@ function createReportFromForm(formData, report, eventTracking, selectedPivotTabl
48187
48483
  return newReport;
48188
48484
  }
48189
48485
  function ChartBuilderWithModal(props) {
48190
- const parentRef = useRef19(null);
48486
+ const parentRef = useRef20(null);
48191
48487
  const [modalWidth, setModalWidth] = useState31(200);
48192
48488
  const [modalHeight, setModalHeight] = useState31(200);
48193
48489
  const { isOpen, setIsOpen, title, isHorizontalView } = props;
@@ -48354,8 +48650,8 @@ function ChartBuilder({
48354
48650
  const MIN_FORM_WIDTH = 700;
48355
48651
  const [pivotCardWidth, setPivotCardWidth] = useState31(MIN_FORM_WIDTH);
48356
48652
  const [formWidth, setFormWidth] = useState31(MIN_FORM_WIDTH);
48357
- const inputRef = useRef19(null);
48358
- const selectRef = useRef19(null);
48653
+ const inputRef = useRef20(null);
48654
+ const selectRef = useRef20(null);
48359
48655
  const processColumns = (columns2) => {
48360
48656
  if (schemaData.schemaWithCustomFields) {
48361
48657
  const newProcessedColumns = columns2?.map((col) => {
@@ -48414,8 +48710,8 @@ function ChartBuilder({
48414
48710
  processColumns(report?.columnInternal ?? [])
48415
48711
  );
48416
48712
  const [currentPage, setCurrentPage] = useState31(0);
48417
- const parentRef = useRef19(null);
48418
- const deleteRef = useRef19(null);
48713
+ const parentRef = useRef20(null);
48714
+ const deleteRef = useRef20(null);
48419
48715
  const modalPadding = 20;
48420
48716
  const deleteButtonMargin = -12;
48421
48717
  const { dashboardFilters } = useContext28(DashboardFiltersContext);
@@ -48468,7 +48764,7 @@ function ChartBuilder({
48468
48764
  abortLoadingFilters
48469
48765
  } = useContext28(ReportFiltersContext);
48470
48766
  const { reportsDispatch } = useContext28(ReportsContext);
48471
- const initialFilters = useRef19(reportFilters[report?.id ?? TEMP_REPORT_ID]);
48767
+ const initialFilters = useRef20(reportFilters[report?.id ?? TEMP_REPORT_ID]);
48472
48768
  const [reportFiltersLoaded, setReportFiltersLoaded] = useState31(!filtersEnabled);
48473
48769
  const hasExistingData = useMemo26(() => {
48474
48770
  return report?.rows && report.rows.length > 0 || report?.pivotRows && report.pivotRows.length > 0;
@@ -48664,7 +48960,7 @@ function ChartBuilder({
48664
48960
  task: "dashboard",
48665
48961
  metadata: {
48666
48962
  name: dashboardName,
48667
- clientId: client.clientId,
48963
+ clientId: client.id,
48668
48964
  databaseType: client.databaseType,
48669
48965
  useNewNodeSql: true,
48670
48966
  tenants
@@ -48724,11 +49020,11 @@ function ChartBuilder({
48724
49020
  const getReferencedTables = async (client2, dbTables, sqlQuery, reportBuilderState2, skipStar) => {
48725
49021
  const metadata = reportBuilderState2 ? {
48726
49022
  reportBuilderState: reportBuilderState2,
48727
- clientId: client2.clientId,
49023
+ clientId: client2.id,
48728
49024
  useNewNodeSql: true
48729
49025
  } : {
48730
49026
  query: sqlQuery,
48731
- clientId: client2.clientId,
49027
+ clientId: client2.id,
48732
49028
  useNewNodeSql: true
48733
49029
  };
48734
49030
  try {
@@ -48762,7 +49058,7 @@ function ChartBuilder({
48762
49058
  };
48763
49059
  }
48764
49060
  };
48765
- const initializedRef = useRef19(false);
49061
+ const initializedRef = useRef20(false);
48766
49062
  const getCurrentSection = () => {
48767
49063
  let id = report?.id ?? "";
48768
49064
  if (id === "" || id === TEMP_REPORT_ID) {
@@ -48954,7 +49250,7 @@ function ChartBuilder({
48954
49250
  client,
48955
49251
  task: "dashnames",
48956
49252
  metadata: {
48957
- clientId: client.clientId
49253
+ clientId: client.id
48958
49254
  }
48959
49255
  });
48960
49256
  dashNames = resp.dashboardNames;
@@ -49091,7 +49387,7 @@ function ChartBuilder({
49091
49387
  }));
49092
49388
  }
49093
49389
  }, [report?.triggerReload, report?.columns, formData.columns.length]);
49094
- const ranMountQuery = useRef19(false);
49390
+ const ranMountQuery = useRef20(false);
49095
49391
  useEffect23(() => {
49096
49392
  if (runQueryOnMount && reportFiltersLoaded && filtersEnabled && !ranMountQuery.current) {
49097
49393
  ranMountQuery.current = true;
@@ -49328,7 +49624,7 @@ function ChartBuilder({
49328
49624
  return handleRunQuery(baseProcessing, updatedFilters);
49329
49625
  });
49330
49626
  };
49331
- const filtersEnabledRef = useRef19(filtersEnabled);
49627
+ const filtersEnabledRef = useRef20(filtersEnabled);
49332
49628
  useEffect23(() => {
49333
49629
  if (filtersEnabledRef.current !== filtersEnabled) {
49334
49630
  filtersEnabledRef.current = filtersEnabled;
@@ -52333,7 +52629,7 @@ function SQLEditor({
52333
52629
  }) {
52334
52630
  const computedButtonLabel = addToDashboardButtonLabel === "Add to dashboard" ? reportId || report?.id ? "Save changes" : "Add to dashboard" : addToDashboardButtonLabel;
52335
52631
  const [sqlPrompt, setSqlPrompt] = useState33("");
52336
- const sqlPromptFormRef = useRef20(null);
52632
+ const sqlPromptFormRef = useRef21(null);
52337
52633
  const sqlPromptInputWidth = useResponsiveFirstChildWidth_default(sqlPromptFormRef, {
52338
52634
  gap: 12,
52339
52635
  initialWidth: 320,
@@ -52393,7 +52689,7 @@ function SQLEditor({
52393
52689
  };
52394
52690
  return initial;
52395
52691
  });
52396
- const tableRef = useRef20(null);
52692
+ const tableRef = useRef21(null);
52397
52693
  const [cachedHeight, setCachedHeight] = useState33(0);
52398
52694
  const DEFAULT_ROWS_PER_PAGE = 5;
52399
52695
  const ROW_HEIGHT = 37;
@@ -52499,7 +52795,7 @@ function SQLEditor({
52499
52795
  setColumns([]);
52500
52796
  setDisplayTable(false);
52501
52797
  }
52502
- }, [client?.publicKey]);
52798
+ }, [client?.id]);
52503
52799
  useEffect25(() => {
52504
52800
  if (isChartBuilderOpen === false) {
52505
52801
  onCloseChartBuilder && onCloseChartBuilder();
@@ -52758,7 +53054,7 @@ function SQLEditor({
52758
53054
  task: "astify",
52759
53055
  metadata: {
52760
53056
  query: sqlQuery,
52761
- clientId: client2.clientId,
53057
+ clientId: client2.id,
52762
53058
  useNewNodeSql: true
52763
53059
  }
52764
53060
  });
@@ -52951,7 +53247,7 @@ function SQLEditor({
52951
53247
  query: query || "",
52952
53248
  schema: filteredSchema,
52953
53249
  databaseType: client?.databaseType ?? "postgresql",
52954
- clientName: client?.publicKey || "",
53250
+ clientName: client?.id || "",
52955
53251
  setQuery,
52956
53252
  handleRunQuery: () => {
52957
53253
  handleRunQuery(currentProcessing, true);
@@ -53395,7 +53691,7 @@ var SQLEditorComponent = ({
53395
53691
  }) => {
53396
53692
  const [editorKey, setEditorKey] = useState33(0);
53397
53693
  const { eventTracking } = useContext30(EventTrackingContext);
53398
- const currentProvider = useRef20(null);
53694
+ const currentProvider = useRef21(null);
53399
53695
  useEffect25(() => {
53400
53696
  if (currentProvider.current) {
53401
53697
  currentProvider.current.dispose();
@@ -53867,7 +54163,7 @@ function SchemaItem({
53867
54163
  import {
53868
54164
  useContext as useContext34,
53869
54165
  useEffect as useEffect29,
53870
- useRef as useRef22,
54166
+ useRef as useRef23,
53871
54167
  useState as useState39
53872
54168
  } from "react";
53873
54169
  init_constants();
@@ -55110,7 +55406,7 @@ var useReportBuilderInternal = ({
55110
55406
  !client.featureFlags?.["recommendedPivotsDisabled"]
55111
55407
  );
55112
55408
  }
55113
- if (!initialTableName && !reportId && client.publicKey) {
55409
+ if (!initialTableName && !reportId && client.id) {
55114
55410
  clearAllState();
55115
55411
  }
55116
55412
  }, [client]);
@@ -55403,7 +55699,7 @@ var useReportBuilder = ({
55403
55699
  init_ReportBuilder();
55404
55700
 
55405
55701
  // src/components/ReportBuilder/AddColumnModal.tsx
55406
- import { useState as useState35, useRef as useRef21, useMemo as useMemo29, useEffect as useEffect27, useContext as useContext32 } from "react";
55702
+ import { useState as useState35, useRef as useRef22, useMemo as useMemo29, useEffect as useEffect27, useContext as useContext32 } from "react";
55407
55703
  import {
55408
55704
  DndContext as DndContext2,
55409
55705
  closestCenter as closestCenter2,
@@ -55444,7 +55740,7 @@ function AddColumnModal({
55444
55740
  const [theme] = useContext32(ThemeContext);
55445
55741
  const [search, setSearch] = useState35("");
55446
55742
  const [initialLoad, setInitialLoad] = useState35(true);
55447
- const textInputContainerRef = useRef21(null);
55743
+ const textInputContainerRef = useRef22(null);
55448
55744
  const [modalSelectedColumns, setModalSelectedColumns] = useState35(
55449
55745
  selectedColumns.map((col) => `${col.table}.${col.field}`)
55450
55746
  );
@@ -57898,8 +58194,8 @@ function ReportBuilder({
57898
58194
  const [theme] = useContext34(ThemeContext);
57899
58195
  const [client] = useContext34(ClientContext);
57900
58196
  const { getToken } = useContext34(FetchContext);
57901
- const parentRef = useRef22(null);
57902
- const askAIFormRef = useRef22(null);
58197
+ const parentRef = useRef23(null);
58198
+ const askAIFormRef = useRef23(null);
57903
58199
  const [isCopying, setIsCopying] = useState39(false);
57904
58200
  const [isChartBuilderOpen, setIsChartBuilderOpen] = useState39(false);
57905
58201
  const [isSaveQueryModalOpen, setIsSaveQueryModalOpen] = useState39(false);
@@ -58406,7 +58702,7 @@ import {
58406
58702
  useContext as useContext35,
58407
58703
  useEffect as useEffect30,
58408
58704
  useMemo as useMemo31,
58409
- useRef as useRef23,
58705
+ useRef as useRef24,
58410
58706
  useState as useState40
58411
58707
  } from "react";
58412
58708
  import { jsx as jsx86 } from "react/jsx-runtime";
@@ -58455,7 +58751,7 @@ function ChartEditor({
58455
58751
  onClickChartElement,
58456
58752
  onClickChartError
58457
58753
  }) {
58458
- const parentRef = useRef23(null);
58754
+ const parentRef = useRef24(null);
58459
58755
  const [modalWidth, setModalWidth] = useState40(200);
58460
58756
  const [modalHeight, setModalHeight] = useState40(200);
58461
58757
  const { allReportsById } = useAllReports();
@@ -58633,23 +58929,23 @@ function ChartEditor({
58633
58929
  }
58634
58930
 
58635
58931
  // src/Chat.tsx
58636
- import { useContext as useContext37, useEffect as useEffect32, useRef as useRef26, useState as useState43 } from "react";
58932
+ import { useContext as useContext37, useEffect as useEffect32, useRef as useRef26, useState as useState42 } from "react";
58637
58933
 
58638
58934
  // src/ChatChartCard.tsx
58639
- import { useMemo as useMemo34 } from "react";
58935
+ import { useMemo as useMemo33 } from "react";
58640
58936
 
58641
58937
  // src/hooks/useForm.tsx
58642
58938
  init_Filter();
58643
58939
  init_ReportBuilder();
58644
58940
  import {
58645
- useCallback as useCallback6,
58941
+ useCallback as useCallback5,
58646
58942
  useContext as useContext36,
58647
58943
  useEffect as useEffect31,
58648
58944
  useLayoutEffect as useLayoutEffect4,
58649
- useMemo as useMemo33,
58945
+ useMemo as useMemo32,
58650
58946
  useReducer as useReducer2,
58651
58947
  useRef as useRef25,
58652
- useState as useState42
58948
+ useState as useState41
58653
58949
  } from "react";
58654
58950
  import { keepPreviousData, useQuery } from "@tanstack/react-query";
58655
58951
  init_util();
@@ -58665,6 +58961,7 @@ init_valueFormatter();
58665
58961
  // src/utils/queryBuilderFilters.ts
58666
58962
  init_Filter();
58667
58963
  init_reportBuilder();
58964
+ init_dates();
58668
58965
  var buildOperatorOption = (value, label, arity) => ({
58669
58966
  name: value,
58670
58967
  value,
@@ -58833,6 +59130,26 @@ var DATE_UNIT_BY_KEY = {
58833
59130
  day: TimeUnit.Day,
58834
59131
  hour: TimeUnit.Hour
58835
59132
  };
59133
+ var DATE_BUCKETS = /* @__PURE__ */ new Set(["day", "week", "month", "year"]);
59134
+ var parseInBucketValue = (value) => {
59135
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
59136
+ throw new Error(
59137
+ 'inBucket value must be `{ start: string, bucket: "day"|"week"|"month"|"year" }`'
59138
+ );
59139
+ }
59140
+ const record = value;
59141
+ const start = String(record.start ?? "").trim();
59142
+ const bucket = String(record.bucket ?? "").trim().toLowerCase();
59143
+ if (!start) {
59144
+ throw new Error("inBucket value.start is required");
59145
+ }
59146
+ if (!DATE_BUCKETS.has(bucket)) {
59147
+ throw new Error(
59148
+ `inBucket value.bucket must be day|week|month|year (got "${String(record.bucket)}")`
59149
+ );
59150
+ }
59151
+ return { start, bucket };
59152
+ };
58836
59153
  var EMPTY_QUERY_GROUP = {
58837
59154
  combinator: "and",
58838
59155
  rules: []
@@ -59052,6 +59369,17 @@ var internalFilterToRule = (filter) => {
59052
59369
  }
59053
59370
  case "date-custom-filter" /* DateCustomFilter */: {
59054
59371
  const customDate = filter.value;
59372
+ const dateCustom = filter;
59373
+ if (dateCustom.fromInBucket && dateCustom.dateBucket) {
59374
+ return {
59375
+ field,
59376
+ operator: "inBucket",
59377
+ value: {
59378
+ start: customDate.startDate,
59379
+ bucket: dateCustom.dateBucket
59380
+ }
59381
+ };
59382
+ }
59055
59383
  return {
59056
59384
  field,
59057
59385
  operator: "between",
@@ -59236,6 +59564,24 @@ var queryRuleToInternalFilter = (rule, fieldConfigByName) => {
59236
59564
  }
59237
59565
  };
59238
59566
  }
59567
+ if (compactOperatorKey === "inbucket") {
59568
+ const { start, bucket } = parseInBucketValue(rule.value);
59569
+ const range = getExclusiveDateBucketRange(start, bucket);
59570
+ const endInclusive = new Date(Date.parse(range.endExclusive) - 1).toISOString();
59571
+ return {
59572
+ filterType: "date-custom-filter" /* DateCustomFilter */,
59573
+ fieldType: FieldType.Date,
59574
+ operator: DateOperator.Custom,
59575
+ field,
59576
+ table,
59577
+ value: {
59578
+ startDate: range.start,
59579
+ endDate: endInclusive
59580
+ },
59581
+ dateBucket: bucket,
59582
+ fromInBucket: true
59583
+ };
59584
+ }
59239
59585
  const dateComparisonOperator = QUERY_TO_DATE_COMPARISON_OPERATOR[compactOperatorKey] ?? QUERY_TO_DATE_COMPARISON_OPERATOR[operatorKey];
59240
59586
  if (!dateComparisonOperator) {
59241
59587
  throw new Error(`Unsupported date operator "${String(rule.operator)}"`);
@@ -59422,6 +59768,31 @@ var filterStackToQueryBuilderFilters = (filterStack, fieldConfigByName, qualifyA
59422
59768
  ) : base;
59423
59769
  return qualified;
59424
59770
  };
59771
+ var queryBuilderFiltersForEditor = (group) => {
59772
+ const mapEntry = (entry) => {
59773
+ if (isCombinator(entry)) return entry;
59774
+ if (isRuleGroup(entry)) {
59775
+ return queryBuilderFiltersForEditor(entry);
59776
+ }
59777
+ if (!isRule(entry)) return entry;
59778
+ const operator = String(entry.operator ?? "").trim().toLowerCase().replace(/[_\s]+/g, "");
59779
+ if (operator !== "inbucket") return entry;
59780
+ const { start, bucket } = parseInBucketValue(entry.value);
59781
+ const range = getExclusiveDateBucketRange(start, bucket);
59782
+ const endInclusive = new Date(
59783
+ Date.parse(range.endExclusive) - 1
59784
+ ).toISOString();
59785
+ return {
59786
+ ...entry,
59787
+ operator: "between",
59788
+ value: [range.start, endInclusive]
59789
+ };
59790
+ };
59791
+ return {
59792
+ combinator: normalizeCombinator(group.combinator, "and"),
59793
+ rules: (group.rules ?? []).map(mapEntry)
59794
+ };
59795
+ };
59425
59796
  var queryBuilderFiltersToFilterStack = (query, fieldConfigByName) => {
59426
59797
  if (!isRuleGroup(query)) {
59427
59798
  throw new Error("Query must be a rule group");
@@ -59657,171 +60028,6 @@ function countFilterRules(value) {
59657
60028
  }, 0);
59658
60029
  }
59659
60030
 
59660
- // src/hooks/useReportFilterDraft.ts
59661
- import { useCallback as useCallback5, useMemo as useMemo32, useRef as useRef24, useState as useState41 } from "react";
59662
- var normalizeOperatorKey = (operator) => String(operator ?? "").trim().toLowerCase().replace(/[_\s]+/g, "");
59663
- var defaultFilterRuleValueForOperator = (operator) => {
59664
- const key = normalizeOperatorKey(operator);
59665
- if (key === "in" || key === "notin") {
59666
- return [];
59667
- }
59668
- return "";
59669
- };
59670
- var buildSeededFilterQuery = (queryBuilderProps) => {
59671
- const fieldData = queryBuilderProps?.fields?.[0];
59672
- const fieldName = String(fieldData?.name ?? "").trim();
59673
- let operator = "in";
59674
- const firstOperator = queryBuilderProps?.getOperators?.(fieldName, {
59675
- fieldData
59676
- })?.[0];
59677
- if (firstOperator) {
59678
- operator = String(firstOperator.name ?? firstOperator.value ?? "in");
59679
- }
59680
- return {
59681
- combinator: "and",
59682
- rules: [
59683
- {
59684
- field: fieldName,
59685
- operator,
59686
- value: defaultFilterRuleValueForOperator(operator)
59687
- }
59688
- ]
59689
- };
59690
- };
59691
- var EMPTY_COMMITTED_FILTERS = {
59692
- combinator: "and",
59693
- rules: []
59694
- };
59695
- var hashString2 = (input) => {
59696
- let hash = 2166136261;
59697
- for (let i = 0; i < input.length; i++) {
59698
- hash ^= input.charCodeAt(i);
59699
- hash = Math.imul(hash, 16777619);
59700
- }
59701
- return String(hash >>> 0);
59702
- };
59703
- var fieldCatalogSignature = (fields) => {
59704
- const names = fields.map((field) => String(field.name ?? "").trim()).filter(Boolean).sort();
59705
- return `${names.length}:${hashString2(names.join("\0"))}`;
59706
- };
59707
- var committedFiltersSignature = (committed) => {
59708
- try {
59709
- return hashString2(
59710
- JSON.stringify(stripQueryBuilderTransientFields(committed))
59711
- );
59712
- } catch {
59713
- return "unserializable";
59714
- }
59715
- };
59716
- function useReportFilterDraft(args) {
59717
- const { reportId, committedFilters, queryBuilderProps, setFilters } = args;
59718
- const committed = isQueryBuilderDisplayGroup(committedFilters) ? committedFilters : EMPTY_COMMITTED_FILTERS;
59719
- const committedRef = useRef24(committed);
59720
- committedRef.current = committed;
59721
- const setFiltersRef = useRef24(setFilters);
59722
- setFiltersRef.current = setFilters;
59723
- const lastNonEmptyFieldsRef = useRef24([]);
59724
- const prevReportIdForFieldsRef = useRef24(reportId);
59725
- if (prevReportIdForFieldsRef.current !== reportId) {
59726
- prevReportIdForFieldsRef.current = reportId;
59727
- lastNonEmptyFieldsRef.current = [];
59728
- }
59729
- if (queryBuilderProps.fields.length > 0) {
59730
- lastNonEmptyFieldsRef.current = queryBuilderProps.fields;
59731
- }
59732
- const effectiveFields = queryBuilderProps.fields.length > 0 ? queryBuilderProps.fields : lastNonEmptyFieldsRef.current;
59733
- const effectiveFieldsRef = useRef24(effectiveFields);
59734
- effectiveFieldsRef.current = effectiveFields;
59735
- const getOperatorsRef = useRef24(queryBuilderProps.getOperators);
59736
- getOperatorsRef.current = queryBuilderProps.getOperators;
59737
- const committedSignature = useMemo32(
59738
- () => committedFiltersSignature(committed),
59739
- // eslint-disable-next-line react-hooks/exhaustive-deps -- `committed` normalizes null to a stable constant
59740
- [committedFilters]
59741
- );
59742
- const fieldsSignature = useMemo32(
59743
- () => fieldCatalogSignature(effectiveFields),
59744
- [effectiveFields]
59745
- );
59746
- const [resetEpoch, setResetEpoch] = useState41(0);
59747
- const [seedEpoch, setSeedEpoch] = useState41(0);
59748
- const draftRef = useRef24(committed);
59749
- const [isFilterDraftDirty, setIsFilterDraftDirty] = useState41(false);
59750
- const [isFilterDraftEmpty, setIsFilterDraftEmpty] = useState41(
59751
- committed.rules.length === 0
59752
- );
59753
- const draftResetKey = `${reportId}|${committedSignature}|${resetEpoch}`;
59754
- const prevDraftResetKeyRef = useRef24(draftResetKey);
59755
- if (prevDraftResetKeyRef.current !== draftResetKey) {
59756
- prevDraftResetKeyRef.current = draftResetKey;
59757
- draftRef.current = committed;
59758
- const nextEmpty = committed.rules.length === 0;
59759
- if (isFilterDraftDirty) setIsFilterDraftDirty(false);
59760
- if (isFilterDraftEmpty !== nextEmpty) setIsFilterDraftEmpty(nextEmpty);
59761
- }
59762
- const filterDraftKey = `${draftResetKey}|${seedEpoch}|${fieldsSignature}`;
59763
- const handleQueryChange = useCallback5((next) => {
59764
- if (!isQueryBuilderDisplayGroup(next)) return;
59765
- const nextGroup = next;
59766
- draftRef.current = nextGroup;
59767
- const nextDirty = areQueryBuilderFilterDraftsDirty(
59768
- nextGroup,
59769
- committedRef.current
59770
- );
59771
- const nextEmpty = nextGroup.rules.length === 0;
59772
- setIsFilterDraftDirty((prev) => prev === nextDirty ? prev : nextDirty);
59773
- setIsFilterDraftEmpty((prev) => prev === nextEmpty ? prev : nextEmpty);
59774
- }, []);
59775
- const commitFilterDraft = useCallback5(() => {
59776
- setFiltersRef.current(draftRef.current);
59777
- }, []);
59778
- const resetFilterDraft = useCallback5(() => {
59779
- draftRef.current = committedRef.current;
59780
- setIsFilterDraftDirty(false);
59781
- setIsFilterDraftEmpty(committedRef.current.rules.length === 0);
59782
- setResetEpoch((epoch) => epoch + 1);
59783
- }, []);
59784
- const seedFilterDraft = useCallback5(() => {
59785
- const seeded = buildSeededFilterQuery({
59786
- fields: effectiveFieldsRef.current,
59787
- getOperators: getOperatorsRef.current
59788
- });
59789
- draftRef.current = seeded;
59790
- setIsFilterDraftDirty(
59791
- areQueryBuilderFilterDraftsDirty(seeded, committedRef.current)
59792
- );
59793
- setIsFilterDraftEmpty(false);
59794
- setSeedEpoch((epoch) => epoch + 1);
59795
- }, []);
59796
- const getDefaultValue = useCallback5(
59797
- (rule) => defaultFilterRuleValueForOperator(rule?.operator),
59798
- []
59799
- );
59800
- const filterDraftQueryBuilderProps = useMemo32(
59801
- () => ({
59802
- ...queryBuilderProps,
59803
- fields: effectiveFields,
59804
- // Uncontrolled: react-querybuilder owns the draft; only read at mount,
59805
- // so passing the live draft means popover/remount cycles keep edits.
59806
- defaultQuery: draftRef.current,
59807
- onQueryChange: handleQueryChange,
59808
- addRuleToNewGroups: true,
59809
- getDefaultValue
59810
- }),
59811
- // eslint-disable-next-line react-hooks/exhaustive-deps -- filterDraftKey covers draftRef resets
59812
- [queryBuilderProps, effectiveFields, handleQueryChange, getDefaultValue, filterDraftKey]
59813
- );
59814
- return {
59815
- filterDraftKey,
59816
- filterDraftQueryBuilderProps,
59817
- isFilterDraftDirty,
59818
- isFilterDraftEmpty,
59819
- commitFilterDraft,
59820
- resetFilterDraft,
59821
- seedFilterDraft
59822
- };
59823
- }
59824
-
59825
60031
  // src/hooks/useFormRefreshDecision.ts
59826
60032
  var normalize = (value) => String(value ?? "").trim();
59827
60033
  var toColumnKey = (table, field) => `${table}::${field}`;
@@ -60079,6 +60285,13 @@ var AGGREGATION_OPTION_TYPES = [
60079
60285
  var QUERY_BUILDER_MULTI_VALUE_OPERATORS = /* @__PURE__ */ new Set(["in", "notin"]);
60080
60286
  var TABLE_FORMAT_CACHE_MAX_ENTRIES = 5e3;
60081
60287
  var PIVOT_DATE_BUCKET_FORMAT_OPTIONS = ["date"];
60288
+ var PIVOT_DATE_BUCKET_OPTIONS = [
60289
+ { label: "Automatic", value: "" },
60290
+ { label: "Daily", value: "day" },
60291
+ { label: "Weekly", value: "week" },
60292
+ { label: "Monthly", value: "month" },
60293
+ { label: "Yearly", value: "year" }
60294
+ ];
60082
60295
  var AXIS_FORMAT_OPTIONS = [
60083
60296
  { value: "string", label: "string" },
60084
60297
  { value: "whole_number", label: "whole number" },
@@ -60098,6 +60311,7 @@ var AXIS_FORMAT_OPTIONS = [
60098
60311
  var USEFORM_FILTERS_DEBUG_FLAG = "__QUILL_DEBUG_USEFORM_FILTERS__";
60099
60312
  var USEFORM_REFRESH_DEBUG_FLAG = "__QUILL_DEBUG_USEFORM_REFRESH__";
60100
60313
  var USEFORM_PIVOT_SHAPE_DEBUG_FLAG = "__QUILL_DEBUG_USEFORM_PIVOT_SHAPE__";
60314
+ var USEFORM_TASK_DEBUG_FLAG = "__QUILL_DEBUG_USEFORM_TASKS__";
60101
60315
  var isUseFormFiltersDebugEnabled = () => {
60102
60316
  const globalValue = typeof globalThis !== "undefined" ? globalThis?.[USEFORM_FILTERS_DEBUG_FLAG] : void 0;
60103
60317
  if (globalValue === true) {
@@ -60124,6 +60338,23 @@ var isUseFormRefreshDebugEnabled = () => {
60124
60338
  }
60125
60339
  return false;
60126
60340
  };
60341
+ var isUseFormTaskDebugEnabled = () => {
60342
+ const globalValue = typeof globalThis !== "undefined" ? globalThis?.[USEFORM_TASK_DEBUG_FLAG] : void 0;
60343
+ if (globalValue === true) {
60344
+ return true;
60345
+ }
60346
+ if (typeof process !== "undefined" && typeof process.env !== "undefined") {
60347
+ const envValue = String(
60348
+ process?.env?.QUILL_DEBUG_USEFORM_TASKS ?? ""
60349
+ ).trim().toLowerCase();
60350
+ return envValue === "1" || envValue === "true";
60351
+ }
60352
+ return false;
60353
+ };
60354
+ var logUseFormTaskDebug = (label, payload) => {
60355
+ if (!isUseFormTaskDebugEnabled()) return;
60356
+ console.log(`[useReport][task] ${label}`, payload);
60357
+ };
60127
60358
  var isUseFormPivotShapeDebugEnabled = () => {
60128
60359
  const globalValue = typeof globalThis !== "undefined" ? globalThis?.[USEFORM_PIVOT_SHAPE_DEBUG_FLAG] : void 0;
60129
60360
  if (globalValue === true) {
@@ -60141,6 +60372,10 @@ var logUseFormPivotShapeDebug = (label, payload) => {
60141
60372
  if (!isUseFormPivotShapeDebugEnabled()) return;
60142
60373
  console.log(`[useReport][pivot-shape] ${label}`, payload);
60143
60374
  };
60375
+ var BOOLEAN_FILTER_VALUE_OPTIONS = [
60376
+ { name: "true", label: "True", value: "true" },
60377
+ { name: "false", label: "False", value: "false" }
60378
+ ];
60144
60379
  function canonicalTablesForFilterUniqueValuesQueryKey(tables) {
60145
60380
  return (tables ?? []).map((table) => {
60146
60381
  const name2 = String(table?.name ?? "").trim();
@@ -60604,6 +60839,8 @@ function normalizePivotForRefreshComparison(pivot) {
60604
60839
  const {
60605
60840
  rowFieldTable: _pivotRowTable,
60606
60841
  columnFieldTable: _pivotColumnTable,
60842
+ rowFilter: _rowFilter,
60843
+ columnFilter: _columnFilter,
60607
60844
  aggregations,
60608
60845
  ...pivotRest
60609
60846
  } = record;
@@ -62213,16 +62450,6 @@ function mergeDisplayAndSourceForTableFormats(args) {
62213
62450
  });
62214
62451
  return { columns, formatByColumnOptionId };
62215
62452
  }
62216
- var USE_FORM_AXIS_SERIES_COLORS = [
62217
- "#6366f1",
62218
- "#f59e0b",
62219
- "#10b981",
62220
- "#ef4444",
62221
- "#8b5cf6",
62222
- "#06b6d4",
62223
- "#f97316",
62224
- "#84cc16"
62225
- ];
62226
62453
  function axisFormatToSelectLabel(format9) {
62227
62454
  const raw = String(format9 ?? "").trim();
62228
62455
  const exact = AXIS_FORMAT_OPTIONS.find((option) => option.value === raw);
@@ -62283,9 +62510,6 @@ function getChartTypeOptions2(formData) {
62283
62510
  (elem) => !(formData.pivot && formData.pivot.columnField && (elem === "bar" || elem === "pie" || elem === "US map" || elem === "World map"))
62284
62511
  ).map((elem) => ({ label: elem, value: elem }));
62285
62512
  }
62286
- function isSetReportTableColumnSidebarPatch(columns) {
62287
- return Boolean(columns) && typeof columns === "object" && !Array.isArray(columns) && "patch" in columns && typeof columns.patch === "object" && columns.patch !== null && typeof columns.patch.id === "string";
62288
- }
62289
62513
  function processPivotState(next, options = {}) {
62290
62514
  const {
62291
62515
  nextState,
@@ -62342,7 +62566,10 @@ function processPivotState(next, options = {}) {
62342
62566
  }
62343
62567
  const valueField = String(aggregation.valueField ?? "").trim();
62344
62568
  if (!valueField) {
62345
- return { ...aggregation, aggregationType: "count" };
62569
+ return {
62570
+ ...aggregation,
62571
+ aggregationType: "count"
62572
+ };
62346
62573
  }
62347
62574
  const valueField2 = String(aggregation.valueField2 ?? "").trim();
62348
62575
  if (valueField2 && valueField2 !== valueField) {
@@ -62702,6 +62929,9 @@ async function loadViaInMemoryEngines({
62702
62929
  pivot,
62703
62930
  reportBuilderState,
62704
62931
  allowReportTaskBootstrap = false,
62932
+ debugSource,
62933
+ debugRunId,
62934
+ debugLoadRequestId,
62705
62935
  draftSessionId
62706
62936
  }) {
62707
62937
  const requestedTask = allowReportTaskBootstrap ? "report" : "item";
@@ -62711,6 +62941,17 @@ async function loadViaInMemoryEngines({
62711
62941
  rowsPerRequest: DEFAULT_USE_REPORT_ROWS_PER_REQUEST
62712
62942
  }
62713
62943
  } : {};
62944
+ logUseFormTaskDebug("dispatch fetchReport", {
62945
+ reportId,
62946
+ task: requestedTask,
62947
+ source: debugSource ?? "unknown",
62948
+ runId: debugRunId ?? null,
62949
+ loadRequestId: debugLoadRequestId ?? null,
62950
+ allowReportTaskBootstrap,
62951
+ filterCount: internalFilters.length,
62952
+ hasPivot: Boolean(pivot),
62953
+ hasReportBuilderState: Boolean(reportBuilderState)
62954
+ });
62714
62955
  const { report, error } = await fetchReport({
62715
62956
  reportId,
62716
62957
  client,
@@ -62790,6 +63031,9 @@ async function loadViaPivotTemplate({
62790
63031
  reportBuilderState,
62791
63032
  baseReport,
62792
63033
  schema,
63034
+ debugSource,
63035
+ debugRunId,
63036
+ debugLoadRequestId,
62793
63037
  draftSessionId
62794
63038
  }) {
62795
63039
  const pivotForTemplate = enrichPivotRowFieldTypeForTemplate(
@@ -62797,6 +63041,16 @@ async function loadViaPivotTemplate({
62797
63041
  schema,
62798
63042
  baseReport
62799
63043
  );
63044
+ logUseFormTaskDebug("dispatch fetchReport", {
63045
+ reportId,
63046
+ task: "pivot-template",
63047
+ source: debugSource ?? "unknown",
63048
+ runId: debugRunId ?? null,
63049
+ loadRequestId: debugLoadRequestId ?? null,
63050
+ filterCount: internalFilters.length,
63051
+ hasPivot: Boolean(pivotForTemplate),
63052
+ hasReportBuilderState: Boolean(reportBuilderState)
63053
+ });
62800
63054
  const { report, error } = await fetchPivotTemplateReportForUseForm({
62801
63055
  reportId,
62802
63056
  client,
@@ -63024,8 +63278,19 @@ async function loadPivotTemplateInParallelWithReportTask({
63024
63278
  customFields,
63025
63279
  dashboardName,
63026
63280
  pivotRefreshOnly = false,
63281
+ debugSource,
63282
+ debugRunId,
63283
+ debugLoadRequestId,
63027
63284
  draftSessionId
63028
63285
  }) {
63286
+ logUseFormTaskDebug("parallel loader route", {
63287
+ reportId,
63288
+ source: debugSource ?? "unknown",
63289
+ runId: debugRunId ?? null,
63290
+ loadRequestId: debugLoadRequestId ?? null,
63291
+ pivotRefreshOnly,
63292
+ tasks: pivotRefreshOnly ? ["pivot-template"] : ["report", "pivot-template", "report-builder-state"]
63293
+ });
63029
63294
  if (pivotRefreshOnly) {
63030
63295
  const pivotOnlyResult = await loadViaPivotTemplate({
63031
63296
  reportId,
@@ -63038,6 +63303,9 @@ async function loadPivotTemplateInParallelWithReportTask({
63038
63303
  reportBuilderState,
63039
63304
  baseReport,
63040
63305
  schema,
63306
+ debugSource,
63307
+ debugRunId,
63308
+ debugLoadRequestId,
63041
63309
  draftSessionId
63042
63310
  });
63043
63311
  return pivotOnlyResult;
@@ -63053,6 +63321,9 @@ async function loadPivotTemplateInParallelWithReportTask({
63053
63321
  pivot,
63054
63322
  reportBuilderState,
63055
63323
  allowReportTaskBootstrap: true,
63324
+ debugSource,
63325
+ debugRunId,
63326
+ debugLoadRequestId,
63056
63327
  draftSessionId
63057
63328
  }),
63058
63329
  loadViaPivotTemplate({
@@ -63066,6 +63337,9 @@ async function loadPivotTemplateInParallelWithReportTask({
63066
63337
  reportBuilderState,
63067
63338
  baseReport,
63068
63339
  schema,
63340
+ debugSource,
63341
+ debugRunId,
63342
+ debugLoadRequestId,
63069
63343
  draftSessionId
63070
63344
  }),
63071
63345
  fetchReportBuilderStateByReportId({
@@ -63248,6 +63522,9 @@ async function loadReportForUseForm({
63248
63522
  customFields,
63249
63523
  dashboardName,
63250
63524
  useInMemoryEngines,
63525
+ debugSource,
63526
+ debugRunId,
63527
+ debugLoadRequestId,
63251
63528
  draftSessionId
63252
63529
  }) {
63253
63530
  const effectivePivot = pivot ?? initialReportBuilderState?.pivot ?? void 0;
@@ -63256,6 +63533,18 @@ async function loadReportForUseForm({
63256
63533
  ...initialReportBuilderState,
63257
63534
  pivot: effectivePivot ?? initialReportBuilderState.pivot ?? null
63258
63535
  } : void 0;
63536
+ logUseFormTaskDebug("resolve loader route", {
63537
+ reportId,
63538
+ source: debugSource ?? "unknown",
63539
+ runId: debugRunId ?? null,
63540
+ loadRequestId: debugLoadRequestId ?? null,
63541
+ hasPivot,
63542
+ hasReportBuilderState: Boolean(reportBuilderStateForLoad),
63543
+ allowReportTaskBootstrap,
63544
+ includeReportBuilderStateInPivotTask,
63545
+ filterCount: internalFilters.length,
63546
+ useInMemoryEngines
63547
+ });
63259
63548
  if (hasPivot) {
63260
63549
  const pivotResult = await loadPivotTemplateInParallelWithReportTask({
63261
63550
  reportId,
@@ -63271,6 +63560,9 @@ async function loadReportForUseForm({
63271
63560
  customFields,
63272
63561
  dashboardName,
63273
63562
  pivotRefreshOnly: includeReportBuilderStateInPivotTask,
63563
+ debugSource,
63564
+ debugRunId,
63565
+ debugLoadRequestId,
63274
63566
  draftSessionId
63275
63567
  });
63276
63568
  const pivotRows = pivotResult.report?.pivotRows;
@@ -63319,6 +63611,9 @@ async function loadReportForUseForm({
63319
63611
  schema,
63320
63612
  customFields,
63321
63613
  dashboardName,
63614
+ debugSource,
63615
+ debugRunId,
63616
+ debugLoadRequestId,
63322
63617
  draftSessionId
63323
63618
  });
63324
63619
  const normalizedBootstrapResult = bootstrapResult.report?.pivot == null ? stripPivotFromResult(bootstrapResult) : bootstrapResult;
@@ -63326,6 +63621,15 @@ async function loadReportForUseForm({
63326
63621
  }
63327
63622
  const shouldUseReportTaskForReload = internalFilters.length > 0;
63328
63623
  const resolvedTask = shouldUseReportTaskForReload ? "report" : "item";
63624
+ logUseFormTaskDebug("non-bootstrap task route", {
63625
+ reportId,
63626
+ task: resolvedTask,
63627
+ source: debugSource ?? "unknown",
63628
+ runId: debugRunId ?? null,
63629
+ loadRequestId: debugLoadRequestId ?? null,
63630
+ reason: shouldUseReportTaskForReload ? "live internal filters are present" : "no live internal filters are present",
63631
+ filterCount: internalFilters.length
63632
+ });
63329
63633
  return loadViaInMemoryEngines({
63330
63634
  reportId,
63331
63635
  client,
@@ -63334,6 +63638,9 @@ async function loadReportForUseForm({
63334
63638
  tenants,
63335
63639
  flags,
63336
63640
  allowReportTaskBootstrap: shouldUseReportTaskForReload,
63641
+ debugSource,
63642
+ debugRunId,
63643
+ debugLoadRequestId,
63337
63644
  draftSessionId
63338
63645
  });
63339
63646
  }
@@ -63352,12 +63659,18 @@ async function loadReportForUseForm({
63352
63659
  function generateDraftSessionId() {
63353
63660
  return typeof crypto !== "undefined" && typeof crypto.randomUUID === "function" ? crypto.randomUUID() : `draft-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;
63354
63661
  }
63662
+ var nextUseReportDebugRunId = 0;
63355
63663
  function useReport(reportIdArg, options = {}) {
63356
63664
  const propReportId = String(reportIdArg ?? "").trim();
63357
- const [createdReportId, setCreatedReportId] = useState42(null);
63665
+ const [createdReportId, setCreatedReportId] = useState41(null);
63358
63666
  const effectiveReportId = propReportId || createdReportId || "";
63359
63667
  const { eventTracking } = useContext36(EventTrackingContext);
63360
- const [draftSessionId, setDraftSessionId] = useState42(generateDraftSessionId);
63668
+ const [draftSessionId, setDraftSessionId] = useState41(generateDraftSessionId);
63669
+ const [taskDebugRunId] = useState41(() => {
63670
+ nextUseReportDebugRunId += 1;
63671
+ return nextUseReportDebugRunId;
63672
+ });
63673
+ const taskDebugLoadRequestIdRef = useRef25(0);
63361
63674
  const useInMemoryEngines = options.useInMemoryEngines ?? false;
63362
63675
  const restrictFieldOptionsToSelectedDatasources = options.restrictFieldOptionsToSelectedDatasources ?? true;
63363
63676
  const reportOverride = options.reportOverride ?? null;
@@ -63370,10 +63683,10 @@ function useReport(reportIdArg, options = {}) {
63370
63683
  ...getDefaultPaginationState(),
63371
63684
  ...options.initialState?.pagination ?? {}
63372
63685
  });
63373
- const [internalPagination, setInternalPagination] = useState42(
63686
+ const [internalPagination, setInternalPagination] = useState41(
63374
63687
  initialPaginationRef.current
63375
63688
  );
63376
- const [paginationInteracted, setPaginationInteracted] = useState42(
63689
+ const [paginationInteracted, setPaginationInteracted] = useState41(
63377
63690
  () => Boolean(
63378
63691
  options.state?.pagination || options.initialState?.pagination || options.onPaginationChange
63379
63692
  )
@@ -63389,7 +63702,7 @@ function useReport(reportIdArg, options = {}) {
63389
63702
  const autoResetPageIndexRef = useRef25(true);
63390
63703
  autoResetPageIndexRef.current = options.autoResetPageIndex ?? true;
63391
63704
  const paginationPageCountRef = useRef25(-1);
63392
- const applyPaginationUpdate = useCallback6(
63705
+ const applyPaginationUpdate = useCallback5(
63393
63706
  (updater, { activate = true } = {}) => {
63394
63707
  if (activate) {
63395
63708
  setPaginationInteracted(true);
@@ -63401,11 +63714,11 @@ function useReport(reportIdArg, options = {}) {
63401
63714
  },
63402
63715
  []
63403
63716
  );
63404
- const setPagination = useCallback6(
63717
+ const setPagination = useCallback5(
63405
63718
  (updater) => applyPaginationUpdate(updater),
63406
63719
  [applyPaginationUpdate]
63407
63720
  );
63408
- const setPageIndex = useCallback6(
63721
+ const setPageIndex = useCallback5(
63409
63722
  (updater) => applyPaginationUpdate((old) => ({
63410
63723
  ...old,
63411
63724
  pageIndex: clampPageIndex(
@@ -63415,7 +63728,7 @@ function useReport(reportIdArg, options = {}) {
63415
63728
  })),
63416
63729
  [applyPaginationUpdate]
63417
63730
  );
63418
- const setPageSize = useCallback6(
63731
+ const setPageSize = useCallback5(
63419
63732
  (updater) => applyPaginationUpdate(
63420
63733
  (old) => paginationStateAfterPageSizeChange(
63421
63734
  old,
@@ -63424,36 +63737,36 @@ function useReport(reportIdArg, options = {}) {
63424
63737
  ),
63425
63738
  [applyPaginationUpdate]
63426
63739
  );
63427
- const resetPagination = useCallback6(
63740
+ const resetPagination = useCallback5(
63428
63741
  (defaultState) => applyPaginationUpdate(
63429
63742
  defaultState ? getDefaultPaginationState() : initialPaginationRef.current
63430
63743
  ),
63431
63744
  [applyPaginationUpdate]
63432
63745
  );
63433
- const resetPageIndex = useCallback6(
63746
+ const resetPageIndex = useCallback5(
63434
63747
  (defaultState) => {
63435
63748
  const target = defaultState ? 0 : initialPaginationRef.current.pageIndex;
63436
63749
  setPageIndex(target);
63437
63750
  },
63438
63751
  [setPageIndex]
63439
63752
  );
63440
- const resetPageSize = useCallback6(
63753
+ const resetPageSize = useCallback5(
63441
63754
  (defaultState) => {
63442
63755
  const target = defaultState ? getDefaultPaginationState().pageSize : initialPaginationRef.current.pageSize;
63443
63756
  setPageSize(target);
63444
63757
  },
63445
63758
  [setPageSize]
63446
63759
  );
63447
- const nextPage = useCallback6(
63760
+ const nextPage = useCallback5(
63448
63761
  () => setPageIndex((old) => old + 1),
63449
63762
  [setPageIndex]
63450
63763
  );
63451
- const previousPage = useCallback6(
63764
+ const previousPage = useCallback5(
63452
63765
  () => setPageIndex((old) => old - 1),
63453
63766
  [setPageIndex]
63454
63767
  );
63455
- const firstPage = useCallback6(() => setPageIndex(0), [setPageIndex]);
63456
- const lastPage = useCallback6(
63768
+ const firstPage = useCallback5(() => setPageIndex(0), [setPageIndex]);
63769
+ const lastPage = useCallback5(
63457
63770
  () => setPageIndex(paginationPageCountRef.current - 1),
63458
63771
  [setPageIndex]
63459
63772
  );
@@ -63461,6 +63774,7 @@ function useReport(reportIdArg, options = {}) {
63461
63774
  const lastPivotHydrateCompletedSourceIdRef = useRef25(null);
63462
63775
  const groupRowsBySetViaSetReportRef = useRef25(false);
63463
63776
  const groupColumnsBySetViaSetReportRef = useRef25(false);
63777
+ const dateBucketSetViaSetReportRef = useRef25(false);
63464
63778
  const aggregationStateSetViaSetReportRef = useRef25(false);
63465
63779
  const prevReportIdForChartPivotHydrationRef = useRef25(effectiveReportId);
63466
63780
  if (prevReportIdForChartPivotHydrationRef.current !== effectiveReportId) {
@@ -63468,15 +63782,16 @@ function useReport(reportIdArg, options = {}) {
63468
63782
  chartPivotHydratedFromSourceRef.current = false;
63469
63783
  groupRowsBySetViaSetReportRef.current = false;
63470
63784
  groupColumnsBySetViaSetReportRef.current = false;
63785
+ dateBucketSetViaSetReportRef.current = false;
63471
63786
  aggregationStateSetViaSetReportRef.current = false;
63472
63787
  }
63473
- const [chartPivotHydrationEpoch, setChartPivotHydrationEpoch] = useState42(0);
63788
+ const [chartPivotHydrationEpoch, setChartPivotHydrationEpoch] = useState41(0);
63474
63789
  const [
63475
63790
  expandReportBuilderColumnsForFlatTable,
63476
63791
  setExpandReportBuilderColumnsForFlatTable
63477
- ] = useState42(false);
63792
+ ] = useState41(false);
63478
63793
  const prevPivotStateForColumnExpansionRef = useRef25(null);
63479
- const [sourceReport, setSourceReport] = useState42(
63794
+ const [sourceReport, setSourceReport] = useState41(
63480
63795
  null
63481
63796
  );
63482
63797
  const prevSourceReportIdForPivotHydrationRef = useRef25(null);
@@ -63491,11 +63806,11 @@ function useReport(reportIdArg, options = {}) {
63491
63806
  lastPivotHydrateCompletedSourceIdRef.current = null;
63492
63807
  }
63493
63808
  }
63494
- const [preserveSchemaWideOptions, setPreserveSchemaWideOptions] = useState42(false);
63495
- const [initialSchemaScopedTableNames, setInitialSchemaScopedTableNames] = useState42(null);
63496
- const [tableColumnsEditedSignature, setTableColumnsEditedSignature] = useState42(null);
63497
- const [chartAxisEdits, setChartAxisEdits] = useState42({});
63498
- const [chartVisibilityOverrides, setChartVisibilityOverrides] = useState42({});
63809
+ const [preserveSchemaWideOptions, setPreserveSchemaWideOptions] = useState41(false);
63810
+ const [initialSchemaScopedTableNames, setInitialSchemaScopedTableNames] = useState41(null);
63811
+ const [tableColumnsEditedSignature, setTableColumnsEditedSignature] = useState41(null);
63812
+ const [chartAxisEdits, setChartAxisEdits] = useState41({});
63813
+ const [chartVisibilityOverrides, setChartVisibilityOverrides] = useState41({});
63499
63814
  const [client] = useContext36(ClientContext);
63500
63815
  const [schemaData] = useContext36(SchemaDataContext);
63501
63816
  const { tenants, flags } = useContext36(TenantContext);
@@ -63508,7 +63823,7 @@ function useReport(reportIdArg, options = {}) {
63508
63823
  clientDefaultDashboardName,
63509
63824
  destinationDashboardName
63510
63825
  ].map((entry) => String(entry ?? "").trim()).find((entry) => entry.length > 0) ?? "";
63511
- const initialFormState = useMemo33(
63826
+ const initialFormState = useMemo32(
63512
63827
  () => ({
63513
63828
  columns: [],
63514
63829
  queryColumns: [],
@@ -63516,6 +63831,7 @@ function useReport(reportIdArg, options = {}) {
63516
63831
  queryFilters: { combinator: "and", rules: [] },
63517
63832
  groupRowsBy: void 0,
63518
63833
  groupColumnsBy: void 0,
63834
+ dateBucket: void 0,
63519
63835
  aggregationState: [],
63520
63836
  aggregationTablesByIndex: [],
63521
63837
  pivotSort: void 0,
@@ -63545,6 +63861,7 @@ function useReport(reportIdArg, options = {}) {
63545
63861
  queryFilters,
63546
63862
  groupRowsBy,
63547
63863
  groupColumnsBy,
63864
+ dateBucket,
63548
63865
  aggregationState,
63549
63866
  aggregationTablesByIndex,
63550
63867
  pivotSort,
@@ -63554,13 +63871,13 @@ function useReport(reportIdArg, options = {}) {
63554
63871
  schemaDatasourceIds
63555
63872
  } = formState;
63556
63873
  const schemaDatasourceIdsKey = schemaDatasourceIds?.map((id) => String(id ?? "").trim()).join("\0") ?? "";
63557
- const queryColumnsBootstrapKey = useMemo33(
63874
+ const queryColumnsBootstrapKey = useMemo32(
63558
63875
  () => queryColumns.map(
63559
63876
  (c) => `${String(c.table ?? "").trim()}\0${String(c.field ?? "").trim()}`
63560
63877
  ).join("\n"),
63561
63878
  [queryColumns]
63562
63879
  );
63563
- const dashboardNameForNewReport = useMemo33(() => {
63880
+ const dashboardNameForNewReport = useMemo32(() => {
63564
63881
  return [clientDefaultDashboardName, destinationDashboardName].map((entry) => String(entry ?? "").trim()).find((entry) => entry.length > 0) ?? "";
63565
63882
  }, [clientDefaultDashboardName, destinationDashboardName]);
63566
63883
  const filterStackRef = useRef25(filterStack);
@@ -63592,16 +63909,16 @@ function useReport(reportIdArg, options = {}) {
63592
63909
  );
63593
63910
  schemaScopeInitializedForReportIdRef.current = effectiveReportId;
63594
63911
  };
63595
- const internalFilters = useMemo33(
63912
+ const internalFilters = useMemo32(
63596
63913
  () => internalFiltersFromFilterStack(filterStack),
63597
63914
  [filterStack]
63598
63915
  );
63599
- const customFilters = useMemo33(
63916
+ const customFilters = useMemo32(
63600
63917
  () => customFiltersFromFilterStack(filterStack),
63601
63918
  [filterStack]
63602
63919
  );
63603
- const reloadKey = useMemo33(() => 0, []);
63604
- const schemaForReportBuilderState = useMemo33(() => {
63920
+ const reloadKey = useMemo32(() => 0, []);
63921
+ const schemaForReportBuilderState = useMemo32(() => {
63605
63922
  if (schemaData.schemaWithCustomFields?.length) {
63606
63923
  return schemaData.schemaWithCustomFields;
63607
63924
  }
@@ -63611,7 +63928,7 @@ function useReport(reportIdArg, options = {}) {
63611
63928
  const customFieldsRef = useRef25(schemaData.customFields);
63612
63929
  schemaForReportBuilderStateRef.current = schemaForReportBuilderState;
63613
63930
  customFieldsRef.current = schemaData.customFields;
63614
- const isBoolAggregationField = useCallback6(
63931
+ const isBoolAggregationField = useCallback5(
63615
63932
  (field, table2) => {
63616
63933
  const fieldType = resolveFieldType({
63617
63934
  field,
@@ -63624,19 +63941,19 @@ function useReport(reportIdArg, options = {}) {
63624
63941
  },
63625
63942
  []
63626
63943
  );
63627
- const schemaForeignKeyMap = useMemo33(
63944
+ const schemaForeignKeyMap = useMemo32(
63628
63945
  () => getSchemaForeignKeyMapping(schemaForReportBuilderState),
63629
63946
  [schemaForReportBuilderState]
63630
63947
  );
63631
63948
  const reportBuilderBaseTableNamesKey = (sourceReport?.reportBuilderState?.tables ?? []).map((t) => String(t?.name ?? "").trim()).filter(Boolean).join("\0") ?? "";
63632
- const selectedBaseTableNamesForFieldOptions = useMemo33(() => {
63949
+ const selectedBaseTableNamesForFieldOptions = useMemo32(() => {
63633
63950
  const fromPicker = schemaDatasourceIds?.map((id) => String(id ?? "").trim()).filter(Boolean) ?? [];
63634
63951
  if (fromPicker.length > 0) {
63635
63952
  return fromPicker;
63636
63953
  }
63637
63954
  return (sourceReport?.reportBuilderState?.tables ?? []).map((t) => String(t?.name ?? "").trim()).filter(Boolean);
63638
63955
  }, [schemaDatasourceIdsKey, reportBuilderBaseTableNamesKey]);
63639
- const fieldOptionsAllowedTableNames = useMemo33(() => {
63956
+ const fieldOptionsAllowedTableNames = useMemo32(() => {
63640
63957
  if (!restrictFieldOptionsToSelectedDatasources) {
63641
63958
  return null;
63642
63959
  }
@@ -63738,18 +64055,18 @@ function useReport(reportIdArg, options = {}) {
63738
64055
  schemaForReportBuilderState,
63739
64056
  queryColumnsBootstrapKey
63740
64057
  ]);
63741
- const datasourceOptions = useMemo33(() => {
64058
+ const datasourceOptions = useMemo32(() => {
63742
64059
  const seen = /* @__PURE__ */ new Set();
63743
64060
  const result = [];
63744
64061
  for (const table2 of schemaForReportBuilderState) {
63745
64062
  const name2 = String(table2.name ?? "").trim();
63746
64063
  if (!name2 || seen.has(name2)) continue;
63747
64064
  seen.add(name2);
63748
- result.push({ id: name2, label: toTitleCaseLabel(name2) });
64065
+ result.push({ value: name2, label: toTitleCaseLabel(name2) });
63749
64066
  }
63750
64067
  return result;
63751
64068
  }, [schemaForReportBuilderState]);
63752
- const queryBuilderFieldConfigByName = useMemo33(() => {
64069
+ const queryBuilderFieldConfigByName = useMemo32(() => {
63753
64070
  const configByName = buildQueryBuilderFieldConfigByName(
63754
64071
  schemaForReportBuilderState
63755
64072
  );
@@ -63883,7 +64200,7 @@ function useReport(reportIdArg, options = {}) {
63883
64200
  sourceReport?.columns,
63884
64201
  sourceReport?.reportBuilderState?.columns
63885
64202
  ]);
63886
- const filterUniqueValuesRequest = useMemo33(() => {
64203
+ const filterUniqueValuesRequest = useMemo32(() => {
63887
64204
  const dashboardName = resolvedSourceDashboardName;
63888
64205
  const reportBuilderStateFromSource = sourceReport?.reportBuilderState;
63889
64206
  const isStringReportBuilderColumn = (column) => {
@@ -64104,13 +64421,13 @@ function useReport(reportIdArg, options = {}) {
64104
64421
  sourceReport?.reportBuilderState,
64105
64422
  resolvedSourceDashboardName
64106
64423
  ]);
64107
- const filterUniqueValuesRequestHash = useMemo33(
64424
+ const filterUniqueValuesRequestHash = useMemo32(
64108
64425
  () => stableSerializeForQueryKey(
64109
64426
  filterUniqueValuesRequestForQueryKey(filterUniqueValuesRequest)
64110
64427
  ),
64111
64428
  [filterUniqueValuesRequest]
64112
64429
  );
64113
- const customFiltersHashForUniqueValues = useMemo33(
64430
+ const customFiltersHashForUniqueValues = useMemo32(
64114
64431
  () => stableSerializeForQueryKey(customFilters),
64115
64432
  [customFilters]
64116
64433
  );
@@ -64207,7 +64524,7 @@ function useReport(reportIdArg, options = {}) {
64207
64524
  enabled: filterUniqueValuesEnabled,
64208
64525
  retry: false
64209
64526
  });
64210
- const backendUniqueValuesByFieldName = useMemo33(() => {
64527
+ const backendUniqueValuesByFieldName = useMemo32(() => {
64211
64528
  const valuesByField = /* @__PURE__ */ new Map();
64212
64529
  const uniqueValuesByColumn = filterUniqueValuesQuery.data?.uniqueValuesByColumn;
64213
64530
  if (!uniqueValuesByColumn || typeof uniqueValuesByColumn !== "object") {
@@ -64256,7 +64573,7 @@ function useReport(reportIdArg, options = {}) {
64256
64573
  effectiveReportId,
64257
64574
  useFormFiltersDebugEnabled
64258
64575
  ]);
64259
- const filterValueOptionsByFieldName = useMemo33(() => {
64576
+ const filterValueOptionsByFieldName = useMemo32(() => {
64260
64577
  const optionsByField = /* @__PURE__ */ new Map();
64261
64578
  const selectedMultiselectByField = collectSelectedStringMultiselectValuesByField(queryFilters);
64262
64579
  const collectValuesForField = (fieldName) => {
@@ -64322,7 +64639,7 @@ function useReport(reportIdArg, options = {}) {
64322
64639
  queryBuilderFieldConfigByName,
64323
64640
  queryFilters
64324
64641
  ]);
64325
- const filterFieldsComputed = useMemo33(() => {
64642
+ const filterFieldsComputed = useMemo32(() => {
64326
64643
  const fields = [];
64327
64644
  const seen = /* @__PURE__ */ new Set();
64328
64645
  const addField = (fieldName, fieldType, tableName, rawFieldName) => {
@@ -64425,7 +64742,7 @@ function useReport(reportIdArg, options = {}) {
64425
64742
  ]);
64426
64743
  const filterFieldsStableReportIdRef = useRef25("");
64427
64744
  const filterFieldsStableCacheRef = useRef25([]);
64428
- const filterFields = useMemo33(() => {
64745
+ const filterFields = useMemo32(() => {
64429
64746
  const rid = String(effectiveReportId ?? "");
64430
64747
  if (filterFieldsStableReportIdRef.current !== rid) {
64431
64748
  filterFieldsStableReportIdRef.current = rid;
@@ -64440,14 +64757,14 @@ function useReport(reportIdArg, options = {}) {
64440
64757
  }
64441
64758
  return filterFieldsComputed;
64442
64759
  }, [effectiveReportId, filterFieldsComputed]);
64443
- const getFilterOperators = useMemo33(
64760
+ const getFilterOperators = useMemo32(
64444
64761
  () => (_field, misc) => {
64445
64762
  const fieldType = misc?.fieldData?.quillFieldType ?? queryBuilderFieldConfigByName[String(_field ?? "").trim()]?.fieldType ?? "string";
64446
64763
  return QUERY_BUILDER_OPERATORS_BY_FIELD_TYPE[fieldType] ?? QUERY_BUILDER_OPERATORS_BY_FIELD_TYPE.string;
64447
64764
  },
64448
64765
  [queryBuilderFieldConfigByName]
64449
64766
  );
64450
- const getFilterInputType = useMemo33(
64767
+ const getFilterInputType = useMemo32(
64451
64768
  () => (_field, operator, misc) => {
64452
64769
  const fieldType = misc?.fieldData?.quillFieldType ?? queryBuilderFieldConfigByName[String(_field ?? "").trim()]?.fieldType ?? "string";
64453
64770
  if (fieldType === "date" && isRelativeDateQueryBuilderOperator(operator)) {
@@ -64457,17 +64774,20 @@ function useReport(reportIdArg, options = {}) {
64457
64774
  },
64458
64775
  [queryBuilderFieldConfigByName]
64459
64776
  );
64460
- const getFilterValueEditorType = useMemo33(
64777
+ const getFilterValueEditorType = useMemo32(
64461
64778
  () => (_field, operator, misc) => {
64462
64779
  const fieldType = misc?.fieldData?.quillFieldType ?? queryBuilderFieldConfigByName[String(_field ?? "").trim()]?.fieldType;
64463
64780
  if (fieldType === "string" && isMultiValueOperator(operator)) {
64464
64781
  return "multiselect";
64465
64782
  }
64783
+ if (fieldType === "boolean") {
64784
+ return "select";
64785
+ }
64466
64786
  return void 0;
64467
64787
  },
64468
64788
  [queryBuilderFieldConfigByName]
64469
64789
  );
64470
- const getFilterValues = useMemo33(
64790
+ const getFilterValues = useMemo32(
64471
64791
  () => (_field, operator, misc) => {
64472
64792
  const fieldName = String(_field ?? "").trim();
64473
64793
  if (!fieldName) {
@@ -64478,6 +64798,9 @@ function useReport(reportIdArg, options = {}) {
64478
64798
  misc,
64479
64799
  queryBuilderFieldConfigByName
64480
64800
  );
64801
+ if (fieldType === "boolean") {
64802
+ return BOOLEAN_FILTER_VALUE_OPTIONS;
64803
+ }
64481
64804
  if (fieldType !== "string" || !isMultiValueOperator(operator)) {
64482
64805
  return [];
64483
64806
  }
@@ -64494,7 +64817,7 @@ function useReport(reportIdArg, options = {}) {
64494
64817
  },
64495
64818
  [filterValueOptionsByFieldName, queryBuilderFieldConfigByName]
64496
64819
  );
64497
- const filterQueryBuilderProps = useMemo33(
64820
+ const filterQueryBuilderProps = useMemo32(
64498
64821
  () => ({
64499
64822
  fields: filterFields,
64500
64823
  listsAsArrays: true,
@@ -64511,7 +64834,7 @@ function useReport(reportIdArg, options = {}) {
64511
64834
  getFilterValues
64512
64835
  ]
64513
64836
  );
64514
- const filtersForQueryBuilder = useMemo33(
64837
+ const filtersForQueryBuilder = useMemo32(
64515
64838
  () => canonicalizeMultiselectStringRulesToOptionValues(
64516
64839
  queryFilters,
64517
64840
  filterValueOptionsByFieldName,
@@ -64578,12 +64901,12 @@ function useReport(reportIdArg, options = {}) {
64578
64901
  ...table2 ? { table: table2 } : {}
64579
64902
  };
64580
64903
  };
64581
- const tenantHash = useMemo33(
64904
+ const tenantHash = useMemo32(
64582
64905
  () => stableSerializeForQueryKey(tenants),
64583
64906
  [tenants]
64584
64907
  );
64585
- const flagHash = useMemo33(() => stableSerializeForQueryKey(flags), [flags]);
64586
- const clientHash = useMemo33(
64908
+ const flagHash = useMemo32(() => stableSerializeForQueryKey(flags), [flags]);
64909
+ const clientHash = useMemo32(
64587
64910
  () => stableSerializeForQueryKey({
64588
64911
  publicKey: client?.publicKey,
64589
64912
  clientId: client?.clientId,
@@ -64591,7 +64914,7 @@ function useReport(reportIdArg, options = {}) {
64591
64914
  }),
64592
64915
  [client]
64593
64916
  );
64594
- const reloadKeyHash = useMemo33(
64917
+ const reloadKeyHash = useMemo32(
64595
64918
  () => stableSerializeForQueryKey(reloadKey),
64596
64919
  [reloadKey]
64597
64920
  );
@@ -64624,6 +64947,7 @@ function useReport(reportIdArg, options = {}) {
64624
64947
  // grouping from the prior report would otherwise win over the new report.
64625
64948
  groupRowsBy: void 0,
64626
64949
  groupColumnsBy: void 0,
64950
+ dateBucket: void 0,
64627
64951
  aggregationState: [],
64628
64952
  aggregationTablesByIndex: [],
64629
64953
  pivotSort: void 0,
@@ -64649,6 +64973,8 @@ function useReport(reportIdArg, options = {}) {
64649
64973
  clientHash
64650
64974
  }),
64651
64975
  queryFn: createUseFormQueryFn(async () => {
64976
+ taskDebugLoadRequestIdRef.current += 1;
64977
+ const debugLoadRequestId = taskDebugLoadRequestIdRef.current;
64652
64978
  const allowReportTaskBootstrap = !initialReportBuilderState && bootstrapReportTaskUsedForReportIdRef.current !== effectiveReportId;
64653
64979
  const loadTargetId = String(effectiveReportId ?? "").trim();
64654
64980
  const sourceReportIdentity = String(
@@ -64672,6 +64998,9 @@ function useReport(reportIdArg, options = {}) {
64672
64998
  customFields: customFieldsRef.current,
64673
64999
  dashboardName: resolvedSourceDashboardName,
64674
65000
  useInMemoryEngines,
65001
+ debugSource: "initial-load",
65002
+ debugRunId: taskDebugRunId,
65003
+ debugLoadRequestId,
64675
65004
  draftSessionId: draftSessionId || void 0
64676
65005
  });
64677
65006
  return loadResult;
@@ -64810,6 +65139,8 @@ function useReport(reportIdArg, options = {}) {
64810
65139
  const sourceDisplayColumns = sourceDisplayColumnsFromSchema.length > 0 ? sourceDisplayColumnsFromSchema : sourceQueryColumns;
64811
65140
  const nextGroupRowsBy = shouldTakePivotGroupsFromSource ? groupRowsBySetViaSetReportRef.current ? prev.groupRowsBy : sourceRowGroupOption : prev.groupRowsBy !== void 0 ? prev.groupRowsBy : groupRowsBySetViaSetReportRef.current ? prev.groupRowsBy : sourceRowGroupOption;
64812
65141
  const nextGroupColumnsBy = shouldTakePivotGroupsFromSource ? groupColumnsBySetViaSetReportRef.current ? prev.groupColumnsBy : sourceColumnGroupOption : prev.groupColumnsBy !== void 0 ? prev.groupColumnsBy : prev.groupRowsBy !== void 0 ? prev.groupColumnsBy : sourceColumnGroupOption;
65142
+ const sourceDateBucket = sourceReport.pivot?.dateBucket ?? sourceReport.reportBuilderState?.pivot?.dateBucket;
65143
+ const nextDateBucket = dateBucketSetViaSetReportRef.current ? prev.dateBucket : sourceDateBucket;
64813
65144
  const nextFromSource = {
64814
65145
  ...prev,
64815
65146
  queryColumns: prev.queryColumns.length ? prev.queryColumns : sourceQueryColumns,
@@ -64818,6 +65149,7 @@ function useReport(reportIdArg, options = {}) {
64818
65149
  queryFilters: nextQueryFilters,
64819
65150
  groupRowsBy: nextGroupRowsBy,
64820
65151
  groupColumnsBy: nextGroupColumnsBy,
65152
+ dateBucket: nextDateBucket,
64821
65153
  aggregationState: nextAggregationState,
64822
65154
  aggregationTablesByIndex: nextAggregationTablesByIndex,
64823
65155
  pivotSort: prev.pivotSort ?? (sourceReport.pivot?.sort && sourceReport.pivot?.sortField && sourceReport.pivot?.sortDirection ? {
@@ -64850,11 +65182,11 @@ function useReport(reportIdArg, options = {}) {
64850
65182
  schemaForReportBuilderState,
64851
65183
  sourceReport
64852
65184
  ]);
64853
- const appliedAggregationState = useMemo33(
65185
+ const appliedAggregationState = useMemo32(
64854
65186
  () => aggregationState.filter(isAppliedAggregation),
64855
65187
  [aggregationState]
64856
65188
  );
64857
- const pivotState = useMemo33(() => {
65189
+ const pivotState = useMemo32(() => {
64858
65190
  if (!resolvedGroupRowsBy && !resolvedGroupColumnsBy && appliedAggregationState.length === 0) {
64859
65191
  return null;
64860
65192
  }
@@ -64898,6 +65230,7 @@ function useReport(reportIdArg, options = {}) {
64898
65230
  rowFieldType,
64899
65231
  columnField: effectiveColumnField,
64900
65232
  columnFieldType,
65233
+ dateBucket: chartPivotHydratedFromSourceRef.current ? dateBucket : dateBucket ?? priorPivot?.dateBucket,
64901
65234
  aggregations,
64902
65235
  ...rowFieldTable ? { rowFieldTable } : {},
64903
65236
  ...columnFieldTable ? { columnFieldTable } : {}
@@ -64908,6 +65241,7 @@ function useReport(reportIdArg, options = {}) {
64908
65241
  aggregationTablesByIndex,
64909
65242
  appliedAggregationState,
64910
65243
  baseReportBuilderTables,
65244
+ dateBucket,
64911
65245
  groupColumnsBy,
64912
65246
  groupRowsBy,
64913
65247
  schemaForReportBuilderState,
@@ -64929,7 +65263,7 @@ function useReport(reportIdArg, options = {}) {
64929
65263
  }
64930
65264
  prevPivotStateForColumnExpansionRef.current = pivotState;
64931
65265
  }, [pivotState]);
64932
- const effectiveReportBuilderTables = useMemo33(() => {
65266
+ const effectiveReportBuilderTables = useMemo32(() => {
64933
65267
  const explicitBaseFromSchemaPicker = Array.isArray(schemaDatasourceIds) && schemaDatasourceIds.length > 0 ? schemaDatasourceIds.map((tableName) => String(tableName ?? "").trim()).filter(Boolean).map((name2) => ({ name: name2 })) : null;
64934
65268
  const baseTablesForMerge = explicitBaseFromSchemaPicker ?? baseReportBuilderTables;
64935
65269
  return mergeReportBuilderTables(
@@ -64953,28 +65287,18 @@ function useReport(reportIdArg, options = {}) {
64953
65287
  queryColumns,
64954
65288
  schemaDatasourceIds
64955
65289
  ]);
64956
- const datasources = useMemo33(() => {
64957
- return effectiveReportBuilderTables.map((table2) => {
64958
- const name2 = String(table2.name ?? "").trim();
64959
- if (!name2) return null;
64960
- const alias = String(table2.alias ?? "").trim();
64961
- return {
64962
- id: name2,
64963
- label: alias || name2
64964
- };
64965
- }).filter(
64966
- (entry) => Boolean(entry)
64967
- );
65290
+ const datasources = useMemo32(() => {
65291
+ return effectiveReportBuilderTables.map((table2) => String(table2.name ?? "").trim()).filter((name2) => Boolean(name2));
64968
65292
  }, [effectiveReportBuilderTables]);
64969
- const effectiveReportBuilderTableNames = useMemo33(
65293
+ const effectiveReportBuilderTableNames = useMemo32(
64970
65294
  () => effectiveReportBuilderTables.map((table2) => String(table2.name ?? "").trim()).filter((name2) => Boolean(name2)),
64971
65295
  [effectiveReportBuilderTables]
64972
65296
  );
64973
- const baseReportBuilderTableNames = useMemo33(
65297
+ const baseReportBuilderTableNames = useMemo32(
64974
65298
  () => baseReportBuilderTables.map((table2) => String(table2.name ?? "").trim()).filter((name2) => Boolean(name2)),
64975
65299
  [baseReportBuilderTables]
64976
65300
  );
64977
- const normalizeQueryBuilderFieldNameForConfig = useMemo33(() => {
65301
+ const normalizeQueryBuilderFieldNameForConfig = useMemo32(() => {
64978
65302
  const configEntries = Object.entries(queryBuilderFieldConfigByName);
64979
65303
  const preferredTableNames = /* @__PURE__ */ new Set([
64980
65304
  ...effectiveReportBuilderTableNames,
@@ -65036,7 +65360,7 @@ function useReport(reportIdArg, options = {}) {
65036
65360
  effectiveReportBuilderTableNames,
65037
65361
  queryBuilderFieldConfigByName
65038
65362
  ]);
65039
- const normalizeQueryBuilderFiltersForConfig = useMemo33(() => {
65363
+ const normalizeQueryBuilderFiltersForConfig = useMemo32(() => {
65040
65364
  const normalizeGroup = (group) => {
65041
65365
  const groupRules = Array.isArray(group.rules) ? group.rules : [];
65042
65366
  const nextRules = groupRules.map((entry) => {
@@ -65073,14 +65397,14 @@ function useReport(reportIdArg, options = {}) {
65073
65397
  return normalizeGroup(group);
65074
65398
  };
65075
65399
  }, [normalizeQueryBuilderFieldNameForConfig, queryBuilderFieldConfigByName]);
65076
- const refreshSelectionTables = useMemo33(() => {
65400
+ const refreshSelectionTables = useMemo32(() => {
65077
65401
  return [
65078
65402
  getPivotGroupOptionTable(groupRowsBy),
65079
65403
  getPivotGroupOptionTable(groupColumnsBy),
65080
65404
  ...aggregationTablesByIndex
65081
65405
  ].map((tableName) => String(tableName ?? "").trim()).filter((tableName) => Boolean(tableName));
65082
65406
  }, [aggregationTablesByIndex, groupColumnsBy, groupRowsBy]);
65083
- const refreshSelectionFields = useMemo33(() => {
65407
+ const refreshSelectionFields = useMemo32(() => {
65084
65408
  const resolveFieldTableForSelection = (field, tableHint) => {
65085
65409
  const fieldName = String(field ?? "").trim();
65086
65410
  if (!fieldName) return "";
@@ -65130,7 +65454,7 @@ function useReport(reportIdArg, options = {}) {
65130
65454
  schemaForReportBuilderState,
65131
65455
  sourceReport
65132
65456
  ]);
65133
- const refreshDecision = useMemo33(
65457
+ const refreshDecision = useMemo32(
65134
65458
  () => decideReportBuilderRefresh({
65135
65459
  baseTables: baseReportBuilderTables,
65136
65460
  baseColumns: baseReportBuilderColumns,
@@ -65144,7 +65468,7 @@ function useReport(reportIdArg, options = {}) {
65144
65468
  refreshSelectionTables
65145
65469
  ]
65146
65470
  );
65147
- const effectiveReportBuilderColumns = useMemo33(() => {
65471
+ const effectiveReportBuilderColumns = useMemo32(() => {
65148
65472
  const columnsFromPivot = [];
65149
65473
  const appendPivotColumn = (field, tableHint) => {
65150
65474
  const normalizedField = String(field ?? "").trim();
@@ -65242,7 +65566,7 @@ function useReport(reportIdArg, options = {}) {
65242
65566
  queryBuilderFieldConfigByName,
65243
65567
  queryFilters
65244
65568
  ]);
65245
- const resolvedSortFieldType = useMemo33(() => {
65569
+ const resolvedSortFieldType = useMemo32(() => {
65246
65570
  const sortField = pivotSort?.sortField;
65247
65571
  if (!sortField || !pivotState) return void 0;
65248
65572
  if (sortField === resolvedGroupRowsBy) {
@@ -65263,7 +65587,7 @@ function useReport(reportIdArg, options = {}) {
65263
65587
  resolvedGroupColumnsBy,
65264
65588
  resolvedGroupRowsBy
65265
65589
  ]);
65266
- const effectiveReportBuilderState = useMemo33(() => {
65590
+ const effectiveReportBuilderState = useMemo32(() => {
65267
65591
  if (!sourceReport && effectiveReportBuilderTables.length === 0) {
65268
65592
  return void 0;
65269
65593
  }
@@ -65302,7 +65626,7 @@ function useReport(reportIdArg, options = {}) {
65302
65626
  resolvedSortFieldType,
65303
65627
  sourceReport
65304
65628
  ]);
65305
- const effectiveReportBuilderStateHash = useMemo33(
65629
+ const effectiveReportBuilderStateHash = useMemo32(
65306
65630
  () => stableSerializeForQueryKey(effectiveReportBuilderState),
65307
65631
  [effectiveReportBuilderState]
65308
65632
  );
@@ -65323,7 +65647,7 @@ function useReport(reportIdArg, options = {}) {
65323
65647
  activate: false
65324
65648
  });
65325
65649
  }, [applyPaginationUpdate, effectiveReportBuilderStateHash]);
65326
- const pivotTableDataReportBuilderState = useMemo33(() => {
65650
+ const pivotTableDataReportBuilderState = useMemo32(() => {
65327
65651
  if (!effectiveReportBuilderState?.pivot) {
65328
65652
  return void 0;
65329
65653
  }
@@ -65343,11 +65667,11 @@ function useReport(reportIdArg, options = {}) {
65343
65667
  limit: null
65344
65668
  };
65345
65669
  }, [effectiveReportBuilderState, schemaForReportBuilderState]);
65346
- const pivotTableDataReportBuilderStateHash = useMemo33(
65670
+ const pivotTableDataReportBuilderStateHash = useMemo32(
65347
65671
  () => stableSerializeForQueryKey(pivotTableDataReportBuilderState),
65348
65672
  [pivotTableDataReportBuilderState]
65349
65673
  );
65350
- const sourceReportMatchesEffectiveReportId = useMemo33(() => {
65674
+ const sourceReportMatchesEffectiveReportId = useMemo32(() => {
65351
65675
  const loadTarget = String(effectiveReportId ?? "").trim();
65352
65676
  if (!loadTarget || !sourceReport) {
65353
65677
  return true;
@@ -65357,7 +65681,7 @@ function useReport(reportIdArg, options = {}) {
65357
65681
  ).trim();
65358
65682
  return sid === loadTarget;
65359
65683
  }, [effectiveReportId, sourceReport]);
65360
- const shouldSkipRedundantFlatTableReportBuilderQuery = useMemo33(() => {
65684
+ const shouldSkipRedundantFlatTableReportBuilderQuery = useMemo32(() => {
65361
65685
  if (!sourceReport || pivotState) {
65362
65686
  return false;
65363
65687
  }
@@ -65423,7 +65747,7 @@ function useReport(reportIdArg, options = {}) {
65423
65747
  tableRefreshQueryEnabled,
65424
65748
  useFormRefreshDebugEnabled
65425
65749
  ]);
65426
- const chartTypes = useMemo33(() => {
65750
+ const chartTypes = useMemo32(() => {
65427
65751
  return getChartTypeOptions2({ pivot: pivotState });
65428
65752
  }, [pivotState]);
65429
65753
  useEffect31(() => {
@@ -65461,7 +65785,7 @@ function useReport(reportIdArg, options = {}) {
65461
65785
  });
65462
65786
  }
65463
65787
  }, [chartType, chartTypes, sourceReport]);
65464
- const schemaScopedTableNames = useMemo33(() => {
65788
+ const schemaScopedTableNames = useMemo32(() => {
65465
65789
  if (preserveSchemaWideOptions) {
65466
65790
  return [];
65467
65791
  }
@@ -65476,7 +65800,7 @@ function useReport(reportIdArg, options = {}) {
65476
65800
  preserveSchemaWideOptions,
65477
65801
  sourceReport?.reportBuilderState?.tables
65478
65802
  ]);
65479
- const joinCompatibleSchemaTableNames = useMemo33(() => {
65803
+ const joinCompatibleSchemaTableNames = useMemo32(() => {
65480
65804
  if (schemaScopedTableNames.length === 0) {
65481
65805
  return [];
65482
65806
  }
@@ -65485,7 +65809,7 @@ function useReport(reportIdArg, options = {}) {
65485
65809
  schemaForeignKeyMap
65486
65810
  );
65487
65811
  }, [schemaForeignKeyMap, schemaScopedTableNames]);
65488
- const aggregationFallbackTarget = useMemo33(() => {
65812
+ const aggregationFallbackTarget = useMemo32(() => {
65489
65813
  const tableNames = effectiveReportBuilderTables.map((table2) => table2.name).filter((name2) => Boolean(name2));
65490
65814
  const referencedTableNames = (sourceReport?.referencedTables ?? []).filter(
65491
65815
  (name2) => typeof name2 === "string" && name2.length > 0
@@ -65493,7 +65817,7 @@ function useReport(reportIdArg, options = {}) {
65493
65817
  const tableNamesToUse = tableNames.length ? tableNames : referencedTableNames;
65494
65818
  return tableNamesToUse.length > 0 ? tableNamesToUse.join(", ") : "table";
65495
65819
  }, [effectiveReportBuilderTables, sourceReport?.referencedTables]);
65496
- const aggregationFallbackTableName = useMemo33(() => {
65820
+ const aggregationFallbackTableName = useMemo32(() => {
65497
65821
  const tableNames = effectiveReportBuilderTables.map((table2) => table2.name).filter((name2) => Boolean(name2));
65498
65822
  const referencedTableNames = (sourceReport?.referencedTables ?? []).filter(
65499
65823
  (name2) => typeof name2 === "string" && name2.length > 0
@@ -65501,7 +65825,7 @@ function useReport(reportIdArg, options = {}) {
65501
65825
  const tableNamesToUse = tableNames.length ? tableNames : referencedTableNames;
65502
65826
  return tableNamesToUse[0] ?? "table";
65503
65827
  }, [effectiveReportBuilderTables, sourceReport?.referencedTables]);
65504
- const cleanedAggregations = useMemo33(() => {
65828
+ const cleanedAggregations = useMemo32(() => {
65505
65829
  return aggregationState.filter((aggregation) => Boolean(aggregation?.aggregationType)).map((aggregation, index) => {
65506
65830
  const aggregationType = String(aggregation.aggregationType);
65507
65831
  const normalizedAggregationType = aggregationType.toLowerCase();
@@ -65523,7 +65847,7 @@ function useReport(reportIdArg, options = {}) {
65523
65847
  aggregationTablesByIndex,
65524
65848
  isBoolAggregationField
65525
65849
  ]);
65526
- const { aggregationBaseOptions, aggregationOptionTableLookup } = useMemo33(() => {
65850
+ const { aggregationBaseOptions, aggregationOptionTableLookup } = useMemo32(() => {
65527
65851
  const joinScoped = fieldOptionsAllowedTableNames ? joinCompatibleSchemaTableNames.filter(
65528
65852
  (name2) => fieldOptionsAllowedTableNames.has(name2)
65529
65853
  ) : joinCompatibleSchemaTableNames;
@@ -65569,7 +65893,7 @@ function useReport(reportIdArg, options = {}) {
65569
65893
  if (!canAggregateColumn(column, aggregationType)) continue;
65570
65894
  const isNumberSharePercentage = aggregationType === "percentage" && !isBoolColumn;
65571
65895
  if (isNumberSharePercentage && !resolvedGroupRowsBy) continue;
65572
- const value = `${aggregationType}:${fieldName}`;
65896
+ const value = tableName ? `${aggregationType}:${tableName}::${fieldName}` : `${aggregationType}:${fieldName}`;
65573
65897
  if (seen.has(value)) continue;
65574
65898
  const aggregationWord = aggregationType === "percentage" ? isBoolColumn ? "Percent" : "Percent of Total" : formatAggregationTypeForDisplay(aggregationType);
65575
65899
  options2.push({
@@ -65577,8 +65901,14 @@ function useReport(reportIdArg, options = {}) {
65577
65901
  label: tableName ? `${aggregationWord} ${toTitleCaseLabel(tableName)} ${toTitleCaseLabel(fieldName)}` : `${aggregationWord} ${toTitleCaseLabel(fieldName)}`
65578
65902
  });
65579
65903
  seen.add(value);
65580
- if (tableName && !tableLookup.has(value)) {
65581
- tableLookup.set(value, tableName);
65904
+ if (tableName) {
65905
+ if (!tableLookup.has(value)) {
65906
+ tableLookup.set(value, tableName);
65907
+ }
65908
+ const unqualifiedValue = `${aggregationType}:${fieldName}`;
65909
+ if (!tableLookup.has(unqualifiedValue)) {
65910
+ tableLookup.set(unqualifiedValue, tableName);
65911
+ }
65582
65912
  }
65583
65913
  }
65584
65914
  }
@@ -65600,7 +65930,7 @@ function useReport(reportIdArg, options = {}) {
65600
65930
  resolvedGroupRowsBy,
65601
65931
  schemaForReportBuilderState
65602
65932
  ]);
65603
- const { schemaColumnOptions, columnIdentifierLookup } = useMemo33(() => {
65933
+ const { schemaColumnOptions, columnIdentifierLookup } = useMemo32(() => {
65604
65934
  const lookup = /* @__PURE__ */ new Map();
65605
65935
  const options2 = [];
65606
65936
  for (const table2 of schemaData.schemaWithCustomFields) {
@@ -65627,7 +65957,7 @@ function useReport(reportIdArg, options = {}) {
65627
65957
  columnIdentifierLookup: lookup
65628
65958
  };
65629
65959
  }, [schemaData.schemaWithCustomFields]);
65630
- const tableColumnPickerPoolOptions = useMemo33(() => {
65960
+ const tableColumnPickerPoolOptions = useMemo32(() => {
65631
65961
  const allowed = new Set(
65632
65962
  effectiveReportBuilderTableNames.map((name2) => String(name2 ?? "").trim()).filter(Boolean)
65633
65963
  );
@@ -65638,16 +65968,16 @@ function useReport(reportIdArg, options = {}) {
65638
65968
  (option) => allowed.has(String(option.tableName ?? "").trim())
65639
65969
  );
65640
65970
  }, [effectiveReportBuilderTableNames, schemaColumnOptions]);
65641
- const columns = useMemo33(() => {
65971
+ const columns = useMemo32(() => {
65642
65972
  return displayColumns.filter((column) => Boolean(column.field)).map((column) => encodeColumnOptionValue(column.table, column.field));
65643
65973
  }, [displayColumns]);
65644
- const selectedColumnOptions = useMemo33(() => {
65974
+ const selectedColumnOptions = useMemo32(() => {
65645
65975
  return displayColumns.map((column) => {
65646
65976
  const value = column.alias || column.field;
65647
65977
  return value ? { label: value, value } : null;
65648
65978
  }).filter((option) => option !== null);
65649
65979
  }, [displayColumns]);
65650
- const scopedSchemaColumns = useMemo33(() => {
65980
+ const scopedSchemaColumns = useMemo32(() => {
65651
65981
  const tableNames = fieldOptionsAllowedTableNames ? Array.from(fieldOptionsAllowedTableNames) : joinCompatibleSchemaTableNames;
65652
65982
  const schemaTables = schemaForReportBuilderState;
65653
65983
  const tablesToUse = tableNames.length ? schemaTables.filter((table2) => tableNames.includes(table2.name ?? "")) : schemaTables;
@@ -65668,7 +65998,7 @@ function useReport(reportIdArg, options = {}) {
65668
65998
  joinCompatibleSchemaTableNames,
65669
65999
  schemaForReportBuilderState
65670
66000
  ]);
65671
- const pivotUniqueValuesByColumn = useMemo33(() => {
66001
+ const pivotUniqueValuesByColumn = useMemo32(() => {
65672
66002
  const explicitUniqueValues = sourceReport?.uniqueStringsByColumn ?? sourceReport?.columnUniqueValues ?? sourceReport?.uniqueValues;
65673
66003
  if (explicitUniqueValues && typeof explicitUniqueValues === "object" && !Array.isArray(explicitUniqueValues)) {
65674
66004
  return explicitUniqueValues;
@@ -65694,7 +66024,7 @@ function useReport(reportIdArg, options = {}) {
65694
66024
  }
65695
66025
  return result;
65696
66026
  }, [sourceReport]);
65697
- const possiblePivotFields = useMemo33(() => {
66027
+ const possiblePivotFields = useMemo32(() => {
65698
66028
  const options2 = getPossiblePivotFieldOptions(
65699
66029
  scopedSchemaColumns,
65700
66030
  pivotUniqueValuesByColumn
@@ -65705,7 +66035,7 @@ function useReport(reportIdArg, options = {}) {
65705
66035
  columnFields: options2.columnFields.filter((field) => !isIdColumn(field))
65706
66036
  };
65707
66037
  }, [scopedSchemaColumns, pivotUniqueValuesByColumn]);
65708
- const groupRowsByOptions = useMemo33(() => {
66038
+ const groupRowsByOptions = useMemo32(() => {
65709
66039
  const allowedFields = new Set(possiblePivotFields.rowFields);
65710
66040
  const seenValues = /* @__PURE__ */ new Set();
65711
66041
  const options2 = [];
@@ -65732,7 +66062,7 @@ function useReport(reportIdArg, options = {}) {
65732
66062
  }
65733
66063
  return options2;
65734
66064
  }, [groupRowsBy, possiblePivotFields.rowFields, scopedSchemaColumns]);
65735
- const groupColumnsByOptions = useMemo33(() => {
66065
+ const groupColumnsByOptions = useMemo32(() => {
65736
66066
  const allowedFields = new Set(possiblePivotFields.columnFields);
65737
66067
  const seenValues = /* @__PURE__ */ new Set();
65738
66068
  const options2 = [];
@@ -65759,19 +66089,19 @@ function useReport(reportIdArg, options = {}) {
65759
66089
  }
65760
66090
  return options2;
65761
66091
  }, [groupColumnsBy, possiblePivotFields.columnFields, scopedSchemaColumns]);
65762
- const cleanedSort = useMemo33(() => {
66092
+ const cleanedSort = useMemo32(() => {
65763
66093
  const activeSort = resolvedGroupRowsBy ? pivotSort : regularSort;
65764
66094
  if (!activeSort?.sortField || !activeSort?.sortDirection) {
65765
66095
  return "";
65766
66096
  }
65767
66097
  return toFlatSortValue(activeSort.sortField, activeSort.sortDirection);
65768
66098
  }, [pivotSort, regularSort, resolvedGroupRowsBy]);
65769
- const aggregationSortLabelFallbackTable = useMemo33(() => {
66099
+ const aggregationSortLabelFallbackTable = useMemo32(() => {
65770
66100
  const reportBuilderTableName = effectiveReportBuilderTables.map((table2) => String(table2.name ?? "").trim()).find((tableName) => Boolean(tableName));
65771
66101
  if (reportBuilderTableName) return reportBuilderTableName;
65772
66102
  return (sourceReport?.referencedTables ?? []).map((tableName) => String(tableName ?? "").trim()).find((tableName) => Boolean(tableName));
65773
66103
  }, [effectiveReportBuilderTables, sourceReport?.referencedTables]);
65774
- const sortOptions = useMemo33(() => {
66104
+ const sortOptions = useMemo32(() => {
65775
66105
  if (resolvedGroupRowsBy) {
65776
66106
  const aggregationSortFields = getPivotAggregationSortFields(
65777
66107
  aggregationState,
@@ -65830,12 +66160,14 @@ function useReport(reportIdArg, options = {}) {
65830
66160
  resolvedGroupRowsBy,
65831
66161
  selectedColumnOptions
65832
66162
  ]);
65833
- const aggregationOptions = useMemo33(() => {
66163
+ const { aggregationValues, aggregationOptions } = useMemo32(() => {
65834
66164
  const baseOptions = aggregationBaseOptions.map((option) => ({
65835
66165
  value: option.value,
65836
66166
  label: option.label
65837
66167
  }));
65838
- return aggregationState.map((aggregation, index) => {
66168
+ const seenValues = new Set(baseOptions.map((option) => option.value));
66169
+ const injectedOptions = [];
66170
+ const values = aggregationState.map((aggregation, index) => {
65839
66171
  const normalizedAggregationType = String(
65840
66172
  aggregation.aggregationType ?? ""
65841
66173
  ).toLowerCase();
@@ -65843,27 +66175,36 @@ function useReport(reportIdArg, options = {}) {
65843
66175
  const currentValueField = String(aggregation.valueField ?? "").trim();
65844
66176
  const currentValueField2 = String(aggregation.valueField2 ?? "").trim();
65845
66177
  const isPercentageRatio = normalizedAggregationType === "percentage" && Boolean(currentValueField) && Boolean(currentValueField2);
65846
- const currentTarget = isPercentageRatio ? `${currentValueField}:${currentValueField2}` : currentValueField ? currentValueField : normalizedAggregationType === "count" || normalizedAggregationType === "percentage" ? tableHint || aggregationFallbackTableName : aggregationFallbackTarget;
65847
- const currentValue = aggregation.aggregationType ? `${aggregation.aggregationType}:${currentTarget}` : void 0;
65848
- const isBoolPercentage = normalizedAggregationType === "percentage" && Boolean(currentValueField) && isBoolAggregationField(currentValueField, tableHint || void 0) === true;
65849
- const currentLabel = aggregation.aggregationType ? isPercentageRatio ? `Percent ${toTitleCaseLabel(currentValueField)} of ${toTitleCaseLabel(currentValueField2)}` : normalizedAggregationType === "percentage" ? isBoolPercentage ? `Percent ${toTitleCaseLabel(currentTarget)}` : `Percent of Total ${toTitleCaseLabel(currentTarget)}` : `${formatAggregationTypeForDisplay(aggregation.aggregationType)} ${toTitleCaseLabel(currentTarget)}` : "Select aggregation";
65850
- const options2 = currentValue ? baseOptions.some((option) => option.value === currentValue) ? baseOptions : [{ value: currentValue, label: currentLabel }, ...baseOptions] : baseOptions;
65851
- return {
65852
- key: `aggregation-${index}`,
65853
- label: `Aggregation ${index + 1}`,
65854
- value: currentValue ?? "",
65855
- options: options2
65856
- };
66178
+ const isTableTarget = !isPercentageRatio && !currentValueField && (normalizedAggregationType === "count" || normalizedAggregationType === "percentage");
66179
+ const labelTarget = isPercentageRatio ? `${currentValueField}:${currentValueField2}` : currentValueField ? currentValueField : isTableTarget ? tableHint || aggregationFallbackTableName : aggregationFallbackTarget;
66180
+ const fieldTable = isTableTarget || !aggregation.aggregationType ? "" : tableHint || String(
66181
+ aggregationOptionTableLookup.get(
66182
+ `${aggregation.aggregationType}:${labelTarget}`
66183
+ ) ?? ""
66184
+ ).trim();
66185
+ const currentValue = aggregation.aggregationType ? `${aggregation.aggregationType}:${fieldTable ? `${fieldTable}::` : ""}${labelTarget}` : "";
66186
+ if (currentValue && !seenValues.has(currentValue)) {
66187
+ const isBoolPercentage = normalizedAggregationType === "percentage" && Boolean(currentValueField) && isBoolAggregationField(currentValueField, tableHint || void 0) === true;
66188
+ const currentLabel = isPercentageRatio ? `Percent ${toTitleCaseLabel(currentValueField)} of ${toTitleCaseLabel(currentValueField2)}` : normalizedAggregationType === "percentage" ? isBoolPercentage ? `Percent ${toTitleCaseLabel(labelTarget)}` : `Percent of Total ${toTitleCaseLabel(labelTarget)}` : `${formatAggregationTypeForDisplay(aggregation.aggregationType)} ${toTitleCaseLabel(labelTarget)}`;
66189
+ injectedOptions.push({ value: currentValue, label: currentLabel });
66190
+ seenValues.add(currentValue);
66191
+ }
66192
+ return currentValue;
65857
66193
  });
66194
+ return {
66195
+ aggregationValues: values,
66196
+ aggregationOptions: [...injectedOptions, ...baseOptions]
66197
+ };
65858
66198
  }, [
65859
66199
  aggregationFallbackTableName,
65860
66200
  aggregationFallbackTarget,
65861
66201
  aggregationState,
65862
66202
  aggregationBaseOptions,
66203
+ aggregationOptionTableLookup,
65863
66204
  aggregationTablesByIndex,
65864
66205
  isBoolAggregationField
65865
66206
  ]);
65866
- const nextPivot = useMemo33(() => {
66207
+ const nextPivot = useMemo32(() => {
65867
66208
  if (!sourceReport) return null;
65868
66209
  return pivotState ? {
65869
66210
  ...pivotState,
@@ -65874,15 +66215,15 @@ function useReport(reportIdArg, options = {}) {
65874
66215
  rowLimit: limit?.value
65875
66216
  } : null;
65876
66217
  }, [sourceReport, pivotState, pivotSort, limit, resolvedSortFieldType]);
65877
- const nextPivotHash = useMemo33(
66218
+ const nextPivotHash = useMemo32(
65878
66219
  () => stableSerializeForQueryKey(nextPivot),
65879
66220
  [nextPivot]
65880
66221
  );
65881
- const filterStackHash = useMemo33(
66222
+ const filterStackHash = useMemo32(
65882
66223
  () => stableSerializeForQueryKey(filterStack),
65883
66224
  [filterStack]
65884
66225
  );
65885
- const shouldSkipPivotRefreshForUnchangedPivot = useMemo33(() => {
66226
+ const shouldSkipPivotRefreshForUnchangedPivot = useMemo32(() => {
65886
66227
  if (!sourceReport || !nextPivot) return false;
65887
66228
  if (!Array.isArray(sourceReport.rows) || sourceReport.rows.length === 0) {
65888
66229
  return false;
@@ -65920,7 +66261,7 @@ function useReport(reportIdArg, options = {}) {
65920
66261
  shouldSkipPivotRefreshForUnchangedPivot,
65921
66262
  sourceReport
65922
66263
  ]);
65923
- const shouldSkipRedundantPivotTableDataReportBuilderQuery = useMemo33(() => {
66264
+ const shouldSkipRedundantPivotTableDataReportBuilderQuery = useMemo32(() => {
65924
66265
  if (!sourceReport || !nextPivot) {
65925
66266
  return false;
65926
66267
  }
@@ -65967,6 +66308,7 @@ function useReport(reportIdArg, options = {}) {
65967
66308
  ...sourceReport,
65968
66309
  reportBuilderState: effectiveReportBuilderState
65969
66310
  };
66311
+ taskDebugLoadRequestIdRef.current += 1;
65970
66312
  const pivotRefreshResult = await loadReportForUseForm({
65971
66313
  reportId: effectiveReportId,
65972
66314
  initialReportBuilderState: effectiveReportBuilderState,
@@ -65982,6 +66324,9 @@ function useReport(reportIdArg, options = {}) {
65982
66324
  customFields: schemaData.customFields,
65983
66325
  dashboardName: resolvedSourceDashboardName,
65984
66326
  useInMemoryEngines,
66327
+ debugSource: "pivot-refresh",
66328
+ debugRunId: taskDebugRunId,
66329
+ debugLoadRequestId: taskDebugLoadRequestIdRef.current,
65985
66330
  draftSessionId: draftSessionId || void 0
65986
66331
  });
65987
66332
  return pivotRefreshResult;
@@ -66022,7 +66367,7 @@ function useReport(reportIdArg, options = {}) {
66022
66367
  });
66023
66368
  const tablePageReportBuilderState = pivotTableDataReportBuilderState ?? effectiveReportBuilderState;
66024
66369
  const tablePageReportBuilderStateHash = pivotTableDataReportBuilderState ? pivotTableDataReportBuilderStateHash : effectiveReportBuilderStateHash;
66025
- const tablePaginationSort = useMemo33(() => {
66370
+ const tablePaginationSort = useMemo32(() => {
66026
66371
  const sortEntry = tablePageReportBuilderState?.sort?.[0];
66027
66372
  const field = String(sortEntry?.field ?? "").trim();
66028
66373
  if (!field || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(field)) {
@@ -66084,7 +66429,7 @@ function useReport(reportIdArg, options = {}) {
66084
66429
  const tablePageRows = tablePageQueryEnabled && !tablePageQuery.data?.error && Array.isArray(tablePageQuery.data?.report?.rows) ? tablePageQuery.data.report.rows : void 0;
66085
66430
  const tablePageRowCount = tablePageQueryEnabled && typeof tablePageQuery.data?.report?.rowCount === "number" && tablePageQuery.data.report.rowCount > 0 ? tablePageQuery.data.report.rowCount : void 0;
66086
66431
  const tablePageFetching = tablePageQueryEnabled && tablePageQuery.isFetching;
66087
- const paginationTotalRowCount = useMemo33(() => {
66432
+ const paginationTotalRowCount = useMemo32(() => {
66088
66433
  if (tablePageRowCount !== void 0) {
66089
66434
  return Math.max(tablePageRowCount, baseWindowRowsLength);
66090
66435
  }
@@ -66126,6 +66471,9 @@ function useReport(reportIdArg, options = {}) {
66126
66471
  return {
66127
66472
  ...previousReport,
66128
66473
  ...report,
66474
+ xAxisFormat: previousReport.xAxisFormat,
66475
+ columns: previousReport.columns,
66476
+ yAxisFields: previousReport.yAxisFields,
66129
66477
  pivot: previousReport.pivot,
66130
66478
  pivotRows: previousReport.pivotRows,
66131
66479
  pivotColumns: previousReport.pivotColumns,
@@ -66198,7 +66546,7 @@ function useReport(reportIdArg, options = {}) {
66198
66546
  effectiveReportId,
66199
66547
  useFormRefreshDebugEnabled
66200
66548
  ]);
66201
- const chartData = useMemo33(() => {
66549
+ const chartData = useMemo32(() => {
66202
66550
  if (!sourceReport) return void 0;
66203
66551
  const rowsForChart = Array.isArray(sourceReport.rows) ? sourceReport.rows : [];
66204
66552
  const chartPivotForDisplay = nextPivot ?? (!chartPivotHydratedFromSourceRef.current ? sourceReport.pivot ?? null : null);
@@ -66234,18 +66582,18 @@ function useReport(reportIdArg, options = {}) {
66234
66582
  useInMemoryEngines,
66235
66583
  chartPivotHydrationEpoch
66236
66584
  ]);
66237
- const baseChart = useMemo33(
66585
+ const baseChart = useMemo32(
66238
66586
  () => normalizePivotChartForDisplay(chartData),
66239
66587
  [chartData]
66240
66588
  );
66241
- const chartAxesBaseChart = useMemo33(() => {
66589
+ const chartAxesBaseChart = useMemo32(() => {
66242
66590
  if (!chartData) return void 0;
66243
66591
  if (chartData.pivot?.columnField) {
66244
66592
  return normalizePivotChartForAxisControls(chartData, effectiveReportId);
66245
66593
  }
66246
66594
  return baseChart;
66247
66595
  }, [baseChart, chartData, effectiveReportId]);
66248
- const chartAxisOptions = useMemo33(() => {
66596
+ const chartAxisOptions = useMemo32(() => {
66249
66597
  if (!chartAxesBaseChart) return [];
66250
66598
  const optionsByField = /* @__PURE__ */ new Map();
66251
66599
  const registerOption = (fieldRaw, labelRaw, formatRaw) => {
@@ -66262,8 +66610,8 @@ function useReport(reportIdArg, options = {}) {
66262
66610
  for (const column of chartAxesBaseChart.columns ?? []) {
66263
66611
  registerOption(column.field, column.label, column.format);
66264
66612
  }
66265
- for (const yAxis of chartAxesBaseChart.yAxisFields ?? []) {
66266
- registerOption(yAxis.field, yAxis.label, yAxis.format);
66613
+ for (const yAxis2 of chartAxesBaseChart.yAxisFields ?? []) {
66614
+ registerOption(yAxis2.field, yAxis2.label, yAxis2.format);
66267
66615
  }
66268
66616
  if (chartAxesBaseChart.pivot?.columnField) {
66269
66617
  for (const aggregationAxis of buildPivotAggregationAxisFields(
@@ -66283,14 +66631,14 @@ function useReport(reportIdArg, options = {}) {
66283
66631
  );
66284
66632
  return Array.from(optionsByField.values());
66285
66633
  }, [chartAxesBaseChart]);
66286
- const chartAxisOptionByField = useMemo33(() => {
66634
+ const chartAxisOptionByField = useMemo32(() => {
66287
66635
  const optionsByField = /* @__PURE__ */ new Map();
66288
66636
  for (const option of chartAxisOptions) {
66289
66637
  optionsByField.set(option.value, option);
66290
66638
  }
66291
66639
  return optionsByField;
66292
66640
  }, [chartAxisOptions]);
66293
- const xAxisOptions = useMemo33(() => {
66641
+ const xAxisOptions = useMemo32(() => {
66294
66642
  if (!chartAxesBaseChart) return chartAxisOptions;
66295
66643
  const pivot = chartAxesBaseChart.pivot;
66296
66644
  const pivotRowField = String(pivot?.rowField ?? "").trim();
@@ -66313,7 +66661,7 @@ function useReport(reportIdArg, options = {}) {
66313
66661
  }
66314
66662
  return chartAxisOptions;
66315
66663
  }, [chartAxesBaseChart, chartAxisOptions, chartAxisOptionByField]);
66316
- const yAxisOptions = useMemo33(() => {
66664
+ const yAxisOptions = useMemo32(() => {
66317
66665
  if (!chartAxesBaseChart) return [];
66318
66666
  const keepOption = (option) => {
66319
66667
  const col = findSchemaColumnForChartAxisField(
@@ -66349,21 +66697,21 @@ function useReport(reportIdArg, options = {}) {
66349
66697
  chartAxisOptions,
66350
66698
  schemaColumnOptions
66351
66699
  ]);
66352
- const normalizedChartXAxisOptions = useMemo33(() => {
66700
+ const normalizedChartXAxisOptions = useMemo32(() => {
66353
66701
  return xAxisOptions.map((option) => ({
66354
66702
  value: String(option.value ?? "").trim(),
66355
66703
  label: String(option.label ?? option.value ?? "").trim(),
66356
66704
  format: String(option.format ?? "").trim()
66357
66705
  }));
66358
66706
  }, [xAxisOptions]);
66359
- const normalizedChartYAxisOptions = useMemo33(() => {
66707
+ const normalizedChartYAxisOptions = useMemo32(() => {
66360
66708
  return yAxisOptions.map((option) => ({
66361
66709
  value: String(option.value ?? "").trim(),
66362
66710
  label: String(option.label ?? option.value ?? "").trim(),
66363
66711
  format: String(option.format ?? "").trim()
66364
66712
  }));
66365
66713
  }, [yAxisOptions]);
66366
- const resolvedYAxisFields = useMemo33(() => {
66714
+ const resolvedYAxisFields = useMemo32(() => {
66367
66715
  if (!chartAxesBaseChart) return [];
66368
66716
  const normalizeYAxisField = (yAxisFieldRaw) => {
66369
66717
  const field = String(yAxisFieldRaw?.field ?? "").trim();
@@ -66406,7 +66754,7 @@ function useReport(reportIdArg, options = {}) {
66406
66754
  chartAxisOptionByField,
66407
66755
  chartAxisOptions
66408
66756
  ]);
66409
- const resolvedXAxisField = useMemo33(() => {
66757
+ const resolvedXAxisField = useMemo32(() => {
66410
66758
  if (!chartAxesBaseChart) return "";
66411
66759
  const chartType2 = String(chartAxesBaseChart.chartType ?? "").toLowerCase();
66412
66760
  const pivotRowField = String(
@@ -66438,7 +66786,7 @@ function useReport(reportIdArg, options = {}) {
66438
66786
  chartAxisOptions,
66439
66787
  resolvedYAxisFields
66440
66788
  ]);
66441
- const resolvedXAxisFormat = useMemo33(() => {
66789
+ const resolvedXAxisFormat = useMemo32(() => {
66442
66790
  if (!chartAxesBaseChart) {
66443
66791
  return "string";
66444
66792
  }
@@ -66466,7 +66814,7 @@ function useReport(reportIdArg, options = {}) {
66466
66814
  resolvedXAxisField,
66467
66815
  resolvedYAxisFields
66468
66816
  ]);
66469
- const resolvedXAxisLabel = useMemo33(() => {
66817
+ const resolvedXAxisLabel = useMemo32(() => {
66470
66818
  const defaultXLabel = String(
66471
66819
  chartAxesBaseChart?.xAxisLabel ?? chartAxisOptionByField.get(resolvedXAxisField)?.label ?? ""
66472
66820
  ).trim();
@@ -66480,62 +66828,49 @@ function useReport(reportIdArg, options = {}) {
66480
66828
  chartAxisOptionByField,
66481
66829
  resolvedXAxisField
66482
66830
  ]);
66483
- const chartVisibility = useMemo33(
66831
+ const chartVisibility = useMemo32(
66484
66832
  () => ({
66485
66833
  showLegend: chartVisibilityOverrides.showLegend ?? Boolean(baseChart?.showLegend ?? false)
66486
66834
  }),
66487
66835
  [baseChart?.showLegend, chartVisibilityOverrides]
66488
66836
  );
66489
- const axisConfig = useMemo33(() => {
66837
+ const xAxis = useMemo32(() => {
66490
66838
  const pivotBucketXAxis = isPivotTableDateBucketRowAxis(
66491
66839
  chartAxesBaseChart,
66492
66840
  resolvedXAxisField
66493
66841
  );
66494
66842
  const xFormatLabel = pivotBucketXAxis && String(resolvedXAxisFormat ?? "").trim() === "string" ? "date" : axisFormatToSelectLabel(resolvedXAxisFormat);
66495
66843
  return {
66496
- xAxis: {
66497
- field: resolvedXAxisField,
66498
- label: resolvedXAxisLabel,
66499
- format: xFormatLabel,
66500
- show: true,
66501
- rotation: 0,
66502
- fontSize: 12
66503
- },
66504
- yAxis: {
66505
- fields: resolvedYAxisFields.map((yAxisField, index) => ({
66506
- field: yAxisField.field,
66507
- label: String(yAxisField.label ?? "").trim(),
66508
- format: axisFormatToSelectLabel(
66509
- toAxisFormat(yAxisField.format, "string")
66510
- ),
66511
- color: USE_FORM_AXIS_SERIES_COLORS[index % USE_FORM_AXIS_SERIES_COLORS.length]
66512
- })),
66513
- label: "",
66514
- show: true,
66515
- min: "",
66516
- max: "",
66517
- fontSize: 12
66518
- },
66519
- legend: {
66520
- show: chartVisibility.showLegend
66521
- }
66844
+ field: resolvedXAxisField,
66845
+ label: resolvedXAxisLabel,
66846
+ format: xFormatLabel
66522
66847
  };
66523
66848
  }, [
66524
66849
  chartAxesBaseChart,
66525
66850
  resolvedXAxisLabel,
66526
66851
  resolvedXAxisField,
66527
- resolvedXAxisFormat,
66528
- resolvedYAxisFields,
66529
- chartVisibility.showLegend
66852
+ resolvedXAxisFormat
66530
66853
  ]);
66531
- const resolvedYAxisFieldsForDisplay = useMemo33(() => {
66854
+ const yAxis = useMemo32(
66855
+ () => ({
66856
+ fields: resolvedYAxisFields.map((yAxisField) => ({
66857
+ field: yAxisField.field,
66858
+ label: String(yAxisField.label ?? "").trim(),
66859
+ format: axisFormatToSelectLabel(
66860
+ toAxisFormat(yAxisField.format, "string")
66861
+ )
66862
+ }))
66863
+ }),
66864
+ [resolvedYAxisFields]
66865
+ );
66866
+ const resolvedYAxisFieldsForDisplay = useMemo32(() => {
66532
66867
  if (!baseChart) return resolvedYAxisFields;
66533
66868
  return mapResolvedPivotYAxisFieldsForDisplay({
66534
66869
  chart: baseChart,
66535
66870
  resolvedYAxisFields
66536
66871
  });
66537
66872
  }, [baseChart, resolvedYAxisFields]);
66538
- const chart = useMemo33(() => {
66873
+ const chart = useMemo32(() => {
66539
66874
  if (!baseChart) return void 0;
66540
66875
  let columns2 = mergeChartColumnFormatsFromYAxisFields(
66541
66876
  baseChart.columns,
@@ -66584,10 +66919,128 @@ function useReport(reportIdArg, options = {}) {
66584
66919
  resolvedXAxisLabel,
66585
66920
  resolvedYAxisFieldsForDisplay
66586
66921
  ]);
66922
+ const filterOptions = useMemo32(() => {
66923
+ const out = [];
66924
+ for (const [field, values] of filterValueOptionsByFieldName) {
66925
+ out.push({
66926
+ field,
66927
+ fieldType: "string",
66928
+ operator: "in",
66929
+ options: values.map(({ label, value }) => ({ label, value }))
66930
+ });
66931
+ }
66932
+ const pivot = chart?.pivot;
66933
+ const rowField = String(pivot?.rowField ?? "").trim();
66934
+ if (rowField && isDateType(String(pivot?.rowFieldType ?? ""))) {
66935
+ const field = pivot?.rowFieldTable ? `${pivot.rowFieldTable}.${rowField}` : rowField;
66936
+ const bucket = dateBucket || pivot?.dateBucket || "month";
66937
+ const byRaw = /* @__PURE__ */ new Map();
66938
+ for (const row of chart?.rows ?? []) {
66939
+ const record = row;
66940
+ const raw = record.__quillRawDate;
66941
+ if (raw == null || raw === "") continue;
66942
+ const key = String(raw);
66943
+ if (!byRaw.has(key)) {
66944
+ byRaw.set(key, String(record[rowField] ?? key));
66945
+ }
66946
+ }
66947
+ out.push({
66948
+ field,
66949
+ fieldType: "date",
66950
+ operator: "inBucket",
66951
+ dateBucket: bucket,
66952
+ options: [...byRaw.keys()].sort().map((value) => ({
66953
+ value,
66954
+ label: byRaw.get(value) ?? value
66955
+ }))
66956
+ });
66957
+ }
66958
+ return out;
66959
+ }, [
66960
+ chart?.pivot,
66961
+ chart?.rows,
66962
+ dateBucket,
66963
+ filterValueOptionsByFieldName
66964
+ ]);
66965
+ const chartForUi = useMemo32(() => {
66966
+ if (!chart?.pivot) return chart;
66967
+ const pivot = chart.pivot;
66968
+ const qualify = (field, table2) => table2 ? `${table2}.${field}` : field;
66969
+ const labelFor = (field) => chart.columns?.find((column) => column.field === field)?.label ?? field.split(".").pop().replace(/[_-]+/g, " ").replace(/\b\w/g, (char) => char.toUpperCase());
66970
+ const matchField = (entryField, field, table2) => {
66971
+ const qualified = qualify(field, table2);
66972
+ return entryField === qualified || entryField === field || entryField.endsWith(`.${field}`);
66973
+ };
66974
+ const selectedValue = (field, operator, options2) => {
66975
+ const rule = filtersForQueryBuilder.rules.find(
66976
+ (entry) => typeof entry === "object" && entry !== null && "field" in entry && entry.field === field && entry.operator === operator
66977
+ );
66978
+ if (!rule) return null;
66979
+ const raw = operator === "inBucket" ? rule.value?.start : Array.isArray(rule.value) ? rule.value[0] : void 0;
66980
+ if (raw == null) return null;
66981
+ const value = String(raw);
66982
+ return options2.some((option) => option.value === value) ? value : null;
66983
+ };
66984
+ let rowFilter = null;
66985
+ const rowField = String(pivot.rowField ?? "").trim();
66986
+ if (rowField) {
66987
+ if (isDateType(String(pivot.rowFieldType ?? ""))) {
66988
+ const entry = filterOptions.find(
66989
+ (option) => option.operator === "inBucket" && matchField(option.field, rowField, pivot.rowFieldTable)
66990
+ );
66991
+ if (entry) {
66992
+ const field = qualify(rowField, pivot.rowFieldTable);
66993
+ rowFilter = {
66994
+ ...entry,
66995
+ field,
66996
+ label: labelFor(rowField),
66997
+ value: selectedValue(field, entry.operator, entry.options)
66998
+ };
66999
+ }
67000
+ } else {
67001
+ const entry = filterOptions.find(
67002
+ (option) => option.operator === "in" && matchField(option.field, rowField, pivot.rowFieldTable)
67003
+ );
67004
+ if (entry) {
67005
+ const field = qualify(rowField, pivot.rowFieldTable);
67006
+ rowFilter = {
67007
+ ...entry,
67008
+ field,
67009
+ label: labelFor(rowField),
67010
+ value: selectedValue(field, entry.operator, entry.options)
67011
+ };
67012
+ }
67013
+ }
67014
+ }
67015
+ let columnFilter = null;
67016
+ const columnField = String(pivot.columnField ?? "").trim();
67017
+ if (columnField) {
67018
+ const entry = filterOptions.find(
67019
+ (option) => option.operator === "in" && matchField(option.field, columnField, pivot.columnFieldTable)
67020
+ );
67021
+ if (entry) {
67022
+ const field = qualify(columnField, pivot.columnFieldTable);
67023
+ columnFilter = {
67024
+ ...entry,
67025
+ field,
67026
+ label: labelFor(columnField),
67027
+ value: selectedValue(field, entry.operator, entry.options)
67028
+ };
67029
+ }
67030
+ }
67031
+ return {
67032
+ ...chart,
67033
+ pivot: {
67034
+ ...pivot,
67035
+ rowFilter,
67036
+ columnFilter
67037
+ }
67038
+ };
67039
+ }, [chart, filterOptions, filtersForQueryBuilder]);
66587
67040
  const isPivotTableChart = String(chartType ?? "").toLowerCase() === "table" && Boolean(
66588
67041
  chart && chart.pivot && Array.isArray(chart.columns) && chart.columns.length > 0
66589
67042
  );
66590
- const chartAxes = useMemo33(() => {
67043
+ const chartAxes = useMemo32(() => {
66591
67044
  const yAxisItems = resolvedYAxisFields.map(
66592
67045
  (yAxisField, index) => ({
66593
67046
  id: String(index),
@@ -66737,7 +67190,7 @@ function useReport(reportIdArg, options = {}) {
66737
67190
  yAxisOptions
66738
67191
  ]);
66739
67192
  const tableFormatCacheRef = useRef25(/* @__PURE__ */ new Map());
66740
- const tableFormatMerge = useMemo33(
67193
+ const tableFormatMerge = useMemo32(
66741
67194
  () => mergeDisplayAndSourceForTableFormats({
66742
67195
  effectiveReportBuilderTableNames,
66743
67196
  scopedSchemaColumns,
@@ -66751,7 +67204,7 @@ function useReport(reportIdArg, options = {}) {
66751
67204
  sourceReport
66752
67205
  ]
66753
67206
  );
66754
- const table = useMemo33(() => {
67207
+ const table = useMemo32(() => {
66755
67208
  const baseWindowRows = Array.isArray(sourceReport?.rows) ? sourceReport.rows : [];
66756
67209
  const rawRows = !paginationActive ? baseWindowRows : tablePageRows ?? baseWindowRows.slice(paginationRangeStart, paginationRangeEnd);
66757
67210
  const { columns: mergedFromReport } = mergeDisplayAndSourceForTableFormats({
@@ -66880,7 +67333,7 @@ function useReport(reportIdArg, options = {}) {
66880
67333
  const {
66881
67334
  columnsOptions: tableFormattingColumnOptions,
66882
67335
  hasTableDrivenColumnOrder
66883
- } = useMemo33(() => {
67336
+ } = useMemo32(() => {
66884
67337
  if (isPivotTableChart && chart?.columns?.length) {
66885
67338
  const aggregationSlotColumns = buildPivotColumnPivotTableFormattingColumns(chart);
66886
67339
  const pivotTableColumns = aggregationSlotColumns ? aggregationSlotColumns.tableColumns : chart.columns.map((c) => ({
@@ -66914,32 +67367,24 @@ function useReport(reportIdArg, options = {}) {
66914
67367
  schemaColumnOptions,
66915
67368
  table.columns
66916
67369
  ]);
66917
- const availableFields = useMemo33(
66918
- () => tableColumnPickerPoolOptions.map((option) => ({
66919
- id: option.value,
66920
- label: option.label,
66921
- type: option.type
66922
- })),
66923
- [tableColumnPickerPoolOptions]
66924
- );
66925
- const axisSelectFormatLabels = useMemo33(
67370
+ const axisSelectFormatLabels = useMemo32(
66926
67371
  () => AXIS_FORMAT_OPTIONS.map((option) => option.label),
66927
67372
  []
66928
67373
  );
66929
- const xAxisFormatOptionLabels = useMemo33(() => {
67374
+ const xAxisFormatOptionLabels = useMemo32(() => {
66930
67375
  if (isPivotTableDateBucketRowAxis(chartAxesBaseChart, resolvedXAxisField)) {
66931
67376
  return ["date", ...axisSelectFormatLabels];
66932
67377
  }
66933
67378
  return axisSelectFormatLabels;
66934
67379
  }, [chartAxesBaseChart, resolvedXAxisField, axisSelectFormatLabels]);
66935
- const tableDerivedColumnOrder = useMemo33(() => {
67380
+ const tableDerivedColumnOrder = useMemo32(() => {
66936
67381
  return tableFormattingColumnOptions.map((option) => option.value);
66937
67382
  }, [tableFormattingColumnOptions]);
66938
- const tableDerivedColumnOrderSignature = useMemo33(
67383
+ const tableDerivedColumnOrderSignature = useMemo32(
66939
67384
  () => tableDerivedColumnOrder.join("|"),
66940
67385
  [tableDerivedColumnOrder]
66941
67386
  );
66942
- const activeTableColumnIds = useMemo33(() => {
67387
+ const activeTableColumnIds = useMemo32(() => {
66943
67388
  if (isPivotTableChart && chart?.columns?.length) {
66944
67389
  const aggregationSlotColumns = buildPivotColumnPivotTableFormattingColumns(chart);
66945
67390
  if (aggregationSlotColumns) {
@@ -66978,7 +67423,7 @@ function useReport(reportIdArg, options = {}) {
66978
67423
  tableDerivedColumnOrder,
66979
67424
  tableFormattingColumnOptions
66980
67425
  ]);
66981
- const columnOptionById = useMemo33(() => {
67426
+ const columnOptionById = useMemo32(() => {
66982
67427
  const map = /* @__PURE__ */ new Map();
66983
67428
  for (const option of tableColumnPickerPoolOptions) {
66984
67429
  map.set(option.value, option);
@@ -66990,7 +67435,7 @@ function useReport(reportIdArg, options = {}) {
66990
67435
  }
66991
67436
  return map;
66992
67437
  }, [tableColumnPickerPoolOptions, tableFormattingColumnOptions]);
66993
- const displayColumnById = useMemo33(() => {
67438
+ const displayColumnById = useMemo32(() => {
66994
67439
  const map = /* @__PURE__ */ new Map();
66995
67440
  for (const column of displayColumns) {
66996
67441
  const field = String(column.field ?? "").trim();
@@ -67001,7 +67446,7 @@ function useReport(reportIdArg, options = {}) {
67001
67446
  }
67002
67447
  return map;
67003
67448
  }, [displayColumns]);
67004
- const tableColumnSettingsById = useMemo33(() => {
67449
+ const tableColumnSettingsById = useMemo32(() => {
67005
67450
  const map = /* @__PURE__ */ new Map();
67006
67451
  const effectiveById = tableFormatMerge.formatByColumnOptionId;
67007
67452
  const chartColById = /* @__PURE__ */ new Map();
@@ -67125,7 +67570,7 @@ function useReport(reportIdArg, options = {}) {
67125
67570
  useLayoutEffect4(() => {
67126
67571
  tableColumnSettingsCoalesceRef.current = new Map(tableColumnSettingsById);
67127
67572
  }, [tableColumnSettingsById]);
67128
- const tableColumnItems = useMemo33(() => {
67573
+ const tableColumnItems = useMemo32(() => {
67129
67574
  const pivotRowFieldForFormat = String(chart?.pivot?.rowField ?? "").trim();
67130
67575
  const pivotRowFieldType = String(chart?.pivot?.rowFieldType ?? "").trim();
67131
67576
  const items = activeTableColumnIds.map((columnId) => {
@@ -67161,19 +67606,18 @@ function useReport(reportIdArg, options = {}) {
67161
67606
  isPivotTableChart,
67162
67607
  tableColumnSettingsById
67163
67608
  ]);
67164
- const tableColumnById = useMemo33(() => {
67609
+ const tableColumnById = useMemo32(() => {
67165
67610
  return new Map(tableColumnItems.map((item) => [item.id, item]));
67166
67611
  }, [tableColumnItems]);
67167
- const tableColumnList = useMemo33(() => {
67612
+ const tableColumnValues = useMemo32(() => {
67168
67613
  const pivotRowFieldForFormat = String(chart?.pivot?.rowField ?? "").trim();
67169
67614
  const pivotRowFieldType = String(chart?.pivot?.rowFieldType ?? "").trim();
67170
67615
  return tableColumnItems.map((item) => {
67171
67616
  const coerced = coerceTableColumnFormatToAxisValue(item.format);
67172
67617
  const usePivotDateOptions = isPivotTableChart && item.field === pivotRowFieldForFormat && isDateType(pivotRowFieldType) && coerced === "string";
67173
67618
  return {
67174
- id: item.id,
67619
+ value: item.id,
67175
67620
  label: item.label,
67176
- visible: true,
67177
67621
  format: item.formatLabel,
67178
67622
  ...usePivotDateOptions ? { formatOptions: [...PIVOT_DATE_BUCKET_FORMAT_OPTIONS] } : {}
67179
67623
  };
@@ -67336,30 +67780,44 @@ function useReport(reportIdArg, options = {}) {
67336
67780
  columns: buildSetReportColumnsFromIds(nextColumnIds, nextSettingsById)
67337
67781
  };
67338
67782
  };
67339
- let setReport;
67783
+ let applyReportChange;
67784
+ const setReport = (nextState) => {
67785
+ const { columns: nextColumns, ...rest } = nextState;
67786
+ const nextSettingsById = nextColumns === void 0 ? tableColumnSettingsById : new Map(
67787
+ nextColumns.map((column) => [
67788
+ column.value,
67789
+ { label: column.label, format: column.format }
67790
+ ])
67791
+ );
67792
+ applyReportChange({
67793
+ ...rest,
67794
+ ...nextColumns !== void 0 ? {
67795
+ columns: buildSetReportColumnsFromIds(
67796
+ nextColumns.map((column) => column.value),
67797
+ nextSettingsById
67798
+ )
67799
+ } : {}
67800
+ });
67801
+ };
67340
67802
  const commitTableColumns = (nextColumnIds, settingsById) => {
67341
- setReport({
67803
+ applyReportChange({
67342
67804
  columns: buildSetReportColumnsFromIds(nextColumnIds, settingsById)
67343
67805
  });
67344
67806
  };
67345
- setReport = (nextState) => {
67346
- let effectiveNextState = nextState;
67347
- if (isSetReportTableColumnSidebarPatch(nextState.columns)) {
67348
- const expanded = buildColumnSidebarSetReportInput(
67349
- nextState.columns.patch
67350
- );
67351
- if (!expanded) return;
67352
- const { columns: _omitSidebarColumnPatch, ...rest } = nextState;
67353
- effectiveNextState = { ...rest, ...expanded };
67354
- }
67807
+ applyReportChange = (nextState) => {
67808
+ const effectiveNextState = nextState;
67355
67809
  if (effectiveNextState.showLegend !== void 0) {
67356
67810
  setChartVisibilityOverrides((previous) => ({
67357
67811
  ...previous,
67358
67812
  showLegend: Boolean(effectiveNextState.showLegend)
67359
67813
  }));
67360
67814
  }
67361
- if (effectiveNextState.chartAxes !== void 0) {
67362
- const cx = effectiveNextState.chartAxes;
67815
+ if (effectiveNextState.xAxis !== void 0 || effectiveNextState.yAxis !== void 0 || effectiveNextState.chartAxes !== void 0) {
67816
+ const cx = {
67817
+ ...effectiveNextState.chartAxes,
67818
+ ...effectiveNextState.xAxis !== void 0 ? { xAxis: effectiveNextState.xAxis } : {},
67819
+ ...effectiveNextState.yAxis !== void 0 ? { yAxis: effectiveNextState.yAxis } : {}
67820
+ };
67363
67821
  setChartAxisEdits((previousEdits) => {
67364
67822
  const nextEdits = { ...previousEdits };
67365
67823
  if (cx.xAxis) {
@@ -67424,15 +67882,18 @@ function useReport(reportIdArg, options = {}) {
67424
67882
  });
67425
67883
  }
67426
67884
  const isPivotSortUpdate = effectiveNextState.sort !== void 0 && Boolean(nextPivot);
67427
- const indexedAggregationUpdate = effectiveNextState.aggregations !== void 0 && typeof effectiveNextState.aggregations === "object" && !Array.isArray(effectiveNextState.aggregations) && "index" in effectiveNextState.aggregations && "value" in effectiveNextState.aggregations ? effectiveNextState.aggregations : null;
67428
- const isAppendingEmptyAggregationPlaceholder = indexedAggregationUpdate !== null && indexedAggregationUpdate.index === aggregationState.length && String(indexedAggregationUpdate.value ?? "").trim().length === 0;
67429
- const touchesPivotState = effectiveNextState.groupRowsBy !== void 0 || effectiveNextState.groupColumnsBy !== void 0 || effectiveNextState.aggregations !== void 0 && !isAppendingEmptyAggregationPlaceholder || isPivotSortUpdate || effectiveNextState.limit !== void 0;
67885
+ const isAppendingEmptyAggregationPlaceholder = Array.isArray(effectiveNextState.aggregations) && effectiveNextState.aggregations.length === aggregationValues.length + 1 && effectiveNextState.aggregations.slice(0, aggregationValues.length).every(
67886
+ (value, index) => String(value ?? "") === aggregationValues[index]
67887
+ ) && String(
67888
+ effectiveNextState.aggregations[aggregationValues.length] ?? ""
67889
+ ).trim().length === 0;
67890
+ const touchesPivotState = effectiveNextState.groupRowsBy !== void 0 || effectiveNextState.groupColumnsBy !== void 0 || effectiveNextState.dateBucket !== void 0 || effectiveNextState.aggregations !== void 0 && !isAppendingEmptyAggregationPlaceholder || isPivotSortUpdate || effectiveNextState.limit !== void 0;
67430
67891
  const isDatasourceUpdate = effectiveNextState.datasources !== void 0;
67431
67892
  const hasRowGroupSelection = typeof effectiveNextState.groupRowsBy === "string" && effectiveNextState.groupRowsBy.trim().length > 0;
67432
67893
  const hasColumnGroupSelection = typeof effectiveNextState.groupColumnsBy === "string" && effectiveNextState.groupColumnsBy.trim().length > 0;
67433
- const hasAggregationSelection = effectiveNextState.aggregations !== void 0 && (typeof effectiveNextState.aggregations === "string" ? effectiveNextState.aggregations.trim().length > 0 : Array.isArray(effectiveNextState.aggregations) ? effectiveNextState.aggregations.some(
67434
- (aggregation) => Boolean(aggregation?.aggregationType) && Boolean(String(aggregation?.valueField ?? "").trim())
67435
- ) : String(effectiveNextState.aggregations.value ?? "").trim().length > 0);
67894
+ const hasAggregationSelection = effectiveNextState.aggregations !== void 0 && (typeof effectiveNextState.aggregations === "string" ? effectiveNextState.aggregations.trim().length > 0 : effectiveNextState.aggregations.some(
67895
+ (aggregation) => typeof aggregation === "string" ? aggregation.trim().length > 0 : Boolean(aggregation?.aggregationType) && Boolean(String(aggregation?.valueField ?? "").trim())
67896
+ ));
67436
67897
  const isClearingRowGrouping = effectiveNextState.groupRowsBy !== void 0 && String(effectiveNextState.groupRowsBy ?? "").trim().length === 0;
67437
67898
  const queuePromoteColumnToRow = isClearingRowGrouping && !sourceReport;
67438
67899
  const shouldRefreshExpandedTableData = useInMemoryEngines && (hasRowGroupSelection || hasColumnGroupSelection || hasAggregationSelection) || !useInMemoryEngines && !nextPivot && effectiveNextState.sort !== void 0;
@@ -67505,7 +67966,7 @@ function useReport(reportIdArg, options = {}) {
67505
67966
  }
67506
67967
  }
67507
67968
  }
67508
- if (effectiveNextState.columns !== void 0 && !isSetReportTableColumnSidebarPatch(effectiveNextState.columns)) {
67969
+ if (effectiveNextState.columns !== void 0) {
67509
67970
  const normalizedDisplayColumns = normalizeColumnsInput(
67510
67971
  effectiveNextState.columns,
67511
67972
  columnIdentifierLookup
@@ -67592,6 +68053,10 @@ function useReport(reportIdArg, options = {}) {
67592
68053
  groupColumnsBySetViaSetReportRef.current = true;
67593
68054
  next.groupColumnsBy = effectiveNextState.groupColumnsBy || void 0;
67594
68055
  }
68056
+ if (effectiveNextState.dateBucket !== void 0) {
68057
+ dateBucketSetViaSetReportRef.current = true;
68058
+ next.dateBucket = effectiveNextState.dateBucket || void 0;
68059
+ }
67595
68060
  if (effectiveNextState.aggregations !== void 0) {
67596
68061
  aggregationStateSetViaSetReportRef.current = true;
67597
68062
  next.aggregationTablesByIndex = [...next.aggregationTablesByIndex];
@@ -67606,54 +68071,7 @@ function useReport(reportIdArg, options = {}) {
67606
68071
  ],
67607
68072
  schemaForeignKeyMap
67608
68073
  ).map((table2) => table2.name).filter((name2) => Boolean(name2));
67609
- if (typeof effectiveNextState.aggregations === "object" && !Array.isArray(effectiveNextState.aggregations) && "index" in effectiveNextState.aggregations && "value" in effectiveNextState.aggregations) {
67610
- const { index, value } = effectiveNextState.aggregations;
67611
- if (index >= 0 && index <= next.aggregationState.length) {
67612
- const rawValue = String(value ?? "").trim();
67613
- next.aggregationState = [...next.aggregationState];
67614
- if (!rawValue) {
67615
- if (index === next.aggregationState.length) {
67616
- next.aggregationState.push({ valueField: "" });
67617
- next.aggregationTablesByIndex.push(void 0);
67618
- } else if (index < next.aggregationState.length) {
67619
- next.aggregationState.splice(index, 1);
67620
- next.aggregationTablesByIndex.splice(index, 1);
67621
- }
67622
- } else {
67623
- const [aggregationTypeRaw] = rawValue.split(":");
67624
- const aggregationType = aggregationTypeRaw;
67625
- const { field: target, table: table2 } = resolveAggregationSelection(
67626
- rawValue,
67627
- aggregationOptionTableLookup,
67628
- preferredTables
67629
- );
67630
- const normalizedSelection = normalizeAggregationSelection(
67631
- aggregationType,
67632
- target,
67633
- table2,
67634
- preferredTables
67635
- );
67636
- const existing = next.aggregationState[index];
67637
- const preservedValueField2 = aggregationType !== "percentage" && existing?.valueField2 ? { valueField2: existing.valueField2 } : {};
67638
- const nextAggregation = {
67639
- ...preservedValueField2,
67640
- aggregationType,
67641
- ...normalizedSelection.valueField ? { valueField: normalizedSelection.valueField } : {},
67642
- ...normalizedSelection.valueField2 ? { valueField2: normalizedSelection.valueField2 } : {},
67643
- ...normalizedSelection.table ? { valueFieldTable: normalizedSelection.table } : {}
67644
- };
67645
- if (index === next.aggregationState.length) {
67646
- next.aggregationState.push(nextAggregation);
67647
- next.aggregationTablesByIndex.push(
67648
- normalizedSelection.table || void 0
67649
- );
67650
- } else {
67651
- next.aggregationState[index] = nextAggregation;
67652
- next.aggregationTablesByIndex[index] = normalizedSelection.table || void 0;
67653
- }
67654
- }
67655
- }
67656
- } else if (typeof effectiveNextState.aggregations === "string") {
68074
+ if (typeof effectiveNextState.aggregations === "string") {
67657
68075
  const rawValue = effectiveNextState.aggregations.trim();
67658
68076
  if (!rawValue) {
67659
68077
  next.aggregationState = [];
@@ -67685,15 +68103,49 @@ function useReport(reportIdArg, options = {}) {
67685
68103
  ];
67686
68104
  }
67687
68105
  } else {
67688
- next.aggregationState = effectiveNextState.aggregations;
67689
- next.aggregationTablesByIndex = effectiveNextState.aggregations.map(
67690
- (aggregation) => String(aggregation.valueFieldTable ?? "").trim() || resolveFieldTable({
67691
- report: sourceReport,
67692
- field: aggregation.valueField,
67693
- schemaTables: schemaForReportBuilderState,
67694
- preferredTables
67695
- }) || void 0
68106
+ const decoded = effectiveNextState.aggregations.map(
68107
+ (aggregation) => {
68108
+ if (typeof aggregation !== "string") {
68109
+ return {
68110
+ aggregation,
68111
+ table: String(aggregation.valueFieldTable ?? "").trim() || resolveFieldTable({
68112
+ report: sourceReport,
68113
+ field: aggregation.valueField,
68114
+ schemaTables: schemaForReportBuilderState,
68115
+ preferredTables
68116
+ }) || void 0
68117
+ };
68118
+ }
68119
+ const rawValue = aggregation.trim();
68120
+ if (!rawValue) {
68121
+ return { aggregation: { valueField: "" }, table: void 0 };
68122
+ }
68123
+ const [aggregationTypeRaw] = rawValue.split(":");
68124
+ const aggregationType = aggregationTypeRaw;
68125
+ const { field: target, table: table2 } = resolveAggregationSelection(
68126
+ rawValue,
68127
+ aggregationOptionTableLookup,
68128
+ preferredTables
68129
+ );
68130
+ const normalizedSelection = normalizeAggregationSelection(
68131
+ aggregationType,
68132
+ target,
68133
+ table2,
68134
+ preferredTables
68135
+ );
68136
+ return {
68137
+ aggregation: {
68138
+ aggregationType,
68139
+ ...normalizedSelection.valueField ? { valueField: normalizedSelection.valueField } : {},
68140
+ ...normalizedSelection.valueField2 ? { valueField2: normalizedSelection.valueField2 } : {},
68141
+ ...normalizedSelection.table ? { valueFieldTable: normalizedSelection.table } : {}
68142
+ },
68143
+ table: normalizedSelection.table || void 0
68144
+ };
68145
+ }
67696
68146
  );
68147
+ next.aggregationState = decoded.map((entry) => entry.aggregation);
68148
+ next.aggregationTablesByIndex = decoded.map((entry) => entry.table);
67697
68149
  }
67698
68150
  }
67699
68151
  if (effectiveNextState.sort !== void 0) {
@@ -67808,29 +68260,9 @@ function useReport(reportIdArg, options = {}) {
67808
68260
  }
67809
68261
  });
67810
68262
  };
67811
- const tableColumns = {
67812
- items: tableColumnItems,
67813
- optionById: columnOptionById,
67814
- byId: tableColumnById,
67815
- columnList: tableColumnList,
67816
- getSetReportColumns: (ids) => {
67817
- const out = [];
67818
- for (const rawId of ids) {
67819
- const id = String(rawId ?? "").trim();
67820
- if (!id) continue;
67821
- const option = columnOptionById.get(id);
67822
- if (!option) continue;
67823
- const item = tableColumnById.get(id);
67824
- const customLabel = String(item?.customLabel ?? "").trim();
67825
- const format9 = String(item?.format ?? "").trim();
67826
- out.push({
67827
- field: option.field,
67828
- ...option.tableName ? { table: option.tableName } : {},
67829
- ...customLabel ? { label: customLabel } : {},
67830
- ...format9 ? { format: format9 } : {}
67831
- });
67832
- }
67833
- return out;
68263
+ const columnActions = {
68264
+ replace: (nextColumns) => {
68265
+ applyReportChange({ columns: nextColumns });
67834
68266
  },
67835
68267
  reorder: (oldIndex, newIndex) => {
67836
68268
  if (loading || isPivotTableChart) return;
@@ -67894,25 +68326,20 @@ function useReport(reportIdArg, options = {}) {
67894
68326
  setTableColumnsEditedSignature(tableDerivedColumnOrderSignature);
67895
68327
  commitTableColumns(nextColumnIds, tableColumnSettingsById);
67896
68328
  },
67897
- getColumnSidebarSetReportInput: (id, updates) => {
67898
- const normalizedId = String(id ?? "").trim();
67899
- if (!normalizedId) return null;
67900
- return {
67901
- columns: { patch: { id: normalizedId, ...updates } }
67902
- };
67903
- },
67904
68329
  update: (id, updates) => {
67905
68330
  const normalizedId = String(id ?? "").trim();
67906
68331
  if (!normalizedId) return;
67907
- setReport({
67908
- columns: { patch: { id: normalizedId, ...updates } }
68332
+ const expanded = buildColumnSidebarSetReportInput({
68333
+ id: normalizedId,
68334
+ ...updates
67909
68335
  });
67910
- },
67911
- structureEditsLocked: isPivotTableChart
68336
+ if (expanded) applyReportChange(expanded);
68337
+ }
67912
68338
  };
67913
68339
  const setFilters = (nextFilters) => {
68340
+ const resolved = typeof nextFilters === "function" ? nextFilters(filtersForQueryBuilder) : nextFilters;
67914
68341
  const preparedForStack = prepareQueryBuilderFiltersForSet(
67915
- nextFilters,
68342
+ resolved,
67916
68343
  queryFilters
67917
68344
  );
67918
68345
  const nextFiltersNormalizedForConfig = normalizeQueryBuilderFiltersForConfig(preparedForStack);
@@ -67953,26 +68380,19 @@ function useReport(reportIdArg, options = {}) {
67953
68380
  });
67954
68381
  }
67955
68382
  } catch (error) {
67956
- if (isUseFormFiltersDebugEnabled()) {
67957
- console.error("[useForm-debug] setFilters swallowed error", {
67958
- error: error instanceof Error ? error.message : String(error),
67959
- requestedRules: (nextFilters?.rules ?? []).map((rule) => ({
67960
- table: rule?.table,
67961
- field: rule?.field,
67962
- operator: rule?.operator
67963
- })),
67964
- fieldConfigKeys: Object.keys(queryBuilderFieldConfigByName ?? {})
67965
- });
67966
- }
68383
+ console.error("[useForm] setFilters swallowed error", {
68384
+ error: error instanceof Error ? error.message : String(error),
68385
+ requestedRules: (resolved?.rules ?? []).map((rule) => ({
68386
+ table: rule?.table,
68387
+ field: rule?.field,
68388
+ operator: rule?.operator,
68389
+ value: rule?.value
68390
+ })),
68391
+ fieldConfigKeys: Object.keys(queryBuilderFieldConfigByName ?? {})
68392
+ });
67967
68393
  }
67968
68394
  };
67969
- const filterDraft = useReportFilterDraft({
67970
- reportId: effectiveReportId,
67971
- committedFilters: filtersForQueryBuilder,
67972
- queryBuilderProps: filterQueryBuilderProps,
67973
- setFilters
67974
- });
67975
- const saveChanges = useCallback6(async () => {
68395
+ const saveChanges = useCallback5(async () => {
67976
68396
  if (!client) return;
67977
68397
  if (!String(dashboardNameForNewReport ?? "").trim()) return;
67978
68398
  if (!sourceReport) return;
@@ -68031,7 +68451,7 @@ function useReport(reportIdArg, options = {}) {
68031
68451
  ]);
68032
68452
  return {
68033
68453
  /* ── Chart & table (exceptions: not value/options pairs) ── */
68034
- chart,
68454
+ chart: chartForUi,
68035
68455
  chartLoading,
68036
68456
  table,
68037
68457
  tableLoading,
@@ -68050,22 +68470,28 @@ function useReport(reportIdArg, options = {}) {
68050
68470
  groupRowsByOptions,
68051
68471
  groupColumnsBy,
68052
68472
  groupColumnsByOptions,
68053
- aggregations: aggregationState,
68473
+ dateBucket,
68474
+ dateBucketOptions: PIVOT_DATE_BUCKET_OPTIONS,
68475
+ /** Encoded selection per aggregation slot (`'sum:transactions::amount'`, `'count:transactions'`, `''` = placeholder). Update via `setReport({ aggregations: nextStringArray })`. */
68476
+ aggregations: aggregationValues,
68477
+ /** Flat aggregation pick list shared by all slots; always contains every non-empty `aggregations` entry. */
68054
68478
  aggregationOptions,
68055
68479
  aggregationDescriptionOptions: cleanedAggregations,
68056
68480
  sort: cleanedSort,
68057
68481
  sortOptions,
68058
68482
  chartType,
68059
68483
  chartTypeOptions: chartTypes,
68060
- /** Encoded field keys for the current column selection (for `setReport({ columns })`, etc.). */
68061
- columnIds: columns,
68062
- /** Selected columns + `reorder` / `toggle` / `update` / `remove`. */
68063
- columns: tableColumns,
68484
+ /** Selected tabular columns in display order. */
68485
+ columns: tableColumnValues,
68486
+ /** Pivot table columns only allow label and format changes. */
68487
+ columnStructureEditsLocked: isPivotTableChart,
68488
+ /** Optional rich operations; simple selection updates use `setReport({ columns })`. */
68489
+ columnActions,
68064
68490
  /** Schema columns for current datasources — pool for the table column picker. */
68065
68491
  columnOptions: tableColumnPickerPoolOptions,
68066
- xAxis: chartAxes.xAxis,
68492
+ xAxis,
68067
68493
  xAxisOptions: normalizedChartXAxisOptions,
68068
- yAxis: chartAxes.yAxis,
68494
+ yAxis,
68069
68495
  yAxisOptions: normalizedChartYAxisOptions,
68070
68496
  /** Same strings as `axisSelectFormatLabels` (X/Y share chart format presets). */
68071
68497
  xAxisFormatOptions: xAxisFormatOptionLabels,
@@ -68073,8 +68499,6 @@ function useReport(reportIdArg, options = {}) {
68073
68499
  /** Table column format dropdown labels (same set as chart axis formats). */
68074
68500
  tableFormatOptions: axisSelectFormatLabels,
68075
68501
  showLegend: chartVisibility.showLegend,
68076
- axisConfig,
68077
- availableFields,
68078
68502
  axisSelectFormatLabels,
68079
68503
  /** @deprecated Prefer top-level `xAxis`, `yAxis`, and `showLegend`. */
68080
68504
  chartAxes,
@@ -68088,12 +68512,11 @@ function useReport(reportIdArg, options = {}) {
68088
68512
  filters: filtersForQueryBuilder,
68089
68513
  filterQueryBuilderProps,
68090
68514
  /**
68091
- * Draft Apply lifecycle for react-querybuilder (flat keys):
68092
- * `<QueryBuilder key={filterDraftKey} {...filterDraftQueryBuilderProps} />`
68093
- * plus `isFilterDraftDirty` / `isFilterDraftEmpty` /
68094
- * `commitFilterDraft` / `resetFilterDraft` / `seedFilterDraft`.
68515
+ * Filter value pick lists for custom UIs (string unique values + pivot date
68516
+ * buckets). Same string data as `filterQueryBuilderProps.getValues`; not
68517
+ * wired into react-querybuilder unless you use it yourself.
68095
68518
  */
68096
- ...filterDraft,
68519
+ filterOptions,
68097
68520
  /** True while `report-builder-unique-values` runs for filter value options (not chart/table load). */
68098
68521
  filterUniqueValuesLoading,
68099
68522
  limit,
@@ -68101,7 +68524,6 @@ function useReport(reportIdArg, options = {}) {
68101
68524
  chartTypes,
68102
68525
  columnsOptions: tableColumnPickerPoolOptions,
68103
68526
  tableColumnOptions: tableColumnPickerPoolOptions,
68104
- tableColumns,
68105
68527
  setReport,
68106
68528
  saveChanges,
68107
68529
  setFilters,
@@ -68119,7 +68541,7 @@ function ChatChartCard({
68119
68541
  ButtonComponent = MemoizedButton
68120
68542
  }) {
68121
68543
  const {
68122
- columnIds,
68544
+ columns,
68123
68545
  columnOptions,
68124
68546
  groupRowsBy,
68125
68547
  groupRowsByOptions,
@@ -68133,20 +68555,10 @@ function ChatChartCard({
68133
68555
  loading,
68134
68556
  setReport
68135
68557
  } = useReport(reportId);
68136
- const columnSelectOptions = useMemo34(() => {
68137
- return (columnOptions ?? []).map((option) => {
68138
- const value = String(option?.value ?? "").trim();
68139
- if (!value) return null;
68140
- const tableName = String(option?.tableName ?? "").trim();
68141
- const fieldName = String(option?.field ?? "").trim() || String(option?.label ?? "").trim() || value;
68142
- return {
68143
- value,
68144
- label: tableName ? `${tableName}.${fieldName}` : fieldName
68145
- };
68146
- }).filter(
68147
- (option) => Boolean(option)
68148
- );
68149
- }, [columnOptions]);
68558
+ const selectedColumnValues = useMemo33(
68559
+ () => columns.map((column) => column.value),
68560
+ [columns]
68561
+ );
68150
68562
  return /* @__PURE__ */ jsxs64(
68151
68563
  "div",
68152
68564
  {
@@ -68182,7 +68594,7 @@ function ChatChartCard({
68182
68594
  padding: 16
68183
68595
  },
68184
68596
  children: [
68185
- JSON.stringify(columnIds, null, 2),
68597
+ JSON.stringify(columns, null, 2),
68186
68598
  /* @__PURE__ */ jsxs64(
68187
68599
  "label",
68188
68600
  {
@@ -68199,13 +68611,24 @@ function ChatChartCard({
68199
68611
  "select",
68200
68612
  {
68201
68613
  multiple: true,
68202
- size: Math.min(10, Math.max(4, columnSelectOptions.length || 4)),
68203
- value: columnIds,
68614
+ size: Math.min(10, Math.max(4, columnOptions.length || 4)),
68615
+ value: selectedColumnValues,
68204
68616
  onChange: (event) => {
68205
- const nextColumns = Array.from(event.target.selectedOptions).map(
68206
- (option) => option.value
68617
+ const selectedByValue = new Map(
68618
+ columns.map((column) => [column.value, column])
68207
68619
  );
68208
- setReport({ columns: nextColumns });
68620
+ const optionByValue = new Map(
68621
+ columnOptions.map((option) => [option.value, option])
68622
+ );
68623
+ setReport({
68624
+ columns: Array.from(event.target.selectedOptions).map(
68625
+ (selectedOption) => selectedByValue.get(selectedOption.value) ?? {
68626
+ value: selectedOption.value,
68627
+ label: optionByValue.get(selectedOption.value)?.label ?? selectedOption.value,
68628
+ format: ""
68629
+ }
68630
+ )
68631
+ });
68209
68632
  },
68210
68633
  style: {
68211
68634
  width: 200,
@@ -68215,7 +68638,7 @@ function ChatChartCard({
68215
68638
  padding: 8,
68216
68639
  background: "#fff"
68217
68640
  },
68218
- children: columnSelectOptions.map((option) => /* @__PURE__ */ jsx87("option", { value: option.value, children: option.label }, option.value))
68641
+ children: columnOptions.map((option) => /* @__PURE__ */ jsx87("option", { value: option.value, children: option.label }, option.value))
68219
68642
  }
68220
68643
  )
68221
68644
  ]
@@ -68241,28 +68664,27 @@ function ChatChartCard({
68241
68664
  onChange: (e) => setReport({ groupColumnsBy: e.target.value ?? "" })
68242
68665
  }
68243
68666
  ),
68244
- aggregationOptions.map((row, index) => /* @__PURE__ */ jsx87(
68667
+ aggregations.map((value, index) => /* @__PURE__ */ jsx87(
68245
68668
  SelectComponent,
68246
68669
  {
68247
- value: row.value,
68248
- label: row.label,
68670
+ value,
68671
+ label: `Aggregation ${index + 1}`,
68249
68672
  width: 200,
68250
- options: row.options,
68673
+ options: aggregationOptions,
68251
68674
  onChange: (e) => setReport({
68252
- aggregations: { index, value: e.target.value ?? "" }
68675
+ aggregations: aggregations.map(
68676
+ (aggregation, i) => i === index ? e.target.value ?? "" : aggregation
68677
+ )
68253
68678
  })
68254
68679
  },
68255
- row.key
68680
+ `aggregation-${index}`
68256
68681
  )),
68257
68682
  /* @__PURE__ */ jsx87(
68258
68683
  ButtonComponent,
68259
68684
  {
68260
68685
  label: "Add aggregation",
68261
68686
  onClick: () => setReport({
68262
- aggregations: {
68263
- index: aggregations.length,
68264
- value: "count transactions"
68265
- }
68687
+ aggregations: [...aggregations, "count:transactions"]
68266
68688
  })
68267
68689
  }
68268
68690
  ),
@@ -68400,7 +68822,7 @@ function ToolCallBlock({ toolCall }) {
68400
68822
  );
68401
68823
  }
68402
68824
  function ToolCallResult({ content }) {
68403
- const [expanded, setExpanded] = useState43(false);
68825
+ const [expanded, setExpanded] = useState42(false);
68404
68826
  if (!content) return null;
68405
68827
  const isLong = content.length > 300;
68406
68828
  const displayed = isLong && !expanded ? content.slice(0, 300) + "..." : content;
@@ -68455,11 +68877,11 @@ function Chat({
68455
68877
  const [client] = useContext37(ClientContext);
68456
68878
  const { getToken } = useContext37(FetchContext);
68457
68879
  const { tenants } = useContext37(TenantContext);
68458
- const [messages, setMessages] = useState43([]);
68459
- const [input, setInput] = useState43("");
68460
- const [inputError, setInputError] = useState43("");
68461
- const [isLoading, setIsLoading] = useState43(false);
68462
- const [model, setModel] = useState43("gemini-3-flash-preview");
68880
+ const [messages, setMessages] = useState42([]);
68881
+ const [input, setInput] = useState42("");
68882
+ const [inputError, setInputError] = useState42("");
68883
+ const [isLoading, setIsLoading] = useState42(false);
68884
+ const [model, setModel] = useState42("gemini-3-flash-preview");
68463
68885
  const containerRef = useRef26(null);
68464
68886
  const textareaRef = useRef26(null);
68465
68887
  const abortControllerRef = useRef26(null);
@@ -68475,11 +68897,11 @@ function Chat({
68475
68897
  setIsLoading(false);
68476
68898
  };
68477
68899
  const submitDefaultMessage = async (nextMessages, abortController) => {
68478
- const clientId = client.clientId ?? client.publicKey;
68900
+ const clientId = client.id;
68479
68901
  let responseBuffer = "";
68480
68902
  for await (const chunk of quillStream({
68481
68903
  client: {
68482
- clientId,
68904
+ id: clientId,
68483
68905
  queryEndpoint: client.queryEndpoint,
68484
68906
  streamEndpoint: client.streamEndpoint,
68485
68907
  queryHeaders: client.queryHeaders,
@@ -68563,12 +68985,12 @@ function Chat({
68563
68985
  }
68564
68986
  };
68565
68987
  const submitAgentMessage = async (nextMessages, abortController) => {
68566
- const clientId = client.clientId ?? client.publicKey;
68988
+ const clientId = client.id;
68567
68989
  let updatedMessages = [...nextMessages];
68568
68990
  for await (const event of quillAgentStream({
68569
68991
  endpoint: `${agentEndpoint}/agent/chat`,
68570
68992
  messages: updatedMessages,
68571
- sourceClientId: clientId,
68993
+ sourceClientId: clientId ?? "<unknown>",
68572
68994
  getToken,
68573
68995
  abortSignal: abortController.signal
68574
68996
  })) {
@@ -68636,7 +69058,7 @@ function Chat({
68636
69058
  setIsLoading(true);
68637
69059
  const abortController = new AbortController();
68638
69060
  abortControllerRef.current = abortController;
68639
- const clientId = client.clientId ?? client.publicKey;
69061
+ const clientId = client.id;
68640
69062
  if (!clientId) {
68641
69063
  setInputError("No client selected.");
68642
69064
  setIsLoading(false);
@@ -68896,11 +69318,167 @@ function Chat({
68896
69318
  );
68897
69319
  }
68898
69320
 
69321
+ // src/hooks/useReportFilterDraft.ts
69322
+ import { useCallback as useCallback6, useMemo as useMemo34, useRef as useRef27, useState as useState43 } from "react";
69323
+ var normalizeOperatorKey = (operator) => String(operator ?? "").trim().toLowerCase().replace(/[_\s]+/g, "");
69324
+ var defaultFilterRuleValueForOperator = (operator) => {
69325
+ const key = normalizeOperatorKey(operator);
69326
+ if (key === "in" || key === "notin") {
69327
+ return [];
69328
+ }
69329
+ return "";
69330
+ };
69331
+ var EMPTY_COMMITTED_FILTERS = {
69332
+ combinator: "and",
69333
+ rules: []
69334
+ };
69335
+ var hashString2 = (input) => {
69336
+ let hash = 2166136261;
69337
+ for (let i = 0; i < input.length; i++) {
69338
+ hash ^= input.charCodeAt(i);
69339
+ hash = Math.imul(hash, 16777619);
69340
+ }
69341
+ return String(hash >>> 0);
69342
+ };
69343
+ var fieldCatalogSignature = (fields) => {
69344
+ const names = fields.map((field) => String(field.name ?? "").trim()).filter(Boolean).sort();
69345
+ return `${names.length}:${hashString2(names.join("\0"))}`;
69346
+ };
69347
+ var committedFiltersSignature = (committed) => {
69348
+ try {
69349
+ return hashString2(
69350
+ JSON.stringify(stripQueryBuilderTransientFields(committed))
69351
+ );
69352
+ } catch {
69353
+ return "unserializable";
69354
+ }
69355
+ };
69356
+ function useReportFilterDraft(args) {
69357
+ const { reportId, committedFilters, queryBuilderProps, setFilters } = args;
69358
+ const committed = queryBuilderFiltersForEditor(
69359
+ isQueryBuilderDisplayGroup(committedFilters) ? committedFilters : EMPTY_COMMITTED_FILTERS
69360
+ );
69361
+ const committedRef = useRef27(committed);
69362
+ committedRef.current = committed;
69363
+ const setFiltersRef = useRef27(setFilters);
69364
+ setFiltersRef.current = setFilters;
69365
+ const lastNonEmptyFieldsRef = useRef27([]);
69366
+ const prevReportIdForFieldsRef = useRef27(reportId);
69367
+ if (prevReportIdForFieldsRef.current !== reportId) {
69368
+ prevReportIdForFieldsRef.current = reportId;
69369
+ lastNonEmptyFieldsRef.current = [];
69370
+ }
69371
+ if (queryBuilderProps.fields.length > 0) {
69372
+ lastNonEmptyFieldsRef.current = queryBuilderProps.fields;
69373
+ }
69374
+ const effectiveFields = queryBuilderProps.fields.length > 0 ? queryBuilderProps.fields : lastNonEmptyFieldsRef.current;
69375
+ const committedSignature = useMemo34(
69376
+ () => committedFiltersSignature(committed),
69377
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- `committed` normalizes null to a stable constant
69378
+ [committedFilters]
69379
+ );
69380
+ const fieldsSignature = useMemo34(
69381
+ () => fieldCatalogSignature(effectiveFields),
69382
+ [effectiveFields]
69383
+ );
69384
+ const [resetEpoch, setResetEpoch] = useState43(0);
69385
+ const [draftQuery, setDraftQuery] = useState43(committed);
69386
+ const [hasUnappliedFilterChanges, setHasUnappliedFilterChanges] = useState43(false);
69387
+ const draftResetKey = `${reportId}|${committedSignature}|${resetEpoch}`;
69388
+ const prevDraftResetKeyRef = useRef27(draftResetKey);
69389
+ if (prevDraftResetKeyRef.current !== draftResetKey) {
69390
+ prevDraftResetKeyRef.current = draftResetKey;
69391
+ setDraftQuery(committed);
69392
+ if (hasUnappliedFilterChanges) setHasUnappliedFilterChanges(false);
69393
+ }
69394
+ const filterDraftKey = `${draftResetKey}|${fieldsSignature}`;
69395
+ const handleQueryChange = useCallback6((next) => {
69396
+ if (!isQueryBuilderDisplayGroup(next)) return;
69397
+ const nextGroup = next;
69398
+ setDraftQuery(nextGroup);
69399
+ const nextDirty = areQueryBuilderFilterDraftsDirty(
69400
+ nextGroup,
69401
+ committedRef.current
69402
+ );
69403
+ setHasUnappliedFilterChanges(
69404
+ (prev) => prev === nextDirty ? prev : nextDirty
69405
+ );
69406
+ }, []);
69407
+ const applyFilterDraft = useCallback6(() => {
69408
+ setFiltersRef.current(draftQuery);
69409
+ }, [draftQuery]);
69410
+ const resetFilterDraft = useCallback6(() => {
69411
+ setDraftQuery(committedRef.current);
69412
+ setHasUnappliedFilterChanges(false);
69413
+ setResetEpoch((epoch) => epoch + 1);
69414
+ }, []);
69415
+ const getDefaultField = useCallback6((fields) => {
69416
+ const stringField = fields.find(
69417
+ (field) => field.quillFieldType === "string" && String(field.name ?? "").trim()
69418
+ );
69419
+ return stringField?.name ?? fields[0]?.name ?? "";
69420
+ }, []);
69421
+ const getDefaultValue = useCallback6(
69422
+ (rule) => defaultFilterRuleValueForOperator(rule?.operator),
69423
+ []
69424
+ );
69425
+ const filterDraftQueryBuilderProps = useMemo34(
69426
+ () => ({
69427
+ ...queryBuilderProps,
69428
+ fields: effectiveFields,
69429
+ // Uncontrolled: react-querybuilder owns the draft; only read at mount,
69430
+ // while state keeps the next mount hydrated from the latest edits.
69431
+ // Empty draft: omit defaultQuery so addRuleToNewGroups seeds a root rule
69432
+ // (RQB ignores auto-add when defaultQuery.rules is []).
69433
+ ...draftQuery.rules.length > 0 ? { defaultQuery: draftQuery } : {},
69434
+ onQueryChange: handleQueryChange,
69435
+ addRuleToNewGroups: true,
69436
+ getDefaultField,
69437
+ getDefaultValue
69438
+ }),
69439
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- filterDraftKey covers draftRef resets
69440
+ [
69441
+ queryBuilderProps,
69442
+ effectiveFields,
69443
+ draftQuery,
69444
+ handleQueryChange,
69445
+ getDefaultField,
69446
+ getDefaultValue,
69447
+ filterDraftKey
69448
+ ]
69449
+ );
69450
+ return {
69451
+ filterDraftKey,
69452
+ filterDraftQueryBuilderProps,
69453
+ hasUnappliedFilterChanges,
69454
+ applyFilterDraft,
69455
+ resetFilterDraft
69456
+ };
69457
+ }
69458
+
69459
+ // src/hooks/useReportQueryBuilder.ts
69460
+ function useReportQueryBuilder(args) {
69461
+ const draft = useReportFilterDraft({
69462
+ reportId: args.reportId ?? "",
69463
+ committedFilters: args.filters,
69464
+ queryBuilderProps: args.queryBuilderProps,
69465
+ setFilters: args.onApply
69466
+ });
69467
+ return {
69468
+ key: draft.filterDraftKey,
69469
+ props: draft.filterDraftQueryBuilderProps,
69470
+ hasUnappliedChanges: draft.hasUnappliedFilterChanges,
69471
+ apply: draft.applyFilterDraft,
69472
+ discard: draft.resetFilterDraft,
69473
+ reset: draft.resetFilterDraft
69474
+ };
69475
+ }
69476
+
68899
69477
  // src/ReportDetail.tsx
68900
69478
  import {
68901
69479
  useContext as useContext38,
68902
69480
  useLayoutEffect as useLayoutEffect5,
68903
- useRef as useRef27,
69481
+ useRef as useRef28,
68904
69482
  useState as useState44
68905
69483
  } from "react";
68906
69484
  import { jsx as jsx89, jsxs as jsxs66 } from "react/jsx-runtime";
@@ -69001,7 +69579,7 @@ function ReportDetail({
69001
69579
  const isTableChart = type === "table";
69002
69580
  const useDetailTableFromUseForm = isTableChart && !isPivotTableChartConfig(chart);
69003
69581
  const showBottomRawTable = !isTableChart;
69004
- const chartSlotRef = useRef27(null);
69582
+ const chartSlotRef = useRef28(null);
69005
69583
  const [chartHeightPx, setChartHeightPx] = useState44(360);
69006
69584
  useLayoutEffect5(() => {
69007
69585
  const el = chartSlotRef.current;
@@ -69753,7 +70331,7 @@ var useVirtualTables = () => {
69753
70331
  };
69754
70332
  };
69755
70333
  const handleRefreshSome = async (client, tables) => {
69756
- if (!client.clientId) return schemaData;
70334
+ if (!client.id) return schemaData;
69757
70335
  setLoadingTables({
69758
70336
  ...loadingTables,
69759
70337
  ...tables.reduce((acc, table) => {
@@ -69771,7 +70349,7 @@ var useVirtualTables = () => {
69771
70349
  name: table.name,
69772
70350
  customFieldInfo: table.customFieldInfo,
69773
70351
  id: table._id,
69774
- clientId: client.clientId,
70352
+ clientId: client.id,
69775
70353
  runQueryConfig: { getColumns: true },
69776
70354
  databaseType: client.databaseType,
69777
70355
  useNewNodeSql: true
@@ -69919,11 +70497,12 @@ var useChangelogRefresh = () => {
69919
70497
  reportsDispatch({ type: "DELETE_REPORT", id: reportId });
69920
70498
  dashboardDispatch({ type: "REMOVE_DASHBOARD_ITEM", id: reportId });
69921
70499
  }
69922
- const finalDashboardSet = reloadAllDashboards ? new Set(
69923
- Object.keys(dashboardConfig).filter(
70500
+ const finalDashboardSet = reloadAllDashboards ? /* @__PURE__ */ new Set([
70501
+ ...Object.keys(dashboardConfig).filter(
69924
70502
  (d) => !dashboardsToRemove.has(d)
69925
- )
69926
- ) : dashboardsToReload;
70503
+ ),
70504
+ ...dashboardsToReload
70505
+ ]) : dashboardsToReload;
69927
70506
  const tasks = [];
69928
70507
  const schemaIdsToReload = schemaIds.filter(
69929
70508
  (id) => !schemaIdsToRemove.has(id)
@@ -70030,7 +70609,6 @@ export {
70030
70609
  Table_default as Table,
70031
70610
  ThemeContext,
70032
70611
  areQueryBuilderFilterDraftsDirty,
70033
- buildSeededFilterQuery,
70034
70612
  countFilterRules,
70035
70613
  defaultFilterRuleValueForOperator,
70036
70614
  downloadCSV,
@@ -70039,6 +70617,7 @@ export {
70039
70617
  isQueryBuilderDisplayRule,
70040
70618
  normalizeRelativeDateRules,
70041
70619
  prepareQueryBuilderFiltersForSet,
70620
+ queryBuilderFiltersForEditor,
70042
70621
  quillFetch,
70043
70622
  stripQueryBuilderTransientFields,
70044
70623
  tableColumnFormatFromUiSelection,
@@ -70055,6 +70634,7 @@ export {
70055
70634
  useQuill,
70056
70635
  useReport,
70057
70636
  useReportBuilder,
70637
+ useReportQueryBuilder,
70058
70638
  useReports,
70059
70639
  useTenants,
70060
70640
  useVirtualTables