@quillsql/react 2.16.67 → 2.16.69

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
@@ -17269,6 +17269,7 @@ async function generatePivotWithSQL({
17269
17269
  sort: pivot.sort,
17270
17270
  sortDirection: pivot.sortDirection,
17271
17271
  sortField: pivot.sortField,
17272
+ sortFieldTable: pivot.sortFieldTable,
17272
17273
  sortFieldType: pivot.sortFieldType,
17273
17274
  rowLimit: pivot.rowLimit,
17274
17275
  dateBucket: resolvedDateBucket
@@ -28132,12 +28133,10 @@ var useDashboardReportInternal = (reportId, config) => {
28132
28133
  const { dashboardCustomFilters } = (0, import_react2.useContext)(DashboardFiltersContext);
28133
28134
  const reportState = reports[reportId];
28134
28135
  const reportDashboardName = reportState?.dashboardName;
28136
+ const reportDashboardFilterState = reportDashboardName ? dashboardFilters[reportDashboardName] : void 0;
28135
28137
  const reportDashboardFilters = (0, import_react2.useMemo)(() => {
28136
- if (!reportDashboardName) return [];
28137
- return Object.values(dashboardFilters[reportDashboardName] ?? {}).map(
28138
- (f) => f.filter
28139
- );
28140
- }, [dashboardFilters, reportDashboardName]);
28138
+ return Object.values(reportDashboardFilterState ?? {}).map((f) => f.filter);
28139
+ }, [reportDashboardFilterState]);
28141
28140
  const {
28142
28141
  data: dashboardData,
28143
28142
  dashboardFilters: dashboardFiltersInternal,
@@ -31769,7 +31768,7 @@ var import_jsx_runtime28 = require("react/jsx-runtime");
31769
31768
  var defaultValueFormatter = (value) => (value * 1).toFixed(1) + "%";
31770
31769
  var parseData2 = (data, colors, categoryKey, valueKey) => {
31771
31770
  const maxItems = 20;
31772
- const slicedData = deepCopy(data).slice(0, maxItems);
31771
+ const slicedData = deepCopy(data.slice(0, maxItems));
31773
31772
  const totalValue = slicedData.reduce(
31774
31773
  (acc, dataPoint) => (
31775
31774
  // Big(acc)
@@ -32015,8 +32014,8 @@ var PieChartWrapper = import_react13.default.forwardRef(
32015
32014
  category = "pct_of_the_total",
32016
32015
  index = "status",
32017
32016
  data,
32018
- colors = [],
32019
- colorMap = {},
32017
+ colors,
32018
+ colorMap,
32020
32019
  variant = "donut",
32021
32020
  valueFormatter: valueFormatter2 = defaultValueFormatter,
32022
32021
  className,
@@ -32026,10 +32025,24 @@ var PieChartWrapper = import_react13.default.forwardRef(
32026
32025
  onClickLegendElement,
32027
32026
  yAxisFields,
32028
32027
  showLegend = false,
32028
+ showAnimation,
32029
+ isAnimationActive,
32029
32030
  ...other
32030
32031
  } = props;
32031
32032
  const isDonut = variant == "donut";
32032
- if (!data || data.length === 0) {
32033
+ const chartData = data ?? [];
32034
+ const parsedData = (0, import_react13.useMemo)(() => {
32035
+ const palette = colorMap?.[category]?.primary ?? colors ?? [];
32036
+ const containsCssVars = palette.some(
32037
+ (color) => typeof color === "string" && color.includes("var(")
32038
+ );
32039
+ const resolvedColors = containsCssVars ? Array.from({ length: chartData.length }).map(
32040
+ (_, idx) => palette[idx % palette.length] ?? palette[palette.length - 1] ?? "#808080"
32041
+ ) : palette.length >= chartData.length ? palette.slice(0, chartData.length) : generateArrayFromColor(palette, chartData.length);
32042
+ return parseData2(chartData, resolvedColors, index, category);
32043
+ }, [category, colorMap, colors, chartData, index]);
32044
+ const animationActive = isAnimationActive ?? showAnimation ?? true;
32045
+ if (chartData.length === 0) {
32033
32046
  return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
32034
32047
  "div",
32035
32048
  {
@@ -32072,28 +32085,11 @@ var PieChartWrapper = import_react13.default.forwardRef(
32072
32085
  height: "100%",
32073
32086
  minWidth: 0,
32074
32087
  minHeight: 0,
32075
- initialDimension: { width: 1, height: 1 },
32076
32088
  children: /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)(import_recharts.PieChart, { children: [
32077
32089
  /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
32078
32090
  import_recharts.Pie,
32079
32091
  {
32080
- data: parseData2(
32081
- data,
32082
- (() => {
32083
- const colorArray = colorMap[category] && colorMap[category]["primary"] && colorMap[category]["primary"] || colors;
32084
- const containsCssVars = colorArray.some(
32085
- (color) => typeof color === "string" && color.includes("var(")
32086
- );
32087
- if (containsCssVars) {
32088
- return Array.from({ length: data.length }).map(
32089
- (_, idx) => colorArray[idx % colorArray.length] ?? colorArray[colorArray.length - 1] ?? "#808080"
32090
- );
32091
- }
32092
- return colorArray.length >= data.length ? colorArray.slice(0, data.length) : generateArrayFromColor(colorArray, data.length);
32093
- })(),
32094
- index,
32095
- category
32096
- ),
32092
+ data: parsedData,
32097
32093
  cx: "50%",
32098
32094
  cy: "50%",
32099
32095
  startAngle: 90,
@@ -32103,7 +32099,7 @@ var PieChartWrapper = import_react13.default.forwardRef(
32103
32099
  paddingAngle: 0,
32104
32100
  dataKey: category,
32105
32101
  nameKey: index,
32106
- isAnimationActive: true,
32102
+ isAnimationActive: animationActive,
32107
32103
  onClick: onClickChartElement,
32108
32104
  labelLine: false,
32109
32105
  label: false
@@ -33554,7 +33550,6 @@ function LineChart({
33554
33550
  height: "100%",
33555
33551
  minWidth: 0,
33556
33552
  minHeight: 0,
33557
- initialDimension: { width: 1, height: 1 },
33558
33553
  children: /* @__PURE__ */ (0, import_jsx_runtime35.jsxs)(
33559
33554
  import_recharts2.ComposedChart,
33560
33555
  {
@@ -33840,7 +33835,7 @@ function RadarChart({
33840
33835
  );
33841
33836
  }
33842
33837
  const getCustomColor = (index, field) => {
33843
- let key = index === 0 ? "comparison" : "primary";
33838
+ const key = index === 0 ? "comparison" : "primary";
33844
33839
  field = field.replace("comparison_", "");
33845
33840
  if (colorMap && colorMap[field]) {
33846
33841
  return colorMap[field][key];
@@ -33864,7 +33859,6 @@ function RadarChart({
33864
33859
  height: "100%",
33865
33860
  minWidth: 0,
33866
33861
  minHeight: 0,
33867
- initialDimension: { width: 1, height: 1 },
33868
33862
  children: /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)(
33869
33863
  import_recharts3.RadarChart,
33870
33864
  {
@@ -34290,7 +34284,6 @@ function BarChart({
34290
34284
  height: "100%",
34291
34285
  minWidth: 0,
34292
34286
  minHeight: 0,
34293
- initialDimension: { width: 1, height: 1 },
34294
34287
  children: /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)(
34295
34288
  import_recharts4.BarChart,
34296
34289
  {
@@ -39591,12 +39584,6 @@ function QuillTableDashboardComponent({
39591
39584
  init_valueFormatter();
39592
39585
  var import_jsx_runtime50 = require("react/jsx-runtime");
39593
39586
  var MAX_ROWS_FOR_GENERIC_TABLE = 500;
39594
- function sumByKey(arr, key) {
39595
- return arr.reduce((acc, cur) => {
39596
- const val = parseInt(cur[key], 10);
39597
- return isNaN(val) ? acc : acc + val;
39598
- }, 0);
39599
- }
39600
39587
  function Chart({
39601
39588
  colors,
39602
39589
  reportId,
@@ -40135,6 +40122,22 @@ var ChartDisplay = ({
40135
40122
  )
40136
40123
  };
40137
40124
  }, [config]);
40125
+ const pieData = (0, import_react32.useMemo)(() => {
40126
+ if (!config || config.chartType?.toLowerCase() !== "pie") return [];
40127
+ if (config.pivot) return config.rows ?? [];
40128
+ const rows = config.rows ?? [];
40129
+ const configuredValueField = config.yAxisFields?.[0]?.field;
40130
+ if (!configuredValueField) return rows;
40131
+ const valueField = configuredValueField;
40132
+ const total = rows.reduce((sum, row) => {
40133
+ const value = parseInt(row[valueField] ?? "", 10);
40134
+ return isNaN(value) ? sum : sum + value;
40135
+ }, 0);
40136
+ return rows.map((row) => ({
40137
+ ...row,
40138
+ count: parseInt(row[valueField] ?? "", 10) / total
40139
+ }));
40140
+ }, [config]);
40138
40141
  if (loading) {
40139
40142
  return /* @__PURE__ */ (0, import_jsx_runtime50.jsx)("div", { className, style: containerStyle, children: /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(LoadingComponent, {}) });
40140
40143
  } else if (config && !["metric", "table", "gauge", "US map", "World map"].includes(
@@ -40153,15 +40156,7 @@ var ChartDisplay = ({
40153
40156
  {
40154
40157
  className,
40155
40158
  containerStyle,
40156
- data: !config?.pivot ? config?.rows?.map((row) => {
40157
- return {
40158
- ...row,
40159
- count: (
40160
- // @ts-ignore
40161
- parseInt(row[config?.yAxisFields[0]?.field]) / sumByKey(config?.rows, config?.yAxisFields[0]?.field)
40162
- )
40163
- };
40164
- }) || [] : config?.rows || [],
40159
+ data: pieData,
40165
40160
  category: config?.yAxisFields?.[0]?.field,
40166
40161
  index: config?.xAxisField,
40167
40162
  colors: chartColors,
@@ -40170,7 +40165,8 @@ var ChartDisplay = ({
40170
40165
  onClickChartElement,
40171
40166
  onClickLegendElement,
40172
40167
  yAxisFields: config?.yAxisFields,
40173
- showLegend: resolvedShowLegend
40168
+ showLegend: resolvedShowLegend,
40169
+ isAnimationActive
40174
40170
  }
40175
40171
  );
40176
40172
  }
@@ -40220,7 +40216,8 @@ var ChartDisplay = ({
40220
40216
  className,
40221
40217
  colorMap,
40222
40218
  onClickChartElement,
40223
- scrollable
40219
+ scrollable,
40220
+ showAnimation: isAnimationActive
40224
40221
  }
40225
40222
  );
40226
40223
  }
@@ -43583,6 +43580,7 @@ function StaticChart(props) {
43583
43580
  onClickLegendElement,
43584
43581
  containerStyle,
43585
43582
  showLegend,
43583
+ showAnimation,
43586
43584
  className,
43587
43585
  hideTableChartOuterBorder = true
43588
43586
  } = props;
@@ -43641,6 +43639,7 @@ function StaticChart(props) {
43641
43639
  className,
43642
43640
  containerStyle: safeContainerStyle,
43643
43641
  showLegend,
43642
+ isAnimationActive: showAnimation,
43644
43643
  onPageChange: useLocalPivotTablePagination ? void 0 : onPageChange,
43645
43644
  tableRowsLoading: useLocalPivotTablePagination ? false : pageLoading,
43646
43645
  onSortChange: useLocalPivotTablePagination ? void 0 : onSortChange,
@@ -59993,12 +59992,13 @@ var QUERY_BUILDER_MULTI_VALUE_OPERATORS = /* @__PURE__ */ new Set(["in", "notin"
59993
59992
  var TABLE_FORMAT_CACHE_MAX_ENTRIES = 5e3;
59994
59993
  var PIVOT_DATE_BUCKET_FORMAT_OPTIONS = ["date"];
59995
59994
  var PIVOT_DATE_BUCKET_OPTIONS = [
59996
- { label: "Automatic", value: "" },
59995
+ { label: "Dynamic", value: "" },
59997
59996
  { label: "Daily", value: "day" },
59998
59997
  { label: "Weekly", value: "week" },
59999
59998
  { label: "Monthly", value: "month" },
60000
59999
  { label: "Yearly", value: "year" }
60001
60000
  ];
60001
+ var STANDARD_PIVOT_DATE_BUCKET_OPTIONS = PIVOT_DATE_BUCKET_OPTIONS.slice(1);
60002
60002
  var AXIS_FORMAT_OPTIONS = [
60003
60003
  { value: "string", label: "string" },
60004
60004
  { value: "whole_number", label: "whole number" },
@@ -60476,17 +60476,26 @@ function buildPivotAggregationsWithFieldTables({
60476
60476
  columnFieldTable
60477
60477
  };
60478
60478
  }
60479
+ function resolvePivotSortFieldTable(pivot, sortField) {
60480
+ const explicitTable = String(pivot?.sortFieldTable ?? "").trim();
60481
+ if (explicitTable && sortField === pivot?.sortField) return explicitTable;
60482
+ if (sortField === pivot?.rowField) return pivot?.rowFieldTable;
60483
+ if (sortField === pivot?.columnField) return pivot?.columnFieldTable;
60484
+ return void 0;
60485
+ }
60479
60486
  function normalizePivotForRefreshComparison(pivot) {
60480
60487
  if (pivot == null) return pivot;
60481
60488
  const record = pivot;
60482
60489
  const {
60483
60490
  rowFieldTable: _pivotRowTable,
60484
60491
  columnFieldTable: _pivotColumnTable,
60492
+ sortFieldTable: _pivotSortTable,
60485
60493
  rowFilter: _rowFilter,
60486
60494
  columnFilter: _columnFilter,
60487
60495
  aggregations,
60488
60496
  ...pivotRest
60489
60497
  } = record;
60498
+ void _pivotSortTable;
60490
60499
  const next = { ...pivotRest };
60491
60500
  if (Array.isArray(aggregations)) {
60492
60501
  next.aggregations = aggregations.map((entry) => {
@@ -63288,6 +63297,7 @@ function useReport(reportIdArg, options = {}) {
63288
63297
  const { eventTracking } = (0, import_react61.useContext)(EventTrackingContext);
63289
63298
  const [draftSessionId, setDraftSessionId] = (0, import_react61.useState)(generateDraftSessionId);
63290
63299
  const useInMemoryEngines = options.useInMemoryEngines ?? false;
63300
+ const dateBucketMode = options.dateBucketMode ?? "dynamic";
63291
63301
  const restrictFieldOptionsToSelectedDatasources = options.restrictFieldOptionsToSelectedDatasources ?? true;
63292
63302
  const reportOverride = options.reportOverride ?? null;
63293
63303
  const initialReportBuilderState = options.initialReportBuilderState ?? null;
@@ -64836,17 +64846,24 @@ function useReport(reportIdArg, options = {}) {
64836
64846
  rowTableHint,
64837
64847
  columnTableHint
64838
64848
  });
64849
+ const configuredDateBucket = chartPivotHydratedFromSourceRef.current ? dateBucket : dateBucket ?? priorPivot?.dateBucket;
64839
64850
  const built = {
64840
64851
  ...priorPivot ?? {},
64841
64852
  rowField: effectiveRowField,
64842
64853
  rowFieldType,
64843
64854
  columnField: effectiveColumnField,
64844
64855
  columnFieldType,
64845
- dateBucket: chartPivotHydratedFromSourceRef.current ? dateBucket : dateBucket ?? priorPivot?.dateBucket,
64856
+ dateBucket: configuredDateBucket,
64846
64857
  aggregations,
64847
64858
  ...rowFieldTable ? { rowFieldTable } : {},
64848
64859
  ...columnFieldTable ? { columnFieldTable } : {}
64849
64860
  };
64861
+ if (dateBucketMode === "standard" && effectiveRowField && isDateType(String(rowFieldType ?? ""))) {
64862
+ built.dateBucket = resolvePivotDateBucket({
64863
+ pivot: built,
64864
+ filters: internalFilters
64865
+ }) ?? "month";
64866
+ }
64850
64867
  return built;
64851
64868
  }, [
64852
64869
  aggregationState,
@@ -64854,8 +64871,10 @@ function useReport(reportIdArg, options = {}) {
64854
64871
  appliedAggregationState,
64855
64872
  baseReportBuilderTables,
64856
64873
  dateBucket,
64874
+ dateBucketMode,
64857
64875
  groupColumnsBy,
64858
64876
  groupRowsBy,
64877
+ internalFilters,
64859
64878
  schemaForReportBuilderState,
64860
64879
  sourceReport?.columnInternal,
64861
64880
  sourceReport?.columns,
@@ -65199,6 +65218,10 @@ function useReport(reportIdArg, options = {}) {
65199
65218
  ...pivotState,
65200
65219
  sort: Boolean(pivotSort?.sortField),
65201
65220
  sortField: pivotSort?.sortField,
65221
+ sortFieldTable: resolvePivotSortFieldTable(
65222
+ pivotState,
65223
+ pivotSort?.sortField
65224
+ ),
65202
65225
  sortDirection: pivotSort?.sortDirection,
65203
65226
  sortFieldType: resolvedSortFieldType,
65204
65227
  rowLimit: limit?.value
@@ -65856,6 +65879,10 @@ function useReport(reportIdArg, options = {}) {
65856
65879
  ...pivotState,
65857
65880
  sort: Boolean(pivotSort?.sortField),
65858
65881
  sortField: pivotSort?.sortField,
65882
+ sortFieldTable: resolvePivotSortFieldTable(
65883
+ pivotState,
65884
+ pivotSort?.sortField
65885
+ ),
65859
65886
  sortDirection: pivotSort?.sortDirection,
65860
65887
  sortFieldType: resolvedSortFieldType,
65861
65888
  rowLimit: limit?.value
@@ -68158,8 +68185,8 @@ function useReport(reportIdArg, options = {}) {
68158
68185
  groupRowsByOptions,
68159
68186
  groupColumnsBy,
68160
68187
  groupColumnsByOptions,
68161
- dateBucket,
68162
- dateBucketOptions: hasDatePivotRow ? PIVOT_DATE_BUCKET_OPTIONS : [],
68188
+ dateBucket: dateBucketMode === "standard" ? pivotState?.dateBucket : dateBucket,
68189
+ dateBucketOptions: hasDatePivotRow ? dateBucketMode === "standard" ? STANDARD_PIVOT_DATE_BUCKET_OPTIONS : PIVOT_DATE_BUCKET_OPTIONS : [],
68163
68190
  /** Encoded selection per aggregation slot (`'sum:transactions::amount'`, `'count:transactions'`, `''` = placeholder). Update via `setReport({ aggregations: nextStringArray })`. */
68164
68191
  aggregations: aggregationValues,
68165
68192
  /** Flat aggregation pick list shared by all slots; always contains every non-empty `aggregations` entry. */
package/dist/index.d.cts CHANGED
@@ -558,6 +558,8 @@ interface BasePivot {
558
558
  sort?: boolean;
559
559
  sortDirection?: 'ASC' | 'DESC';
560
560
  sortField?: string;
561
+ /** Source table for sortField when it references a pivot dimension. */
562
+ sortFieldTable?: string;
561
563
  sortFieldType?: string;
562
564
  title?: string;
563
565
  triggerButtonText?: string;
@@ -2724,6 +2726,7 @@ interface StaticChartBaseProps {
2724
2726
  showLegend?: boolean;
2725
2727
  /** Strip QuillTable's outer frame when chart type is `table` (cell borders unchanged). */
2726
2728
  hideTableChartOuterBorder?: boolean;
2729
+ showAnimation?: boolean;
2727
2730
  }
2728
2731
  type StaticChartProps = (StaticChartBaseProps & {
2729
2732
  className: string;
@@ -3052,6 +3055,12 @@ interface UseReportOptions {
3052
3055
  useInMemoryEngines?: boolean;
3053
3056
  reportOverride?: QuillReportInternal | null;
3054
3057
  initialReportBuilderState?: ReportBuilderState | null;
3058
+ /**
3059
+ * `dynamic` exposes an empty "Dynamic" selection when the bucket is inferred.
3060
+ * `standard` exposes only concrete buckets and returns the currently resolved
3061
+ * bucket from `useReport().dateBucket`. Defaults to `dynamic`.
3062
+ */
3063
+ dateBucketMode?: 'dynamic' | 'standard';
3055
3064
  /**
3056
3065
  * When the report payload has no `dashboardName` and the client has no
3057
3066
  * `defaultDashboard`, use this for engine tasks that require a dashboard
package/dist/index.d.ts CHANGED
@@ -558,6 +558,8 @@ interface BasePivot {
558
558
  sort?: boolean;
559
559
  sortDirection?: 'ASC' | 'DESC';
560
560
  sortField?: string;
561
+ /** Source table for sortField when it references a pivot dimension. */
562
+ sortFieldTable?: string;
561
563
  sortFieldType?: string;
562
564
  title?: string;
563
565
  triggerButtonText?: string;
@@ -2724,6 +2726,7 @@ interface StaticChartBaseProps {
2724
2726
  showLegend?: boolean;
2725
2727
  /** Strip QuillTable's outer frame when chart type is `table` (cell borders unchanged). */
2726
2728
  hideTableChartOuterBorder?: boolean;
2729
+ showAnimation?: boolean;
2727
2730
  }
2728
2731
  type StaticChartProps = (StaticChartBaseProps & {
2729
2732
  className: string;
@@ -3052,6 +3055,12 @@ interface UseReportOptions {
3052
3055
  useInMemoryEngines?: boolean;
3053
3056
  reportOverride?: QuillReportInternal | null;
3054
3057
  initialReportBuilderState?: ReportBuilderState | null;
3058
+ /**
3059
+ * `dynamic` exposes an empty "Dynamic" selection when the bucket is inferred.
3060
+ * `standard` exposes only concrete buckets and returns the currently resolved
3061
+ * bucket from `useReport().dateBucket`. Defaults to `dynamic`.
3062
+ */
3063
+ dateBucketMode?: 'dynamic' | 'standard';
3055
3064
  /**
3056
3065
  * When the report payload has no `dashboardName` and the client has no
3057
3066
  * `defaultDashboard`, use this for engine tasks that require a dashboard