@quillsql/react 2.16.47 → 2.16.49

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -21022,7 +21022,6 @@ __export(index_exports, {
21022
21022
  Table: () => Table_default,
21023
21023
  ThemeContext: () => ThemeContext,
21024
21024
  areQueryBuilderFilterDraftsDirty: () => areQueryBuilderFilterDraftsDirty,
21025
- buildSeededFilterQuery: () => buildSeededFilterQuery,
21026
21025
  countFilterRules: () => countFilterRules,
21027
21026
  defaultFilterRuleValueForOperator: () => defaultFilterRuleValueForOperator,
21028
21027
  downloadCSV: () => downloadCSV,
@@ -21047,6 +21046,7 @@ __export(index_exports, {
21047
21046
  useQuill: () => useQuill,
21048
21047
  useReport: () => useReport,
21049
21048
  useReportBuilder: () => useReportBuilder,
21049
+ useReportQueryBuilder: () => useReportQueryBuilder,
21050
21050
  useReports: () => useReports,
21051
21051
  useTenants: () => useTenants,
21052
21052
  useVirtualTables: () => useVirtualTables
@@ -58434,13 +58434,13 @@ function ChartEditor({
58434
58434
  }
58435
58435
 
58436
58436
  // src/Chat.tsx
58437
- var import_react64 = require("react");
58437
+ var import_react63 = require("react");
58438
58438
 
58439
58439
  // src/ChatChartCard.tsx
58440
- var import_react63 = require("react");
58440
+ var import_react62 = require("react");
58441
58441
 
58442
58442
  // src/hooks/useForm.tsx
58443
- var import_react62 = require("react");
58443
+ var import_react61 = require("react");
58444
58444
  var import_react_query2 = require("@tanstack/react-query");
58445
58445
  init_Filter();
58446
58446
  init_ReportBuilder();
@@ -59449,171 +59449,6 @@ function countFilterRules(value) {
59449
59449
  }, 0);
59450
59450
  }
59451
59451
 
59452
- // src/hooks/useReportFilterDraft.ts
59453
- var import_react61 = require("react");
59454
- var normalizeOperatorKey = (operator) => String(operator ?? "").trim().toLowerCase().replace(/[_\s]+/g, "");
59455
- var defaultFilterRuleValueForOperator = (operator) => {
59456
- const key = normalizeOperatorKey(operator);
59457
- if (key === "in" || key === "notin") {
59458
- return [];
59459
- }
59460
- return "";
59461
- };
59462
- var buildSeededFilterQuery = (queryBuilderProps) => {
59463
- const fieldData = queryBuilderProps?.fields?.[0];
59464
- const fieldName = String(fieldData?.name ?? "").trim();
59465
- let operator = "in";
59466
- const firstOperator = queryBuilderProps?.getOperators?.(fieldName, {
59467
- fieldData
59468
- })?.[0];
59469
- if (firstOperator) {
59470
- operator = String(firstOperator.name ?? firstOperator.value ?? "in");
59471
- }
59472
- return {
59473
- combinator: "and",
59474
- rules: [
59475
- {
59476
- field: fieldName,
59477
- operator,
59478
- value: defaultFilterRuleValueForOperator(operator)
59479
- }
59480
- ]
59481
- };
59482
- };
59483
- var EMPTY_COMMITTED_FILTERS = {
59484
- combinator: "and",
59485
- rules: []
59486
- };
59487
- var hashString2 = (input) => {
59488
- let hash = 2166136261;
59489
- for (let i = 0; i < input.length; i++) {
59490
- hash ^= input.charCodeAt(i);
59491
- hash = Math.imul(hash, 16777619);
59492
- }
59493
- return String(hash >>> 0);
59494
- };
59495
- var fieldCatalogSignature = (fields) => {
59496
- const names = fields.map((field) => String(field.name ?? "").trim()).filter(Boolean).sort();
59497
- return `${names.length}:${hashString2(names.join("\0"))}`;
59498
- };
59499
- var committedFiltersSignature = (committed) => {
59500
- try {
59501
- return hashString2(
59502
- JSON.stringify(stripQueryBuilderTransientFields(committed))
59503
- );
59504
- } catch {
59505
- return "unserializable";
59506
- }
59507
- };
59508
- function useReportFilterDraft(args) {
59509
- const { reportId, committedFilters, queryBuilderProps, setFilters } = args;
59510
- const committed = isQueryBuilderDisplayGroup(committedFilters) ? committedFilters : EMPTY_COMMITTED_FILTERS;
59511
- const committedRef = (0, import_react61.useRef)(committed);
59512
- committedRef.current = committed;
59513
- const setFiltersRef = (0, import_react61.useRef)(setFilters);
59514
- setFiltersRef.current = setFilters;
59515
- const lastNonEmptyFieldsRef = (0, import_react61.useRef)([]);
59516
- const prevReportIdForFieldsRef = (0, import_react61.useRef)(reportId);
59517
- if (prevReportIdForFieldsRef.current !== reportId) {
59518
- prevReportIdForFieldsRef.current = reportId;
59519
- lastNonEmptyFieldsRef.current = [];
59520
- }
59521
- if (queryBuilderProps.fields.length > 0) {
59522
- lastNonEmptyFieldsRef.current = queryBuilderProps.fields;
59523
- }
59524
- const effectiveFields = queryBuilderProps.fields.length > 0 ? queryBuilderProps.fields : lastNonEmptyFieldsRef.current;
59525
- const effectiveFieldsRef = (0, import_react61.useRef)(effectiveFields);
59526
- effectiveFieldsRef.current = effectiveFields;
59527
- const getOperatorsRef = (0, import_react61.useRef)(queryBuilderProps.getOperators);
59528
- getOperatorsRef.current = queryBuilderProps.getOperators;
59529
- const committedSignature = (0, import_react61.useMemo)(
59530
- () => committedFiltersSignature(committed),
59531
- // eslint-disable-next-line react-hooks/exhaustive-deps -- `committed` normalizes null to a stable constant
59532
- [committedFilters]
59533
- );
59534
- const fieldsSignature = (0, import_react61.useMemo)(
59535
- () => fieldCatalogSignature(effectiveFields),
59536
- [effectiveFields]
59537
- );
59538
- const [resetEpoch, setResetEpoch] = (0, import_react61.useState)(0);
59539
- const [seedEpoch, setSeedEpoch] = (0, import_react61.useState)(0);
59540
- const draftRef = (0, import_react61.useRef)(committed);
59541
- const [isFilterDraftDirty, setIsFilterDraftDirty] = (0, import_react61.useState)(false);
59542
- const [isFilterDraftEmpty, setIsFilterDraftEmpty] = (0, import_react61.useState)(
59543
- committed.rules.length === 0
59544
- );
59545
- const draftResetKey = `${reportId}|${committedSignature}|${resetEpoch}`;
59546
- const prevDraftResetKeyRef = (0, import_react61.useRef)(draftResetKey);
59547
- if (prevDraftResetKeyRef.current !== draftResetKey) {
59548
- prevDraftResetKeyRef.current = draftResetKey;
59549
- draftRef.current = committed;
59550
- const nextEmpty = committed.rules.length === 0;
59551
- if (isFilterDraftDirty) setIsFilterDraftDirty(false);
59552
- if (isFilterDraftEmpty !== nextEmpty) setIsFilterDraftEmpty(nextEmpty);
59553
- }
59554
- const filterDraftKey = `${draftResetKey}|${seedEpoch}|${fieldsSignature}`;
59555
- const handleQueryChange = (0, import_react61.useCallback)((next) => {
59556
- if (!isQueryBuilderDisplayGroup(next)) return;
59557
- const nextGroup = next;
59558
- draftRef.current = nextGroup;
59559
- const nextDirty = areQueryBuilderFilterDraftsDirty(
59560
- nextGroup,
59561
- committedRef.current
59562
- );
59563
- const nextEmpty = nextGroup.rules.length === 0;
59564
- setIsFilterDraftDirty((prev) => prev === nextDirty ? prev : nextDirty);
59565
- setIsFilterDraftEmpty((prev) => prev === nextEmpty ? prev : nextEmpty);
59566
- }, []);
59567
- const commitFilterDraft = (0, import_react61.useCallback)(() => {
59568
- setFiltersRef.current(draftRef.current);
59569
- }, []);
59570
- const resetFilterDraft = (0, import_react61.useCallback)(() => {
59571
- draftRef.current = committedRef.current;
59572
- setIsFilterDraftDirty(false);
59573
- setIsFilterDraftEmpty(committedRef.current.rules.length === 0);
59574
- setResetEpoch((epoch) => epoch + 1);
59575
- }, []);
59576
- const seedFilterDraft = (0, import_react61.useCallback)(() => {
59577
- const seeded = buildSeededFilterQuery({
59578
- fields: effectiveFieldsRef.current,
59579
- getOperators: getOperatorsRef.current
59580
- });
59581
- draftRef.current = seeded;
59582
- setIsFilterDraftDirty(
59583
- areQueryBuilderFilterDraftsDirty(seeded, committedRef.current)
59584
- );
59585
- setIsFilterDraftEmpty(false);
59586
- setSeedEpoch((epoch) => epoch + 1);
59587
- }, []);
59588
- const getDefaultValue = (0, import_react61.useCallback)(
59589
- (rule) => defaultFilterRuleValueForOperator(rule?.operator),
59590
- []
59591
- );
59592
- const filterDraftQueryBuilderProps = (0, import_react61.useMemo)(
59593
- () => ({
59594
- ...queryBuilderProps,
59595
- fields: effectiveFields,
59596
- // Uncontrolled: react-querybuilder owns the draft; only read at mount,
59597
- // so passing the live draft means popover/remount cycles keep edits.
59598
- defaultQuery: draftRef.current,
59599
- onQueryChange: handleQueryChange,
59600
- addRuleToNewGroups: true,
59601
- getDefaultValue
59602
- }),
59603
- // eslint-disable-next-line react-hooks/exhaustive-deps -- filterDraftKey covers draftRef resets
59604
- [queryBuilderProps, effectiveFields, handleQueryChange, getDefaultValue, filterDraftKey]
59605
- );
59606
- return {
59607
- filterDraftKey,
59608
- filterDraftQueryBuilderProps,
59609
- isFilterDraftDirty,
59610
- isFilterDraftEmpty,
59611
- commitFilterDraft,
59612
- resetFilterDraft,
59613
- seedFilterDraft
59614
- };
59615
- }
59616
-
59617
59452
  // src/hooks/useFormRefreshDecision.ts
59618
59453
  var normalize = (value) => String(value ?? "").trim();
59619
59454
  var toColumnKey = (table, field) => `${table}::${field}`;
@@ -59871,6 +59706,13 @@ var AGGREGATION_OPTION_TYPES = [
59871
59706
  var QUERY_BUILDER_MULTI_VALUE_OPERATORS = /* @__PURE__ */ new Set(["in", "notin"]);
59872
59707
  var TABLE_FORMAT_CACHE_MAX_ENTRIES = 5e3;
59873
59708
  var PIVOT_DATE_BUCKET_FORMAT_OPTIONS = ["date"];
59709
+ var PIVOT_DATE_BUCKET_OPTIONS = [
59710
+ { label: "Automatic", value: "" },
59711
+ { label: "Daily", value: "day" },
59712
+ { label: "Weekly", value: "week" },
59713
+ { label: "Monthly", value: "month" },
59714
+ { label: "Yearly", value: "year" }
59715
+ ];
59874
59716
  var AXIS_FORMAT_OPTIONS = [
59875
59717
  { value: "string", label: "string" },
59876
59718
  { value: "whole_number", label: "whole number" },
@@ -59933,6 +59775,10 @@ var logUseFormPivotShapeDebug = (label, payload) => {
59933
59775
  if (!isUseFormPivotShapeDebugEnabled()) return;
59934
59776
  console.log(`[useReport][pivot-shape] ${label}`, payload);
59935
59777
  };
59778
+ var BOOLEAN_FILTER_VALUE_OPTIONS = [
59779
+ { name: "true", label: "True", value: "true" },
59780
+ { name: "false", label: "False", value: "false" }
59781
+ ];
59936
59782
  function canonicalTablesForFilterUniqueValuesQueryKey(tables) {
59937
59783
  return (tables ?? []).map((table) => {
59938
59784
  const name2 = String(table?.name ?? "").trim();
@@ -60879,6 +60725,13 @@ function normalizePivotChartForDisplay(chart) {
60879
60725
  if (aggregation?.aggregationType === "count") {
60880
60726
  return "whole_number";
60881
60727
  }
60728
+ if (aggregation?.aggregationType === "percentage") {
60729
+ const savedFormat = yAxisFormatByField.get(field);
60730
+ if (savedFormat === "percent" || savedFormat === "percentage") {
60731
+ return savedFormat;
60732
+ }
60733
+ return "percentage";
60734
+ }
60882
60735
  const directAxisFormat = yAxisFormatByField.get(field);
60883
60736
  if (directAxisFormat) return directAxisFormat;
60884
60737
  const aggType = aggregation?.aggregationType ? String(aggregation.aggregationType) : void 0;
@@ -62068,9 +61921,6 @@ function getChartTypeOptions2(formData) {
62068
61921
  (elem) => !(formData.pivot && formData.pivot.columnField && (elem === "bar" || elem === "pie" || elem === "US map" || elem === "World map"))
62069
61922
  ).map((elem) => ({ label: elem, value: elem }));
62070
61923
  }
62071
- function isSetReportTableColumnSidebarPatch(columns) {
62072
- return Boolean(columns) && typeof columns === "object" && !Array.isArray(columns) && "patch" in columns && typeof columns.patch === "object" && columns.patch !== null && typeof columns.patch.id === "string";
62073
- }
62074
61924
  function processPivotState(next, options = {}) {
62075
61925
  const {
62076
61926
  nextState,
@@ -62127,7 +61977,10 @@ function processPivotState(next, options = {}) {
62127
61977
  }
62128
61978
  const valueField = String(aggregation.valueField ?? "").trim();
62129
61979
  if (!valueField) {
62130
- return { ...aggregation, aggregationType: "count" };
61980
+ return {
61981
+ ...aggregation,
61982
+ aggregationType: "count"
61983
+ };
62131
61984
  }
62132
61985
  const valueField2 = String(aggregation.valueField2 ?? "").trim();
62133
61986
  if (valueField2 && valueField2 !== valueField) {
@@ -63139,10 +62992,10 @@ function generateDraftSessionId() {
63139
62992
  }
63140
62993
  function useReport(reportIdArg, options = {}) {
63141
62994
  const propReportId = String(reportIdArg ?? "").trim();
63142
- const [createdReportId, setCreatedReportId] = (0, import_react62.useState)(null);
62995
+ const [createdReportId, setCreatedReportId] = (0, import_react61.useState)(null);
63143
62996
  const effectiveReportId = propReportId || createdReportId || "";
63144
- const { eventTracking } = (0, import_react62.useContext)(EventTrackingContext);
63145
- const [draftSessionId, setDraftSessionId] = (0, import_react62.useState)(generateDraftSessionId);
62997
+ const { eventTracking } = (0, import_react61.useContext)(EventTrackingContext);
62998
+ const [draftSessionId, setDraftSessionId] = (0, import_react61.useState)(generateDraftSessionId);
63146
62999
  const useInMemoryEngines = options.useInMemoryEngines ?? false;
63147
63000
  const restrictFieldOptionsToSelectedDatasources = options.restrictFieldOptionsToSelectedDatasources ?? true;
63148
63001
  const reportOverride = options.reportOverride ?? null;
@@ -63151,30 +63004,30 @@ function useReport(reportIdArg, options = {}) {
63151
63004
  options.destinationDashboardName ?? ""
63152
63005
  ).trim();
63153
63006
  const controlledPagination = options.state?.pagination;
63154
- const initialPaginationRef = (0, import_react62.useRef)({
63007
+ const initialPaginationRef = (0, import_react61.useRef)({
63155
63008
  ...getDefaultPaginationState(),
63156
63009
  ...options.initialState?.pagination ?? {}
63157
63010
  });
63158
- const [internalPagination, setInternalPagination] = (0, import_react62.useState)(
63011
+ const [internalPagination, setInternalPagination] = (0, import_react61.useState)(
63159
63012
  initialPaginationRef.current
63160
63013
  );
63161
- const [paginationInteracted, setPaginationInteracted] = (0, import_react62.useState)(
63014
+ const [paginationInteracted, setPaginationInteracted] = (0, import_react61.useState)(
63162
63015
  () => Boolean(
63163
63016
  options.state?.pagination || options.initialState?.pagination || options.onPaginationChange
63164
63017
  )
63165
63018
  );
63166
63019
  const pagination = controlledPagination ?? internalPagination;
63167
63020
  const paginationActive = paginationInteracted || Boolean(controlledPagination);
63168
- const paginationRef = (0, import_react62.useRef)(pagination);
63021
+ const paginationRef = (0, import_react61.useRef)(pagination);
63169
63022
  paginationRef.current = pagination;
63170
- const onPaginationChangeRef = (0, import_react62.useRef)(options.onPaginationChange);
63023
+ const onPaginationChangeRef = (0, import_react61.useRef)(options.onPaginationChange);
63171
63024
  onPaginationChangeRef.current = options.onPaginationChange;
63172
- const controlledPaginationRef = (0, import_react62.useRef)(Boolean(controlledPagination));
63025
+ const controlledPaginationRef = (0, import_react61.useRef)(Boolean(controlledPagination));
63173
63026
  controlledPaginationRef.current = Boolean(controlledPagination);
63174
- const autoResetPageIndexRef = (0, import_react62.useRef)(true);
63027
+ const autoResetPageIndexRef = (0, import_react61.useRef)(true);
63175
63028
  autoResetPageIndexRef.current = options.autoResetPageIndex ?? true;
63176
- const paginationPageCountRef = (0, import_react62.useRef)(-1);
63177
- const applyPaginationUpdate = (0, import_react62.useCallback)(
63029
+ const paginationPageCountRef = (0, import_react61.useRef)(-1);
63030
+ const applyPaginationUpdate = (0, import_react61.useCallback)(
63178
63031
  (updater, { activate = true } = {}) => {
63179
63032
  if (activate) {
63180
63033
  setPaginationInteracted(true);
@@ -63186,11 +63039,11 @@ function useReport(reportIdArg, options = {}) {
63186
63039
  },
63187
63040
  []
63188
63041
  );
63189
- const setPagination = (0, import_react62.useCallback)(
63042
+ const setPagination = (0, import_react61.useCallback)(
63190
63043
  (updater) => applyPaginationUpdate(updater),
63191
63044
  [applyPaginationUpdate]
63192
63045
  );
63193
- const setPageIndex = (0, import_react62.useCallback)(
63046
+ const setPageIndex = (0, import_react61.useCallback)(
63194
63047
  (updater) => applyPaginationUpdate((old) => ({
63195
63048
  ...old,
63196
63049
  pageIndex: clampPageIndex(
@@ -63200,7 +63053,7 @@ function useReport(reportIdArg, options = {}) {
63200
63053
  })),
63201
63054
  [applyPaginationUpdate]
63202
63055
  );
63203
- const setPageSize = (0, import_react62.useCallback)(
63056
+ const setPageSize = (0, import_react61.useCallback)(
63204
63057
  (updater) => applyPaginationUpdate(
63205
63058
  (old) => paginationStateAfterPageSizeChange(
63206
63059
  old,
@@ -63209,62 +63062,64 @@ function useReport(reportIdArg, options = {}) {
63209
63062
  ),
63210
63063
  [applyPaginationUpdate]
63211
63064
  );
63212
- const resetPagination = (0, import_react62.useCallback)(
63065
+ const resetPagination = (0, import_react61.useCallback)(
63213
63066
  (defaultState) => applyPaginationUpdate(
63214
63067
  defaultState ? getDefaultPaginationState() : initialPaginationRef.current
63215
63068
  ),
63216
63069
  [applyPaginationUpdate]
63217
63070
  );
63218
- const resetPageIndex = (0, import_react62.useCallback)(
63071
+ const resetPageIndex = (0, import_react61.useCallback)(
63219
63072
  (defaultState) => {
63220
63073
  const target = defaultState ? 0 : initialPaginationRef.current.pageIndex;
63221
63074
  setPageIndex(target);
63222
63075
  },
63223
63076
  [setPageIndex]
63224
63077
  );
63225
- const resetPageSize = (0, import_react62.useCallback)(
63078
+ const resetPageSize = (0, import_react61.useCallback)(
63226
63079
  (defaultState) => {
63227
63080
  const target = defaultState ? getDefaultPaginationState().pageSize : initialPaginationRef.current.pageSize;
63228
63081
  setPageSize(target);
63229
63082
  },
63230
63083
  [setPageSize]
63231
63084
  );
63232
- const nextPage = (0, import_react62.useCallback)(
63085
+ const nextPage = (0, import_react61.useCallback)(
63233
63086
  () => setPageIndex((old) => old + 1),
63234
63087
  [setPageIndex]
63235
63088
  );
63236
- const previousPage = (0, import_react62.useCallback)(
63089
+ const previousPage = (0, import_react61.useCallback)(
63237
63090
  () => setPageIndex((old) => old - 1),
63238
63091
  [setPageIndex]
63239
63092
  );
63240
- const firstPage = (0, import_react62.useCallback)(() => setPageIndex(0), [setPageIndex]);
63241
- const lastPage = (0, import_react62.useCallback)(
63093
+ const firstPage = (0, import_react61.useCallback)(() => setPageIndex(0), [setPageIndex]);
63094
+ const lastPage = (0, import_react61.useCallback)(
63242
63095
  () => setPageIndex(paginationPageCountRef.current - 1),
63243
63096
  [setPageIndex]
63244
63097
  );
63245
- const chartPivotHydratedFromSourceRef = (0, import_react62.useRef)(false);
63246
- const lastPivotHydrateCompletedSourceIdRef = (0, import_react62.useRef)(null);
63247
- const groupRowsBySetViaSetReportRef = (0, import_react62.useRef)(false);
63248
- const groupColumnsBySetViaSetReportRef = (0, import_react62.useRef)(false);
63249
- const aggregationStateSetViaSetReportRef = (0, import_react62.useRef)(false);
63250
- const prevReportIdForChartPivotHydrationRef = (0, import_react62.useRef)(effectiveReportId);
63098
+ const chartPivotHydratedFromSourceRef = (0, import_react61.useRef)(false);
63099
+ const lastPivotHydrateCompletedSourceIdRef = (0, import_react61.useRef)(null);
63100
+ const groupRowsBySetViaSetReportRef = (0, import_react61.useRef)(false);
63101
+ const groupColumnsBySetViaSetReportRef = (0, import_react61.useRef)(false);
63102
+ const dateBucketSetViaSetReportRef = (0, import_react61.useRef)(false);
63103
+ const aggregationStateSetViaSetReportRef = (0, import_react61.useRef)(false);
63104
+ const prevReportIdForChartPivotHydrationRef = (0, import_react61.useRef)(effectiveReportId);
63251
63105
  if (prevReportIdForChartPivotHydrationRef.current !== effectiveReportId) {
63252
63106
  prevReportIdForChartPivotHydrationRef.current = effectiveReportId;
63253
63107
  chartPivotHydratedFromSourceRef.current = false;
63254
63108
  groupRowsBySetViaSetReportRef.current = false;
63255
63109
  groupColumnsBySetViaSetReportRef.current = false;
63110
+ dateBucketSetViaSetReportRef.current = false;
63256
63111
  aggregationStateSetViaSetReportRef.current = false;
63257
63112
  }
63258
- const [chartPivotHydrationEpoch, setChartPivotHydrationEpoch] = (0, import_react62.useState)(0);
63113
+ const [chartPivotHydrationEpoch, setChartPivotHydrationEpoch] = (0, import_react61.useState)(0);
63259
63114
  const [
63260
63115
  expandReportBuilderColumnsForFlatTable,
63261
63116
  setExpandReportBuilderColumnsForFlatTable
63262
- ] = (0, import_react62.useState)(false);
63263
- const prevPivotStateForColumnExpansionRef = (0, import_react62.useRef)(null);
63264
- const [sourceReport, setSourceReport] = (0, import_react62.useState)(
63117
+ ] = (0, import_react61.useState)(false);
63118
+ const prevPivotStateForColumnExpansionRef = (0, import_react61.useRef)(null);
63119
+ const [sourceReport, setSourceReport] = (0, import_react61.useState)(
63265
63120
  null
63266
63121
  );
63267
- const prevSourceReportIdForPivotHydrationRef = (0, import_react62.useRef)(null);
63122
+ const prevSourceReportIdForPivotHydrationRef = (0, import_react61.useRef)(null);
63268
63123
  {
63269
63124
  const currentSourceId = sourceReport ? String(
63270
63125
  sourceReport.id ?? sourceReport._id ?? ""
@@ -63276,15 +63131,15 @@ function useReport(reportIdArg, options = {}) {
63276
63131
  lastPivotHydrateCompletedSourceIdRef.current = null;
63277
63132
  }
63278
63133
  }
63279
- const [preserveSchemaWideOptions, setPreserveSchemaWideOptions] = (0, import_react62.useState)(false);
63280
- const [initialSchemaScopedTableNames, setInitialSchemaScopedTableNames] = (0, import_react62.useState)(null);
63281
- const [tableColumnsEditedSignature, setTableColumnsEditedSignature] = (0, import_react62.useState)(null);
63282
- const [chartAxisEdits, setChartAxisEdits] = (0, import_react62.useState)({});
63283
- const [chartVisibilityOverrides, setChartVisibilityOverrides] = (0, import_react62.useState)({});
63284
- const [client] = (0, import_react62.useContext)(ClientContext);
63285
- const [schemaData] = (0, import_react62.useContext)(SchemaDataContext);
63286
- const { tenants, flags } = (0, import_react62.useContext)(TenantContext);
63287
- const { getToken } = (0, import_react62.useContext)(FetchContext);
63134
+ const [preserveSchemaWideOptions, setPreserveSchemaWideOptions] = (0, import_react61.useState)(false);
63135
+ const [initialSchemaScopedTableNames, setInitialSchemaScopedTableNames] = (0, import_react61.useState)(null);
63136
+ const [tableColumnsEditedSignature, setTableColumnsEditedSignature] = (0, import_react61.useState)(null);
63137
+ const [chartAxisEdits, setChartAxisEdits] = (0, import_react61.useState)({});
63138
+ const [chartVisibilityOverrides, setChartVisibilityOverrides] = (0, import_react61.useState)({});
63139
+ const [client] = (0, import_react61.useContext)(ClientContext);
63140
+ const [schemaData] = (0, import_react61.useContext)(SchemaDataContext);
63141
+ const { tenants, flags } = (0, import_react61.useContext)(TenantContext);
63142
+ const { getToken } = (0, import_react61.useContext)(FetchContext);
63288
63143
  const clientDefaultDashboardName = String(
63289
63144
  client?.defaultDashboard?.name ?? ""
63290
63145
  ).trim();
@@ -63293,7 +63148,7 @@ function useReport(reportIdArg, options = {}) {
63293
63148
  clientDefaultDashboardName,
63294
63149
  destinationDashboardName
63295
63150
  ].map((entry) => String(entry ?? "").trim()).find((entry) => entry.length > 0) ?? "";
63296
- const initialFormState = (0, import_react62.useMemo)(
63151
+ const initialFormState = (0, import_react61.useMemo)(
63297
63152
  () => ({
63298
63153
  columns: [],
63299
63154
  queryColumns: [],
@@ -63301,6 +63156,7 @@ function useReport(reportIdArg, options = {}) {
63301
63156
  queryFilters: { combinator: "and", rules: [] },
63302
63157
  groupRowsBy: void 0,
63303
63158
  groupColumnsBy: void 0,
63159
+ dateBucket: void 0,
63304
63160
  aggregationState: [],
63305
63161
  aggregationTablesByIndex: [],
63306
63162
  pivotSort: void 0,
@@ -63311,7 +63167,7 @@ function useReport(reportIdArg, options = {}) {
63311
63167
  }),
63312
63168
  []
63313
63169
  );
63314
- const [formRuntimeState, dispatchFormRuntime] = (0, import_react62.useReducer)(
63170
+ const [formRuntimeState, dispatchFormRuntime] = (0, import_react61.useReducer)(
63315
63171
  useFormReducer,
63316
63172
  initialFormState,
63317
63173
  createInitialUseFormReducerState
@@ -63330,6 +63186,7 @@ function useReport(reportIdArg, options = {}) {
63330
63186
  queryFilters,
63331
63187
  groupRowsBy,
63332
63188
  groupColumnsBy,
63189
+ dateBucket,
63333
63190
  aggregationState,
63334
63191
  aggregationTablesByIndex,
63335
63192
  pivotSort,
@@ -63339,32 +63196,32 @@ function useReport(reportIdArg, options = {}) {
63339
63196
  schemaDatasourceIds
63340
63197
  } = formState;
63341
63198
  const schemaDatasourceIdsKey = schemaDatasourceIds?.map((id) => String(id ?? "").trim()).join("\0") ?? "";
63342
- const queryColumnsBootstrapKey = (0, import_react62.useMemo)(
63199
+ const queryColumnsBootstrapKey = (0, import_react61.useMemo)(
63343
63200
  () => queryColumns.map(
63344
63201
  (c) => `${String(c.table ?? "").trim()}\0${String(c.field ?? "").trim()}`
63345
63202
  ).join("\n"),
63346
63203
  [queryColumns]
63347
63204
  );
63348
- const dashboardNameForNewReport = (0, import_react62.useMemo)(() => {
63205
+ const dashboardNameForNewReport = (0, import_react61.useMemo)(() => {
63349
63206
  return [clientDefaultDashboardName, destinationDashboardName].map((entry) => String(entry ?? "").trim()).find((entry) => entry.length > 0) ?? "";
63350
63207
  }, [clientDefaultDashboardName, destinationDashboardName]);
63351
- const filterStackRef = (0, import_react62.useRef)(filterStack);
63208
+ const filterStackRef = (0, import_react61.useRef)(filterStack);
63352
63209
  filterStackRef.current = filterStack;
63353
63210
  const resolvedGroupRowsBy = decodePivotGroupOptionValue(groupRowsBy);
63354
63211
  const resolvedGroupColumnsBy = decodePivotGroupOptionValue(groupColumnsBy);
63355
63212
  const useFormRefreshDebugEnabled = isUseFormRefreshDebugEnabled();
63356
63213
  const useFormFiltersDebugEnabled = isUseFormFiltersDebugEnabled();
63357
- (0, import_react62.useEffect)(() => {
63214
+ (0, import_react61.useEffect)(() => {
63358
63215
  if (propReportId) {
63359
63216
  setCreatedReportId(null);
63360
63217
  }
63361
63218
  }, [propReportId]);
63362
- (0, import_react62.useEffect)(() => {
63219
+ (0, import_react61.useEffect)(() => {
63363
63220
  setChartAxisEdits({});
63364
63221
  setChartVisibilityOverrides({});
63365
63222
  }, [effectiveReportId]);
63366
- const bootstrapReportTaskUsedForReportIdRef = (0, import_react62.useRef)(null);
63367
- const schemaScopeInitializedForReportIdRef = (0, import_react62.useRef)(null);
63223
+ const bootstrapReportTaskUsedForReportIdRef = (0, import_react61.useRef)(null);
63224
+ const schemaScopeInitializedForReportIdRef = (0, import_react61.useRef)(null);
63368
63225
  const initializeSchemaScopeForReport = (report) => {
63369
63226
  if (!report) return;
63370
63227
  if (schemaScopeInitializedForReportIdRef.current === effectiveReportId)
@@ -63377,26 +63234,26 @@ function useReport(reportIdArg, options = {}) {
63377
63234
  );
63378
63235
  schemaScopeInitializedForReportIdRef.current = effectiveReportId;
63379
63236
  };
63380
- const internalFilters = (0, import_react62.useMemo)(
63237
+ const internalFilters = (0, import_react61.useMemo)(
63381
63238
  () => internalFiltersFromFilterStack(filterStack),
63382
63239
  [filterStack]
63383
63240
  );
63384
- const customFilters = (0, import_react62.useMemo)(
63241
+ const customFilters = (0, import_react61.useMemo)(
63385
63242
  () => customFiltersFromFilterStack(filterStack),
63386
63243
  [filterStack]
63387
63244
  );
63388
- const reloadKey = (0, import_react62.useMemo)(() => 0, []);
63389
- const schemaForReportBuilderState = (0, import_react62.useMemo)(() => {
63245
+ const reloadKey = (0, import_react61.useMemo)(() => 0, []);
63246
+ const schemaForReportBuilderState = (0, import_react61.useMemo)(() => {
63390
63247
  if (schemaData.schemaWithCustomFields?.length) {
63391
63248
  return schemaData.schemaWithCustomFields;
63392
63249
  }
63393
63250
  return schemaData.schema ?? [];
63394
63251
  }, [schemaData.schema, schemaData.schemaWithCustomFields]);
63395
- const schemaForReportBuilderStateRef = (0, import_react62.useRef)(schemaForReportBuilderState);
63396
- const customFieldsRef = (0, import_react62.useRef)(schemaData.customFields);
63252
+ const schemaForReportBuilderStateRef = (0, import_react61.useRef)(schemaForReportBuilderState);
63253
+ const customFieldsRef = (0, import_react61.useRef)(schemaData.customFields);
63397
63254
  schemaForReportBuilderStateRef.current = schemaForReportBuilderState;
63398
63255
  customFieldsRef.current = schemaData.customFields;
63399
- const isBoolAggregationField = (0, import_react62.useCallback)(
63256
+ const isBoolAggregationField = (0, import_react61.useCallback)(
63400
63257
  (field, table2) => {
63401
63258
  const fieldType = resolveFieldType({
63402
63259
  field,
@@ -63409,19 +63266,19 @@ function useReport(reportIdArg, options = {}) {
63409
63266
  },
63410
63267
  []
63411
63268
  );
63412
- const schemaForeignKeyMap = (0, import_react62.useMemo)(
63269
+ const schemaForeignKeyMap = (0, import_react61.useMemo)(
63413
63270
  () => getSchemaForeignKeyMapping(schemaForReportBuilderState),
63414
63271
  [schemaForReportBuilderState]
63415
63272
  );
63416
63273
  const reportBuilderBaseTableNamesKey = (sourceReport?.reportBuilderState?.tables ?? []).map((t) => String(t?.name ?? "").trim()).filter(Boolean).join("\0") ?? "";
63417
- const selectedBaseTableNamesForFieldOptions = (0, import_react62.useMemo)(() => {
63274
+ const selectedBaseTableNamesForFieldOptions = (0, import_react61.useMemo)(() => {
63418
63275
  const fromPicker = schemaDatasourceIds?.map((id) => String(id ?? "").trim()).filter(Boolean) ?? [];
63419
63276
  if (fromPicker.length > 0) {
63420
63277
  return fromPicker;
63421
63278
  }
63422
63279
  return (sourceReport?.reportBuilderState?.tables ?? []).map((t) => String(t?.name ?? "").trim()).filter(Boolean);
63423
63280
  }, [schemaDatasourceIdsKey, reportBuilderBaseTableNamesKey]);
63424
- const fieldOptionsAllowedTableNames = (0, import_react62.useMemo)(() => {
63281
+ const fieldOptionsAllowedTableNames = (0, import_react61.useMemo)(() => {
63425
63282
  if (!restrictFieldOptionsToSelectedDatasources) {
63426
63283
  return null;
63427
63284
  }
@@ -63433,7 +63290,7 @@ function useReport(reportIdArg, options = {}) {
63433
63290
  restrictFieldOptionsToSelectedDatasources,
63434
63291
  selectedBaseTableNamesForFieldOptions
63435
63292
  ]);
63436
- (0, import_react62.useEffect)(() => {
63293
+ (0, import_react61.useEffect)(() => {
63437
63294
  if (reportOverride) return;
63438
63295
  if (propReportId) return;
63439
63296
  if (createdReportId) return;
@@ -63523,18 +63380,18 @@ function useReport(reportIdArg, options = {}) {
63523
63380
  schemaForReportBuilderState,
63524
63381
  queryColumnsBootstrapKey
63525
63382
  ]);
63526
- const datasourceOptions = (0, import_react62.useMemo)(() => {
63383
+ const datasourceOptions = (0, import_react61.useMemo)(() => {
63527
63384
  const seen = /* @__PURE__ */ new Set();
63528
63385
  const result = [];
63529
63386
  for (const table2 of schemaForReportBuilderState) {
63530
63387
  const name2 = String(table2.name ?? "").trim();
63531
63388
  if (!name2 || seen.has(name2)) continue;
63532
63389
  seen.add(name2);
63533
- result.push({ id: name2, label: toTitleCaseLabel(name2) });
63390
+ result.push({ value: name2, label: toTitleCaseLabel(name2) });
63534
63391
  }
63535
63392
  return result;
63536
63393
  }, [schemaForReportBuilderState]);
63537
- const queryBuilderFieldConfigByName = (0, import_react62.useMemo)(() => {
63394
+ const queryBuilderFieldConfigByName = (0, import_react61.useMemo)(() => {
63538
63395
  const configByName = buildQueryBuilderFieldConfigByName(
63539
63396
  schemaForReportBuilderState
63540
63397
  );
@@ -63668,7 +63525,7 @@ function useReport(reportIdArg, options = {}) {
63668
63525
  sourceReport?.columns,
63669
63526
  sourceReport?.reportBuilderState?.columns
63670
63527
  ]);
63671
- const filterUniqueValuesRequest = (0, import_react62.useMemo)(() => {
63528
+ const filterUniqueValuesRequest = (0, import_react61.useMemo)(() => {
63672
63529
  const dashboardName = resolvedSourceDashboardName;
63673
63530
  const reportBuilderStateFromSource = sourceReport?.reportBuilderState;
63674
63531
  const isStringReportBuilderColumn = (column) => {
@@ -63889,20 +63746,20 @@ function useReport(reportIdArg, options = {}) {
63889
63746
  sourceReport?.reportBuilderState,
63890
63747
  resolvedSourceDashboardName
63891
63748
  ]);
63892
- const filterUniqueValuesRequestHash = (0, import_react62.useMemo)(
63749
+ const filterUniqueValuesRequestHash = (0, import_react61.useMemo)(
63893
63750
  () => stableSerializeForQueryKey(
63894
63751
  filterUniqueValuesRequestForQueryKey(filterUniqueValuesRequest)
63895
63752
  ),
63896
63753
  [filterUniqueValuesRequest]
63897
63754
  );
63898
- const customFiltersHashForUniqueValues = (0, import_react62.useMemo)(
63755
+ const customFiltersHashForUniqueValues = (0, import_react61.useMemo)(
63899
63756
  () => stableSerializeForQueryKey(customFilters),
63900
63757
  [customFilters]
63901
63758
  );
63902
63759
  const filterUniqueValuesEnabled = Boolean(
63903
63760
  client && client?.queryEndpoint && filterUniqueValuesRequest && filterUniqueValuesRequest.stringColumns.length > 0
63904
63761
  );
63905
- (0, import_react62.useEffect)(() => {
63762
+ (0, import_react61.useEffect)(() => {
63906
63763
  if (!useFormFiltersDebugEnabled) return;
63907
63764
  const hasClient = Boolean(client);
63908
63765
  const hasQueryEndpoint = Boolean(client?.queryEndpoint);
@@ -63992,7 +63849,7 @@ function useReport(reportIdArg, options = {}) {
63992
63849
  enabled: filterUniqueValuesEnabled,
63993
63850
  retry: false
63994
63851
  });
63995
- const backendUniqueValuesByFieldName = (0, import_react62.useMemo)(() => {
63852
+ const backendUniqueValuesByFieldName = (0, import_react61.useMemo)(() => {
63996
63853
  const valuesByField = /* @__PURE__ */ new Map();
63997
63854
  const uniqueValuesByColumn = filterUniqueValuesQuery.data?.uniqueValuesByColumn;
63998
63855
  if (!uniqueValuesByColumn || typeof uniqueValuesByColumn !== "object") {
@@ -64025,7 +63882,7 @@ function useReport(reportIdArg, options = {}) {
64025
63882
  filterUniqueValuesQuery.data?.uniqueValuesByColumn,
64026
63883
  filterUniqueValuesRequest?.stringColumnsByTable
64027
63884
  ]);
64028
- (0, import_react62.useEffect)(() => {
63885
+ (0, import_react61.useEffect)(() => {
64029
63886
  if (!useFormFiltersDebugEnabled) return;
64030
63887
  if (filterUniqueValuesQuery.status !== "success" && filterUniqueValuesQuery.status !== "error") {
64031
63888
  return;
@@ -64041,7 +63898,7 @@ function useReport(reportIdArg, options = {}) {
64041
63898
  effectiveReportId,
64042
63899
  useFormFiltersDebugEnabled
64043
63900
  ]);
64044
- const filterValueOptionsByFieldName = (0, import_react62.useMemo)(() => {
63901
+ const filterValueOptionsByFieldName = (0, import_react61.useMemo)(() => {
64045
63902
  const optionsByField = /* @__PURE__ */ new Map();
64046
63903
  const selectedMultiselectByField = collectSelectedStringMultiselectValuesByField(queryFilters);
64047
63904
  const collectValuesForField = (fieldName) => {
@@ -64107,7 +63964,7 @@ function useReport(reportIdArg, options = {}) {
64107
63964
  queryBuilderFieldConfigByName,
64108
63965
  queryFilters
64109
63966
  ]);
64110
- const filterFieldsComputed = (0, import_react62.useMemo)(() => {
63967
+ const filterFieldsComputed = (0, import_react61.useMemo)(() => {
64111
63968
  const fields = [];
64112
63969
  const seen = /* @__PURE__ */ new Set();
64113
63970
  const addField = (fieldName, fieldType, tableName, rawFieldName) => {
@@ -64208,9 +64065,9 @@ function useReport(reportIdArg, options = {}) {
64208
64065
  queryBuilderFieldConfigByName,
64209
64066
  queryFilters
64210
64067
  ]);
64211
- const filterFieldsStableReportIdRef = (0, import_react62.useRef)("");
64212
- const filterFieldsStableCacheRef = (0, import_react62.useRef)([]);
64213
- const filterFields = (0, import_react62.useMemo)(() => {
64068
+ const filterFieldsStableReportIdRef = (0, import_react61.useRef)("");
64069
+ const filterFieldsStableCacheRef = (0, import_react61.useRef)([]);
64070
+ const filterFields = (0, import_react61.useMemo)(() => {
64214
64071
  const rid = String(effectiveReportId ?? "");
64215
64072
  if (filterFieldsStableReportIdRef.current !== rid) {
64216
64073
  filterFieldsStableReportIdRef.current = rid;
@@ -64225,14 +64082,14 @@ function useReport(reportIdArg, options = {}) {
64225
64082
  }
64226
64083
  return filterFieldsComputed;
64227
64084
  }, [effectiveReportId, filterFieldsComputed]);
64228
- const getFilterOperators = (0, import_react62.useMemo)(
64085
+ const getFilterOperators = (0, import_react61.useMemo)(
64229
64086
  () => (_field, misc) => {
64230
64087
  const fieldType = misc?.fieldData?.quillFieldType ?? queryBuilderFieldConfigByName[String(_field ?? "").trim()]?.fieldType ?? "string";
64231
64088
  return QUERY_BUILDER_OPERATORS_BY_FIELD_TYPE[fieldType] ?? QUERY_BUILDER_OPERATORS_BY_FIELD_TYPE.string;
64232
64089
  },
64233
64090
  [queryBuilderFieldConfigByName]
64234
64091
  );
64235
- const getFilterInputType = (0, import_react62.useMemo)(
64092
+ const getFilterInputType = (0, import_react61.useMemo)(
64236
64093
  () => (_field, operator, misc) => {
64237
64094
  const fieldType = misc?.fieldData?.quillFieldType ?? queryBuilderFieldConfigByName[String(_field ?? "").trim()]?.fieldType ?? "string";
64238
64095
  if (fieldType === "date" && isRelativeDateQueryBuilderOperator(operator)) {
@@ -64242,17 +64099,20 @@ function useReport(reportIdArg, options = {}) {
64242
64099
  },
64243
64100
  [queryBuilderFieldConfigByName]
64244
64101
  );
64245
- const getFilterValueEditorType = (0, import_react62.useMemo)(
64102
+ const getFilterValueEditorType = (0, import_react61.useMemo)(
64246
64103
  () => (_field, operator, misc) => {
64247
64104
  const fieldType = misc?.fieldData?.quillFieldType ?? queryBuilderFieldConfigByName[String(_field ?? "").trim()]?.fieldType;
64248
64105
  if (fieldType === "string" && isMultiValueOperator(operator)) {
64249
64106
  return "multiselect";
64250
64107
  }
64108
+ if (fieldType === "boolean") {
64109
+ return "select";
64110
+ }
64251
64111
  return void 0;
64252
64112
  },
64253
64113
  [queryBuilderFieldConfigByName]
64254
64114
  );
64255
- const getFilterValues = (0, import_react62.useMemo)(
64115
+ const getFilterValues = (0, import_react61.useMemo)(
64256
64116
  () => (_field, operator, misc) => {
64257
64117
  const fieldName = String(_field ?? "").trim();
64258
64118
  if (!fieldName) {
@@ -64263,6 +64123,9 @@ function useReport(reportIdArg, options = {}) {
64263
64123
  misc,
64264
64124
  queryBuilderFieldConfigByName
64265
64125
  );
64126
+ if (fieldType === "boolean") {
64127
+ return BOOLEAN_FILTER_VALUE_OPTIONS;
64128
+ }
64266
64129
  if (fieldType !== "string" || !isMultiValueOperator(operator)) {
64267
64130
  return [];
64268
64131
  }
@@ -64279,7 +64142,7 @@ function useReport(reportIdArg, options = {}) {
64279
64142
  },
64280
64143
  [filterValueOptionsByFieldName, queryBuilderFieldConfigByName]
64281
64144
  );
64282
- const filterQueryBuilderProps = (0, import_react62.useMemo)(
64145
+ const filterQueryBuilderProps = (0, import_react61.useMemo)(
64283
64146
  () => ({
64284
64147
  fields: filterFields,
64285
64148
  listsAsArrays: true,
@@ -64296,7 +64159,7 @@ function useReport(reportIdArg, options = {}) {
64296
64159
  getFilterValues
64297
64160
  ]
64298
64161
  );
64299
- const filtersForQueryBuilder = (0, import_react62.useMemo)(
64162
+ const filtersForQueryBuilder = (0, import_react61.useMemo)(
64300
64163
  () => canonicalizeMultiselectStringRulesToOptionValues(
64301
64164
  queryFilters,
64302
64165
  filterValueOptionsByFieldName,
@@ -64363,12 +64226,12 @@ function useReport(reportIdArg, options = {}) {
64363
64226
  ...table2 ? { table: table2 } : {}
64364
64227
  };
64365
64228
  };
64366
- const tenantHash = (0, import_react62.useMemo)(
64229
+ const tenantHash = (0, import_react61.useMemo)(
64367
64230
  () => stableSerializeForQueryKey(tenants),
64368
64231
  [tenants]
64369
64232
  );
64370
- const flagHash = (0, import_react62.useMemo)(() => stableSerializeForQueryKey(flags), [flags]);
64371
- const clientHash = (0, import_react62.useMemo)(
64233
+ const flagHash = (0, import_react61.useMemo)(() => stableSerializeForQueryKey(flags), [flags]);
64234
+ const clientHash = (0, import_react61.useMemo)(
64372
64235
  () => stableSerializeForQueryKey({
64373
64236
  publicKey: client?.publicKey,
64374
64237
  clientId: client?.clientId,
@@ -64376,16 +64239,16 @@ function useReport(reportIdArg, options = {}) {
64376
64239
  }),
64377
64240
  [client]
64378
64241
  );
64379
- const reloadKeyHash = (0, import_react62.useMemo)(
64242
+ const reloadKeyHash = (0, import_react61.useMemo)(
64380
64243
  () => stableSerializeForQueryKey(reloadKey),
64381
64244
  [reloadKey]
64382
64245
  );
64383
- (0, import_react62.useEffect)(() => {
64246
+ (0, import_react61.useEffect)(() => {
64384
64247
  if (!reportOverride) return;
64385
64248
  initializeSchemaScopeForReport(reportOverride);
64386
64249
  setSourceReport(reportOverride);
64387
64250
  }, [reportOverride, propReportId]);
64388
- (0, import_react62.useEffect)(() => {
64251
+ (0, import_react61.useEffect)(() => {
64389
64252
  schemaScopeInitializedForReportIdRef.current = null;
64390
64253
  bootstrapReportTaskUsedForReportIdRef.current = null;
64391
64254
  setPreserveSchemaWideOptions(false);
@@ -64409,6 +64272,7 @@ function useReport(reportIdArg, options = {}) {
64409
64272
  // grouping from the prior report would otherwise win over the new report.
64410
64273
  groupRowsBy: void 0,
64411
64274
  groupColumnsBy: void 0,
64275
+ dateBucket: void 0,
64412
64276
  aggregationState: [],
64413
64277
  aggregationTablesByIndex: [],
64414
64278
  pivotSort: void 0,
@@ -64490,13 +64354,13 @@ function useReport(reportIdArg, options = {}) {
64490
64354
  const sourceReportNameForTitle = String(sourceReport?.name ?? "").trim();
64491
64355
  const reportTitleFromTask = String(reportNameQuery.data?.name ?? "").trim();
64492
64356
  const resolvedReportName = reportNameQueryReportId && sourceReportIdForTitle === reportNameQueryReportId && sourceReportNameForTitle ? sourceReportNameForTitle : reportTitleFromTask || sourceReportNameForTitle || "";
64493
- (0, import_react62.useEffect)(() => {
64357
+ (0, import_react61.useEffect)(() => {
64494
64358
  if (reportOverride) return;
64495
64359
  const report = initialLoadQuery.data?.report ?? null;
64496
64360
  initializeSchemaScopeForReport(report);
64497
64361
  setSourceReport(report);
64498
64362
  }, [initialLoadQuery.data, reportOverride, effectiveReportId]);
64499
- (0, import_react62.useEffect)(() => {
64363
+ (0, import_react61.useEffect)(() => {
64500
64364
  if (!sourceReport) {
64501
64365
  return;
64502
64366
  }
@@ -64595,6 +64459,8 @@ function useReport(reportIdArg, options = {}) {
64595
64459
  const sourceDisplayColumns = sourceDisplayColumnsFromSchema.length > 0 ? sourceDisplayColumnsFromSchema : sourceQueryColumns;
64596
64460
  const nextGroupRowsBy = shouldTakePivotGroupsFromSource ? groupRowsBySetViaSetReportRef.current ? prev.groupRowsBy : sourceRowGroupOption : prev.groupRowsBy !== void 0 ? prev.groupRowsBy : groupRowsBySetViaSetReportRef.current ? prev.groupRowsBy : sourceRowGroupOption;
64597
64461
  const nextGroupColumnsBy = shouldTakePivotGroupsFromSource ? groupColumnsBySetViaSetReportRef.current ? prev.groupColumnsBy : sourceColumnGroupOption : prev.groupColumnsBy !== void 0 ? prev.groupColumnsBy : prev.groupRowsBy !== void 0 ? prev.groupColumnsBy : sourceColumnGroupOption;
64462
+ const sourceDateBucket = sourceReport.pivot?.dateBucket ?? sourceReport.reportBuilderState?.pivot?.dateBucket;
64463
+ const nextDateBucket = dateBucketSetViaSetReportRef.current ? prev.dateBucket : sourceDateBucket;
64598
64464
  const nextFromSource = {
64599
64465
  ...prev,
64600
64466
  queryColumns: prev.queryColumns.length ? prev.queryColumns : sourceQueryColumns,
@@ -64603,6 +64469,7 @@ function useReport(reportIdArg, options = {}) {
64603
64469
  queryFilters: nextQueryFilters,
64604
64470
  groupRowsBy: nextGroupRowsBy,
64605
64471
  groupColumnsBy: nextGroupColumnsBy,
64472
+ dateBucket: nextDateBucket,
64606
64473
  aggregationState: nextAggregationState,
64607
64474
  aggregationTablesByIndex: nextAggregationTablesByIndex,
64608
64475
  pivotSort: prev.pivotSort ?? (sourceReport.pivot?.sort && sourceReport.pivot?.sortField && sourceReport.pivot?.sortDirection ? {
@@ -64635,11 +64502,11 @@ function useReport(reportIdArg, options = {}) {
64635
64502
  schemaForReportBuilderState,
64636
64503
  sourceReport
64637
64504
  ]);
64638
- const appliedAggregationState = (0, import_react62.useMemo)(
64505
+ const appliedAggregationState = (0, import_react61.useMemo)(
64639
64506
  () => aggregationState.filter(isAppliedAggregation),
64640
64507
  [aggregationState]
64641
64508
  );
64642
- const pivotState = (0, import_react62.useMemo)(() => {
64509
+ const pivotState = (0, import_react61.useMemo)(() => {
64643
64510
  if (!resolvedGroupRowsBy && !resolvedGroupColumnsBy && appliedAggregationState.length === 0) {
64644
64511
  return null;
64645
64512
  }
@@ -64683,6 +64550,7 @@ function useReport(reportIdArg, options = {}) {
64683
64550
  rowFieldType,
64684
64551
  columnField: effectiveColumnField,
64685
64552
  columnFieldType,
64553
+ dateBucket: chartPivotHydratedFromSourceRef.current ? dateBucket : dateBucket ?? priorPivot?.dateBucket,
64686
64554
  aggregations,
64687
64555
  ...rowFieldTable ? { rowFieldTable } : {},
64688
64556
  ...columnFieldTable ? { columnFieldTable } : {}
@@ -64693,6 +64561,7 @@ function useReport(reportIdArg, options = {}) {
64693
64561
  aggregationTablesByIndex,
64694
64562
  appliedAggregationState,
64695
64563
  baseReportBuilderTables,
64564
+ dateBucket,
64696
64565
  groupColumnsBy,
64697
64566
  groupRowsBy,
64698
64567
  schemaForReportBuilderState,
@@ -64704,7 +64573,7 @@ function useReport(reportIdArg, options = {}) {
64704
64573
  effectiveReportId,
64705
64574
  chartPivotHydrationEpoch
64706
64575
  ]);
64707
- (0, import_react62.useEffect)(() => {
64576
+ (0, import_react61.useEffect)(() => {
64708
64577
  const previous = prevPivotStateForColumnExpansionRef.current;
64709
64578
  if (previous && !pivotState) {
64710
64579
  setExpandReportBuilderColumnsForFlatTable(true);
@@ -64714,7 +64583,7 @@ function useReport(reportIdArg, options = {}) {
64714
64583
  }
64715
64584
  prevPivotStateForColumnExpansionRef.current = pivotState;
64716
64585
  }, [pivotState]);
64717
- const effectiveReportBuilderTables = (0, import_react62.useMemo)(() => {
64586
+ const effectiveReportBuilderTables = (0, import_react61.useMemo)(() => {
64718
64587
  const explicitBaseFromSchemaPicker = Array.isArray(schemaDatasourceIds) && schemaDatasourceIds.length > 0 ? schemaDatasourceIds.map((tableName) => String(tableName ?? "").trim()).filter(Boolean).map((name2) => ({ name: name2 })) : null;
64719
64588
  const baseTablesForMerge = explicitBaseFromSchemaPicker ?? baseReportBuilderTables;
64720
64589
  return mergeReportBuilderTables(
@@ -64738,28 +64607,18 @@ function useReport(reportIdArg, options = {}) {
64738
64607
  queryColumns,
64739
64608
  schemaDatasourceIds
64740
64609
  ]);
64741
- const datasources = (0, import_react62.useMemo)(() => {
64742
- return effectiveReportBuilderTables.map((table2) => {
64743
- const name2 = String(table2.name ?? "").trim();
64744
- if (!name2) return null;
64745
- const alias = String(table2.alias ?? "").trim();
64746
- return {
64747
- id: name2,
64748
- label: alias || name2
64749
- };
64750
- }).filter(
64751
- (entry) => Boolean(entry)
64752
- );
64610
+ const datasources = (0, import_react61.useMemo)(() => {
64611
+ return effectiveReportBuilderTables.map((table2) => String(table2.name ?? "").trim()).filter((name2) => Boolean(name2));
64753
64612
  }, [effectiveReportBuilderTables]);
64754
- const effectiveReportBuilderTableNames = (0, import_react62.useMemo)(
64613
+ const effectiveReportBuilderTableNames = (0, import_react61.useMemo)(
64755
64614
  () => effectiveReportBuilderTables.map((table2) => String(table2.name ?? "").trim()).filter((name2) => Boolean(name2)),
64756
64615
  [effectiveReportBuilderTables]
64757
64616
  );
64758
- const baseReportBuilderTableNames = (0, import_react62.useMemo)(
64617
+ const baseReportBuilderTableNames = (0, import_react61.useMemo)(
64759
64618
  () => baseReportBuilderTables.map((table2) => String(table2.name ?? "").trim()).filter((name2) => Boolean(name2)),
64760
64619
  [baseReportBuilderTables]
64761
64620
  );
64762
- const normalizeQueryBuilderFieldNameForConfig = (0, import_react62.useMemo)(() => {
64621
+ const normalizeQueryBuilderFieldNameForConfig = (0, import_react61.useMemo)(() => {
64763
64622
  const configEntries = Object.entries(queryBuilderFieldConfigByName);
64764
64623
  const preferredTableNames = /* @__PURE__ */ new Set([
64765
64624
  ...effectiveReportBuilderTableNames,
@@ -64821,7 +64680,7 @@ function useReport(reportIdArg, options = {}) {
64821
64680
  effectiveReportBuilderTableNames,
64822
64681
  queryBuilderFieldConfigByName
64823
64682
  ]);
64824
- const normalizeQueryBuilderFiltersForConfig = (0, import_react62.useMemo)(() => {
64683
+ const normalizeQueryBuilderFiltersForConfig = (0, import_react61.useMemo)(() => {
64825
64684
  const normalizeGroup = (group) => {
64826
64685
  const groupRules = Array.isArray(group.rules) ? group.rules : [];
64827
64686
  const nextRules = groupRules.map((entry) => {
@@ -64858,14 +64717,14 @@ function useReport(reportIdArg, options = {}) {
64858
64717
  return normalizeGroup(group);
64859
64718
  };
64860
64719
  }, [normalizeQueryBuilderFieldNameForConfig, queryBuilderFieldConfigByName]);
64861
- const refreshSelectionTables = (0, import_react62.useMemo)(() => {
64720
+ const refreshSelectionTables = (0, import_react61.useMemo)(() => {
64862
64721
  return [
64863
64722
  getPivotGroupOptionTable(groupRowsBy),
64864
64723
  getPivotGroupOptionTable(groupColumnsBy),
64865
64724
  ...aggregationTablesByIndex
64866
64725
  ].map((tableName) => String(tableName ?? "").trim()).filter((tableName) => Boolean(tableName));
64867
64726
  }, [aggregationTablesByIndex, groupColumnsBy, groupRowsBy]);
64868
- const refreshSelectionFields = (0, import_react62.useMemo)(() => {
64727
+ const refreshSelectionFields = (0, import_react61.useMemo)(() => {
64869
64728
  const resolveFieldTableForSelection = (field, tableHint) => {
64870
64729
  const fieldName = String(field ?? "").trim();
64871
64730
  if (!fieldName) return "";
@@ -64915,7 +64774,7 @@ function useReport(reportIdArg, options = {}) {
64915
64774
  schemaForReportBuilderState,
64916
64775
  sourceReport
64917
64776
  ]);
64918
- const refreshDecision = (0, import_react62.useMemo)(
64777
+ const refreshDecision = (0, import_react61.useMemo)(
64919
64778
  () => decideReportBuilderRefresh({
64920
64779
  baseTables: baseReportBuilderTables,
64921
64780
  baseColumns: baseReportBuilderColumns,
@@ -64929,7 +64788,7 @@ function useReport(reportIdArg, options = {}) {
64929
64788
  refreshSelectionTables
64930
64789
  ]
64931
64790
  );
64932
- const effectiveReportBuilderColumns = (0, import_react62.useMemo)(() => {
64791
+ const effectiveReportBuilderColumns = (0, import_react61.useMemo)(() => {
64933
64792
  const columnsFromPivot = [];
64934
64793
  const appendPivotColumn = (field, tableHint) => {
64935
64794
  const normalizedField = String(field ?? "").trim();
@@ -64992,7 +64851,7 @@ function useReport(reportIdArg, options = {}) {
64992
64851
  queryColumns,
64993
64852
  sourceReport
64994
64853
  ]);
64995
- (0, import_react62.useEffect)(() => {
64854
+ (0, import_react61.useEffect)(() => {
64996
64855
  if (!Array.isArray(filterStack) || filterStack.length === 0) {
64997
64856
  return;
64998
64857
  }
@@ -65027,7 +64886,7 @@ function useReport(reportIdArg, options = {}) {
65027
64886
  queryBuilderFieldConfigByName,
65028
64887
  queryFilters
65029
64888
  ]);
65030
- const resolvedSortFieldType = (0, import_react62.useMemo)(() => {
64889
+ const resolvedSortFieldType = (0, import_react61.useMemo)(() => {
65031
64890
  const sortField = pivotSort?.sortField;
65032
64891
  if (!sortField || !pivotState) return void 0;
65033
64892
  if (sortField === resolvedGroupRowsBy) {
@@ -65048,7 +64907,7 @@ function useReport(reportIdArg, options = {}) {
65048
64907
  resolvedGroupColumnsBy,
65049
64908
  resolvedGroupRowsBy
65050
64909
  ]);
65051
- const effectiveReportBuilderState = (0, import_react62.useMemo)(() => {
64910
+ const effectiveReportBuilderState = (0, import_react61.useMemo)(() => {
65052
64911
  if (!sourceReport && effectiveReportBuilderTables.length === 0) {
65053
64912
  return void 0;
65054
64913
  }
@@ -65087,12 +64946,12 @@ function useReport(reportIdArg, options = {}) {
65087
64946
  resolvedSortFieldType,
65088
64947
  sourceReport
65089
64948
  ]);
65090
- const effectiveReportBuilderStateHash = (0, import_react62.useMemo)(
64949
+ const effectiveReportBuilderStateHash = (0, import_react61.useMemo)(
65091
64950
  () => stableSerializeForQueryKey(effectiveReportBuilderState),
65092
64951
  [effectiveReportBuilderState]
65093
64952
  );
65094
- const prevPaginationResetStateHashRef = (0, import_react62.useRef)(null);
65095
- (0, import_react62.useEffect)(() => {
64953
+ const prevPaginationResetStateHashRef = (0, import_react61.useRef)(null);
64954
+ (0, import_react61.useEffect)(() => {
65096
64955
  const prevHash = prevPaginationResetStateHashRef.current;
65097
64956
  prevPaginationResetStateHashRef.current = effectiveReportBuilderStateHash;
65098
64957
  if (prevHash === null || prevHash === effectiveReportBuilderStateHash) {
@@ -65108,7 +64967,7 @@ function useReport(reportIdArg, options = {}) {
65108
64967
  activate: false
65109
64968
  });
65110
64969
  }, [applyPaginationUpdate, effectiveReportBuilderStateHash]);
65111
- const pivotTableDataReportBuilderState = (0, import_react62.useMemo)(() => {
64970
+ const pivotTableDataReportBuilderState = (0, import_react61.useMemo)(() => {
65112
64971
  if (!effectiveReportBuilderState?.pivot) {
65113
64972
  return void 0;
65114
64973
  }
@@ -65128,11 +64987,11 @@ function useReport(reportIdArg, options = {}) {
65128
64987
  limit: null
65129
64988
  };
65130
64989
  }, [effectiveReportBuilderState, schemaForReportBuilderState]);
65131
- const pivotTableDataReportBuilderStateHash = (0, import_react62.useMemo)(
64990
+ const pivotTableDataReportBuilderStateHash = (0, import_react61.useMemo)(
65132
64991
  () => stableSerializeForQueryKey(pivotTableDataReportBuilderState),
65133
64992
  [pivotTableDataReportBuilderState]
65134
64993
  );
65135
- const sourceReportMatchesEffectiveReportId = (0, import_react62.useMemo)(() => {
64994
+ const sourceReportMatchesEffectiveReportId = (0, import_react61.useMemo)(() => {
65136
64995
  const loadTarget = String(effectiveReportId ?? "").trim();
65137
64996
  if (!loadTarget || !sourceReport) {
65138
64997
  return true;
@@ -65142,7 +65001,7 @@ function useReport(reportIdArg, options = {}) {
65142
65001
  ).trim();
65143
65002
  return sid === loadTarget;
65144
65003
  }, [effectiveReportId, sourceReport]);
65145
- const shouldSkipRedundantFlatTableReportBuilderQuery = (0, import_react62.useMemo)(() => {
65004
+ const shouldSkipRedundantFlatTableReportBuilderQuery = (0, import_react61.useMemo)(() => {
65146
65005
  if (!sourceReport || pivotState) {
65147
65006
  return false;
65148
65007
  }
@@ -65197,7 +65056,7 @@ function useReport(reportIdArg, options = {}) {
65197
65056
  enabled: tableRefreshQueryEnabled,
65198
65057
  retry: false
65199
65058
  });
65200
- (0, import_react62.useEffect)(() => {
65059
+ (0, import_react61.useEffect)(() => {
65201
65060
  if (!tableRefreshQueryEnabled) return;
65202
65061
  const report = tableRefreshQuery.data?.report;
65203
65062
  if (tableRefreshQuery.data?.error || !report) return;
@@ -65208,10 +65067,10 @@ function useReport(reportIdArg, options = {}) {
65208
65067
  tableRefreshQueryEnabled,
65209
65068
  useFormRefreshDebugEnabled
65210
65069
  ]);
65211
- const chartTypes = (0, import_react62.useMemo)(() => {
65070
+ const chartTypes = (0, import_react61.useMemo)(() => {
65212
65071
  return getChartTypeOptions2({ pivot: pivotState });
65213
65072
  }, [pivotState]);
65214
- (0, import_react62.useEffect)(() => {
65073
+ (0, import_react61.useEffect)(() => {
65215
65074
  if (!sourceReport) {
65216
65075
  return;
65217
65076
  }
@@ -65246,7 +65105,7 @@ function useReport(reportIdArg, options = {}) {
65246
65105
  });
65247
65106
  }
65248
65107
  }, [chartType, chartTypes, sourceReport]);
65249
- const schemaScopedTableNames = (0, import_react62.useMemo)(() => {
65108
+ const schemaScopedTableNames = (0, import_react61.useMemo)(() => {
65250
65109
  if (preserveSchemaWideOptions) {
65251
65110
  return [];
65252
65111
  }
@@ -65261,7 +65120,7 @@ function useReport(reportIdArg, options = {}) {
65261
65120
  preserveSchemaWideOptions,
65262
65121
  sourceReport?.reportBuilderState?.tables
65263
65122
  ]);
65264
- const joinCompatibleSchemaTableNames = (0, import_react62.useMemo)(() => {
65123
+ const joinCompatibleSchemaTableNames = (0, import_react61.useMemo)(() => {
65265
65124
  if (schemaScopedTableNames.length === 0) {
65266
65125
  return [];
65267
65126
  }
@@ -65270,7 +65129,7 @@ function useReport(reportIdArg, options = {}) {
65270
65129
  schemaForeignKeyMap
65271
65130
  );
65272
65131
  }, [schemaForeignKeyMap, schemaScopedTableNames]);
65273
- const aggregationFallbackTarget = (0, import_react62.useMemo)(() => {
65132
+ const aggregationFallbackTarget = (0, import_react61.useMemo)(() => {
65274
65133
  const tableNames = effectiveReportBuilderTables.map((table2) => table2.name).filter((name2) => Boolean(name2));
65275
65134
  const referencedTableNames = (sourceReport?.referencedTables ?? []).filter(
65276
65135
  (name2) => typeof name2 === "string" && name2.length > 0
@@ -65278,7 +65137,7 @@ function useReport(reportIdArg, options = {}) {
65278
65137
  const tableNamesToUse = tableNames.length ? tableNames : referencedTableNames;
65279
65138
  return tableNamesToUse.length > 0 ? tableNamesToUse.join(", ") : "table";
65280
65139
  }, [effectiveReportBuilderTables, sourceReport?.referencedTables]);
65281
- const aggregationFallbackTableName = (0, import_react62.useMemo)(() => {
65140
+ const aggregationFallbackTableName = (0, import_react61.useMemo)(() => {
65282
65141
  const tableNames = effectiveReportBuilderTables.map((table2) => table2.name).filter((name2) => Boolean(name2));
65283
65142
  const referencedTableNames = (sourceReport?.referencedTables ?? []).filter(
65284
65143
  (name2) => typeof name2 === "string" && name2.length > 0
@@ -65286,7 +65145,7 @@ function useReport(reportIdArg, options = {}) {
65286
65145
  const tableNamesToUse = tableNames.length ? tableNames : referencedTableNames;
65287
65146
  return tableNamesToUse[0] ?? "table";
65288
65147
  }, [effectiveReportBuilderTables, sourceReport?.referencedTables]);
65289
- const cleanedAggregations = (0, import_react62.useMemo)(() => {
65148
+ const cleanedAggregations = (0, import_react61.useMemo)(() => {
65290
65149
  return aggregationState.filter((aggregation) => Boolean(aggregation?.aggregationType)).map((aggregation, index) => {
65291
65150
  const aggregationType = String(aggregation.aggregationType);
65292
65151
  const normalizedAggregationType = aggregationType.toLowerCase();
@@ -65308,7 +65167,7 @@ function useReport(reportIdArg, options = {}) {
65308
65167
  aggregationTablesByIndex,
65309
65168
  isBoolAggregationField
65310
65169
  ]);
65311
- const { aggregationBaseOptions, aggregationOptionTableLookup } = (0, import_react62.useMemo)(() => {
65170
+ const { aggregationBaseOptions, aggregationOptionTableLookup } = (0, import_react61.useMemo)(() => {
65312
65171
  const joinScoped = fieldOptionsAllowedTableNames ? joinCompatibleSchemaTableNames.filter(
65313
65172
  (name2) => fieldOptionsAllowedTableNames.has(name2)
65314
65173
  ) : joinCompatibleSchemaTableNames;
@@ -65354,7 +65213,7 @@ function useReport(reportIdArg, options = {}) {
65354
65213
  if (!canAggregateColumn(column, aggregationType)) continue;
65355
65214
  const isNumberSharePercentage = aggregationType === "percentage" && !isBoolColumn;
65356
65215
  if (isNumberSharePercentage && !resolvedGroupRowsBy) continue;
65357
- const value = `${aggregationType}:${fieldName}`;
65216
+ const value = tableName ? `${aggregationType}:${tableName}::${fieldName}` : `${aggregationType}:${fieldName}`;
65358
65217
  if (seen.has(value)) continue;
65359
65218
  const aggregationWord = aggregationType === "percentage" ? isBoolColumn ? "Percent" : "Percent of Total" : formatAggregationTypeForDisplay(aggregationType);
65360
65219
  options2.push({
@@ -65362,8 +65221,14 @@ function useReport(reportIdArg, options = {}) {
65362
65221
  label: tableName ? `${aggregationWord} ${toTitleCaseLabel(tableName)} ${toTitleCaseLabel(fieldName)}` : `${aggregationWord} ${toTitleCaseLabel(fieldName)}`
65363
65222
  });
65364
65223
  seen.add(value);
65365
- if (tableName && !tableLookup.has(value)) {
65366
- tableLookup.set(value, tableName);
65224
+ if (tableName) {
65225
+ if (!tableLookup.has(value)) {
65226
+ tableLookup.set(value, tableName);
65227
+ }
65228
+ const unqualifiedValue = `${aggregationType}:${fieldName}`;
65229
+ if (!tableLookup.has(unqualifiedValue)) {
65230
+ tableLookup.set(unqualifiedValue, tableName);
65231
+ }
65367
65232
  }
65368
65233
  }
65369
65234
  }
@@ -65385,7 +65250,7 @@ function useReport(reportIdArg, options = {}) {
65385
65250
  resolvedGroupRowsBy,
65386
65251
  schemaForReportBuilderState
65387
65252
  ]);
65388
- const { schemaColumnOptions, columnIdentifierLookup } = (0, import_react62.useMemo)(() => {
65253
+ const { schemaColumnOptions, columnIdentifierLookup } = (0, import_react61.useMemo)(() => {
65389
65254
  const lookup = /* @__PURE__ */ new Map();
65390
65255
  const options2 = [];
65391
65256
  for (const table2 of schemaData.schemaWithCustomFields) {
@@ -65412,7 +65277,7 @@ function useReport(reportIdArg, options = {}) {
65412
65277
  columnIdentifierLookup: lookup
65413
65278
  };
65414
65279
  }, [schemaData.schemaWithCustomFields]);
65415
- const tableColumnPickerPoolOptions = (0, import_react62.useMemo)(() => {
65280
+ const tableColumnPickerPoolOptions = (0, import_react61.useMemo)(() => {
65416
65281
  const allowed = new Set(
65417
65282
  effectiveReportBuilderTableNames.map((name2) => String(name2 ?? "").trim()).filter(Boolean)
65418
65283
  );
@@ -65423,16 +65288,16 @@ function useReport(reportIdArg, options = {}) {
65423
65288
  (option) => allowed.has(String(option.tableName ?? "").trim())
65424
65289
  );
65425
65290
  }, [effectiveReportBuilderTableNames, schemaColumnOptions]);
65426
- const columns = (0, import_react62.useMemo)(() => {
65291
+ const columns = (0, import_react61.useMemo)(() => {
65427
65292
  return displayColumns.filter((column) => Boolean(column.field)).map((column) => encodeColumnOptionValue(column.table, column.field));
65428
65293
  }, [displayColumns]);
65429
- const selectedColumnOptions = (0, import_react62.useMemo)(() => {
65294
+ const selectedColumnOptions = (0, import_react61.useMemo)(() => {
65430
65295
  return displayColumns.map((column) => {
65431
65296
  const value = column.alias || column.field;
65432
65297
  return value ? { label: value, value } : null;
65433
65298
  }).filter((option) => option !== null);
65434
65299
  }, [displayColumns]);
65435
- const scopedSchemaColumns = (0, import_react62.useMemo)(() => {
65300
+ const scopedSchemaColumns = (0, import_react61.useMemo)(() => {
65436
65301
  const tableNames = fieldOptionsAllowedTableNames ? Array.from(fieldOptionsAllowedTableNames) : joinCompatibleSchemaTableNames;
65437
65302
  const schemaTables = schemaForReportBuilderState;
65438
65303
  const tablesToUse = tableNames.length ? schemaTables.filter((table2) => tableNames.includes(table2.name ?? "")) : schemaTables;
@@ -65453,7 +65318,7 @@ function useReport(reportIdArg, options = {}) {
65453
65318
  joinCompatibleSchemaTableNames,
65454
65319
  schemaForReportBuilderState
65455
65320
  ]);
65456
- const pivotUniqueValuesByColumn = (0, import_react62.useMemo)(() => {
65321
+ const pivotUniqueValuesByColumn = (0, import_react61.useMemo)(() => {
65457
65322
  const explicitUniqueValues = sourceReport?.uniqueStringsByColumn ?? sourceReport?.columnUniqueValues ?? sourceReport?.uniqueValues;
65458
65323
  if (explicitUniqueValues && typeof explicitUniqueValues === "object" && !Array.isArray(explicitUniqueValues)) {
65459
65324
  return explicitUniqueValues;
@@ -65479,7 +65344,7 @@ function useReport(reportIdArg, options = {}) {
65479
65344
  }
65480
65345
  return result;
65481
65346
  }, [sourceReport]);
65482
- const possiblePivotFields = (0, import_react62.useMemo)(() => {
65347
+ const possiblePivotFields = (0, import_react61.useMemo)(() => {
65483
65348
  const options2 = getPossiblePivotFieldOptions(
65484
65349
  scopedSchemaColumns,
65485
65350
  pivotUniqueValuesByColumn
@@ -65490,7 +65355,7 @@ function useReport(reportIdArg, options = {}) {
65490
65355
  columnFields: options2.columnFields.filter((field) => !isIdColumn(field))
65491
65356
  };
65492
65357
  }, [scopedSchemaColumns, pivotUniqueValuesByColumn]);
65493
- const groupRowsByOptions = (0, import_react62.useMemo)(() => {
65358
+ const groupRowsByOptions = (0, import_react61.useMemo)(() => {
65494
65359
  const allowedFields = new Set(possiblePivotFields.rowFields);
65495
65360
  const seenValues = /* @__PURE__ */ new Set();
65496
65361
  const options2 = [];
@@ -65517,7 +65382,7 @@ function useReport(reportIdArg, options = {}) {
65517
65382
  }
65518
65383
  return options2;
65519
65384
  }, [groupRowsBy, possiblePivotFields.rowFields, scopedSchemaColumns]);
65520
- const groupColumnsByOptions = (0, import_react62.useMemo)(() => {
65385
+ const groupColumnsByOptions = (0, import_react61.useMemo)(() => {
65521
65386
  const allowedFields = new Set(possiblePivotFields.columnFields);
65522
65387
  const seenValues = /* @__PURE__ */ new Set();
65523
65388
  const options2 = [];
@@ -65544,19 +65409,19 @@ function useReport(reportIdArg, options = {}) {
65544
65409
  }
65545
65410
  return options2;
65546
65411
  }, [groupColumnsBy, possiblePivotFields.columnFields, scopedSchemaColumns]);
65547
- const cleanedSort = (0, import_react62.useMemo)(() => {
65412
+ const cleanedSort = (0, import_react61.useMemo)(() => {
65548
65413
  const activeSort = resolvedGroupRowsBy ? pivotSort : regularSort;
65549
65414
  if (!activeSort?.sortField || !activeSort?.sortDirection) {
65550
65415
  return "";
65551
65416
  }
65552
65417
  return toFlatSortValue(activeSort.sortField, activeSort.sortDirection);
65553
65418
  }, [pivotSort, regularSort, resolvedGroupRowsBy]);
65554
- const aggregationSortLabelFallbackTable = (0, import_react62.useMemo)(() => {
65419
+ const aggregationSortLabelFallbackTable = (0, import_react61.useMemo)(() => {
65555
65420
  const reportBuilderTableName = effectiveReportBuilderTables.map((table2) => String(table2.name ?? "").trim()).find((tableName) => Boolean(tableName));
65556
65421
  if (reportBuilderTableName) return reportBuilderTableName;
65557
65422
  return (sourceReport?.referencedTables ?? []).map((tableName) => String(tableName ?? "").trim()).find((tableName) => Boolean(tableName));
65558
65423
  }, [effectiveReportBuilderTables, sourceReport?.referencedTables]);
65559
- const sortOptions = (0, import_react62.useMemo)(() => {
65424
+ const sortOptions = (0, import_react61.useMemo)(() => {
65560
65425
  if (resolvedGroupRowsBy) {
65561
65426
  const aggregationSortFields = getPivotAggregationSortFields(
65562
65427
  aggregationState,
@@ -65615,12 +65480,14 @@ function useReport(reportIdArg, options = {}) {
65615
65480
  resolvedGroupRowsBy,
65616
65481
  selectedColumnOptions
65617
65482
  ]);
65618
- const aggregationOptions = (0, import_react62.useMemo)(() => {
65483
+ const { aggregationValues, aggregationOptions } = (0, import_react61.useMemo)(() => {
65619
65484
  const baseOptions = aggregationBaseOptions.map((option) => ({
65620
65485
  value: option.value,
65621
65486
  label: option.label
65622
65487
  }));
65623
- return aggregationState.map((aggregation, index) => {
65488
+ const seenValues = new Set(baseOptions.map((option) => option.value));
65489
+ const injectedOptions = [];
65490
+ const values = aggregationState.map((aggregation, index) => {
65624
65491
  const normalizedAggregationType = String(
65625
65492
  aggregation.aggregationType ?? ""
65626
65493
  ).toLowerCase();
@@ -65628,27 +65495,36 @@ function useReport(reportIdArg, options = {}) {
65628
65495
  const currentValueField = String(aggregation.valueField ?? "").trim();
65629
65496
  const currentValueField2 = String(aggregation.valueField2 ?? "").trim();
65630
65497
  const isPercentageRatio = normalizedAggregationType === "percentage" && Boolean(currentValueField) && Boolean(currentValueField2);
65631
- const currentTarget = isPercentageRatio ? `${currentValueField}:${currentValueField2}` : currentValueField ? currentValueField : normalizedAggregationType === "count" || normalizedAggregationType === "percentage" ? tableHint || aggregationFallbackTableName : aggregationFallbackTarget;
65632
- const currentValue = aggregation.aggregationType ? `${aggregation.aggregationType}:${currentTarget}` : void 0;
65633
- const isBoolPercentage = normalizedAggregationType === "percentage" && Boolean(currentValueField) && isBoolAggregationField(currentValueField, tableHint || void 0) === true;
65634
- 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";
65635
- const options2 = currentValue ? baseOptions.some((option) => option.value === currentValue) ? baseOptions : [{ value: currentValue, label: currentLabel }, ...baseOptions] : baseOptions;
65636
- return {
65637
- key: `aggregation-${index}`,
65638
- label: `Aggregation ${index + 1}`,
65639
- value: currentValue ?? "",
65640
- options: options2
65641
- };
65498
+ const isTableTarget = !isPercentageRatio && !currentValueField && (normalizedAggregationType === "count" || normalizedAggregationType === "percentage");
65499
+ const labelTarget = isPercentageRatio ? `${currentValueField}:${currentValueField2}` : currentValueField ? currentValueField : isTableTarget ? tableHint || aggregationFallbackTableName : aggregationFallbackTarget;
65500
+ const fieldTable = isTableTarget || !aggregation.aggregationType ? "" : tableHint || String(
65501
+ aggregationOptionTableLookup.get(
65502
+ `${aggregation.aggregationType}:${labelTarget}`
65503
+ ) ?? ""
65504
+ ).trim();
65505
+ const currentValue = aggregation.aggregationType ? `${aggregation.aggregationType}:${fieldTable ? `${fieldTable}::` : ""}${labelTarget}` : "";
65506
+ if (currentValue && !seenValues.has(currentValue)) {
65507
+ const isBoolPercentage = normalizedAggregationType === "percentage" && Boolean(currentValueField) && isBoolAggregationField(currentValueField, tableHint || void 0) === true;
65508
+ 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)}`;
65509
+ injectedOptions.push({ value: currentValue, label: currentLabel });
65510
+ seenValues.add(currentValue);
65511
+ }
65512
+ return currentValue;
65642
65513
  });
65514
+ return {
65515
+ aggregationValues: values,
65516
+ aggregationOptions: [...injectedOptions, ...baseOptions]
65517
+ };
65643
65518
  }, [
65644
65519
  aggregationFallbackTableName,
65645
65520
  aggregationFallbackTarget,
65646
65521
  aggregationState,
65647
65522
  aggregationBaseOptions,
65523
+ aggregationOptionTableLookup,
65648
65524
  aggregationTablesByIndex,
65649
65525
  isBoolAggregationField
65650
65526
  ]);
65651
- const nextPivot = (0, import_react62.useMemo)(() => {
65527
+ const nextPivot = (0, import_react61.useMemo)(() => {
65652
65528
  if (!sourceReport) return null;
65653
65529
  return pivotState ? {
65654
65530
  ...pivotState,
@@ -65659,15 +65535,15 @@ function useReport(reportIdArg, options = {}) {
65659
65535
  rowLimit: limit?.value
65660
65536
  } : null;
65661
65537
  }, [sourceReport, pivotState, pivotSort, limit, resolvedSortFieldType]);
65662
- const nextPivotHash = (0, import_react62.useMemo)(
65538
+ const nextPivotHash = (0, import_react61.useMemo)(
65663
65539
  () => stableSerializeForQueryKey(nextPivot),
65664
65540
  [nextPivot]
65665
65541
  );
65666
- const filterStackHash = (0, import_react62.useMemo)(
65542
+ const filterStackHash = (0, import_react61.useMemo)(
65667
65543
  () => stableSerializeForQueryKey(filterStack),
65668
65544
  [filterStack]
65669
65545
  );
65670
- const shouldSkipPivotRefreshForUnchangedPivot = (0, import_react62.useMemo)(() => {
65546
+ const shouldSkipPivotRefreshForUnchangedPivot = (0, import_react61.useMemo)(() => {
65671
65547
  if (!sourceReport || !nextPivot) return false;
65672
65548
  if (!Array.isArray(sourceReport.rows) || sourceReport.rows.length === 0) {
65673
65549
  return false;
@@ -65685,7 +65561,7 @@ function useReport(reportIdArg, options = {}) {
65685
65561
  );
65686
65562
  return hasSamePivot && sourceFilterStackHash === filterStackHash;
65687
65563
  }, [filterStackHash, nextPivot, sourceReport]);
65688
- (0, import_react62.useEffect)(() => {
65564
+ (0, import_react61.useEffect)(() => {
65689
65565
  if (!pendingPivotRefresh) return;
65690
65566
  if (!nextPivot) {
65691
65567
  if (!sourceReport) {
@@ -65705,7 +65581,7 @@ function useReport(reportIdArg, options = {}) {
65705
65581
  shouldSkipPivotRefreshForUnchangedPivot,
65706
65582
  sourceReport
65707
65583
  ]);
65708
- const shouldSkipRedundantPivotTableDataReportBuilderQuery = (0, import_react62.useMemo)(() => {
65584
+ const shouldSkipRedundantPivotTableDataReportBuilderQuery = (0, import_react61.useMemo)(() => {
65709
65585
  if (!sourceReport || !nextPivot) {
65710
65586
  return false;
65711
65587
  }
@@ -65807,7 +65683,7 @@ function useReport(reportIdArg, options = {}) {
65807
65683
  });
65808
65684
  const tablePageReportBuilderState = pivotTableDataReportBuilderState ?? effectiveReportBuilderState;
65809
65685
  const tablePageReportBuilderStateHash = pivotTableDataReportBuilderState ? pivotTableDataReportBuilderStateHash : effectiveReportBuilderStateHash;
65810
- const tablePaginationSort = (0, import_react62.useMemo)(() => {
65686
+ const tablePaginationSort = (0, import_react61.useMemo)(() => {
65811
65687
  const sortEntry = tablePageReportBuilderState?.sort?.[0];
65812
65688
  const field = String(sortEntry?.field ?? "").trim();
65813
65689
  if (!field || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(field)) {
@@ -65869,7 +65745,7 @@ function useReport(reportIdArg, options = {}) {
65869
65745
  const tablePageRows = tablePageQueryEnabled && !tablePageQuery.data?.error && Array.isArray(tablePageQuery.data?.report?.rows) ? tablePageQuery.data.report.rows : void 0;
65870
65746
  const tablePageRowCount = tablePageQueryEnabled && typeof tablePageQuery.data?.report?.rowCount === "number" && tablePageQuery.data.report.rowCount > 0 ? tablePageQuery.data.report.rowCount : void 0;
65871
65747
  const tablePageFetching = tablePageQueryEnabled && tablePageQuery.isFetching;
65872
- const paginationTotalRowCount = (0, import_react62.useMemo)(() => {
65748
+ const paginationTotalRowCount = (0, import_react61.useMemo)(() => {
65873
65749
  if (tablePageRowCount !== void 0) {
65874
65750
  return Math.max(tablePageRowCount, baseWindowRowsLength);
65875
65751
  }
@@ -65892,7 +65768,7 @@ function useReport(reportIdArg, options = {}) {
65892
65768
  pagination.pageSize
65893
65769
  );
65894
65770
  paginationPageCountRef.current = paginationPageCount;
65895
- (0, import_react62.useEffect)(() => {
65771
+ (0, import_react61.useEffect)(() => {
65896
65772
  if (!pivotTableDataRefreshQueryEnabled) return;
65897
65773
  if (pivotTableDataRefreshQuery.status !== "success" && pivotTableDataRefreshQuery.status !== "error") {
65898
65774
  return;
@@ -65930,7 +65806,7 @@ function useReport(reportIdArg, options = {}) {
65930
65806
  effectiveReportId,
65931
65807
  useFormRefreshDebugEnabled
65932
65808
  ]);
65933
- (0, import_react62.useEffect)(() => {
65809
+ (0, import_react61.useEffect)(() => {
65934
65810
  if (!pivotRefreshQueryEnabled) return;
65935
65811
  if (pivotRefreshQuery.status !== "success" && pivotRefreshQuery.status !== "error") {
65936
65812
  return;
@@ -65983,7 +65859,7 @@ function useReport(reportIdArg, options = {}) {
65983
65859
  effectiveReportId,
65984
65860
  useFormRefreshDebugEnabled
65985
65861
  ]);
65986
- const chartData = (0, import_react62.useMemo)(() => {
65862
+ const chartData = (0, import_react61.useMemo)(() => {
65987
65863
  if (!sourceReport) return void 0;
65988
65864
  const rowsForChart = Array.isArray(sourceReport.rows) ? sourceReport.rows : [];
65989
65865
  const chartPivotForDisplay = nextPivot ?? (!chartPivotHydratedFromSourceRef.current ? sourceReport.pivot ?? null : null);
@@ -66019,18 +65895,18 @@ function useReport(reportIdArg, options = {}) {
66019
65895
  useInMemoryEngines,
66020
65896
  chartPivotHydrationEpoch
66021
65897
  ]);
66022
- const baseChart = (0, import_react62.useMemo)(
65898
+ const baseChart = (0, import_react61.useMemo)(
66023
65899
  () => normalizePivotChartForDisplay(chartData),
66024
65900
  [chartData]
66025
65901
  );
66026
- const chartAxesBaseChart = (0, import_react62.useMemo)(() => {
65902
+ const chartAxesBaseChart = (0, import_react61.useMemo)(() => {
66027
65903
  if (!chartData) return void 0;
66028
65904
  if (chartData.pivot?.columnField) {
66029
65905
  return normalizePivotChartForAxisControls(chartData, effectiveReportId);
66030
65906
  }
66031
65907
  return baseChart;
66032
65908
  }, [baseChart, chartData, effectiveReportId]);
66033
- const chartAxisOptions = (0, import_react62.useMemo)(() => {
65909
+ const chartAxisOptions = (0, import_react61.useMemo)(() => {
66034
65910
  if (!chartAxesBaseChart) return [];
66035
65911
  const optionsByField = /* @__PURE__ */ new Map();
66036
65912
  const registerOption = (fieldRaw, labelRaw, formatRaw) => {
@@ -66068,14 +65944,14 @@ function useReport(reportIdArg, options = {}) {
66068
65944
  );
66069
65945
  return Array.from(optionsByField.values());
66070
65946
  }, [chartAxesBaseChart]);
66071
- const chartAxisOptionByField = (0, import_react62.useMemo)(() => {
65947
+ const chartAxisOptionByField = (0, import_react61.useMemo)(() => {
66072
65948
  const optionsByField = /* @__PURE__ */ new Map();
66073
65949
  for (const option of chartAxisOptions) {
66074
65950
  optionsByField.set(option.value, option);
66075
65951
  }
66076
65952
  return optionsByField;
66077
65953
  }, [chartAxisOptions]);
66078
- const xAxisOptions = (0, import_react62.useMemo)(() => {
65954
+ const xAxisOptions = (0, import_react61.useMemo)(() => {
66079
65955
  if (!chartAxesBaseChart) return chartAxisOptions;
66080
65956
  const pivot = chartAxesBaseChart.pivot;
66081
65957
  const pivotRowField = String(pivot?.rowField ?? "").trim();
@@ -66098,7 +65974,7 @@ function useReport(reportIdArg, options = {}) {
66098
65974
  }
66099
65975
  return chartAxisOptions;
66100
65976
  }, [chartAxesBaseChart, chartAxisOptions, chartAxisOptionByField]);
66101
- const yAxisOptions = (0, import_react62.useMemo)(() => {
65977
+ const yAxisOptions = (0, import_react61.useMemo)(() => {
66102
65978
  if (!chartAxesBaseChart) return [];
66103
65979
  const keepOption = (option) => {
66104
65980
  const col = findSchemaColumnForChartAxisField(
@@ -66134,21 +66010,21 @@ function useReport(reportIdArg, options = {}) {
66134
66010
  chartAxisOptions,
66135
66011
  schemaColumnOptions
66136
66012
  ]);
66137
- const normalizedChartXAxisOptions = (0, import_react62.useMemo)(() => {
66013
+ const normalizedChartXAxisOptions = (0, import_react61.useMemo)(() => {
66138
66014
  return xAxisOptions.map((option) => ({
66139
66015
  value: String(option.value ?? "").trim(),
66140
66016
  label: String(option.label ?? option.value ?? "").trim(),
66141
66017
  format: String(option.format ?? "").trim()
66142
66018
  }));
66143
66019
  }, [xAxisOptions]);
66144
- const normalizedChartYAxisOptions = (0, import_react62.useMemo)(() => {
66020
+ const normalizedChartYAxisOptions = (0, import_react61.useMemo)(() => {
66145
66021
  return yAxisOptions.map((option) => ({
66146
66022
  value: String(option.value ?? "").trim(),
66147
66023
  label: String(option.label ?? option.value ?? "").trim(),
66148
66024
  format: String(option.format ?? "").trim()
66149
66025
  }));
66150
66026
  }, [yAxisOptions]);
66151
- const resolvedYAxisFields = (0, import_react62.useMemo)(() => {
66027
+ const resolvedYAxisFields = (0, import_react61.useMemo)(() => {
66152
66028
  if (!chartAxesBaseChart) return [];
66153
66029
  const normalizeYAxisField = (yAxisFieldRaw) => {
66154
66030
  const field = String(yAxisFieldRaw?.field ?? "").trim();
@@ -66191,7 +66067,7 @@ function useReport(reportIdArg, options = {}) {
66191
66067
  chartAxisOptionByField,
66192
66068
  chartAxisOptions
66193
66069
  ]);
66194
- const resolvedXAxisField = (0, import_react62.useMemo)(() => {
66070
+ const resolvedXAxisField = (0, import_react61.useMemo)(() => {
66195
66071
  if (!chartAxesBaseChart) return "";
66196
66072
  const chartType2 = String(chartAxesBaseChart.chartType ?? "").toLowerCase();
66197
66073
  const pivotRowField = String(
@@ -66223,7 +66099,7 @@ function useReport(reportIdArg, options = {}) {
66223
66099
  chartAxisOptions,
66224
66100
  resolvedYAxisFields
66225
66101
  ]);
66226
- const resolvedXAxisFormat = (0, import_react62.useMemo)(() => {
66102
+ const resolvedXAxisFormat = (0, import_react61.useMemo)(() => {
66227
66103
  if (!chartAxesBaseChart) {
66228
66104
  return "string";
66229
66105
  }
@@ -66251,7 +66127,7 @@ function useReport(reportIdArg, options = {}) {
66251
66127
  resolvedXAxisField,
66252
66128
  resolvedYAxisFields
66253
66129
  ]);
66254
- const resolvedXAxisLabel = (0, import_react62.useMemo)(() => {
66130
+ const resolvedXAxisLabel = (0, import_react61.useMemo)(() => {
66255
66131
  const defaultXLabel = String(
66256
66132
  chartAxesBaseChart?.xAxisLabel ?? chartAxisOptionByField.get(resolvedXAxisField)?.label ?? ""
66257
66133
  ).trim();
@@ -66265,13 +66141,13 @@ function useReport(reportIdArg, options = {}) {
66265
66141
  chartAxisOptionByField,
66266
66142
  resolvedXAxisField
66267
66143
  ]);
66268
- const chartVisibility = (0, import_react62.useMemo)(
66144
+ const chartVisibility = (0, import_react61.useMemo)(
66269
66145
  () => ({
66270
66146
  showLegend: chartVisibilityOverrides.showLegend ?? Boolean(baseChart?.showLegend ?? false)
66271
66147
  }),
66272
66148
  [baseChart?.showLegend, chartVisibilityOverrides]
66273
66149
  );
66274
- const axisConfig = (0, import_react62.useMemo)(() => {
66150
+ const axisConfig = (0, import_react61.useMemo)(() => {
66275
66151
  const pivotBucketXAxis = isPivotTableDateBucketRowAxis(
66276
66152
  chartAxesBaseChart,
66277
66153
  resolvedXAxisField
@@ -66313,14 +66189,14 @@ function useReport(reportIdArg, options = {}) {
66313
66189
  resolvedYAxisFields,
66314
66190
  chartVisibility.showLegend
66315
66191
  ]);
66316
- const resolvedYAxisFieldsForDisplay = (0, import_react62.useMemo)(() => {
66192
+ const resolvedYAxisFieldsForDisplay = (0, import_react61.useMemo)(() => {
66317
66193
  if (!baseChart) return resolvedYAxisFields;
66318
66194
  return mapResolvedPivotYAxisFieldsForDisplay({
66319
66195
  chart: baseChart,
66320
66196
  resolvedYAxisFields
66321
66197
  });
66322
66198
  }, [baseChart, resolvedYAxisFields]);
66323
- const chart = (0, import_react62.useMemo)(() => {
66199
+ const chart = (0, import_react61.useMemo)(() => {
66324
66200
  if (!baseChart) return void 0;
66325
66201
  let columns2 = mergeChartColumnFormatsFromYAxisFields(
66326
66202
  baseChart.columns,
@@ -66372,7 +66248,7 @@ function useReport(reportIdArg, options = {}) {
66372
66248
  const isPivotTableChart = String(chartType ?? "").toLowerCase() === "table" && Boolean(
66373
66249
  chart && chart.pivot && Array.isArray(chart.columns) && chart.columns.length > 0
66374
66250
  );
66375
- const chartAxes = (0, import_react62.useMemo)(() => {
66251
+ const chartAxes = (0, import_react61.useMemo)(() => {
66376
66252
  const yAxisItems = resolvedYAxisFields.map(
66377
66253
  (yAxisField, index) => ({
66378
66254
  id: String(index),
@@ -66521,8 +66397,8 @@ function useReport(reportIdArg, options = {}) {
66521
66397
  xAxisOptions,
66522
66398
  yAxisOptions
66523
66399
  ]);
66524
- const tableFormatCacheRef = (0, import_react62.useRef)(/* @__PURE__ */ new Map());
66525
- const tableFormatMerge = (0, import_react62.useMemo)(
66400
+ const tableFormatCacheRef = (0, import_react61.useRef)(/* @__PURE__ */ new Map());
66401
+ const tableFormatMerge = (0, import_react61.useMemo)(
66526
66402
  () => mergeDisplayAndSourceForTableFormats({
66527
66403
  effectiveReportBuilderTableNames,
66528
66404
  scopedSchemaColumns,
@@ -66536,7 +66412,7 @@ function useReport(reportIdArg, options = {}) {
66536
66412
  sourceReport
66537
66413
  ]
66538
66414
  );
66539
- const table = (0, import_react62.useMemo)(() => {
66415
+ const table = (0, import_react61.useMemo)(() => {
66540
66416
  const baseWindowRows = Array.isArray(sourceReport?.rows) ? sourceReport.rows : [];
66541
66417
  const rawRows = !paginationActive ? baseWindowRows : tablePageRows ?? baseWindowRows.slice(paginationRangeStart, paginationRangeEnd);
66542
66418
  const { columns: mergedFromReport } = mergeDisplayAndSourceForTableFormats({
@@ -66665,7 +66541,7 @@ function useReport(reportIdArg, options = {}) {
66665
66541
  const {
66666
66542
  columnsOptions: tableFormattingColumnOptions,
66667
66543
  hasTableDrivenColumnOrder
66668
- } = (0, import_react62.useMemo)(() => {
66544
+ } = (0, import_react61.useMemo)(() => {
66669
66545
  if (isPivotTableChart && chart?.columns?.length) {
66670
66546
  const aggregationSlotColumns = buildPivotColumnPivotTableFormattingColumns(chart);
66671
66547
  const pivotTableColumns = aggregationSlotColumns ? aggregationSlotColumns.tableColumns : chart.columns.map((c) => ({
@@ -66699,7 +66575,7 @@ function useReport(reportIdArg, options = {}) {
66699
66575
  schemaColumnOptions,
66700
66576
  table.columns
66701
66577
  ]);
66702
- const availableFields = (0, import_react62.useMemo)(
66578
+ const availableFields = (0, import_react61.useMemo)(
66703
66579
  () => tableColumnPickerPoolOptions.map((option) => ({
66704
66580
  id: option.value,
66705
66581
  label: option.label,
@@ -66707,24 +66583,24 @@ function useReport(reportIdArg, options = {}) {
66707
66583
  })),
66708
66584
  [tableColumnPickerPoolOptions]
66709
66585
  );
66710
- const axisSelectFormatLabels = (0, import_react62.useMemo)(
66586
+ const axisSelectFormatLabels = (0, import_react61.useMemo)(
66711
66587
  () => AXIS_FORMAT_OPTIONS.map((option) => option.label),
66712
66588
  []
66713
66589
  );
66714
- const xAxisFormatOptionLabels = (0, import_react62.useMemo)(() => {
66590
+ const xAxisFormatOptionLabels = (0, import_react61.useMemo)(() => {
66715
66591
  if (isPivotTableDateBucketRowAxis(chartAxesBaseChart, resolvedXAxisField)) {
66716
66592
  return ["date", ...axisSelectFormatLabels];
66717
66593
  }
66718
66594
  return axisSelectFormatLabels;
66719
66595
  }, [chartAxesBaseChart, resolvedXAxisField, axisSelectFormatLabels]);
66720
- const tableDerivedColumnOrder = (0, import_react62.useMemo)(() => {
66596
+ const tableDerivedColumnOrder = (0, import_react61.useMemo)(() => {
66721
66597
  return tableFormattingColumnOptions.map((option) => option.value);
66722
66598
  }, [tableFormattingColumnOptions]);
66723
- const tableDerivedColumnOrderSignature = (0, import_react62.useMemo)(
66599
+ const tableDerivedColumnOrderSignature = (0, import_react61.useMemo)(
66724
66600
  () => tableDerivedColumnOrder.join("|"),
66725
66601
  [tableDerivedColumnOrder]
66726
66602
  );
66727
- const activeTableColumnIds = (0, import_react62.useMemo)(() => {
66603
+ const activeTableColumnIds = (0, import_react61.useMemo)(() => {
66728
66604
  if (isPivotTableChart && chart?.columns?.length) {
66729
66605
  const aggregationSlotColumns = buildPivotColumnPivotTableFormattingColumns(chart);
66730
66606
  if (aggregationSlotColumns) {
@@ -66763,7 +66639,7 @@ function useReport(reportIdArg, options = {}) {
66763
66639
  tableDerivedColumnOrder,
66764
66640
  tableFormattingColumnOptions
66765
66641
  ]);
66766
- const columnOptionById = (0, import_react62.useMemo)(() => {
66642
+ const columnOptionById = (0, import_react61.useMemo)(() => {
66767
66643
  const map = /* @__PURE__ */ new Map();
66768
66644
  for (const option of tableColumnPickerPoolOptions) {
66769
66645
  map.set(option.value, option);
@@ -66775,7 +66651,7 @@ function useReport(reportIdArg, options = {}) {
66775
66651
  }
66776
66652
  return map;
66777
66653
  }, [tableColumnPickerPoolOptions, tableFormattingColumnOptions]);
66778
- const displayColumnById = (0, import_react62.useMemo)(() => {
66654
+ const displayColumnById = (0, import_react61.useMemo)(() => {
66779
66655
  const map = /* @__PURE__ */ new Map();
66780
66656
  for (const column of displayColumns) {
66781
66657
  const field = String(column.field ?? "").trim();
@@ -66786,7 +66662,7 @@ function useReport(reportIdArg, options = {}) {
66786
66662
  }
66787
66663
  return map;
66788
66664
  }, [displayColumns]);
66789
- const tableColumnSettingsById = (0, import_react62.useMemo)(() => {
66665
+ const tableColumnSettingsById = (0, import_react61.useMemo)(() => {
66790
66666
  const map = /* @__PURE__ */ new Map();
66791
66667
  const effectiveById = tableFormatMerge.formatByColumnOptionId;
66792
66668
  const chartColById = /* @__PURE__ */ new Map();
@@ -66904,13 +66780,13 @@ function useReport(reportIdArg, options = {}) {
66904
66780
  sourceReport?.columns,
66905
66781
  tableFormatMerge
66906
66782
  ]);
66907
- const tableColumnSettingsCoalesceRef = (0, import_react62.useRef)(
66783
+ const tableColumnSettingsCoalesceRef = (0, import_react61.useRef)(
66908
66784
  /* @__PURE__ */ new Map()
66909
66785
  );
66910
- (0, import_react62.useLayoutEffect)(() => {
66786
+ (0, import_react61.useLayoutEffect)(() => {
66911
66787
  tableColumnSettingsCoalesceRef.current = new Map(tableColumnSettingsById);
66912
66788
  }, [tableColumnSettingsById]);
66913
- const tableColumnItems = (0, import_react62.useMemo)(() => {
66789
+ const tableColumnItems = (0, import_react61.useMemo)(() => {
66914
66790
  const pivotRowFieldForFormat = String(chart?.pivot?.rowField ?? "").trim();
66915
66791
  const pivotRowFieldType = String(chart?.pivot?.rowFieldType ?? "").trim();
66916
66792
  const items = activeTableColumnIds.map((columnId) => {
@@ -66946,19 +66822,18 @@ function useReport(reportIdArg, options = {}) {
66946
66822
  isPivotTableChart,
66947
66823
  tableColumnSettingsById
66948
66824
  ]);
66949
- const tableColumnById = (0, import_react62.useMemo)(() => {
66825
+ const tableColumnById = (0, import_react61.useMemo)(() => {
66950
66826
  return new Map(tableColumnItems.map((item) => [item.id, item]));
66951
66827
  }, [tableColumnItems]);
66952
- const tableColumnList = (0, import_react62.useMemo)(() => {
66828
+ const tableColumnValues = (0, import_react61.useMemo)(() => {
66953
66829
  const pivotRowFieldForFormat = String(chart?.pivot?.rowField ?? "").trim();
66954
66830
  const pivotRowFieldType = String(chart?.pivot?.rowFieldType ?? "").trim();
66955
66831
  return tableColumnItems.map((item) => {
66956
66832
  const coerced = coerceTableColumnFormatToAxisValue(item.format);
66957
66833
  const usePivotDateOptions = isPivotTableChart && item.field === pivotRowFieldForFormat && isDateType(pivotRowFieldType) && coerced === "string";
66958
66834
  return {
66959
- id: item.id,
66835
+ value: item.id,
66960
66836
  label: item.label,
66961
- visible: true,
66962
66837
  format: item.formatLabel,
66963
66838
  ...usePivotDateOptions ? { formatOptions: [...PIVOT_DATE_BUCKET_FORMAT_OPTIONS] } : {}
66964
66839
  };
@@ -67121,22 +66996,32 @@ function useReport(reportIdArg, options = {}) {
67121
66996
  columns: buildSetReportColumnsFromIds(nextColumnIds, nextSettingsById)
67122
66997
  };
67123
66998
  };
67124
- let setReport;
66999
+ let applyReportChange;
67000
+ const setReport = (nextState) => {
67001
+ const { columns: nextColumns, ...rest } = nextState;
67002
+ const nextSettingsById = nextColumns === void 0 ? tableColumnSettingsById : new Map(
67003
+ nextColumns.map((column) => [
67004
+ column.value,
67005
+ { label: column.label, format: column.format }
67006
+ ])
67007
+ );
67008
+ applyReportChange({
67009
+ ...rest,
67010
+ ...nextColumns !== void 0 ? {
67011
+ columns: buildSetReportColumnsFromIds(
67012
+ nextColumns.map((column) => column.value),
67013
+ nextSettingsById
67014
+ )
67015
+ } : {}
67016
+ });
67017
+ };
67125
67018
  const commitTableColumns = (nextColumnIds, settingsById) => {
67126
- setReport({
67019
+ applyReportChange({
67127
67020
  columns: buildSetReportColumnsFromIds(nextColumnIds, settingsById)
67128
67021
  });
67129
67022
  };
67130
- setReport = (nextState) => {
67131
- let effectiveNextState = nextState;
67132
- if (isSetReportTableColumnSidebarPatch(nextState.columns)) {
67133
- const expanded = buildColumnSidebarSetReportInput(
67134
- nextState.columns.patch
67135
- );
67136
- if (!expanded) return;
67137
- const { columns: _omitSidebarColumnPatch, ...rest } = nextState;
67138
- effectiveNextState = { ...rest, ...expanded };
67139
- }
67023
+ applyReportChange = (nextState) => {
67024
+ const effectiveNextState = nextState;
67140
67025
  if (effectiveNextState.showLegend !== void 0) {
67141
67026
  setChartVisibilityOverrides((previous) => ({
67142
67027
  ...previous,
@@ -67209,15 +67094,18 @@ function useReport(reportIdArg, options = {}) {
67209
67094
  });
67210
67095
  }
67211
67096
  const isPivotSortUpdate = effectiveNextState.sort !== void 0 && Boolean(nextPivot);
67212
- 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;
67213
- const isAppendingEmptyAggregationPlaceholder = indexedAggregationUpdate !== null && indexedAggregationUpdate.index === aggregationState.length && String(indexedAggregationUpdate.value ?? "").trim().length === 0;
67214
- const touchesPivotState = effectiveNextState.groupRowsBy !== void 0 || effectiveNextState.groupColumnsBy !== void 0 || effectiveNextState.aggregations !== void 0 && !isAppendingEmptyAggregationPlaceholder || isPivotSortUpdate || effectiveNextState.limit !== void 0;
67097
+ const isAppendingEmptyAggregationPlaceholder = Array.isArray(effectiveNextState.aggregations) && effectiveNextState.aggregations.length === aggregationValues.length + 1 && effectiveNextState.aggregations.slice(0, aggregationValues.length).every(
67098
+ (value, index) => String(value ?? "") === aggregationValues[index]
67099
+ ) && String(
67100
+ effectiveNextState.aggregations[aggregationValues.length] ?? ""
67101
+ ).trim().length === 0;
67102
+ const touchesPivotState = effectiveNextState.groupRowsBy !== void 0 || effectiveNextState.groupColumnsBy !== void 0 || effectiveNextState.dateBucket !== void 0 || effectiveNextState.aggregations !== void 0 && !isAppendingEmptyAggregationPlaceholder || isPivotSortUpdate || effectiveNextState.limit !== void 0;
67215
67103
  const isDatasourceUpdate = effectiveNextState.datasources !== void 0;
67216
67104
  const hasRowGroupSelection = typeof effectiveNextState.groupRowsBy === "string" && effectiveNextState.groupRowsBy.trim().length > 0;
67217
67105
  const hasColumnGroupSelection = typeof effectiveNextState.groupColumnsBy === "string" && effectiveNextState.groupColumnsBy.trim().length > 0;
67218
- const hasAggregationSelection = effectiveNextState.aggregations !== void 0 && (typeof effectiveNextState.aggregations === "string" ? effectiveNextState.aggregations.trim().length > 0 : Array.isArray(effectiveNextState.aggregations) ? effectiveNextState.aggregations.some(
67219
- (aggregation) => Boolean(aggregation?.aggregationType) && Boolean(String(aggregation?.valueField ?? "").trim())
67220
- ) : String(effectiveNextState.aggregations.value ?? "").trim().length > 0);
67106
+ const hasAggregationSelection = effectiveNextState.aggregations !== void 0 && (typeof effectiveNextState.aggregations === "string" ? effectiveNextState.aggregations.trim().length > 0 : effectiveNextState.aggregations.some(
67107
+ (aggregation) => typeof aggregation === "string" ? aggregation.trim().length > 0 : Boolean(aggregation?.aggregationType) && Boolean(String(aggregation?.valueField ?? "").trim())
67108
+ ));
67221
67109
  const isClearingRowGrouping = effectiveNextState.groupRowsBy !== void 0 && String(effectiveNextState.groupRowsBy ?? "").trim().length === 0;
67222
67110
  const queuePromoteColumnToRow = isClearingRowGrouping && !sourceReport;
67223
67111
  const shouldRefreshExpandedTableData = useInMemoryEngines && (hasRowGroupSelection || hasColumnGroupSelection || hasAggregationSelection) || !useInMemoryEngines && !nextPivot && effectiveNextState.sort !== void 0;
@@ -67290,7 +67178,7 @@ function useReport(reportIdArg, options = {}) {
67290
67178
  }
67291
67179
  }
67292
67180
  }
67293
- if (effectiveNextState.columns !== void 0 && !isSetReportTableColumnSidebarPatch(effectiveNextState.columns)) {
67181
+ if (effectiveNextState.columns !== void 0) {
67294
67182
  const normalizedDisplayColumns = normalizeColumnsInput(
67295
67183
  effectiveNextState.columns,
67296
67184
  columnIdentifierLookup
@@ -67377,6 +67265,10 @@ function useReport(reportIdArg, options = {}) {
67377
67265
  groupColumnsBySetViaSetReportRef.current = true;
67378
67266
  next.groupColumnsBy = effectiveNextState.groupColumnsBy || void 0;
67379
67267
  }
67268
+ if (effectiveNextState.dateBucket !== void 0) {
67269
+ dateBucketSetViaSetReportRef.current = true;
67270
+ next.dateBucket = effectiveNextState.dateBucket || void 0;
67271
+ }
67380
67272
  if (effectiveNextState.aggregations !== void 0) {
67381
67273
  aggregationStateSetViaSetReportRef.current = true;
67382
67274
  next.aggregationTablesByIndex = [...next.aggregationTablesByIndex];
@@ -67391,54 +67283,7 @@ function useReport(reportIdArg, options = {}) {
67391
67283
  ],
67392
67284
  schemaForeignKeyMap
67393
67285
  ).map((table2) => table2.name).filter((name2) => Boolean(name2));
67394
- if (typeof effectiveNextState.aggregations === "object" && !Array.isArray(effectiveNextState.aggregations) && "index" in effectiveNextState.aggregations && "value" in effectiveNextState.aggregations) {
67395
- const { index, value } = effectiveNextState.aggregations;
67396
- if (index >= 0 && index <= next.aggregationState.length) {
67397
- const rawValue = String(value ?? "").trim();
67398
- next.aggregationState = [...next.aggregationState];
67399
- if (!rawValue) {
67400
- if (index === next.aggregationState.length) {
67401
- next.aggregationState.push({ valueField: "" });
67402
- next.aggregationTablesByIndex.push(void 0);
67403
- } else if (index < next.aggregationState.length) {
67404
- next.aggregationState.splice(index, 1);
67405
- next.aggregationTablesByIndex.splice(index, 1);
67406
- }
67407
- } else {
67408
- const [aggregationTypeRaw] = rawValue.split(":");
67409
- const aggregationType = aggregationTypeRaw;
67410
- const { field: target, table: table2 } = resolveAggregationSelection(
67411
- rawValue,
67412
- aggregationOptionTableLookup,
67413
- preferredTables
67414
- );
67415
- const normalizedSelection = normalizeAggregationSelection(
67416
- aggregationType,
67417
- target,
67418
- table2,
67419
- preferredTables
67420
- );
67421
- const existing = next.aggregationState[index];
67422
- const preservedValueField2 = aggregationType !== "percentage" && existing?.valueField2 ? { valueField2: existing.valueField2 } : {};
67423
- const nextAggregation = {
67424
- ...preservedValueField2,
67425
- aggregationType,
67426
- ...normalizedSelection.valueField ? { valueField: normalizedSelection.valueField } : {},
67427
- ...normalizedSelection.valueField2 ? { valueField2: normalizedSelection.valueField2 } : {},
67428
- ...normalizedSelection.table ? { valueFieldTable: normalizedSelection.table } : {}
67429
- };
67430
- if (index === next.aggregationState.length) {
67431
- next.aggregationState.push(nextAggregation);
67432
- next.aggregationTablesByIndex.push(
67433
- normalizedSelection.table || void 0
67434
- );
67435
- } else {
67436
- next.aggregationState[index] = nextAggregation;
67437
- next.aggregationTablesByIndex[index] = normalizedSelection.table || void 0;
67438
- }
67439
- }
67440
- }
67441
- } else if (typeof effectiveNextState.aggregations === "string") {
67286
+ if (typeof effectiveNextState.aggregations === "string") {
67442
67287
  const rawValue = effectiveNextState.aggregations.trim();
67443
67288
  if (!rawValue) {
67444
67289
  next.aggregationState = [];
@@ -67470,15 +67315,49 @@ function useReport(reportIdArg, options = {}) {
67470
67315
  ];
67471
67316
  }
67472
67317
  } else {
67473
- next.aggregationState = effectiveNextState.aggregations;
67474
- next.aggregationTablesByIndex = effectiveNextState.aggregations.map(
67475
- (aggregation) => String(aggregation.valueFieldTable ?? "").trim() || resolveFieldTable({
67476
- report: sourceReport,
67477
- field: aggregation.valueField,
67478
- schemaTables: schemaForReportBuilderState,
67479
- preferredTables
67480
- }) || void 0
67318
+ const decoded = effectiveNextState.aggregations.map(
67319
+ (aggregation) => {
67320
+ if (typeof aggregation !== "string") {
67321
+ return {
67322
+ aggregation,
67323
+ table: String(aggregation.valueFieldTable ?? "").trim() || resolveFieldTable({
67324
+ report: sourceReport,
67325
+ field: aggregation.valueField,
67326
+ schemaTables: schemaForReportBuilderState,
67327
+ preferredTables
67328
+ }) || void 0
67329
+ };
67330
+ }
67331
+ const rawValue = aggregation.trim();
67332
+ if (!rawValue) {
67333
+ return { aggregation: { valueField: "" }, table: void 0 };
67334
+ }
67335
+ const [aggregationTypeRaw] = rawValue.split(":");
67336
+ const aggregationType = aggregationTypeRaw;
67337
+ const { field: target, table: table2 } = resolveAggregationSelection(
67338
+ rawValue,
67339
+ aggregationOptionTableLookup,
67340
+ preferredTables
67341
+ );
67342
+ const normalizedSelection = normalizeAggregationSelection(
67343
+ aggregationType,
67344
+ target,
67345
+ table2,
67346
+ preferredTables
67347
+ );
67348
+ return {
67349
+ aggregation: {
67350
+ aggregationType,
67351
+ ...normalizedSelection.valueField ? { valueField: normalizedSelection.valueField } : {},
67352
+ ...normalizedSelection.valueField2 ? { valueField2: normalizedSelection.valueField2 } : {},
67353
+ ...normalizedSelection.table ? { valueFieldTable: normalizedSelection.table } : {}
67354
+ },
67355
+ table: normalizedSelection.table || void 0
67356
+ };
67357
+ }
67481
67358
  );
67359
+ next.aggregationState = decoded.map((entry) => entry.aggregation);
67360
+ next.aggregationTablesByIndex = decoded.map((entry) => entry.table);
67482
67361
  }
67483
67362
  }
67484
67363
  if (effectiveNextState.sort !== void 0) {
@@ -67593,29 +67472,9 @@ function useReport(reportIdArg, options = {}) {
67593
67472
  }
67594
67473
  });
67595
67474
  };
67596
- const tableColumns = {
67597
- items: tableColumnItems,
67598
- optionById: columnOptionById,
67599
- byId: tableColumnById,
67600
- columnList: tableColumnList,
67601
- getSetReportColumns: (ids) => {
67602
- const out = [];
67603
- for (const rawId of ids) {
67604
- const id = String(rawId ?? "").trim();
67605
- if (!id) continue;
67606
- const option = columnOptionById.get(id);
67607
- if (!option) continue;
67608
- const item = tableColumnById.get(id);
67609
- const customLabel = String(item?.customLabel ?? "").trim();
67610
- const format9 = String(item?.format ?? "").trim();
67611
- out.push({
67612
- field: option.field,
67613
- ...option.tableName ? { table: option.tableName } : {},
67614
- ...customLabel ? { label: customLabel } : {},
67615
- ...format9 ? { format: format9 } : {}
67616
- });
67617
- }
67618
- return out;
67475
+ const columnActions = {
67476
+ replace: (nextColumns) => {
67477
+ applyReportChange({ columns: nextColumns });
67619
67478
  },
67620
67479
  reorder: (oldIndex, newIndex) => {
67621
67480
  if (loading || isPivotTableChart) return;
@@ -67679,21 +67538,15 @@ function useReport(reportIdArg, options = {}) {
67679
67538
  setTableColumnsEditedSignature(tableDerivedColumnOrderSignature);
67680
67539
  commitTableColumns(nextColumnIds, tableColumnSettingsById);
67681
67540
  },
67682
- getColumnSidebarSetReportInput: (id, updates) => {
67683
- const normalizedId = String(id ?? "").trim();
67684
- if (!normalizedId) return null;
67685
- return {
67686
- columns: { patch: { id: normalizedId, ...updates } }
67687
- };
67688
- },
67689
67541
  update: (id, updates) => {
67690
67542
  const normalizedId = String(id ?? "").trim();
67691
67543
  if (!normalizedId) return;
67692
- setReport({
67693
- columns: { patch: { id: normalizedId, ...updates } }
67544
+ const expanded = buildColumnSidebarSetReportInput({
67545
+ id: normalizedId,
67546
+ ...updates
67694
67547
  });
67695
- },
67696
- structureEditsLocked: isPivotTableChart
67548
+ if (expanded) applyReportChange(expanded);
67549
+ }
67697
67550
  };
67698
67551
  const setFilters = (nextFilters) => {
67699
67552
  const preparedForStack = prepareQueryBuilderFiltersForSet(
@@ -67751,13 +67604,7 @@ function useReport(reportIdArg, options = {}) {
67751
67604
  }
67752
67605
  }
67753
67606
  };
67754
- const filterDraft = useReportFilterDraft({
67755
- reportId: effectiveReportId,
67756
- committedFilters: filtersForQueryBuilder,
67757
- queryBuilderProps: filterQueryBuilderProps,
67758
- setFilters
67759
- });
67760
- const saveChanges = (0, import_react62.useCallback)(async () => {
67607
+ const saveChanges = (0, import_react61.useCallback)(async () => {
67761
67608
  if (!client) return;
67762
67609
  if (!String(dashboardNameForNewReport ?? "").trim()) return;
67763
67610
  if (!sourceReport) return;
@@ -67835,17 +67682,23 @@ function useReport(reportIdArg, options = {}) {
67835
67682
  groupRowsByOptions,
67836
67683
  groupColumnsBy,
67837
67684
  groupColumnsByOptions,
67838
- aggregations: aggregationState,
67685
+ dateBucket,
67686
+ dateBucketOptions: PIVOT_DATE_BUCKET_OPTIONS,
67687
+ /** Encoded selection per aggregation slot (`'sum:transactions::amount'`, `'count:transactions'`, `''` = placeholder). Update via `setReport({ aggregations: nextStringArray })`. */
67688
+ aggregations: aggregationValues,
67689
+ /** Flat aggregation pick list shared by all slots; always contains every non-empty `aggregations` entry. */
67839
67690
  aggregationOptions,
67840
67691
  aggregationDescriptionOptions: cleanedAggregations,
67841
67692
  sort: cleanedSort,
67842
67693
  sortOptions,
67843
67694
  chartType,
67844
67695
  chartTypeOptions: chartTypes,
67845
- /** Encoded field keys for the current column selection (for `setReport({ columns })`, etc.). */
67846
- columnIds: columns,
67847
- /** Selected columns + `reorder` / `toggle` / `update` / `remove`. */
67848
- columns: tableColumns,
67696
+ /** Selected tabular columns in display order. */
67697
+ columns: tableColumnValues,
67698
+ /** Pivot table columns only allow label and format changes. */
67699
+ columnStructureEditsLocked: isPivotTableChart,
67700
+ /** Optional rich operations; simple selection updates use `setReport({ columns })`. */
67701
+ columnActions,
67849
67702
  /** Schema columns for current datasources — pool for the table column picker. */
67850
67703
  columnOptions: tableColumnPickerPoolOptions,
67851
67704
  xAxis: chartAxes.xAxis,
@@ -67872,13 +67725,6 @@ function useReport(reportIdArg, options = {}) {
67872
67725
  hasTableDrivenColumnOrder,
67873
67726
  filters: filtersForQueryBuilder,
67874
67727
  filterQueryBuilderProps,
67875
- /**
67876
- * Draft → Apply lifecycle for react-querybuilder (flat keys):
67877
- * `<QueryBuilder key={filterDraftKey} {...filterDraftQueryBuilderProps} />`
67878
- * plus `isFilterDraftDirty` / `isFilterDraftEmpty` /
67879
- * `commitFilterDraft` / `resetFilterDraft` / `seedFilterDraft`.
67880
- */
67881
- ...filterDraft,
67882
67728
  /** True while `report-builder-unique-values` runs for filter value options (not chart/table load). */
67883
67729
  filterUniqueValuesLoading,
67884
67730
  limit,
@@ -67886,7 +67732,6 @@ function useReport(reportIdArg, options = {}) {
67886
67732
  chartTypes,
67887
67733
  columnsOptions: tableColumnPickerPoolOptions,
67888
67734
  tableColumnOptions: tableColumnPickerPoolOptions,
67889
- tableColumns,
67890
67735
  setReport,
67891
67736
  saveChanges,
67892
67737
  setFilters,
@@ -67904,7 +67749,7 @@ function ChatChartCard({
67904
67749
  ButtonComponent = MemoizedButton
67905
67750
  }) {
67906
67751
  const {
67907
- columnIds,
67752
+ columns,
67908
67753
  columnOptions,
67909
67754
  groupRowsBy,
67910
67755
  groupRowsByOptions,
@@ -67918,20 +67763,10 @@ function ChatChartCard({
67918
67763
  loading,
67919
67764
  setReport
67920
67765
  } = useReport(reportId);
67921
- const columnSelectOptions = (0, import_react63.useMemo)(() => {
67922
- return (columnOptions ?? []).map((option) => {
67923
- const value = String(option?.value ?? "").trim();
67924
- if (!value) return null;
67925
- const tableName = String(option?.tableName ?? "").trim();
67926
- const fieldName = String(option?.field ?? "").trim() || String(option?.label ?? "").trim() || value;
67927
- return {
67928
- value,
67929
- label: tableName ? `${tableName}.${fieldName}` : fieldName
67930
- };
67931
- }).filter(
67932
- (option) => Boolean(option)
67933
- );
67934
- }, [columnOptions]);
67766
+ const selectedColumnValues = (0, import_react62.useMemo)(
67767
+ () => columns.map((column) => column.value),
67768
+ [columns]
67769
+ );
67935
67770
  return /* @__PURE__ */ (0, import_jsx_runtime87.jsxs)(
67936
67771
  "div",
67937
67772
  {
@@ -67967,7 +67802,7 @@ function ChatChartCard({
67967
67802
  padding: 16
67968
67803
  },
67969
67804
  children: [
67970
- JSON.stringify(columnIds, null, 2),
67805
+ JSON.stringify(columns, null, 2),
67971
67806
  /* @__PURE__ */ (0, import_jsx_runtime87.jsxs)(
67972
67807
  "label",
67973
67808
  {
@@ -67984,13 +67819,24 @@ function ChatChartCard({
67984
67819
  "select",
67985
67820
  {
67986
67821
  multiple: true,
67987
- size: Math.min(10, Math.max(4, columnSelectOptions.length || 4)),
67988
- value: columnIds,
67822
+ size: Math.min(10, Math.max(4, columnOptions.length || 4)),
67823
+ value: selectedColumnValues,
67989
67824
  onChange: (event) => {
67990
- const nextColumns = Array.from(event.target.selectedOptions).map(
67991
- (option) => option.value
67825
+ const selectedByValue = new Map(
67826
+ columns.map((column) => [column.value, column])
67992
67827
  );
67993
- setReport({ columns: nextColumns });
67828
+ const optionByValue = new Map(
67829
+ columnOptions.map((option) => [option.value, option])
67830
+ );
67831
+ setReport({
67832
+ columns: Array.from(event.target.selectedOptions).map(
67833
+ (selectedOption) => selectedByValue.get(selectedOption.value) ?? {
67834
+ value: selectedOption.value,
67835
+ label: optionByValue.get(selectedOption.value)?.label ?? selectedOption.value,
67836
+ format: ""
67837
+ }
67838
+ )
67839
+ });
67994
67840
  },
67995
67841
  style: {
67996
67842
  width: 200,
@@ -68000,7 +67846,7 @@ function ChatChartCard({
68000
67846
  padding: 8,
68001
67847
  background: "#fff"
68002
67848
  },
68003
- children: columnSelectOptions.map((option) => /* @__PURE__ */ (0, import_jsx_runtime87.jsx)("option", { value: option.value, children: option.label }, option.value))
67849
+ children: columnOptions.map((option) => /* @__PURE__ */ (0, import_jsx_runtime87.jsx)("option", { value: option.value, children: option.label }, option.value))
68004
67850
  }
68005
67851
  )
68006
67852
  ]
@@ -68026,28 +67872,27 @@ function ChatChartCard({
68026
67872
  onChange: (e) => setReport({ groupColumnsBy: e.target.value ?? "" })
68027
67873
  }
68028
67874
  ),
68029
- aggregationOptions.map((row, index) => /* @__PURE__ */ (0, import_jsx_runtime87.jsx)(
67875
+ aggregations.map((value, index) => /* @__PURE__ */ (0, import_jsx_runtime87.jsx)(
68030
67876
  SelectComponent,
68031
67877
  {
68032
- value: row.value,
68033
- label: row.label,
67878
+ value,
67879
+ label: `Aggregation ${index + 1}`,
68034
67880
  width: 200,
68035
- options: row.options,
67881
+ options: aggregationOptions,
68036
67882
  onChange: (e) => setReport({
68037
- aggregations: { index, value: e.target.value ?? "" }
67883
+ aggregations: aggregations.map(
67884
+ (aggregation, i) => i === index ? e.target.value ?? "" : aggregation
67885
+ )
68038
67886
  })
68039
67887
  },
68040
- row.key
67888
+ `aggregation-${index}`
68041
67889
  )),
68042
67890
  /* @__PURE__ */ (0, import_jsx_runtime87.jsx)(
68043
67891
  ButtonComponent,
68044
67892
  {
68045
67893
  label: "Add aggregation",
68046
67894
  onClick: () => setReport({
68047
- aggregations: {
68048
- index: aggregations.length,
68049
- value: "count transactions"
68050
- }
67895
+ aggregations: [...aggregations, "count:transactions"]
68051
67896
  })
68052
67897
  }
68053
67898
  ),
@@ -68185,7 +68030,7 @@ function ToolCallBlock({ toolCall }) {
68185
68030
  );
68186
68031
  }
68187
68032
  function ToolCallResult({ content }) {
68188
- const [expanded, setExpanded] = (0, import_react64.useState)(false);
68033
+ const [expanded, setExpanded] = (0, import_react63.useState)(false);
68189
68034
  if (!content) return null;
68190
68035
  const isLong = content.length > 300;
68191
68036
  const displayed = isLong && !expanded ? content.slice(0, 300) + "..." : content;
@@ -68237,18 +68082,18 @@ function Chat({
68237
68082
  agentEndpoint,
68238
68083
  suggestions
68239
68084
  }) {
68240
- const [client] = (0, import_react64.useContext)(ClientContext);
68241
- const { getToken } = (0, import_react64.useContext)(FetchContext);
68242
- const { tenants } = (0, import_react64.useContext)(TenantContext);
68243
- const [messages, setMessages] = (0, import_react64.useState)([]);
68244
- const [input, setInput] = (0, import_react64.useState)("");
68245
- const [inputError, setInputError] = (0, import_react64.useState)("");
68246
- const [isLoading, setIsLoading] = (0, import_react64.useState)(false);
68247
- const [model, setModel] = (0, import_react64.useState)("gemini-3-flash-preview");
68248
- const containerRef = (0, import_react64.useRef)(null);
68249
- const textareaRef = (0, import_react64.useRef)(null);
68250
- const abortControllerRef = (0, import_react64.useRef)(null);
68251
- (0, import_react64.useEffect)(() => {
68085
+ const [client] = (0, import_react63.useContext)(ClientContext);
68086
+ const { getToken } = (0, import_react63.useContext)(FetchContext);
68087
+ const { tenants } = (0, import_react63.useContext)(TenantContext);
68088
+ const [messages, setMessages] = (0, import_react63.useState)([]);
68089
+ const [input, setInput] = (0, import_react63.useState)("");
68090
+ const [inputError, setInputError] = (0, import_react63.useState)("");
68091
+ const [isLoading, setIsLoading] = (0, import_react63.useState)(false);
68092
+ const [model, setModel] = (0, import_react63.useState)("gemini-3-flash-preview");
68093
+ const containerRef = (0, import_react63.useRef)(null);
68094
+ const textareaRef = (0, import_react63.useRef)(null);
68095
+ const abortControllerRef = (0, import_react63.useRef)(null);
68096
+ (0, import_react63.useEffect)(() => {
68252
68097
  if (!containerRef.current) {
68253
68098
  return;
68254
68099
  }
@@ -68681,6 +68526,150 @@ function Chat({
68681
68526
  );
68682
68527
  }
68683
68528
 
68529
+ // src/hooks/useReportFilterDraft.ts
68530
+ var import_react64 = require("react");
68531
+ var normalizeOperatorKey = (operator) => String(operator ?? "").trim().toLowerCase().replace(/[_\s]+/g, "");
68532
+ var defaultFilterRuleValueForOperator = (operator) => {
68533
+ const key = normalizeOperatorKey(operator);
68534
+ if (key === "in" || key === "notin") {
68535
+ return [];
68536
+ }
68537
+ return "";
68538
+ };
68539
+ var EMPTY_COMMITTED_FILTERS = {
68540
+ combinator: "and",
68541
+ rules: []
68542
+ };
68543
+ var hashString2 = (input) => {
68544
+ let hash = 2166136261;
68545
+ for (let i = 0; i < input.length; i++) {
68546
+ hash ^= input.charCodeAt(i);
68547
+ hash = Math.imul(hash, 16777619);
68548
+ }
68549
+ return String(hash >>> 0);
68550
+ };
68551
+ var fieldCatalogSignature = (fields) => {
68552
+ const names = fields.map((field) => String(field.name ?? "").trim()).filter(Boolean).sort();
68553
+ return `${names.length}:${hashString2(names.join("\0"))}`;
68554
+ };
68555
+ var committedFiltersSignature = (committed) => {
68556
+ try {
68557
+ return hashString2(
68558
+ JSON.stringify(stripQueryBuilderTransientFields(committed))
68559
+ );
68560
+ } catch {
68561
+ return "unserializable";
68562
+ }
68563
+ };
68564
+ function useReportFilterDraft(args) {
68565
+ const { reportId, committedFilters, queryBuilderProps, setFilters } = args;
68566
+ const committed = isQueryBuilderDisplayGroup(committedFilters) ? committedFilters : EMPTY_COMMITTED_FILTERS;
68567
+ const committedRef = (0, import_react64.useRef)(committed);
68568
+ committedRef.current = committed;
68569
+ const setFiltersRef = (0, import_react64.useRef)(setFilters);
68570
+ setFiltersRef.current = setFilters;
68571
+ const lastNonEmptyFieldsRef = (0, import_react64.useRef)([]);
68572
+ const prevReportIdForFieldsRef = (0, import_react64.useRef)(reportId);
68573
+ if (prevReportIdForFieldsRef.current !== reportId) {
68574
+ prevReportIdForFieldsRef.current = reportId;
68575
+ lastNonEmptyFieldsRef.current = [];
68576
+ }
68577
+ if (queryBuilderProps.fields.length > 0) {
68578
+ lastNonEmptyFieldsRef.current = queryBuilderProps.fields;
68579
+ }
68580
+ const effectiveFields = queryBuilderProps.fields.length > 0 ? queryBuilderProps.fields : lastNonEmptyFieldsRef.current;
68581
+ const committedSignature = (0, import_react64.useMemo)(
68582
+ () => committedFiltersSignature(committed),
68583
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- `committed` normalizes null to a stable constant
68584
+ [committedFilters]
68585
+ );
68586
+ const fieldsSignature = (0, import_react64.useMemo)(
68587
+ () => fieldCatalogSignature(effectiveFields),
68588
+ [effectiveFields]
68589
+ );
68590
+ const [resetEpoch, setResetEpoch] = (0, import_react64.useState)(0);
68591
+ const [draftQuery, setDraftQuery] = (0, import_react64.useState)(committed);
68592
+ const [hasUnappliedFilterChanges, setHasUnappliedFilterChanges] = (0, import_react64.useState)(false);
68593
+ const draftResetKey = `${reportId}|${committedSignature}|${resetEpoch}`;
68594
+ const prevDraftResetKeyRef = (0, import_react64.useRef)(draftResetKey);
68595
+ if (prevDraftResetKeyRef.current !== draftResetKey) {
68596
+ prevDraftResetKeyRef.current = draftResetKey;
68597
+ setDraftQuery(committed);
68598
+ if (hasUnappliedFilterChanges) setHasUnappliedFilterChanges(false);
68599
+ }
68600
+ const filterDraftKey = `${draftResetKey}|${fieldsSignature}`;
68601
+ const handleQueryChange = (0, import_react64.useCallback)((next) => {
68602
+ if (!isQueryBuilderDisplayGroup(next)) return;
68603
+ const nextGroup = next;
68604
+ setDraftQuery(nextGroup);
68605
+ const nextDirty = areQueryBuilderFilterDraftsDirty(
68606
+ nextGroup,
68607
+ committedRef.current
68608
+ );
68609
+ setHasUnappliedFilterChanges(
68610
+ (prev) => prev === nextDirty ? prev : nextDirty
68611
+ );
68612
+ }, []);
68613
+ const applyFilterDraft = (0, import_react64.useCallback)(() => {
68614
+ setFiltersRef.current(draftQuery);
68615
+ }, [draftQuery]);
68616
+ const resetFilterDraft = (0, import_react64.useCallback)(() => {
68617
+ setDraftQuery(committedRef.current);
68618
+ setHasUnappliedFilterChanges(false);
68619
+ setResetEpoch((epoch) => epoch + 1);
68620
+ }, []);
68621
+ const getDefaultValue = (0, import_react64.useCallback)(
68622
+ (rule) => defaultFilterRuleValueForOperator(rule?.operator),
68623
+ []
68624
+ );
68625
+ const filterDraftQueryBuilderProps = (0, import_react64.useMemo)(
68626
+ () => ({
68627
+ ...queryBuilderProps,
68628
+ fields: effectiveFields,
68629
+ // Uncontrolled: react-querybuilder owns the draft; only read at mount,
68630
+ // while state keeps the next mount hydrated from the latest edits.
68631
+ defaultQuery: draftQuery,
68632
+ onQueryChange: handleQueryChange,
68633
+ addRuleToNewGroups: true,
68634
+ getDefaultValue
68635
+ }),
68636
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- filterDraftKey covers draftRef resets
68637
+ [
68638
+ queryBuilderProps,
68639
+ effectiveFields,
68640
+ draftQuery,
68641
+ handleQueryChange,
68642
+ getDefaultValue,
68643
+ filterDraftKey
68644
+ ]
68645
+ );
68646
+ return {
68647
+ filterDraftKey,
68648
+ filterDraftQueryBuilderProps,
68649
+ hasUnappliedFilterChanges,
68650
+ applyFilterDraft,
68651
+ resetFilterDraft
68652
+ };
68653
+ }
68654
+
68655
+ // src/hooks/useReportQueryBuilder.ts
68656
+ function useReportQueryBuilder(args) {
68657
+ const draft = useReportFilterDraft({
68658
+ reportId: args.reportId ?? "",
68659
+ committedFilters: args.filters,
68660
+ queryBuilderProps: args.queryBuilderProps,
68661
+ setFilters: args.onApply
68662
+ });
68663
+ return {
68664
+ key: draft.filterDraftKey,
68665
+ props: draft.filterDraftQueryBuilderProps,
68666
+ hasUnappliedChanges: draft.hasUnappliedFilterChanges,
68667
+ apply: draft.applyFilterDraft,
68668
+ discard: draft.resetFilterDraft,
68669
+ reset: draft.resetFilterDraft
68670
+ };
68671
+ }
68672
+
68684
68673
  // src/ReportDetail.tsx
68685
68674
  var import_react65 = require("react");
68686
68675
  var import_jsx_runtime89 = require("react/jsx-runtime");
@@ -69811,7 +69800,6 @@ init_constants();
69811
69800
  Table,
69812
69801
  ThemeContext,
69813
69802
  areQueryBuilderFilterDraftsDirty,
69814
- buildSeededFilterQuery,
69815
69803
  countFilterRules,
69816
69804
  defaultFilterRuleValueForOperator,
69817
69805
  downloadCSV,
@@ -69836,6 +69824,7 @@ init_constants();
69836
69824
  useQuill,
69837
69825
  useReport,
69838
69826
  useReportBuilder,
69827
+ useReportQueryBuilder,
69839
69828
  useReports,
69840
69829
  useTenants,
69841
69830
  useVirtualTables