@quillsql/react 2.16.48 → 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();
@@ -62075,9 +61921,6 @@ function getChartTypeOptions2(formData) {
62075
61921
  (elem) => !(formData.pivot && formData.pivot.columnField && (elem === "bar" || elem === "pie" || elem === "US map" || elem === "World map"))
62076
61922
  ).map((elem) => ({ label: elem, value: elem }));
62077
61923
  }
62078
- function isSetReportTableColumnSidebarPatch(columns) {
62079
- return Boolean(columns) && typeof columns === "object" && !Array.isArray(columns) && "patch" in columns && typeof columns.patch === "object" && columns.patch !== null && typeof columns.patch.id === "string";
62080
- }
62081
61924
  function processPivotState(next, options = {}) {
62082
61925
  const {
62083
61926
  nextState,
@@ -62134,7 +61977,10 @@ function processPivotState(next, options = {}) {
62134
61977
  }
62135
61978
  const valueField = String(aggregation.valueField ?? "").trim();
62136
61979
  if (!valueField) {
62137
- return { ...aggregation, aggregationType: "count" };
61980
+ return {
61981
+ ...aggregation,
61982
+ aggregationType: "count"
61983
+ };
62138
61984
  }
62139
61985
  const valueField2 = String(aggregation.valueField2 ?? "").trim();
62140
61986
  if (valueField2 && valueField2 !== valueField) {
@@ -63146,10 +62992,10 @@ function generateDraftSessionId() {
63146
62992
  }
63147
62993
  function useReport(reportIdArg, options = {}) {
63148
62994
  const propReportId = String(reportIdArg ?? "").trim();
63149
- const [createdReportId, setCreatedReportId] = (0, import_react62.useState)(null);
62995
+ const [createdReportId, setCreatedReportId] = (0, import_react61.useState)(null);
63150
62996
  const effectiveReportId = propReportId || createdReportId || "";
63151
- const { eventTracking } = (0, import_react62.useContext)(EventTrackingContext);
63152
- 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);
63153
62999
  const useInMemoryEngines = options.useInMemoryEngines ?? false;
63154
63000
  const restrictFieldOptionsToSelectedDatasources = options.restrictFieldOptionsToSelectedDatasources ?? true;
63155
63001
  const reportOverride = options.reportOverride ?? null;
@@ -63158,30 +63004,30 @@ function useReport(reportIdArg, options = {}) {
63158
63004
  options.destinationDashboardName ?? ""
63159
63005
  ).trim();
63160
63006
  const controlledPagination = options.state?.pagination;
63161
- const initialPaginationRef = (0, import_react62.useRef)({
63007
+ const initialPaginationRef = (0, import_react61.useRef)({
63162
63008
  ...getDefaultPaginationState(),
63163
63009
  ...options.initialState?.pagination ?? {}
63164
63010
  });
63165
- const [internalPagination, setInternalPagination] = (0, import_react62.useState)(
63011
+ const [internalPagination, setInternalPagination] = (0, import_react61.useState)(
63166
63012
  initialPaginationRef.current
63167
63013
  );
63168
- const [paginationInteracted, setPaginationInteracted] = (0, import_react62.useState)(
63014
+ const [paginationInteracted, setPaginationInteracted] = (0, import_react61.useState)(
63169
63015
  () => Boolean(
63170
63016
  options.state?.pagination || options.initialState?.pagination || options.onPaginationChange
63171
63017
  )
63172
63018
  );
63173
63019
  const pagination = controlledPagination ?? internalPagination;
63174
63020
  const paginationActive = paginationInteracted || Boolean(controlledPagination);
63175
- const paginationRef = (0, import_react62.useRef)(pagination);
63021
+ const paginationRef = (0, import_react61.useRef)(pagination);
63176
63022
  paginationRef.current = pagination;
63177
- const onPaginationChangeRef = (0, import_react62.useRef)(options.onPaginationChange);
63023
+ const onPaginationChangeRef = (0, import_react61.useRef)(options.onPaginationChange);
63178
63024
  onPaginationChangeRef.current = options.onPaginationChange;
63179
- const controlledPaginationRef = (0, import_react62.useRef)(Boolean(controlledPagination));
63025
+ const controlledPaginationRef = (0, import_react61.useRef)(Boolean(controlledPagination));
63180
63026
  controlledPaginationRef.current = Boolean(controlledPagination);
63181
- const autoResetPageIndexRef = (0, import_react62.useRef)(true);
63027
+ const autoResetPageIndexRef = (0, import_react61.useRef)(true);
63182
63028
  autoResetPageIndexRef.current = options.autoResetPageIndex ?? true;
63183
- const paginationPageCountRef = (0, import_react62.useRef)(-1);
63184
- const applyPaginationUpdate = (0, import_react62.useCallback)(
63029
+ const paginationPageCountRef = (0, import_react61.useRef)(-1);
63030
+ const applyPaginationUpdate = (0, import_react61.useCallback)(
63185
63031
  (updater, { activate = true } = {}) => {
63186
63032
  if (activate) {
63187
63033
  setPaginationInteracted(true);
@@ -63193,11 +63039,11 @@ function useReport(reportIdArg, options = {}) {
63193
63039
  },
63194
63040
  []
63195
63041
  );
63196
- const setPagination = (0, import_react62.useCallback)(
63042
+ const setPagination = (0, import_react61.useCallback)(
63197
63043
  (updater) => applyPaginationUpdate(updater),
63198
63044
  [applyPaginationUpdate]
63199
63045
  );
63200
- const setPageIndex = (0, import_react62.useCallback)(
63046
+ const setPageIndex = (0, import_react61.useCallback)(
63201
63047
  (updater) => applyPaginationUpdate((old) => ({
63202
63048
  ...old,
63203
63049
  pageIndex: clampPageIndex(
@@ -63207,7 +63053,7 @@ function useReport(reportIdArg, options = {}) {
63207
63053
  })),
63208
63054
  [applyPaginationUpdate]
63209
63055
  );
63210
- const setPageSize = (0, import_react62.useCallback)(
63056
+ const setPageSize = (0, import_react61.useCallback)(
63211
63057
  (updater) => applyPaginationUpdate(
63212
63058
  (old) => paginationStateAfterPageSizeChange(
63213
63059
  old,
@@ -63216,62 +63062,64 @@ function useReport(reportIdArg, options = {}) {
63216
63062
  ),
63217
63063
  [applyPaginationUpdate]
63218
63064
  );
63219
- const resetPagination = (0, import_react62.useCallback)(
63065
+ const resetPagination = (0, import_react61.useCallback)(
63220
63066
  (defaultState) => applyPaginationUpdate(
63221
63067
  defaultState ? getDefaultPaginationState() : initialPaginationRef.current
63222
63068
  ),
63223
63069
  [applyPaginationUpdate]
63224
63070
  );
63225
- const resetPageIndex = (0, import_react62.useCallback)(
63071
+ const resetPageIndex = (0, import_react61.useCallback)(
63226
63072
  (defaultState) => {
63227
63073
  const target = defaultState ? 0 : initialPaginationRef.current.pageIndex;
63228
63074
  setPageIndex(target);
63229
63075
  },
63230
63076
  [setPageIndex]
63231
63077
  );
63232
- const resetPageSize = (0, import_react62.useCallback)(
63078
+ const resetPageSize = (0, import_react61.useCallback)(
63233
63079
  (defaultState) => {
63234
63080
  const target = defaultState ? getDefaultPaginationState().pageSize : initialPaginationRef.current.pageSize;
63235
63081
  setPageSize(target);
63236
63082
  },
63237
63083
  [setPageSize]
63238
63084
  );
63239
- const nextPage = (0, import_react62.useCallback)(
63085
+ const nextPage = (0, import_react61.useCallback)(
63240
63086
  () => setPageIndex((old) => old + 1),
63241
63087
  [setPageIndex]
63242
63088
  );
63243
- const previousPage = (0, import_react62.useCallback)(
63089
+ const previousPage = (0, import_react61.useCallback)(
63244
63090
  () => setPageIndex((old) => old - 1),
63245
63091
  [setPageIndex]
63246
63092
  );
63247
- const firstPage = (0, import_react62.useCallback)(() => setPageIndex(0), [setPageIndex]);
63248
- const lastPage = (0, import_react62.useCallback)(
63093
+ const firstPage = (0, import_react61.useCallback)(() => setPageIndex(0), [setPageIndex]);
63094
+ const lastPage = (0, import_react61.useCallback)(
63249
63095
  () => setPageIndex(paginationPageCountRef.current - 1),
63250
63096
  [setPageIndex]
63251
63097
  );
63252
- const chartPivotHydratedFromSourceRef = (0, import_react62.useRef)(false);
63253
- const lastPivotHydrateCompletedSourceIdRef = (0, import_react62.useRef)(null);
63254
- const groupRowsBySetViaSetReportRef = (0, import_react62.useRef)(false);
63255
- const groupColumnsBySetViaSetReportRef = (0, import_react62.useRef)(false);
63256
- const aggregationStateSetViaSetReportRef = (0, import_react62.useRef)(false);
63257
- 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);
63258
63105
  if (prevReportIdForChartPivotHydrationRef.current !== effectiveReportId) {
63259
63106
  prevReportIdForChartPivotHydrationRef.current = effectiveReportId;
63260
63107
  chartPivotHydratedFromSourceRef.current = false;
63261
63108
  groupRowsBySetViaSetReportRef.current = false;
63262
63109
  groupColumnsBySetViaSetReportRef.current = false;
63110
+ dateBucketSetViaSetReportRef.current = false;
63263
63111
  aggregationStateSetViaSetReportRef.current = false;
63264
63112
  }
63265
- const [chartPivotHydrationEpoch, setChartPivotHydrationEpoch] = (0, import_react62.useState)(0);
63113
+ const [chartPivotHydrationEpoch, setChartPivotHydrationEpoch] = (0, import_react61.useState)(0);
63266
63114
  const [
63267
63115
  expandReportBuilderColumnsForFlatTable,
63268
63116
  setExpandReportBuilderColumnsForFlatTable
63269
- ] = (0, import_react62.useState)(false);
63270
- const prevPivotStateForColumnExpansionRef = (0, import_react62.useRef)(null);
63271
- 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)(
63272
63120
  null
63273
63121
  );
63274
- const prevSourceReportIdForPivotHydrationRef = (0, import_react62.useRef)(null);
63122
+ const prevSourceReportIdForPivotHydrationRef = (0, import_react61.useRef)(null);
63275
63123
  {
63276
63124
  const currentSourceId = sourceReport ? String(
63277
63125
  sourceReport.id ?? sourceReport._id ?? ""
@@ -63283,15 +63131,15 @@ function useReport(reportIdArg, options = {}) {
63283
63131
  lastPivotHydrateCompletedSourceIdRef.current = null;
63284
63132
  }
63285
63133
  }
63286
- const [preserveSchemaWideOptions, setPreserveSchemaWideOptions] = (0, import_react62.useState)(false);
63287
- const [initialSchemaScopedTableNames, setInitialSchemaScopedTableNames] = (0, import_react62.useState)(null);
63288
- const [tableColumnsEditedSignature, setTableColumnsEditedSignature] = (0, import_react62.useState)(null);
63289
- const [chartAxisEdits, setChartAxisEdits] = (0, import_react62.useState)({});
63290
- const [chartVisibilityOverrides, setChartVisibilityOverrides] = (0, import_react62.useState)({});
63291
- const [client] = (0, import_react62.useContext)(ClientContext);
63292
- const [schemaData] = (0, import_react62.useContext)(SchemaDataContext);
63293
- const { tenants, flags } = (0, import_react62.useContext)(TenantContext);
63294
- 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);
63295
63143
  const clientDefaultDashboardName = String(
63296
63144
  client?.defaultDashboard?.name ?? ""
63297
63145
  ).trim();
@@ -63300,7 +63148,7 @@ function useReport(reportIdArg, options = {}) {
63300
63148
  clientDefaultDashboardName,
63301
63149
  destinationDashboardName
63302
63150
  ].map((entry) => String(entry ?? "").trim()).find((entry) => entry.length > 0) ?? "";
63303
- const initialFormState = (0, import_react62.useMemo)(
63151
+ const initialFormState = (0, import_react61.useMemo)(
63304
63152
  () => ({
63305
63153
  columns: [],
63306
63154
  queryColumns: [],
@@ -63308,6 +63156,7 @@ function useReport(reportIdArg, options = {}) {
63308
63156
  queryFilters: { combinator: "and", rules: [] },
63309
63157
  groupRowsBy: void 0,
63310
63158
  groupColumnsBy: void 0,
63159
+ dateBucket: void 0,
63311
63160
  aggregationState: [],
63312
63161
  aggregationTablesByIndex: [],
63313
63162
  pivotSort: void 0,
@@ -63318,7 +63167,7 @@ function useReport(reportIdArg, options = {}) {
63318
63167
  }),
63319
63168
  []
63320
63169
  );
63321
- const [formRuntimeState, dispatchFormRuntime] = (0, import_react62.useReducer)(
63170
+ const [formRuntimeState, dispatchFormRuntime] = (0, import_react61.useReducer)(
63322
63171
  useFormReducer,
63323
63172
  initialFormState,
63324
63173
  createInitialUseFormReducerState
@@ -63337,6 +63186,7 @@ function useReport(reportIdArg, options = {}) {
63337
63186
  queryFilters,
63338
63187
  groupRowsBy,
63339
63188
  groupColumnsBy,
63189
+ dateBucket,
63340
63190
  aggregationState,
63341
63191
  aggregationTablesByIndex,
63342
63192
  pivotSort,
@@ -63346,32 +63196,32 @@ function useReport(reportIdArg, options = {}) {
63346
63196
  schemaDatasourceIds
63347
63197
  } = formState;
63348
63198
  const schemaDatasourceIdsKey = schemaDatasourceIds?.map((id) => String(id ?? "").trim()).join("\0") ?? "";
63349
- const queryColumnsBootstrapKey = (0, import_react62.useMemo)(
63199
+ const queryColumnsBootstrapKey = (0, import_react61.useMemo)(
63350
63200
  () => queryColumns.map(
63351
63201
  (c) => `${String(c.table ?? "").trim()}\0${String(c.field ?? "").trim()}`
63352
63202
  ).join("\n"),
63353
63203
  [queryColumns]
63354
63204
  );
63355
- const dashboardNameForNewReport = (0, import_react62.useMemo)(() => {
63205
+ const dashboardNameForNewReport = (0, import_react61.useMemo)(() => {
63356
63206
  return [clientDefaultDashboardName, destinationDashboardName].map((entry) => String(entry ?? "").trim()).find((entry) => entry.length > 0) ?? "";
63357
63207
  }, [clientDefaultDashboardName, destinationDashboardName]);
63358
- const filterStackRef = (0, import_react62.useRef)(filterStack);
63208
+ const filterStackRef = (0, import_react61.useRef)(filterStack);
63359
63209
  filterStackRef.current = filterStack;
63360
63210
  const resolvedGroupRowsBy = decodePivotGroupOptionValue(groupRowsBy);
63361
63211
  const resolvedGroupColumnsBy = decodePivotGroupOptionValue(groupColumnsBy);
63362
63212
  const useFormRefreshDebugEnabled = isUseFormRefreshDebugEnabled();
63363
63213
  const useFormFiltersDebugEnabled = isUseFormFiltersDebugEnabled();
63364
- (0, import_react62.useEffect)(() => {
63214
+ (0, import_react61.useEffect)(() => {
63365
63215
  if (propReportId) {
63366
63216
  setCreatedReportId(null);
63367
63217
  }
63368
63218
  }, [propReportId]);
63369
- (0, import_react62.useEffect)(() => {
63219
+ (0, import_react61.useEffect)(() => {
63370
63220
  setChartAxisEdits({});
63371
63221
  setChartVisibilityOverrides({});
63372
63222
  }, [effectiveReportId]);
63373
- const bootstrapReportTaskUsedForReportIdRef = (0, import_react62.useRef)(null);
63374
- const schemaScopeInitializedForReportIdRef = (0, import_react62.useRef)(null);
63223
+ const bootstrapReportTaskUsedForReportIdRef = (0, import_react61.useRef)(null);
63224
+ const schemaScopeInitializedForReportIdRef = (0, import_react61.useRef)(null);
63375
63225
  const initializeSchemaScopeForReport = (report) => {
63376
63226
  if (!report) return;
63377
63227
  if (schemaScopeInitializedForReportIdRef.current === effectiveReportId)
@@ -63384,26 +63234,26 @@ function useReport(reportIdArg, options = {}) {
63384
63234
  );
63385
63235
  schemaScopeInitializedForReportIdRef.current = effectiveReportId;
63386
63236
  };
63387
- const internalFilters = (0, import_react62.useMemo)(
63237
+ const internalFilters = (0, import_react61.useMemo)(
63388
63238
  () => internalFiltersFromFilterStack(filterStack),
63389
63239
  [filterStack]
63390
63240
  );
63391
- const customFilters = (0, import_react62.useMemo)(
63241
+ const customFilters = (0, import_react61.useMemo)(
63392
63242
  () => customFiltersFromFilterStack(filterStack),
63393
63243
  [filterStack]
63394
63244
  );
63395
- const reloadKey = (0, import_react62.useMemo)(() => 0, []);
63396
- const schemaForReportBuilderState = (0, import_react62.useMemo)(() => {
63245
+ const reloadKey = (0, import_react61.useMemo)(() => 0, []);
63246
+ const schemaForReportBuilderState = (0, import_react61.useMemo)(() => {
63397
63247
  if (schemaData.schemaWithCustomFields?.length) {
63398
63248
  return schemaData.schemaWithCustomFields;
63399
63249
  }
63400
63250
  return schemaData.schema ?? [];
63401
63251
  }, [schemaData.schema, schemaData.schemaWithCustomFields]);
63402
- const schemaForReportBuilderStateRef = (0, import_react62.useRef)(schemaForReportBuilderState);
63403
- 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);
63404
63254
  schemaForReportBuilderStateRef.current = schemaForReportBuilderState;
63405
63255
  customFieldsRef.current = schemaData.customFields;
63406
- const isBoolAggregationField = (0, import_react62.useCallback)(
63256
+ const isBoolAggregationField = (0, import_react61.useCallback)(
63407
63257
  (field, table2) => {
63408
63258
  const fieldType = resolveFieldType({
63409
63259
  field,
@@ -63416,19 +63266,19 @@ function useReport(reportIdArg, options = {}) {
63416
63266
  },
63417
63267
  []
63418
63268
  );
63419
- const schemaForeignKeyMap = (0, import_react62.useMemo)(
63269
+ const schemaForeignKeyMap = (0, import_react61.useMemo)(
63420
63270
  () => getSchemaForeignKeyMapping(schemaForReportBuilderState),
63421
63271
  [schemaForReportBuilderState]
63422
63272
  );
63423
63273
  const reportBuilderBaseTableNamesKey = (sourceReport?.reportBuilderState?.tables ?? []).map((t) => String(t?.name ?? "").trim()).filter(Boolean).join("\0") ?? "";
63424
- const selectedBaseTableNamesForFieldOptions = (0, import_react62.useMemo)(() => {
63274
+ const selectedBaseTableNamesForFieldOptions = (0, import_react61.useMemo)(() => {
63425
63275
  const fromPicker = schemaDatasourceIds?.map((id) => String(id ?? "").trim()).filter(Boolean) ?? [];
63426
63276
  if (fromPicker.length > 0) {
63427
63277
  return fromPicker;
63428
63278
  }
63429
63279
  return (sourceReport?.reportBuilderState?.tables ?? []).map((t) => String(t?.name ?? "").trim()).filter(Boolean);
63430
63280
  }, [schemaDatasourceIdsKey, reportBuilderBaseTableNamesKey]);
63431
- const fieldOptionsAllowedTableNames = (0, import_react62.useMemo)(() => {
63281
+ const fieldOptionsAllowedTableNames = (0, import_react61.useMemo)(() => {
63432
63282
  if (!restrictFieldOptionsToSelectedDatasources) {
63433
63283
  return null;
63434
63284
  }
@@ -63440,7 +63290,7 @@ function useReport(reportIdArg, options = {}) {
63440
63290
  restrictFieldOptionsToSelectedDatasources,
63441
63291
  selectedBaseTableNamesForFieldOptions
63442
63292
  ]);
63443
- (0, import_react62.useEffect)(() => {
63293
+ (0, import_react61.useEffect)(() => {
63444
63294
  if (reportOverride) return;
63445
63295
  if (propReportId) return;
63446
63296
  if (createdReportId) return;
@@ -63530,18 +63380,18 @@ function useReport(reportIdArg, options = {}) {
63530
63380
  schemaForReportBuilderState,
63531
63381
  queryColumnsBootstrapKey
63532
63382
  ]);
63533
- const datasourceOptions = (0, import_react62.useMemo)(() => {
63383
+ const datasourceOptions = (0, import_react61.useMemo)(() => {
63534
63384
  const seen = /* @__PURE__ */ new Set();
63535
63385
  const result = [];
63536
63386
  for (const table2 of schemaForReportBuilderState) {
63537
63387
  const name2 = String(table2.name ?? "").trim();
63538
63388
  if (!name2 || seen.has(name2)) continue;
63539
63389
  seen.add(name2);
63540
- result.push({ id: name2, label: toTitleCaseLabel(name2) });
63390
+ result.push({ value: name2, label: toTitleCaseLabel(name2) });
63541
63391
  }
63542
63392
  return result;
63543
63393
  }, [schemaForReportBuilderState]);
63544
- const queryBuilderFieldConfigByName = (0, import_react62.useMemo)(() => {
63394
+ const queryBuilderFieldConfigByName = (0, import_react61.useMemo)(() => {
63545
63395
  const configByName = buildQueryBuilderFieldConfigByName(
63546
63396
  schemaForReportBuilderState
63547
63397
  );
@@ -63675,7 +63525,7 @@ function useReport(reportIdArg, options = {}) {
63675
63525
  sourceReport?.columns,
63676
63526
  sourceReport?.reportBuilderState?.columns
63677
63527
  ]);
63678
- const filterUniqueValuesRequest = (0, import_react62.useMemo)(() => {
63528
+ const filterUniqueValuesRequest = (0, import_react61.useMemo)(() => {
63679
63529
  const dashboardName = resolvedSourceDashboardName;
63680
63530
  const reportBuilderStateFromSource = sourceReport?.reportBuilderState;
63681
63531
  const isStringReportBuilderColumn = (column) => {
@@ -63896,20 +63746,20 @@ function useReport(reportIdArg, options = {}) {
63896
63746
  sourceReport?.reportBuilderState,
63897
63747
  resolvedSourceDashboardName
63898
63748
  ]);
63899
- const filterUniqueValuesRequestHash = (0, import_react62.useMemo)(
63749
+ const filterUniqueValuesRequestHash = (0, import_react61.useMemo)(
63900
63750
  () => stableSerializeForQueryKey(
63901
63751
  filterUniqueValuesRequestForQueryKey(filterUniqueValuesRequest)
63902
63752
  ),
63903
63753
  [filterUniqueValuesRequest]
63904
63754
  );
63905
- const customFiltersHashForUniqueValues = (0, import_react62.useMemo)(
63755
+ const customFiltersHashForUniqueValues = (0, import_react61.useMemo)(
63906
63756
  () => stableSerializeForQueryKey(customFilters),
63907
63757
  [customFilters]
63908
63758
  );
63909
63759
  const filterUniqueValuesEnabled = Boolean(
63910
63760
  client && client?.queryEndpoint && filterUniqueValuesRequest && filterUniqueValuesRequest.stringColumns.length > 0
63911
63761
  );
63912
- (0, import_react62.useEffect)(() => {
63762
+ (0, import_react61.useEffect)(() => {
63913
63763
  if (!useFormFiltersDebugEnabled) return;
63914
63764
  const hasClient = Boolean(client);
63915
63765
  const hasQueryEndpoint = Boolean(client?.queryEndpoint);
@@ -63999,7 +63849,7 @@ function useReport(reportIdArg, options = {}) {
63999
63849
  enabled: filterUniqueValuesEnabled,
64000
63850
  retry: false
64001
63851
  });
64002
- const backendUniqueValuesByFieldName = (0, import_react62.useMemo)(() => {
63852
+ const backendUniqueValuesByFieldName = (0, import_react61.useMemo)(() => {
64003
63853
  const valuesByField = /* @__PURE__ */ new Map();
64004
63854
  const uniqueValuesByColumn = filterUniqueValuesQuery.data?.uniqueValuesByColumn;
64005
63855
  if (!uniqueValuesByColumn || typeof uniqueValuesByColumn !== "object") {
@@ -64032,7 +63882,7 @@ function useReport(reportIdArg, options = {}) {
64032
63882
  filterUniqueValuesQuery.data?.uniqueValuesByColumn,
64033
63883
  filterUniqueValuesRequest?.stringColumnsByTable
64034
63884
  ]);
64035
- (0, import_react62.useEffect)(() => {
63885
+ (0, import_react61.useEffect)(() => {
64036
63886
  if (!useFormFiltersDebugEnabled) return;
64037
63887
  if (filterUniqueValuesQuery.status !== "success" && filterUniqueValuesQuery.status !== "error") {
64038
63888
  return;
@@ -64048,7 +63898,7 @@ function useReport(reportIdArg, options = {}) {
64048
63898
  effectiveReportId,
64049
63899
  useFormFiltersDebugEnabled
64050
63900
  ]);
64051
- const filterValueOptionsByFieldName = (0, import_react62.useMemo)(() => {
63901
+ const filterValueOptionsByFieldName = (0, import_react61.useMemo)(() => {
64052
63902
  const optionsByField = /* @__PURE__ */ new Map();
64053
63903
  const selectedMultiselectByField = collectSelectedStringMultiselectValuesByField(queryFilters);
64054
63904
  const collectValuesForField = (fieldName) => {
@@ -64114,7 +63964,7 @@ function useReport(reportIdArg, options = {}) {
64114
63964
  queryBuilderFieldConfigByName,
64115
63965
  queryFilters
64116
63966
  ]);
64117
- const filterFieldsComputed = (0, import_react62.useMemo)(() => {
63967
+ const filterFieldsComputed = (0, import_react61.useMemo)(() => {
64118
63968
  const fields = [];
64119
63969
  const seen = /* @__PURE__ */ new Set();
64120
63970
  const addField = (fieldName, fieldType, tableName, rawFieldName) => {
@@ -64215,9 +64065,9 @@ function useReport(reportIdArg, options = {}) {
64215
64065
  queryBuilderFieldConfigByName,
64216
64066
  queryFilters
64217
64067
  ]);
64218
- const filterFieldsStableReportIdRef = (0, import_react62.useRef)("");
64219
- const filterFieldsStableCacheRef = (0, import_react62.useRef)([]);
64220
- 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)(() => {
64221
64071
  const rid = String(effectiveReportId ?? "");
64222
64072
  if (filterFieldsStableReportIdRef.current !== rid) {
64223
64073
  filterFieldsStableReportIdRef.current = rid;
@@ -64232,14 +64082,14 @@ function useReport(reportIdArg, options = {}) {
64232
64082
  }
64233
64083
  return filterFieldsComputed;
64234
64084
  }, [effectiveReportId, filterFieldsComputed]);
64235
- const getFilterOperators = (0, import_react62.useMemo)(
64085
+ const getFilterOperators = (0, import_react61.useMemo)(
64236
64086
  () => (_field, misc) => {
64237
64087
  const fieldType = misc?.fieldData?.quillFieldType ?? queryBuilderFieldConfigByName[String(_field ?? "").trim()]?.fieldType ?? "string";
64238
64088
  return QUERY_BUILDER_OPERATORS_BY_FIELD_TYPE[fieldType] ?? QUERY_BUILDER_OPERATORS_BY_FIELD_TYPE.string;
64239
64089
  },
64240
64090
  [queryBuilderFieldConfigByName]
64241
64091
  );
64242
- const getFilterInputType = (0, import_react62.useMemo)(
64092
+ const getFilterInputType = (0, import_react61.useMemo)(
64243
64093
  () => (_field, operator, misc) => {
64244
64094
  const fieldType = misc?.fieldData?.quillFieldType ?? queryBuilderFieldConfigByName[String(_field ?? "").trim()]?.fieldType ?? "string";
64245
64095
  if (fieldType === "date" && isRelativeDateQueryBuilderOperator(operator)) {
@@ -64249,17 +64099,20 @@ function useReport(reportIdArg, options = {}) {
64249
64099
  },
64250
64100
  [queryBuilderFieldConfigByName]
64251
64101
  );
64252
- const getFilterValueEditorType = (0, import_react62.useMemo)(
64102
+ const getFilterValueEditorType = (0, import_react61.useMemo)(
64253
64103
  () => (_field, operator, misc) => {
64254
64104
  const fieldType = misc?.fieldData?.quillFieldType ?? queryBuilderFieldConfigByName[String(_field ?? "").trim()]?.fieldType;
64255
64105
  if (fieldType === "string" && isMultiValueOperator(operator)) {
64256
64106
  return "multiselect";
64257
64107
  }
64108
+ if (fieldType === "boolean") {
64109
+ return "select";
64110
+ }
64258
64111
  return void 0;
64259
64112
  },
64260
64113
  [queryBuilderFieldConfigByName]
64261
64114
  );
64262
- const getFilterValues = (0, import_react62.useMemo)(
64115
+ const getFilterValues = (0, import_react61.useMemo)(
64263
64116
  () => (_field, operator, misc) => {
64264
64117
  const fieldName = String(_field ?? "").trim();
64265
64118
  if (!fieldName) {
@@ -64270,6 +64123,9 @@ function useReport(reportIdArg, options = {}) {
64270
64123
  misc,
64271
64124
  queryBuilderFieldConfigByName
64272
64125
  );
64126
+ if (fieldType === "boolean") {
64127
+ return BOOLEAN_FILTER_VALUE_OPTIONS;
64128
+ }
64273
64129
  if (fieldType !== "string" || !isMultiValueOperator(operator)) {
64274
64130
  return [];
64275
64131
  }
@@ -64286,7 +64142,7 @@ function useReport(reportIdArg, options = {}) {
64286
64142
  },
64287
64143
  [filterValueOptionsByFieldName, queryBuilderFieldConfigByName]
64288
64144
  );
64289
- const filterQueryBuilderProps = (0, import_react62.useMemo)(
64145
+ const filterQueryBuilderProps = (0, import_react61.useMemo)(
64290
64146
  () => ({
64291
64147
  fields: filterFields,
64292
64148
  listsAsArrays: true,
@@ -64303,7 +64159,7 @@ function useReport(reportIdArg, options = {}) {
64303
64159
  getFilterValues
64304
64160
  ]
64305
64161
  );
64306
- const filtersForQueryBuilder = (0, import_react62.useMemo)(
64162
+ const filtersForQueryBuilder = (0, import_react61.useMemo)(
64307
64163
  () => canonicalizeMultiselectStringRulesToOptionValues(
64308
64164
  queryFilters,
64309
64165
  filterValueOptionsByFieldName,
@@ -64370,12 +64226,12 @@ function useReport(reportIdArg, options = {}) {
64370
64226
  ...table2 ? { table: table2 } : {}
64371
64227
  };
64372
64228
  };
64373
- const tenantHash = (0, import_react62.useMemo)(
64229
+ const tenantHash = (0, import_react61.useMemo)(
64374
64230
  () => stableSerializeForQueryKey(tenants),
64375
64231
  [tenants]
64376
64232
  );
64377
- const flagHash = (0, import_react62.useMemo)(() => stableSerializeForQueryKey(flags), [flags]);
64378
- const clientHash = (0, import_react62.useMemo)(
64233
+ const flagHash = (0, import_react61.useMemo)(() => stableSerializeForQueryKey(flags), [flags]);
64234
+ const clientHash = (0, import_react61.useMemo)(
64379
64235
  () => stableSerializeForQueryKey({
64380
64236
  publicKey: client?.publicKey,
64381
64237
  clientId: client?.clientId,
@@ -64383,16 +64239,16 @@ function useReport(reportIdArg, options = {}) {
64383
64239
  }),
64384
64240
  [client]
64385
64241
  );
64386
- const reloadKeyHash = (0, import_react62.useMemo)(
64242
+ const reloadKeyHash = (0, import_react61.useMemo)(
64387
64243
  () => stableSerializeForQueryKey(reloadKey),
64388
64244
  [reloadKey]
64389
64245
  );
64390
- (0, import_react62.useEffect)(() => {
64246
+ (0, import_react61.useEffect)(() => {
64391
64247
  if (!reportOverride) return;
64392
64248
  initializeSchemaScopeForReport(reportOverride);
64393
64249
  setSourceReport(reportOverride);
64394
64250
  }, [reportOverride, propReportId]);
64395
- (0, import_react62.useEffect)(() => {
64251
+ (0, import_react61.useEffect)(() => {
64396
64252
  schemaScopeInitializedForReportIdRef.current = null;
64397
64253
  bootstrapReportTaskUsedForReportIdRef.current = null;
64398
64254
  setPreserveSchemaWideOptions(false);
@@ -64416,6 +64272,7 @@ function useReport(reportIdArg, options = {}) {
64416
64272
  // grouping from the prior report would otherwise win over the new report.
64417
64273
  groupRowsBy: void 0,
64418
64274
  groupColumnsBy: void 0,
64275
+ dateBucket: void 0,
64419
64276
  aggregationState: [],
64420
64277
  aggregationTablesByIndex: [],
64421
64278
  pivotSort: void 0,
@@ -64497,13 +64354,13 @@ function useReport(reportIdArg, options = {}) {
64497
64354
  const sourceReportNameForTitle = String(sourceReport?.name ?? "").trim();
64498
64355
  const reportTitleFromTask = String(reportNameQuery.data?.name ?? "").trim();
64499
64356
  const resolvedReportName = reportNameQueryReportId && sourceReportIdForTitle === reportNameQueryReportId && sourceReportNameForTitle ? sourceReportNameForTitle : reportTitleFromTask || sourceReportNameForTitle || "";
64500
- (0, import_react62.useEffect)(() => {
64357
+ (0, import_react61.useEffect)(() => {
64501
64358
  if (reportOverride) return;
64502
64359
  const report = initialLoadQuery.data?.report ?? null;
64503
64360
  initializeSchemaScopeForReport(report);
64504
64361
  setSourceReport(report);
64505
64362
  }, [initialLoadQuery.data, reportOverride, effectiveReportId]);
64506
- (0, import_react62.useEffect)(() => {
64363
+ (0, import_react61.useEffect)(() => {
64507
64364
  if (!sourceReport) {
64508
64365
  return;
64509
64366
  }
@@ -64602,6 +64459,8 @@ function useReport(reportIdArg, options = {}) {
64602
64459
  const sourceDisplayColumns = sourceDisplayColumnsFromSchema.length > 0 ? sourceDisplayColumnsFromSchema : sourceQueryColumns;
64603
64460
  const nextGroupRowsBy = shouldTakePivotGroupsFromSource ? groupRowsBySetViaSetReportRef.current ? prev.groupRowsBy : sourceRowGroupOption : prev.groupRowsBy !== void 0 ? prev.groupRowsBy : groupRowsBySetViaSetReportRef.current ? prev.groupRowsBy : sourceRowGroupOption;
64604
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;
64605
64464
  const nextFromSource = {
64606
64465
  ...prev,
64607
64466
  queryColumns: prev.queryColumns.length ? prev.queryColumns : sourceQueryColumns,
@@ -64610,6 +64469,7 @@ function useReport(reportIdArg, options = {}) {
64610
64469
  queryFilters: nextQueryFilters,
64611
64470
  groupRowsBy: nextGroupRowsBy,
64612
64471
  groupColumnsBy: nextGroupColumnsBy,
64472
+ dateBucket: nextDateBucket,
64613
64473
  aggregationState: nextAggregationState,
64614
64474
  aggregationTablesByIndex: nextAggregationTablesByIndex,
64615
64475
  pivotSort: prev.pivotSort ?? (sourceReport.pivot?.sort && sourceReport.pivot?.sortField && sourceReport.pivot?.sortDirection ? {
@@ -64642,11 +64502,11 @@ function useReport(reportIdArg, options = {}) {
64642
64502
  schemaForReportBuilderState,
64643
64503
  sourceReport
64644
64504
  ]);
64645
- const appliedAggregationState = (0, import_react62.useMemo)(
64505
+ const appliedAggregationState = (0, import_react61.useMemo)(
64646
64506
  () => aggregationState.filter(isAppliedAggregation),
64647
64507
  [aggregationState]
64648
64508
  );
64649
- const pivotState = (0, import_react62.useMemo)(() => {
64509
+ const pivotState = (0, import_react61.useMemo)(() => {
64650
64510
  if (!resolvedGroupRowsBy && !resolvedGroupColumnsBy && appliedAggregationState.length === 0) {
64651
64511
  return null;
64652
64512
  }
@@ -64690,6 +64550,7 @@ function useReport(reportIdArg, options = {}) {
64690
64550
  rowFieldType,
64691
64551
  columnField: effectiveColumnField,
64692
64552
  columnFieldType,
64553
+ dateBucket: chartPivotHydratedFromSourceRef.current ? dateBucket : dateBucket ?? priorPivot?.dateBucket,
64693
64554
  aggregations,
64694
64555
  ...rowFieldTable ? { rowFieldTable } : {},
64695
64556
  ...columnFieldTable ? { columnFieldTable } : {}
@@ -64700,6 +64561,7 @@ function useReport(reportIdArg, options = {}) {
64700
64561
  aggregationTablesByIndex,
64701
64562
  appliedAggregationState,
64702
64563
  baseReportBuilderTables,
64564
+ dateBucket,
64703
64565
  groupColumnsBy,
64704
64566
  groupRowsBy,
64705
64567
  schemaForReportBuilderState,
@@ -64711,7 +64573,7 @@ function useReport(reportIdArg, options = {}) {
64711
64573
  effectiveReportId,
64712
64574
  chartPivotHydrationEpoch
64713
64575
  ]);
64714
- (0, import_react62.useEffect)(() => {
64576
+ (0, import_react61.useEffect)(() => {
64715
64577
  const previous = prevPivotStateForColumnExpansionRef.current;
64716
64578
  if (previous && !pivotState) {
64717
64579
  setExpandReportBuilderColumnsForFlatTable(true);
@@ -64721,7 +64583,7 @@ function useReport(reportIdArg, options = {}) {
64721
64583
  }
64722
64584
  prevPivotStateForColumnExpansionRef.current = pivotState;
64723
64585
  }, [pivotState]);
64724
- const effectiveReportBuilderTables = (0, import_react62.useMemo)(() => {
64586
+ const effectiveReportBuilderTables = (0, import_react61.useMemo)(() => {
64725
64587
  const explicitBaseFromSchemaPicker = Array.isArray(schemaDatasourceIds) && schemaDatasourceIds.length > 0 ? schemaDatasourceIds.map((tableName) => String(tableName ?? "").trim()).filter(Boolean).map((name2) => ({ name: name2 })) : null;
64726
64588
  const baseTablesForMerge = explicitBaseFromSchemaPicker ?? baseReportBuilderTables;
64727
64589
  return mergeReportBuilderTables(
@@ -64745,28 +64607,18 @@ function useReport(reportIdArg, options = {}) {
64745
64607
  queryColumns,
64746
64608
  schemaDatasourceIds
64747
64609
  ]);
64748
- const datasources = (0, import_react62.useMemo)(() => {
64749
- return effectiveReportBuilderTables.map((table2) => {
64750
- const name2 = String(table2.name ?? "").trim();
64751
- if (!name2) return null;
64752
- const alias = String(table2.alias ?? "").trim();
64753
- return {
64754
- id: name2,
64755
- label: alias || name2
64756
- };
64757
- }).filter(
64758
- (entry) => Boolean(entry)
64759
- );
64610
+ const datasources = (0, import_react61.useMemo)(() => {
64611
+ return effectiveReportBuilderTables.map((table2) => String(table2.name ?? "").trim()).filter((name2) => Boolean(name2));
64760
64612
  }, [effectiveReportBuilderTables]);
64761
- const effectiveReportBuilderTableNames = (0, import_react62.useMemo)(
64613
+ const effectiveReportBuilderTableNames = (0, import_react61.useMemo)(
64762
64614
  () => effectiveReportBuilderTables.map((table2) => String(table2.name ?? "").trim()).filter((name2) => Boolean(name2)),
64763
64615
  [effectiveReportBuilderTables]
64764
64616
  );
64765
- const baseReportBuilderTableNames = (0, import_react62.useMemo)(
64617
+ const baseReportBuilderTableNames = (0, import_react61.useMemo)(
64766
64618
  () => baseReportBuilderTables.map((table2) => String(table2.name ?? "").trim()).filter((name2) => Boolean(name2)),
64767
64619
  [baseReportBuilderTables]
64768
64620
  );
64769
- const normalizeQueryBuilderFieldNameForConfig = (0, import_react62.useMemo)(() => {
64621
+ const normalizeQueryBuilderFieldNameForConfig = (0, import_react61.useMemo)(() => {
64770
64622
  const configEntries = Object.entries(queryBuilderFieldConfigByName);
64771
64623
  const preferredTableNames = /* @__PURE__ */ new Set([
64772
64624
  ...effectiveReportBuilderTableNames,
@@ -64828,7 +64680,7 @@ function useReport(reportIdArg, options = {}) {
64828
64680
  effectiveReportBuilderTableNames,
64829
64681
  queryBuilderFieldConfigByName
64830
64682
  ]);
64831
- const normalizeQueryBuilderFiltersForConfig = (0, import_react62.useMemo)(() => {
64683
+ const normalizeQueryBuilderFiltersForConfig = (0, import_react61.useMemo)(() => {
64832
64684
  const normalizeGroup = (group) => {
64833
64685
  const groupRules = Array.isArray(group.rules) ? group.rules : [];
64834
64686
  const nextRules = groupRules.map((entry) => {
@@ -64865,14 +64717,14 @@ function useReport(reportIdArg, options = {}) {
64865
64717
  return normalizeGroup(group);
64866
64718
  };
64867
64719
  }, [normalizeQueryBuilderFieldNameForConfig, queryBuilderFieldConfigByName]);
64868
- const refreshSelectionTables = (0, import_react62.useMemo)(() => {
64720
+ const refreshSelectionTables = (0, import_react61.useMemo)(() => {
64869
64721
  return [
64870
64722
  getPivotGroupOptionTable(groupRowsBy),
64871
64723
  getPivotGroupOptionTable(groupColumnsBy),
64872
64724
  ...aggregationTablesByIndex
64873
64725
  ].map((tableName) => String(tableName ?? "").trim()).filter((tableName) => Boolean(tableName));
64874
64726
  }, [aggregationTablesByIndex, groupColumnsBy, groupRowsBy]);
64875
- const refreshSelectionFields = (0, import_react62.useMemo)(() => {
64727
+ const refreshSelectionFields = (0, import_react61.useMemo)(() => {
64876
64728
  const resolveFieldTableForSelection = (field, tableHint) => {
64877
64729
  const fieldName = String(field ?? "").trim();
64878
64730
  if (!fieldName) return "";
@@ -64922,7 +64774,7 @@ function useReport(reportIdArg, options = {}) {
64922
64774
  schemaForReportBuilderState,
64923
64775
  sourceReport
64924
64776
  ]);
64925
- const refreshDecision = (0, import_react62.useMemo)(
64777
+ const refreshDecision = (0, import_react61.useMemo)(
64926
64778
  () => decideReportBuilderRefresh({
64927
64779
  baseTables: baseReportBuilderTables,
64928
64780
  baseColumns: baseReportBuilderColumns,
@@ -64936,7 +64788,7 @@ function useReport(reportIdArg, options = {}) {
64936
64788
  refreshSelectionTables
64937
64789
  ]
64938
64790
  );
64939
- const effectiveReportBuilderColumns = (0, import_react62.useMemo)(() => {
64791
+ const effectiveReportBuilderColumns = (0, import_react61.useMemo)(() => {
64940
64792
  const columnsFromPivot = [];
64941
64793
  const appendPivotColumn = (field, tableHint) => {
64942
64794
  const normalizedField = String(field ?? "").trim();
@@ -64999,7 +64851,7 @@ function useReport(reportIdArg, options = {}) {
64999
64851
  queryColumns,
65000
64852
  sourceReport
65001
64853
  ]);
65002
- (0, import_react62.useEffect)(() => {
64854
+ (0, import_react61.useEffect)(() => {
65003
64855
  if (!Array.isArray(filterStack) || filterStack.length === 0) {
65004
64856
  return;
65005
64857
  }
@@ -65034,7 +64886,7 @@ function useReport(reportIdArg, options = {}) {
65034
64886
  queryBuilderFieldConfigByName,
65035
64887
  queryFilters
65036
64888
  ]);
65037
- const resolvedSortFieldType = (0, import_react62.useMemo)(() => {
64889
+ const resolvedSortFieldType = (0, import_react61.useMemo)(() => {
65038
64890
  const sortField = pivotSort?.sortField;
65039
64891
  if (!sortField || !pivotState) return void 0;
65040
64892
  if (sortField === resolvedGroupRowsBy) {
@@ -65055,7 +64907,7 @@ function useReport(reportIdArg, options = {}) {
65055
64907
  resolvedGroupColumnsBy,
65056
64908
  resolvedGroupRowsBy
65057
64909
  ]);
65058
- const effectiveReportBuilderState = (0, import_react62.useMemo)(() => {
64910
+ const effectiveReportBuilderState = (0, import_react61.useMemo)(() => {
65059
64911
  if (!sourceReport && effectiveReportBuilderTables.length === 0) {
65060
64912
  return void 0;
65061
64913
  }
@@ -65094,12 +64946,12 @@ function useReport(reportIdArg, options = {}) {
65094
64946
  resolvedSortFieldType,
65095
64947
  sourceReport
65096
64948
  ]);
65097
- const effectiveReportBuilderStateHash = (0, import_react62.useMemo)(
64949
+ const effectiveReportBuilderStateHash = (0, import_react61.useMemo)(
65098
64950
  () => stableSerializeForQueryKey(effectiveReportBuilderState),
65099
64951
  [effectiveReportBuilderState]
65100
64952
  );
65101
- const prevPaginationResetStateHashRef = (0, import_react62.useRef)(null);
65102
- (0, import_react62.useEffect)(() => {
64953
+ const prevPaginationResetStateHashRef = (0, import_react61.useRef)(null);
64954
+ (0, import_react61.useEffect)(() => {
65103
64955
  const prevHash = prevPaginationResetStateHashRef.current;
65104
64956
  prevPaginationResetStateHashRef.current = effectiveReportBuilderStateHash;
65105
64957
  if (prevHash === null || prevHash === effectiveReportBuilderStateHash) {
@@ -65115,7 +64967,7 @@ function useReport(reportIdArg, options = {}) {
65115
64967
  activate: false
65116
64968
  });
65117
64969
  }, [applyPaginationUpdate, effectiveReportBuilderStateHash]);
65118
- const pivotTableDataReportBuilderState = (0, import_react62.useMemo)(() => {
64970
+ const pivotTableDataReportBuilderState = (0, import_react61.useMemo)(() => {
65119
64971
  if (!effectiveReportBuilderState?.pivot) {
65120
64972
  return void 0;
65121
64973
  }
@@ -65135,11 +64987,11 @@ function useReport(reportIdArg, options = {}) {
65135
64987
  limit: null
65136
64988
  };
65137
64989
  }, [effectiveReportBuilderState, schemaForReportBuilderState]);
65138
- const pivotTableDataReportBuilderStateHash = (0, import_react62.useMemo)(
64990
+ const pivotTableDataReportBuilderStateHash = (0, import_react61.useMemo)(
65139
64991
  () => stableSerializeForQueryKey(pivotTableDataReportBuilderState),
65140
64992
  [pivotTableDataReportBuilderState]
65141
64993
  );
65142
- const sourceReportMatchesEffectiveReportId = (0, import_react62.useMemo)(() => {
64994
+ const sourceReportMatchesEffectiveReportId = (0, import_react61.useMemo)(() => {
65143
64995
  const loadTarget = String(effectiveReportId ?? "").trim();
65144
64996
  if (!loadTarget || !sourceReport) {
65145
64997
  return true;
@@ -65149,7 +65001,7 @@ function useReport(reportIdArg, options = {}) {
65149
65001
  ).trim();
65150
65002
  return sid === loadTarget;
65151
65003
  }, [effectiveReportId, sourceReport]);
65152
- const shouldSkipRedundantFlatTableReportBuilderQuery = (0, import_react62.useMemo)(() => {
65004
+ const shouldSkipRedundantFlatTableReportBuilderQuery = (0, import_react61.useMemo)(() => {
65153
65005
  if (!sourceReport || pivotState) {
65154
65006
  return false;
65155
65007
  }
@@ -65204,7 +65056,7 @@ function useReport(reportIdArg, options = {}) {
65204
65056
  enabled: tableRefreshQueryEnabled,
65205
65057
  retry: false
65206
65058
  });
65207
- (0, import_react62.useEffect)(() => {
65059
+ (0, import_react61.useEffect)(() => {
65208
65060
  if (!tableRefreshQueryEnabled) return;
65209
65061
  const report = tableRefreshQuery.data?.report;
65210
65062
  if (tableRefreshQuery.data?.error || !report) return;
@@ -65215,10 +65067,10 @@ function useReport(reportIdArg, options = {}) {
65215
65067
  tableRefreshQueryEnabled,
65216
65068
  useFormRefreshDebugEnabled
65217
65069
  ]);
65218
- const chartTypes = (0, import_react62.useMemo)(() => {
65070
+ const chartTypes = (0, import_react61.useMemo)(() => {
65219
65071
  return getChartTypeOptions2({ pivot: pivotState });
65220
65072
  }, [pivotState]);
65221
- (0, import_react62.useEffect)(() => {
65073
+ (0, import_react61.useEffect)(() => {
65222
65074
  if (!sourceReport) {
65223
65075
  return;
65224
65076
  }
@@ -65253,7 +65105,7 @@ function useReport(reportIdArg, options = {}) {
65253
65105
  });
65254
65106
  }
65255
65107
  }, [chartType, chartTypes, sourceReport]);
65256
- const schemaScopedTableNames = (0, import_react62.useMemo)(() => {
65108
+ const schemaScopedTableNames = (0, import_react61.useMemo)(() => {
65257
65109
  if (preserveSchemaWideOptions) {
65258
65110
  return [];
65259
65111
  }
@@ -65268,7 +65120,7 @@ function useReport(reportIdArg, options = {}) {
65268
65120
  preserveSchemaWideOptions,
65269
65121
  sourceReport?.reportBuilderState?.tables
65270
65122
  ]);
65271
- const joinCompatibleSchemaTableNames = (0, import_react62.useMemo)(() => {
65123
+ const joinCompatibleSchemaTableNames = (0, import_react61.useMemo)(() => {
65272
65124
  if (schemaScopedTableNames.length === 0) {
65273
65125
  return [];
65274
65126
  }
@@ -65277,7 +65129,7 @@ function useReport(reportIdArg, options = {}) {
65277
65129
  schemaForeignKeyMap
65278
65130
  );
65279
65131
  }, [schemaForeignKeyMap, schemaScopedTableNames]);
65280
- const aggregationFallbackTarget = (0, import_react62.useMemo)(() => {
65132
+ const aggregationFallbackTarget = (0, import_react61.useMemo)(() => {
65281
65133
  const tableNames = effectiveReportBuilderTables.map((table2) => table2.name).filter((name2) => Boolean(name2));
65282
65134
  const referencedTableNames = (sourceReport?.referencedTables ?? []).filter(
65283
65135
  (name2) => typeof name2 === "string" && name2.length > 0
@@ -65285,7 +65137,7 @@ function useReport(reportIdArg, options = {}) {
65285
65137
  const tableNamesToUse = tableNames.length ? tableNames : referencedTableNames;
65286
65138
  return tableNamesToUse.length > 0 ? tableNamesToUse.join(", ") : "table";
65287
65139
  }, [effectiveReportBuilderTables, sourceReport?.referencedTables]);
65288
- const aggregationFallbackTableName = (0, import_react62.useMemo)(() => {
65140
+ const aggregationFallbackTableName = (0, import_react61.useMemo)(() => {
65289
65141
  const tableNames = effectiveReportBuilderTables.map((table2) => table2.name).filter((name2) => Boolean(name2));
65290
65142
  const referencedTableNames = (sourceReport?.referencedTables ?? []).filter(
65291
65143
  (name2) => typeof name2 === "string" && name2.length > 0
@@ -65293,7 +65145,7 @@ function useReport(reportIdArg, options = {}) {
65293
65145
  const tableNamesToUse = tableNames.length ? tableNames : referencedTableNames;
65294
65146
  return tableNamesToUse[0] ?? "table";
65295
65147
  }, [effectiveReportBuilderTables, sourceReport?.referencedTables]);
65296
- const cleanedAggregations = (0, import_react62.useMemo)(() => {
65148
+ const cleanedAggregations = (0, import_react61.useMemo)(() => {
65297
65149
  return aggregationState.filter((aggregation) => Boolean(aggregation?.aggregationType)).map((aggregation, index) => {
65298
65150
  const aggregationType = String(aggregation.aggregationType);
65299
65151
  const normalizedAggregationType = aggregationType.toLowerCase();
@@ -65315,7 +65167,7 @@ function useReport(reportIdArg, options = {}) {
65315
65167
  aggregationTablesByIndex,
65316
65168
  isBoolAggregationField
65317
65169
  ]);
65318
- const { aggregationBaseOptions, aggregationOptionTableLookup } = (0, import_react62.useMemo)(() => {
65170
+ const { aggregationBaseOptions, aggregationOptionTableLookup } = (0, import_react61.useMemo)(() => {
65319
65171
  const joinScoped = fieldOptionsAllowedTableNames ? joinCompatibleSchemaTableNames.filter(
65320
65172
  (name2) => fieldOptionsAllowedTableNames.has(name2)
65321
65173
  ) : joinCompatibleSchemaTableNames;
@@ -65361,7 +65213,7 @@ function useReport(reportIdArg, options = {}) {
65361
65213
  if (!canAggregateColumn(column, aggregationType)) continue;
65362
65214
  const isNumberSharePercentage = aggregationType === "percentage" && !isBoolColumn;
65363
65215
  if (isNumberSharePercentage && !resolvedGroupRowsBy) continue;
65364
- const value = `${aggregationType}:${fieldName}`;
65216
+ const value = tableName ? `${aggregationType}:${tableName}::${fieldName}` : `${aggregationType}:${fieldName}`;
65365
65217
  if (seen.has(value)) continue;
65366
65218
  const aggregationWord = aggregationType === "percentage" ? isBoolColumn ? "Percent" : "Percent of Total" : formatAggregationTypeForDisplay(aggregationType);
65367
65219
  options2.push({
@@ -65369,8 +65221,14 @@ function useReport(reportIdArg, options = {}) {
65369
65221
  label: tableName ? `${aggregationWord} ${toTitleCaseLabel(tableName)} ${toTitleCaseLabel(fieldName)}` : `${aggregationWord} ${toTitleCaseLabel(fieldName)}`
65370
65222
  });
65371
65223
  seen.add(value);
65372
- if (tableName && !tableLookup.has(value)) {
65373
- 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
+ }
65374
65232
  }
65375
65233
  }
65376
65234
  }
@@ -65392,7 +65250,7 @@ function useReport(reportIdArg, options = {}) {
65392
65250
  resolvedGroupRowsBy,
65393
65251
  schemaForReportBuilderState
65394
65252
  ]);
65395
- const { schemaColumnOptions, columnIdentifierLookup } = (0, import_react62.useMemo)(() => {
65253
+ const { schemaColumnOptions, columnIdentifierLookup } = (0, import_react61.useMemo)(() => {
65396
65254
  const lookup = /* @__PURE__ */ new Map();
65397
65255
  const options2 = [];
65398
65256
  for (const table2 of schemaData.schemaWithCustomFields) {
@@ -65419,7 +65277,7 @@ function useReport(reportIdArg, options = {}) {
65419
65277
  columnIdentifierLookup: lookup
65420
65278
  };
65421
65279
  }, [schemaData.schemaWithCustomFields]);
65422
- const tableColumnPickerPoolOptions = (0, import_react62.useMemo)(() => {
65280
+ const tableColumnPickerPoolOptions = (0, import_react61.useMemo)(() => {
65423
65281
  const allowed = new Set(
65424
65282
  effectiveReportBuilderTableNames.map((name2) => String(name2 ?? "").trim()).filter(Boolean)
65425
65283
  );
@@ -65430,16 +65288,16 @@ function useReport(reportIdArg, options = {}) {
65430
65288
  (option) => allowed.has(String(option.tableName ?? "").trim())
65431
65289
  );
65432
65290
  }, [effectiveReportBuilderTableNames, schemaColumnOptions]);
65433
- const columns = (0, import_react62.useMemo)(() => {
65291
+ const columns = (0, import_react61.useMemo)(() => {
65434
65292
  return displayColumns.filter((column) => Boolean(column.field)).map((column) => encodeColumnOptionValue(column.table, column.field));
65435
65293
  }, [displayColumns]);
65436
- const selectedColumnOptions = (0, import_react62.useMemo)(() => {
65294
+ const selectedColumnOptions = (0, import_react61.useMemo)(() => {
65437
65295
  return displayColumns.map((column) => {
65438
65296
  const value = column.alias || column.field;
65439
65297
  return value ? { label: value, value } : null;
65440
65298
  }).filter((option) => option !== null);
65441
65299
  }, [displayColumns]);
65442
- const scopedSchemaColumns = (0, import_react62.useMemo)(() => {
65300
+ const scopedSchemaColumns = (0, import_react61.useMemo)(() => {
65443
65301
  const tableNames = fieldOptionsAllowedTableNames ? Array.from(fieldOptionsAllowedTableNames) : joinCompatibleSchemaTableNames;
65444
65302
  const schemaTables = schemaForReportBuilderState;
65445
65303
  const tablesToUse = tableNames.length ? schemaTables.filter((table2) => tableNames.includes(table2.name ?? "")) : schemaTables;
@@ -65460,7 +65318,7 @@ function useReport(reportIdArg, options = {}) {
65460
65318
  joinCompatibleSchemaTableNames,
65461
65319
  schemaForReportBuilderState
65462
65320
  ]);
65463
- const pivotUniqueValuesByColumn = (0, import_react62.useMemo)(() => {
65321
+ const pivotUniqueValuesByColumn = (0, import_react61.useMemo)(() => {
65464
65322
  const explicitUniqueValues = sourceReport?.uniqueStringsByColumn ?? sourceReport?.columnUniqueValues ?? sourceReport?.uniqueValues;
65465
65323
  if (explicitUniqueValues && typeof explicitUniqueValues === "object" && !Array.isArray(explicitUniqueValues)) {
65466
65324
  return explicitUniqueValues;
@@ -65486,7 +65344,7 @@ function useReport(reportIdArg, options = {}) {
65486
65344
  }
65487
65345
  return result;
65488
65346
  }, [sourceReport]);
65489
- const possiblePivotFields = (0, import_react62.useMemo)(() => {
65347
+ const possiblePivotFields = (0, import_react61.useMemo)(() => {
65490
65348
  const options2 = getPossiblePivotFieldOptions(
65491
65349
  scopedSchemaColumns,
65492
65350
  pivotUniqueValuesByColumn
@@ -65497,7 +65355,7 @@ function useReport(reportIdArg, options = {}) {
65497
65355
  columnFields: options2.columnFields.filter((field) => !isIdColumn(field))
65498
65356
  };
65499
65357
  }, [scopedSchemaColumns, pivotUniqueValuesByColumn]);
65500
- const groupRowsByOptions = (0, import_react62.useMemo)(() => {
65358
+ const groupRowsByOptions = (0, import_react61.useMemo)(() => {
65501
65359
  const allowedFields = new Set(possiblePivotFields.rowFields);
65502
65360
  const seenValues = /* @__PURE__ */ new Set();
65503
65361
  const options2 = [];
@@ -65524,7 +65382,7 @@ function useReport(reportIdArg, options = {}) {
65524
65382
  }
65525
65383
  return options2;
65526
65384
  }, [groupRowsBy, possiblePivotFields.rowFields, scopedSchemaColumns]);
65527
- const groupColumnsByOptions = (0, import_react62.useMemo)(() => {
65385
+ const groupColumnsByOptions = (0, import_react61.useMemo)(() => {
65528
65386
  const allowedFields = new Set(possiblePivotFields.columnFields);
65529
65387
  const seenValues = /* @__PURE__ */ new Set();
65530
65388
  const options2 = [];
@@ -65551,19 +65409,19 @@ function useReport(reportIdArg, options = {}) {
65551
65409
  }
65552
65410
  return options2;
65553
65411
  }, [groupColumnsBy, possiblePivotFields.columnFields, scopedSchemaColumns]);
65554
- const cleanedSort = (0, import_react62.useMemo)(() => {
65412
+ const cleanedSort = (0, import_react61.useMemo)(() => {
65555
65413
  const activeSort = resolvedGroupRowsBy ? pivotSort : regularSort;
65556
65414
  if (!activeSort?.sortField || !activeSort?.sortDirection) {
65557
65415
  return "";
65558
65416
  }
65559
65417
  return toFlatSortValue(activeSort.sortField, activeSort.sortDirection);
65560
65418
  }, [pivotSort, regularSort, resolvedGroupRowsBy]);
65561
- const aggregationSortLabelFallbackTable = (0, import_react62.useMemo)(() => {
65419
+ const aggregationSortLabelFallbackTable = (0, import_react61.useMemo)(() => {
65562
65420
  const reportBuilderTableName = effectiveReportBuilderTables.map((table2) => String(table2.name ?? "").trim()).find((tableName) => Boolean(tableName));
65563
65421
  if (reportBuilderTableName) return reportBuilderTableName;
65564
65422
  return (sourceReport?.referencedTables ?? []).map((tableName) => String(tableName ?? "").trim()).find((tableName) => Boolean(tableName));
65565
65423
  }, [effectiveReportBuilderTables, sourceReport?.referencedTables]);
65566
- const sortOptions = (0, import_react62.useMemo)(() => {
65424
+ const sortOptions = (0, import_react61.useMemo)(() => {
65567
65425
  if (resolvedGroupRowsBy) {
65568
65426
  const aggregationSortFields = getPivotAggregationSortFields(
65569
65427
  aggregationState,
@@ -65622,12 +65480,14 @@ function useReport(reportIdArg, options = {}) {
65622
65480
  resolvedGroupRowsBy,
65623
65481
  selectedColumnOptions
65624
65482
  ]);
65625
- const aggregationOptions = (0, import_react62.useMemo)(() => {
65483
+ const { aggregationValues, aggregationOptions } = (0, import_react61.useMemo)(() => {
65626
65484
  const baseOptions = aggregationBaseOptions.map((option) => ({
65627
65485
  value: option.value,
65628
65486
  label: option.label
65629
65487
  }));
65630
- 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) => {
65631
65491
  const normalizedAggregationType = String(
65632
65492
  aggregation.aggregationType ?? ""
65633
65493
  ).toLowerCase();
@@ -65635,27 +65495,36 @@ function useReport(reportIdArg, options = {}) {
65635
65495
  const currentValueField = String(aggregation.valueField ?? "").trim();
65636
65496
  const currentValueField2 = String(aggregation.valueField2 ?? "").trim();
65637
65497
  const isPercentageRatio = normalizedAggregationType === "percentage" && Boolean(currentValueField) && Boolean(currentValueField2);
65638
- const currentTarget = isPercentageRatio ? `${currentValueField}:${currentValueField2}` : currentValueField ? currentValueField : normalizedAggregationType === "count" || normalizedAggregationType === "percentage" ? tableHint || aggregationFallbackTableName : aggregationFallbackTarget;
65639
- const currentValue = aggregation.aggregationType ? `${aggregation.aggregationType}:${currentTarget}` : void 0;
65640
- const isBoolPercentage = normalizedAggregationType === "percentage" && Boolean(currentValueField) && isBoolAggregationField(currentValueField, tableHint || void 0) === true;
65641
- 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";
65642
- const options2 = currentValue ? baseOptions.some((option) => option.value === currentValue) ? baseOptions : [{ value: currentValue, label: currentLabel }, ...baseOptions] : baseOptions;
65643
- return {
65644
- key: `aggregation-${index}`,
65645
- label: `Aggregation ${index + 1}`,
65646
- value: currentValue ?? "",
65647
- options: options2
65648
- };
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;
65649
65513
  });
65514
+ return {
65515
+ aggregationValues: values,
65516
+ aggregationOptions: [...injectedOptions, ...baseOptions]
65517
+ };
65650
65518
  }, [
65651
65519
  aggregationFallbackTableName,
65652
65520
  aggregationFallbackTarget,
65653
65521
  aggregationState,
65654
65522
  aggregationBaseOptions,
65523
+ aggregationOptionTableLookup,
65655
65524
  aggregationTablesByIndex,
65656
65525
  isBoolAggregationField
65657
65526
  ]);
65658
- const nextPivot = (0, import_react62.useMemo)(() => {
65527
+ const nextPivot = (0, import_react61.useMemo)(() => {
65659
65528
  if (!sourceReport) return null;
65660
65529
  return pivotState ? {
65661
65530
  ...pivotState,
@@ -65666,15 +65535,15 @@ function useReport(reportIdArg, options = {}) {
65666
65535
  rowLimit: limit?.value
65667
65536
  } : null;
65668
65537
  }, [sourceReport, pivotState, pivotSort, limit, resolvedSortFieldType]);
65669
- const nextPivotHash = (0, import_react62.useMemo)(
65538
+ const nextPivotHash = (0, import_react61.useMemo)(
65670
65539
  () => stableSerializeForQueryKey(nextPivot),
65671
65540
  [nextPivot]
65672
65541
  );
65673
- const filterStackHash = (0, import_react62.useMemo)(
65542
+ const filterStackHash = (0, import_react61.useMemo)(
65674
65543
  () => stableSerializeForQueryKey(filterStack),
65675
65544
  [filterStack]
65676
65545
  );
65677
- const shouldSkipPivotRefreshForUnchangedPivot = (0, import_react62.useMemo)(() => {
65546
+ const shouldSkipPivotRefreshForUnchangedPivot = (0, import_react61.useMemo)(() => {
65678
65547
  if (!sourceReport || !nextPivot) return false;
65679
65548
  if (!Array.isArray(sourceReport.rows) || sourceReport.rows.length === 0) {
65680
65549
  return false;
@@ -65692,7 +65561,7 @@ function useReport(reportIdArg, options = {}) {
65692
65561
  );
65693
65562
  return hasSamePivot && sourceFilterStackHash === filterStackHash;
65694
65563
  }, [filterStackHash, nextPivot, sourceReport]);
65695
- (0, import_react62.useEffect)(() => {
65564
+ (0, import_react61.useEffect)(() => {
65696
65565
  if (!pendingPivotRefresh) return;
65697
65566
  if (!nextPivot) {
65698
65567
  if (!sourceReport) {
@@ -65712,7 +65581,7 @@ function useReport(reportIdArg, options = {}) {
65712
65581
  shouldSkipPivotRefreshForUnchangedPivot,
65713
65582
  sourceReport
65714
65583
  ]);
65715
- const shouldSkipRedundantPivotTableDataReportBuilderQuery = (0, import_react62.useMemo)(() => {
65584
+ const shouldSkipRedundantPivotTableDataReportBuilderQuery = (0, import_react61.useMemo)(() => {
65716
65585
  if (!sourceReport || !nextPivot) {
65717
65586
  return false;
65718
65587
  }
@@ -65814,7 +65683,7 @@ function useReport(reportIdArg, options = {}) {
65814
65683
  });
65815
65684
  const tablePageReportBuilderState = pivotTableDataReportBuilderState ?? effectiveReportBuilderState;
65816
65685
  const tablePageReportBuilderStateHash = pivotTableDataReportBuilderState ? pivotTableDataReportBuilderStateHash : effectiveReportBuilderStateHash;
65817
- const tablePaginationSort = (0, import_react62.useMemo)(() => {
65686
+ const tablePaginationSort = (0, import_react61.useMemo)(() => {
65818
65687
  const sortEntry = tablePageReportBuilderState?.sort?.[0];
65819
65688
  const field = String(sortEntry?.field ?? "").trim();
65820
65689
  if (!field || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(field)) {
@@ -65876,7 +65745,7 @@ function useReport(reportIdArg, options = {}) {
65876
65745
  const tablePageRows = tablePageQueryEnabled && !tablePageQuery.data?.error && Array.isArray(tablePageQuery.data?.report?.rows) ? tablePageQuery.data.report.rows : void 0;
65877
65746
  const tablePageRowCount = tablePageQueryEnabled && typeof tablePageQuery.data?.report?.rowCount === "number" && tablePageQuery.data.report.rowCount > 0 ? tablePageQuery.data.report.rowCount : void 0;
65878
65747
  const tablePageFetching = tablePageQueryEnabled && tablePageQuery.isFetching;
65879
- const paginationTotalRowCount = (0, import_react62.useMemo)(() => {
65748
+ const paginationTotalRowCount = (0, import_react61.useMemo)(() => {
65880
65749
  if (tablePageRowCount !== void 0) {
65881
65750
  return Math.max(tablePageRowCount, baseWindowRowsLength);
65882
65751
  }
@@ -65899,7 +65768,7 @@ function useReport(reportIdArg, options = {}) {
65899
65768
  pagination.pageSize
65900
65769
  );
65901
65770
  paginationPageCountRef.current = paginationPageCount;
65902
- (0, import_react62.useEffect)(() => {
65771
+ (0, import_react61.useEffect)(() => {
65903
65772
  if (!pivotTableDataRefreshQueryEnabled) return;
65904
65773
  if (pivotTableDataRefreshQuery.status !== "success" && pivotTableDataRefreshQuery.status !== "error") {
65905
65774
  return;
@@ -65937,7 +65806,7 @@ function useReport(reportIdArg, options = {}) {
65937
65806
  effectiveReportId,
65938
65807
  useFormRefreshDebugEnabled
65939
65808
  ]);
65940
- (0, import_react62.useEffect)(() => {
65809
+ (0, import_react61.useEffect)(() => {
65941
65810
  if (!pivotRefreshQueryEnabled) return;
65942
65811
  if (pivotRefreshQuery.status !== "success" && pivotRefreshQuery.status !== "error") {
65943
65812
  return;
@@ -65990,7 +65859,7 @@ function useReport(reportIdArg, options = {}) {
65990
65859
  effectiveReportId,
65991
65860
  useFormRefreshDebugEnabled
65992
65861
  ]);
65993
- const chartData = (0, import_react62.useMemo)(() => {
65862
+ const chartData = (0, import_react61.useMemo)(() => {
65994
65863
  if (!sourceReport) return void 0;
65995
65864
  const rowsForChart = Array.isArray(sourceReport.rows) ? sourceReport.rows : [];
65996
65865
  const chartPivotForDisplay = nextPivot ?? (!chartPivotHydratedFromSourceRef.current ? sourceReport.pivot ?? null : null);
@@ -66026,18 +65895,18 @@ function useReport(reportIdArg, options = {}) {
66026
65895
  useInMemoryEngines,
66027
65896
  chartPivotHydrationEpoch
66028
65897
  ]);
66029
- const baseChart = (0, import_react62.useMemo)(
65898
+ const baseChart = (0, import_react61.useMemo)(
66030
65899
  () => normalizePivotChartForDisplay(chartData),
66031
65900
  [chartData]
66032
65901
  );
66033
- const chartAxesBaseChart = (0, import_react62.useMemo)(() => {
65902
+ const chartAxesBaseChart = (0, import_react61.useMemo)(() => {
66034
65903
  if (!chartData) return void 0;
66035
65904
  if (chartData.pivot?.columnField) {
66036
65905
  return normalizePivotChartForAxisControls(chartData, effectiveReportId);
66037
65906
  }
66038
65907
  return baseChart;
66039
65908
  }, [baseChart, chartData, effectiveReportId]);
66040
- const chartAxisOptions = (0, import_react62.useMemo)(() => {
65909
+ const chartAxisOptions = (0, import_react61.useMemo)(() => {
66041
65910
  if (!chartAxesBaseChart) return [];
66042
65911
  const optionsByField = /* @__PURE__ */ new Map();
66043
65912
  const registerOption = (fieldRaw, labelRaw, formatRaw) => {
@@ -66075,14 +65944,14 @@ function useReport(reportIdArg, options = {}) {
66075
65944
  );
66076
65945
  return Array.from(optionsByField.values());
66077
65946
  }, [chartAxesBaseChart]);
66078
- const chartAxisOptionByField = (0, import_react62.useMemo)(() => {
65947
+ const chartAxisOptionByField = (0, import_react61.useMemo)(() => {
66079
65948
  const optionsByField = /* @__PURE__ */ new Map();
66080
65949
  for (const option of chartAxisOptions) {
66081
65950
  optionsByField.set(option.value, option);
66082
65951
  }
66083
65952
  return optionsByField;
66084
65953
  }, [chartAxisOptions]);
66085
- const xAxisOptions = (0, import_react62.useMemo)(() => {
65954
+ const xAxisOptions = (0, import_react61.useMemo)(() => {
66086
65955
  if (!chartAxesBaseChart) return chartAxisOptions;
66087
65956
  const pivot = chartAxesBaseChart.pivot;
66088
65957
  const pivotRowField = String(pivot?.rowField ?? "").trim();
@@ -66105,7 +65974,7 @@ function useReport(reportIdArg, options = {}) {
66105
65974
  }
66106
65975
  return chartAxisOptions;
66107
65976
  }, [chartAxesBaseChart, chartAxisOptions, chartAxisOptionByField]);
66108
- const yAxisOptions = (0, import_react62.useMemo)(() => {
65977
+ const yAxisOptions = (0, import_react61.useMemo)(() => {
66109
65978
  if (!chartAxesBaseChart) return [];
66110
65979
  const keepOption = (option) => {
66111
65980
  const col = findSchemaColumnForChartAxisField(
@@ -66141,21 +66010,21 @@ function useReport(reportIdArg, options = {}) {
66141
66010
  chartAxisOptions,
66142
66011
  schemaColumnOptions
66143
66012
  ]);
66144
- const normalizedChartXAxisOptions = (0, import_react62.useMemo)(() => {
66013
+ const normalizedChartXAxisOptions = (0, import_react61.useMemo)(() => {
66145
66014
  return xAxisOptions.map((option) => ({
66146
66015
  value: String(option.value ?? "").trim(),
66147
66016
  label: String(option.label ?? option.value ?? "").trim(),
66148
66017
  format: String(option.format ?? "").trim()
66149
66018
  }));
66150
66019
  }, [xAxisOptions]);
66151
- const normalizedChartYAxisOptions = (0, import_react62.useMemo)(() => {
66020
+ const normalizedChartYAxisOptions = (0, import_react61.useMemo)(() => {
66152
66021
  return yAxisOptions.map((option) => ({
66153
66022
  value: String(option.value ?? "").trim(),
66154
66023
  label: String(option.label ?? option.value ?? "").trim(),
66155
66024
  format: String(option.format ?? "").trim()
66156
66025
  }));
66157
66026
  }, [yAxisOptions]);
66158
- const resolvedYAxisFields = (0, import_react62.useMemo)(() => {
66027
+ const resolvedYAxisFields = (0, import_react61.useMemo)(() => {
66159
66028
  if (!chartAxesBaseChart) return [];
66160
66029
  const normalizeYAxisField = (yAxisFieldRaw) => {
66161
66030
  const field = String(yAxisFieldRaw?.field ?? "").trim();
@@ -66198,7 +66067,7 @@ function useReport(reportIdArg, options = {}) {
66198
66067
  chartAxisOptionByField,
66199
66068
  chartAxisOptions
66200
66069
  ]);
66201
- const resolvedXAxisField = (0, import_react62.useMemo)(() => {
66070
+ const resolvedXAxisField = (0, import_react61.useMemo)(() => {
66202
66071
  if (!chartAxesBaseChart) return "";
66203
66072
  const chartType2 = String(chartAxesBaseChart.chartType ?? "").toLowerCase();
66204
66073
  const pivotRowField = String(
@@ -66230,7 +66099,7 @@ function useReport(reportIdArg, options = {}) {
66230
66099
  chartAxisOptions,
66231
66100
  resolvedYAxisFields
66232
66101
  ]);
66233
- const resolvedXAxisFormat = (0, import_react62.useMemo)(() => {
66102
+ const resolvedXAxisFormat = (0, import_react61.useMemo)(() => {
66234
66103
  if (!chartAxesBaseChart) {
66235
66104
  return "string";
66236
66105
  }
@@ -66258,7 +66127,7 @@ function useReport(reportIdArg, options = {}) {
66258
66127
  resolvedXAxisField,
66259
66128
  resolvedYAxisFields
66260
66129
  ]);
66261
- const resolvedXAxisLabel = (0, import_react62.useMemo)(() => {
66130
+ const resolvedXAxisLabel = (0, import_react61.useMemo)(() => {
66262
66131
  const defaultXLabel = String(
66263
66132
  chartAxesBaseChart?.xAxisLabel ?? chartAxisOptionByField.get(resolvedXAxisField)?.label ?? ""
66264
66133
  ).trim();
@@ -66272,13 +66141,13 @@ function useReport(reportIdArg, options = {}) {
66272
66141
  chartAxisOptionByField,
66273
66142
  resolvedXAxisField
66274
66143
  ]);
66275
- const chartVisibility = (0, import_react62.useMemo)(
66144
+ const chartVisibility = (0, import_react61.useMemo)(
66276
66145
  () => ({
66277
66146
  showLegend: chartVisibilityOverrides.showLegend ?? Boolean(baseChart?.showLegend ?? false)
66278
66147
  }),
66279
66148
  [baseChart?.showLegend, chartVisibilityOverrides]
66280
66149
  );
66281
- const axisConfig = (0, import_react62.useMemo)(() => {
66150
+ const axisConfig = (0, import_react61.useMemo)(() => {
66282
66151
  const pivotBucketXAxis = isPivotTableDateBucketRowAxis(
66283
66152
  chartAxesBaseChart,
66284
66153
  resolvedXAxisField
@@ -66320,14 +66189,14 @@ function useReport(reportIdArg, options = {}) {
66320
66189
  resolvedYAxisFields,
66321
66190
  chartVisibility.showLegend
66322
66191
  ]);
66323
- const resolvedYAxisFieldsForDisplay = (0, import_react62.useMemo)(() => {
66192
+ const resolvedYAxisFieldsForDisplay = (0, import_react61.useMemo)(() => {
66324
66193
  if (!baseChart) return resolvedYAxisFields;
66325
66194
  return mapResolvedPivotYAxisFieldsForDisplay({
66326
66195
  chart: baseChart,
66327
66196
  resolvedYAxisFields
66328
66197
  });
66329
66198
  }, [baseChart, resolvedYAxisFields]);
66330
- const chart = (0, import_react62.useMemo)(() => {
66199
+ const chart = (0, import_react61.useMemo)(() => {
66331
66200
  if (!baseChart) return void 0;
66332
66201
  let columns2 = mergeChartColumnFormatsFromYAxisFields(
66333
66202
  baseChart.columns,
@@ -66379,7 +66248,7 @@ function useReport(reportIdArg, options = {}) {
66379
66248
  const isPivotTableChart = String(chartType ?? "").toLowerCase() === "table" && Boolean(
66380
66249
  chart && chart.pivot && Array.isArray(chart.columns) && chart.columns.length > 0
66381
66250
  );
66382
- const chartAxes = (0, import_react62.useMemo)(() => {
66251
+ const chartAxes = (0, import_react61.useMemo)(() => {
66383
66252
  const yAxisItems = resolvedYAxisFields.map(
66384
66253
  (yAxisField, index) => ({
66385
66254
  id: String(index),
@@ -66528,8 +66397,8 @@ function useReport(reportIdArg, options = {}) {
66528
66397
  xAxisOptions,
66529
66398
  yAxisOptions
66530
66399
  ]);
66531
- const tableFormatCacheRef = (0, import_react62.useRef)(/* @__PURE__ */ new Map());
66532
- const tableFormatMerge = (0, import_react62.useMemo)(
66400
+ const tableFormatCacheRef = (0, import_react61.useRef)(/* @__PURE__ */ new Map());
66401
+ const tableFormatMerge = (0, import_react61.useMemo)(
66533
66402
  () => mergeDisplayAndSourceForTableFormats({
66534
66403
  effectiveReportBuilderTableNames,
66535
66404
  scopedSchemaColumns,
@@ -66543,7 +66412,7 @@ function useReport(reportIdArg, options = {}) {
66543
66412
  sourceReport
66544
66413
  ]
66545
66414
  );
66546
- const table = (0, import_react62.useMemo)(() => {
66415
+ const table = (0, import_react61.useMemo)(() => {
66547
66416
  const baseWindowRows = Array.isArray(sourceReport?.rows) ? sourceReport.rows : [];
66548
66417
  const rawRows = !paginationActive ? baseWindowRows : tablePageRows ?? baseWindowRows.slice(paginationRangeStart, paginationRangeEnd);
66549
66418
  const { columns: mergedFromReport } = mergeDisplayAndSourceForTableFormats({
@@ -66672,7 +66541,7 @@ function useReport(reportIdArg, options = {}) {
66672
66541
  const {
66673
66542
  columnsOptions: tableFormattingColumnOptions,
66674
66543
  hasTableDrivenColumnOrder
66675
- } = (0, import_react62.useMemo)(() => {
66544
+ } = (0, import_react61.useMemo)(() => {
66676
66545
  if (isPivotTableChart && chart?.columns?.length) {
66677
66546
  const aggregationSlotColumns = buildPivotColumnPivotTableFormattingColumns(chart);
66678
66547
  const pivotTableColumns = aggregationSlotColumns ? aggregationSlotColumns.tableColumns : chart.columns.map((c) => ({
@@ -66706,7 +66575,7 @@ function useReport(reportIdArg, options = {}) {
66706
66575
  schemaColumnOptions,
66707
66576
  table.columns
66708
66577
  ]);
66709
- const availableFields = (0, import_react62.useMemo)(
66578
+ const availableFields = (0, import_react61.useMemo)(
66710
66579
  () => tableColumnPickerPoolOptions.map((option) => ({
66711
66580
  id: option.value,
66712
66581
  label: option.label,
@@ -66714,24 +66583,24 @@ function useReport(reportIdArg, options = {}) {
66714
66583
  })),
66715
66584
  [tableColumnPickerPoolOptions]
66716
66585
  );
66717
- const axisSelectFormatLabels = (0, import_react62.useMemo)(
66586
+ const axisSelectFormatLabels = (0, import_react61.useMemo)(
66718
66587
  () => AXIS_FORMAT_OPTIONS.map((option) => option.label),
66719
66588
  []
66720
66589
  );
66721
- const xAxisFormatOptionLabels = (0, import_react62.useMemo)(() => {
66590
+ const xAxisFormatOptionLabels = (0, import_react61.useMemo)(() => {
66722
66591
  if (isPivotTableDateBucketRowAxis(chartAxesBaseChart, resolvedXAxisField)) {
66723
66592
  return ["date", ...axisSelectFormatLabels];
66724
66593
  }
66725
66594
  return axisSelectFormatLabels;
66726
66595
  }, [chartAxesBaseChart, resolvedXAxisField, axisSelectFormatLabels]);
66727
- const tableDerivedColumnOrder = (0, import_react62.useMemo)(() => {
66596
+ const tableDerivedColumnOrder = (0, import_react61.useMemo)(() => {
66728
66597
  return tableFormattingColumnOptions.map((option) => option.value);
66729
66598
  }, [tableFormattingColumnOptions]);
66730
- const tableDerivedColumnOrderSignature = (0, import_react62.useMemo)(
66599
+ const tableDerivedColumnOrderSignature = (0, import_react61.useMemo)(
66731
66600
  () => tableDerivedColumnOrder.join("|"),
66732
66601
  [tableDerivedColumnOrder]
66733
66602
  );
66734
- const activeTableColumnIds = (0, import_react62.useMemo)(() => {
66603
+ const activeTableColumnIds = (0, import_react61.useMemo)(() => {
66735
66604
  if (isPivotTableChart && chart?.columns?.length) {
66736
66605
  const aggregationSlotColumns = buildPivotColumnPivotTableFormattingColumns(chart);
66737
66606
  if (aggregationSlotColumns) {
@@ -66770,7 +66639,7 @@ function useReport(reportIdArg, options = {}) {
66770
66639
  tableDerivedColumnOrder,
66771
66640
  tableFormattingColumnOptions
66772
66641
  ]);
66773
- const columnOptionById = (0, import_react62.useMemo)(() => {
66642
+ const columnOptionById = (0, import_react61.useMemo)(() => {
66774
66643
  const map = /* @__PURE__ */ new Map();
66775
66644
  for (const option of tableColumnPickerPoolOptions) {
66776
66645
  map.set(option.value, option);
@@ -66782,7 +66651,7 @@ function useReport(reportIdArg, options = {}) {
66782
66651
  }
66783
66652
  return map;
66784
66653
  }, [tableColumnPickerPoolOptions, tableFormattingColumnOptions]);
66785
- const displayColumnById = (0, import_react62.useMemo)(() => {
66654
+ const displayColumnById = (0, import_react61.useMemo)(() => {
66786
66655
  const map = /* @__PURE__ */ new Map();
66787
66656
  for (const column of displayColumns) {
66788
66657
  const field = String(column.field ?? "").trim();
@@ -66793,7 +66662,7 @@ function useReport(reportIdArg, options = {}) {
66793
66662
  }
66794
66663
  return map;
66795
66664
  }, [displayColumns]);
66796
- const tableColumnSettingsById = (0, import_react62.useMemo)(() => {
66665
+ const tableColumnSettingsById = (0, import_react61.useMemo)(() => {
66797
66666
  const map = /* @__PURE__ */ new Map();
66798
66667
  const effectiveById = tableFormatMerge.formatByColumnOptionId;
66799
66668
  const chartColById = /* @__PURE__ */ new Map();
@@ -66911,13 +66780,13 @@ function useReport(reportIdArg, options = {}) {
66911
66780
  sourceReport?.columns,
66912
66781
  tableFormatMerge
66913
66782
  ]);
66914
- const tableColumnSettingsCoalesceRef = (0, import_react62.useRef)(
66783
+ const tableColumnSettingsCoalesceRef = (0, import_react61.useRef)(
66915
66784
  /* @__PURE__ */ new Map()
66916
66785
  );
66917
- (0, import_react62.useLayoutEffect)(() => {
66786
+ (0, import_react61.useLayoutEffect)(() => {
66918
66787
  tableColumnSettingsCoalesceRef.current = new Map(tableColumnSettingsById);
66919
66788
  }, [tableColumnSettingsById]);
66920
- const tableColumnItems = (0, import_react62.useMemo)(() => {
66789
+ const tableColumnItems = (0, import_react61.useMemo)(() => {
66921
66790
  const pivotRowFieldForFormat = String(chart?.pivot?.rowField ?? "").trim();
66922
66791
  const pivotRowFieldType = String(chart?.pivot?.rowFieldType ?? "").trim();
66923
66792
  const items = activeTableColumnIds.map((columnId) => {
@@ -66953,19 +66822,18 @@ function useReport(reportIdArg, options = {}) {
66953
66822
  isPivotTableChart,
66954
66823
  tableColumnSettingsById
66955
66824
  ]);
66956
- const tableColumnById = (0, import_react62.useMemo)(() => {
66825
+ const tableColumnById = (0, import_react61.useMemo)(() => {
66957
66826
  return new Map(tableColumnItems.map((item) => [item.id, item]));
66958
66827
  }, [tableColumnItems]);
66959
- const tableColumnList = (0, import_react62.useMemo)(() => {
66828
+ const tableColumnValues = (0, import_react61.useMemo)(() => {
66960
66829
  const pivotRowFieldForFormat = String(chart?.pivot?.rowField ?? "").trim();
66961
66830
  const pivotRowFieldType = String(chart?.pivot?.rowFieldType ?? "").trim();
66962
66831
  return tableColumnItems.map((item) => {
66963
66832
  const coerced = coerceTableColumnFormatToAxisValue(item.format);
66964
66833
  const usePivotDateOptions = isPivotTableChart && item.field === pivotRowFieldForFormat && isDateType(pivotRowFieldType) && coerced === "string";
66965
66834
  return {
66966
- id: item.id,
66835
+ value: item.id,
66967
66836
  label: item.label,
66968
- visible: true,
66969
66837
  format: item.formatLabel,
66970
66838
  ...usePivotDateOptions ? { formatOptions: [...PIVOT_DATE_BUCKET_FORMAT_OPTIONS] } : {}
66971
66839
  };
@@ -67128,22 +66996,32 @@ function useReport(reportIdArg, options = {}) {
67128
66996
  columns: buildSetReportColumnsFromIds(nextColumnIds, nextSettingsById)
67129
66997
  };
67130
66998
  };
67131
- 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
+ };
67132
67018
  const commitTableColumns = (nextColumnIds, settingsById) => {
67133
- setReport({
67019
+ applyReportChange({
67134
67020
  columns: buildSetReportColumnsFromIds(nextColumnIds, settingsById)
67135
67021
  });
67136
67022
  };
67137
- setReport = (nextState) => {
67138
- let effectiveNextState = nextState;
67139
- if (isSetReportTableColumnSidebarPatch(nextState.columns)) {
67140
- const expanded = buildColumnSidebarSetReportInput(
67141
- nextState.columns.patch
67142
- );
67143
- if (!expanded) return;
67144
- const { columns: _omitSidebarColumnPatch, ...rest } = nextState;
67145
- effectiveNextState = { ...rest, ...expanded };
67146
- }
67023
+ applyReportChange = (nextState) => {
67024
+ const effectiveNextState = nextState;
67147
67025
  if (effectiveNextState.showLegend !== void 0) {
67148
67026
  setChartVisibilityOverrides((previous) => ({
67149
67027
  ...previous,
@@ -67216,15 +67094,18 @@ function useReport(reportIdArg, options = {}) {
67216
67094
  });
67217
67095
  }
67218
67096
  const isPivotSortUpdate = effectiveNextState.sort !== void 0 && Boolean(nextPivot);
67219
- 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;
67220
- const isAppendingEmptyAggregationPlaceholder = indexedAggregationUpdate !== null && indexedAggregationUpdate.index === aggregationState.length && String(indexedAggregationUpdate.value ?? "").trim().length === 0;
67221
- 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;
67222
67103
  const isDatasourceUpdate = effectiveNextState.datasources !== void 0;
67223
67104
  const hasRowGroupSelection = typeof effectiveNextState.groupRowsBy === "string" && effectiveNextState.groupRowsBy.trim().length > 0;
67224
67105
  const hasColumnGroupSelection = typeof effectiveNextState.groupColumnsBy === "string" && effectiveNextState.groupColumnsBy.trim().length > 0;
67225
- const hasAggregationSelection = effectiveNextState.aggregations !== void 0 && (typeof effectiveNextState.aggregations === "string" ? effectiveNextState.aggregations.trim().length > 0 : Array.isArray(effectiveNextState.aggregations) ? effectiveNextState.aggregations.some(
67226
- (aggregation) => Boolean(aggregation?.aggregationType) && Boolean(String(aggregation?.valueField ?? "").trim())
67227
- ) : 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
+ ));
67228
67109
  const isClearingRowGrouping = effectiveNextState.groupRowsBy !== void 0 && String(effectiveNextState.groupRowsBy ?? "").trim().length === 0;
67229
67110
  const queuePromoteColumnToRow = isClearingRowGrouping && !sourceReport;
67230
67111
  const shouldRefreshExpandedTableData = useInMemoryEngines && (hasRowGroupSelection || hasColumnGroupSelection || hasAggregationSelection) || !useInMemoryEngines && !nextPivot && effectiveNextState.sort !== void 0;
@@ -67297,7 +67178,7 @@ function useReport(reportIdArg, options = {}) {
67297
67178
  }
67298
67179
  }
67299
67180
  }
67300
- if (effectiveNextState.columns !== void 0 && !isSetReportTableColumnSidebarPatch(effectiveNextState.columns)) {
67181
+ if (effectiveNextState.columns !== void 0) {
67301
67182
  const normalizedDisplayColumns = normalizeColumnsInput(
67302
67183
  effectiveNextState.columns,
67303
67184
  columnIdentifierLookup
@@ -67384,6 +67265,10 @@ function useReport(reportIdArg, options = {}) {
67384
67265
  groupColumnsBySetViaSetReportRef.current = true;
67385
67266
  next.groupColumnsBy = effectiveNextState.groupColumnsBy || void 0;
67386
67267
  }
67268
+ if (effectiveNextState.dateBucket !== void 0) {
67269
+ dateBucketSetViaSetReportRef.current = true;
67270
+ next.dateBucket = effectiveNextState.dateBucket || void 0;
67271
+ }
67387
67272
  if (effectiveNextState.aggregations !== void 0) {
67388
67273
  aggregationStateSetViaSetReportRef.current = true;
67389
67274
  next.aggregationTablesByIndex = [...next.aggregationTablesByIndex];
@@ -67398,54 +67283,7 @@ function useReport(reportIdArg, options = {}) {
67398
67283
  ],
67399
67284
  schemaForeignKeyMap
67400
67285
  ).map((table2) => table2.name).filter((name2) => Boolean(name2));
67401
- if (typeof effectiveNextState.aggregations === "object" && !Array.isArray(effectiveNextState.aggregations) && "index" in effectiveNextState.aggregations && "value" in effectiveNextState.aggregations) {
67402
- const { index, value } = effectiveNextState.aggregations;
67403
- if (index >= 0 && index <= next.aggregationState.length) {
67404
- const rawValue = String(value ?? "").trim();
67405
- next.aggregationState = [...next.aggregationState];
67406
- if (!rawValue) {
67407
- if (index === next.aggregationState.length) {
67408
- next.aggregationState.push({ valueField: "" });
67409
- next.aggregationTablesByIndex.push(void 0);
67410
- } else if (index < next.aggregationState.length) {
67411
- next.aggregationState.splice(index, 1);
67412
- next.aggregationTablesByIndex.splice(index, 1);
67413
- }
67414
- } else {
67415
- const [aggregationTypeRaw] = rawValue.split(":");
67416
- const aggregationType = aggregationTypeRaw;
67417
- const { field: target, table: table2 } = resolveAggregationSelection(
67418
- rawValue,
67419
- aggregationOptionTableLookup,
67420
- preferredTables
67421
- );
67422
- const normalizedSelection = normalizeAggregationSelection(
67423
- aggregationType,
67424
- target,
67425
- table2,
67426
- preferredTables
67427
- );
67428
- const existing = next.aggregationState[index];
67429
- const preservedValueField2 = aggregationType !== "percentage" && existing?.valueField2 ? { valueField2: existing.valueField2 } : {};
67430
- const nextAggregation = {
67431
- ...preservedValueField2,
67432
- aggregationType,
67433
- ...normalizedSelection.valueField ? { valueField: normalizedSelection.valueField } : {},
67434
- ...normalizedSelection.valueField2 ? { valueField2: normalizedSelection.valueField2 } : {},
67435
- ...normalizedSelection.table ? { valueFieldTable: normalizedSelection.table } : {}
67436
- };
67437
- if (index === next.aggregationState.length) {
67438
- next.aggregationState.push(nextAggregation);
67439
- next.aggregationTablesByIndex.push(
67440
- normalizedSelection.table || void 0
67441
- );
67442
- } else {
67443
- next.aggregationState[index] = nextAggregation;
67444
- next.aggregationTablesByIndex[index] = normalizedSelection.table || void 0;
67445
- }
67446
- }
67447
- }
67448
- } else if (typeof effectiveNextState.aggregations === "string") {
67286
+ if (typeof effectiveNextState.aggregations === "string") {
67449
67287
  const rawValue = effectiveNextState.aggregations.trim();
67450
67288
  if (!rawValue) {
67451
67289
  next.aggregationState = [];
@@ -67477,15 +67315,49 @@ function useReport(reportIdArg, options = {}) {
67477
67315
  ];
67478
67316
  }
67479
67317
  } else {
67480
- next.aggregationState = effectiveNextState.aggregations;
67481
- next.aggregationTablesByIndex = effectiveNextState.aggregations.map(
67482
- (aggregation) => String(aggregation.valueFieldTable ?? "").trim() || resolveFieldTable({
67483
- report: sourceReport,
67484
- field: aggregation.valueField,
67485
- schemaTables: schemaForReportBuilderState,
67486
- preferredTables
67487
- }) || 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
+ }
67488
67358
  );
67359
+ next.aggregationState = decoded.map((entry) => entry.aggregation);
67360
+ next.aggregationTablesByIndex = decoded.map((entry) => entry.table);
67489
67361
  }
67490
67362
  }
67491
67363
  if (effectiveNextState.sort !== void 0) {
@@ -67600,29 +67472,9 @@ function useReport(reportIdArg, options = {}) {
67600
67472
  }
67601
67473
  });
67602
67474
  };
67603
- const tableColumns = {
67604
- items: tableColumnItems,
67605
- optionById: columnOptionById,
67606
- byId: tableColumnById,
67607
- columnList: tableColumnList,
67608
- getSetReportColumns: (ids) => {
67609
- const out = [];
67610
- for (const rawId of ids) {
67611
- const id = String(rawId ?? "").trim();
67612
- if (!id) continue;
67613
- const option = columnOptionById.get(id);
67614
- if (!option) continue;
67615
- const item = tableColumnById.get(id);
67616
- const customLabel = String(item?.customLabel ?? "").trim();
67617
- const format9 = String(item?.format ?? "").trim();
67618
- out.push({
67619
- field: option.field,
67620
- ...option.tableName ? { table: option.tableName } : {},
67621
- ...customLabel ? { label: customLabel } : {},
67622
- ...format9 ? { format: format9 } : {}
67623
- });
67624
- }
67625
- return out;
67475
+ const columnActions = {
67476
+ replace: (nextColumns) => {
67477
+ applyReportChange({ columns: nextColumns });
67626
67478
  },
67627
67479
  reorder: (oldIndex, newIndex) => {
67628
67480
  if (loading || isPivotTableChart) return;
@@ -67686,21 +67538,15 @@ function useReport(reportIdArg, options = {}) {
67686
67538
  setTableColumnsEditedSignature(tableDerivedColumnOrderSignature);
67687
67539
  commitTableColumns(nextColumnIds, tableColumnSettingsById);
67688
67540
  },
67689
- getColumnSidebarSetReportInput: (id, updates) => {
67690
- const normalizedId = String(id ?? "").trim();
67691
- if (!normalizedId) return null;
67692
- return {
67693
- columns: { patch: { id: normalizedId, ...updates } }
67694
- };
67695
- },
67696
67541
  update: (id, updates) => {
67697
67542
  const normalizedId = String(id ?? "").trim();
67698
67543
  if (!normalizedId) return;
67699
- setReport({
67700
- columns: { patch: { id: normalizedId, ...updates } }
67544
+ const expanded = buildColumnSidebarSetReportInput({
67545
+ id: normalizedId,
67546
+ ...updates
67701
67547
  });
67702
- },
67703
- structureEditsLocked: isPivotTableChart
67548
+ if (expanded) applyReportChange(expanded);
67549
+ }
67704
67550
  };
67705
67551
  const setFilters = (nextFilters) => {
67706
67552
  const preparedForStack = prepareQueryBuilderFiltersForSet(
@@ -67758,13 +67604,7 @@ function useReport(reportIdArg, options = {}) {
67758
67604
  }
67759
67605
  }
67760
67606
  };
67761
- const filterDraft = useReportFilterDraft({
67762
- reportId: effectiveReportId,
67763
- committedFilters: filtersForQueryBuilder,
67764
- queryBuilderProps: filterQueryBuilderProps,
67765
- setFilters
67766
- });
67767
- const saveChanges = (0, import_react62.useCallback)(async () => {
67607
+ const saveChanges = (0, import_react61.useCallback)(async () => {
67768
67608
  if (!client) return;
67769
67609
  if (!String(dashboardNameForNewReport ?? "").trim()) return;
67770
67610
  if (!sourceReport) return;
@@ -67842,17 +67682,23 @@ function useReport(reportIdArg, options = {}) {
67842
67682
  groupRowsByOptions,
67843
67683
  groupColumnsBy,
67844
67684
  groupColumnsByOptions,
67845
- 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. */
67846
67690
  aggregationOptions,
67847
67691
  aggregationDescriptionOptions: cleanedAggregations,
67848
67692
  sort: cleanedSort,
67849
67693
  sortOptions,
67850
67694
  chartType,
67851
67695
  chartTypeOptions: chartTypes,
67852
- /** Encoded field keys for the current column selection (for `setReport({ columns })`, etc.). */
67853
- columnIds: columns,
67854
- /** Selected columns + `reorder` / `toggle` / `update` / `remove`. */
67855
- 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,
67856
67702
  /** Schema columns for current datasources — pool for the table column picker. */
67857
67703
  columnOptions: tableColumnPickerPoolOptions,
67858
67704
  xAxis: chartAxes.xAxis,
@@ -67879,13 +67725,6 @@ function useReport(reportIdArg, options = {}) {
67879
67725
  hasTableDrivenColumnOrder,
67880
67726
  filters: filtersForQueryBuilder,
67881
67727
  filterQueryBuilderProps,
67882
- /**
67883
- * Draft → Apply lifecycle for react-querybuilder (flat keys):
67884
- * `<QueryBuilder key={filterDraftKey} {...filterDraftQueryBuilderProps} />`
67885
- * plus `isFilterDraftDirty` / `isFilterDraftEmpty` /
67886
- * `commitFilterDraft` / `resetFilterDraft` / `seedFilterDraft`.
67887
- */
67888
- ...filterDraft,
67889
67728
  /** True while `report-builder-unique-values` runs for filter value options (not chart/table load). */
67890
67729
  filterUniqueValuesLoading,
67891
67730
  limit,
@@ -67893,7 +67732,6 @@ function useReport(reportIdArg, options = {}) {
67893
67732
  chartTypes,
67894
67733
  columnsOptions: tableColumnPickerPoolOptions,
67895
67734
  tableColumnOptions: tableColumnPickerPoolOptions,
67896
- tableColumns,
67897
67735
  setReport,
67898
67736
  saveChanges,
67899
67737
  setFilters,
@@ -67911,7 +67749,7 @@ function ChatChartCard({
67911
67749
  ButtonComponent = MemoizedButton
67912
67750
  }) {
67913
67751
  const {
67914
- columnIds,
67752
+ columns,
67915
67753
  columnOptions,
67916
67754
  groupRowsBy,
67917
67755
  groupRowsByOptions,
@@ -67925,20 +67763,10 @@ function ChatChartCard({
67925
67763
  loading,
67926
67764
  setReport
67927
67765
  } = useReport(reportId);
67928
- const columnSelectOptions = (0, import_react63.useMemo)(() => {
67929
- return (columnOptions ?? []).map((option) => {
67930
- const value = String(option?.value ?? "").trim();
67931
- if (!value) return null;
67932
- const tableName = String(option?.tableName ?? "").trim();
67933
- const fieldName = String(option?.field ?? "").trim() || String(option?.label ?? "").trim() || value;
67934
- return {
67935
- value,
67936
- label: tableName ? `${tableName}.${fieldName}` : fieldName
67937
- };
67938
- }).filter(
67939
- (option) => Boolean(option)
67940
- );
67941
- }, [columnOptions]);
67766
+ const selectedColumnValues = (0, import_react62.useMemo)(
67767
+ () => columns.map((column) => column.value),
67768
+ [columns]
67769
+ );
67942
67770
  return /* @__PURE__ */ (0, import_jsx_runtime87.jsxs)(
67943
67771
  "div",
67944
67772
  {
@@ -67974,7 +67802,7 @@ function ChatChartCard({
67974
67802
  padding: 16
67975
67803
  },
67976
67804
  children: [
67977
- JSON.stringify(columnIds, null, 2),
67805
+ JSON.stringify(columns, null, 2),
67978
67806
  /* @__PURE__ */ (0, import_jsx_runtime87.jsxs)(
67979
67807
  "label",
67980
67808
  {
@@ -67991,13 +67819,24 @@ function ChatChartCard({
67991
67819
  "select",
67992
67820
  {
67993
67821
  multiple: true,
67994
- size: Math.min(10, Math.max(4, columnSelectOptions.length || 4)),
67995
- value: columnIds,
67822
+ size: Math.min(10, Math.max(4, columnOptions.length || 4)),
67823
+ value: selectedColumnValues,
67996
67824
  onChange: (event) => {
67997
- const nextColumns = Array.from(event.target.selectedOptions).map(
67998
- (option) => option.value
67825
+ const selectedByValue = new Map(
67826
+ columns.map((column) => [column.value, column])
67827
+ );
67828
+ const optionByValue = new Map(
67829
+ columnOptions.map((option) => [option.value, option])
67999
67830
  );
68000
- setReport({ columns: nextColumns });
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
+ });
68001
67840
  },
68002
67841
  style: {
68003
67842
  width: 200,
@@ -68007,7 +67846,7 @@ function ChatChartCard({
68007
67846
  padding: 8,
68008
67847
  background: "#fff"
68009
67848
  },
68010
- 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))
68011
67850
  }
68012
67851
  )
68013
67852
  ]
@@ -68033,28 +67872,27 @@ function ChatChartCard({
68033
67872
  onChange: (e) => setReport({ groupColumnsBy: e.target.value ?? "" })
68034
67873
  }
68035
67874
  ),
68036
- aggregationOptions.map((row, index) => /* @__PURE__ */ (0, import_jsx_runtime87.jsx)(
67875
+ aggregations.map((value, index) => /* @__PURE__ */ (0, import_jsx_runtime87.jsx)(
68037
67876
  SelectComponent,
68038
67877
  {
68039
- value: row.value,
68040
- label: row.label,
67878
+ value,
67879
+ label: `Aggregation ${index + 1}`,
68041
67880
  width: 200,
68042
- options: row.options,
67881
+ options: aggregationOptions,
68043
67882
  onChange: (e) => setReport({
68044
- aggregations: { index, value: e.target.value ?? "" }
67883
+ aggregations: aggregations.map(
67884
+ (aggregation, i) => i === index ? e.target.value ?? "" : aggregation
67885
+ )
68045
67886
  })
68046
67887
  },
68047
- row.key
67888
+ `aggregation-${index}`
68048
67889
  )),
68049
67890
  /* @__PURE__ */ (0, import_jsx_runtime87.jsx)(
68050
67891
  ButtonComponent,
68051
67892
  {
68052
67893
  label: "Add aggregation",
68053
67894
  onClick: () => setReport({
68054
- aggregations: {
68055
- index: aggregations.length,
68056
- value: "count transactions"
68057
- }
67895
+ aggregations: [...aggregations, "count:transactions"]
68058
67896
  })
68059
67897
  }
68060
67898
  ),
@@ -68192,7 +68030,7 @@ function ToolCallBlock({ toolCall }) {
68192
68030
  );
68193
68031
  }
68194
68032
  function ToolCallResult({ content }) {
68195
- const [expanded, setExpanded] = (0, import_react64.useState)(false);
68033
+ const [expanded, setExpanded] = (0, import_react63.useState)(false);
68196
68034
  if (!content) return null;
68197
68035
  const isLong = content.length > 300;
68198
68036
  const displayed = isLong && !expanded ? content.slice(0, 300) + "..." : content;
@@ -68244,18 +68082,18 @@ function Chat({
68244
68082
  agentEndpoint,
68245
68083
  suggestions
68246
68084
  }) {
68247
- const [client] = (0, import_react64.useContext)(ClientContext);
68248
- const { getToken } = (0, import_react64.useContext)(FetchContext);
68249
- const { tenants } = (0, import_react64.useContext)(TenantContext);
68250
- const [messages, setMessages] = (0, import_react64.useState)([]);
68251
- const [input, setInput] = (0, import_react64.useState)("");
68252
- const [inputError, setInputError] = (0, import_react64.useState)("");
68253
- const [isLoading, setIsLoading] = (0, import_react64.useState)(false);
68254
- const [model, setModel] = (0, import_react64.useState)("gemini-3-flash-preview");
68255
- const containerRef = (0, import_react64.useRef)(null);
68256
- const textareaRef = (0, import_react64.useRef)(null);
68257
- const abortControllerRef = (0, import_react64.useRef)(null);
68258
- (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)(() => {
68259
68097
  if (!containerRef.current) {
68260
68098
  return;
68261
68099
  }
@@ -68688,6 +68526,150 @@ function Chat({
68688
68526
  );
68689
68527
  }
68690
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
+
68691
68673
  // src/ReportDetail.tsx
68692
68674
  var import_react65 = require("react");
68693
68675
  var import_jsx_runtime89 = require("react/jsx-runtime");
@@ -69818,7 +69800,6 @@ init_constants();
69818
69800
  Table,
69819
69801
  ThemeContext,
69820
69802
  areQueryBuilderFilterDraftsDirty,
69821
- buildSeededFilterQuery,
69822
69803
  countFilterRules,
69823
69804
  defaultFilterRuleValueForOperator,
69824
69805
  downloadCSV,
@@ -69843,6 +69824,7 @@ init_constants();
69843
69824
  useQuill,
69844
69825
  useReport,
69845
69826
  useReportBuilder,
69827
+ useReportQueryBuilder,
69846
69828
  useReports,
69847
69829
  useTenants,
69848
69830
  useVirtualTables