@quillsql/react 2.16.88 → 2.16.90

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
@@ -23705,10 +23705,24 @@ function hasPreformattedDateBucketLabels(report) {
23705
23705
  if (report.chartType?.toLowerCase() === "table") return false;
23706
23706
  return report.xAxisField?.trim() === pivot.rowField?.trim();
23707
23707
  }
23708
+ function applySavedPivotColumnLabels(report, pivotColumns) {
23709
+ return pivotColumns?.map((column) => {
23710
+ const savedColumn = report.columns?.find(
23711
+ ({ field }) => field === column.field
23712
+ );
23713
+ const rowLabel = column.field === report.pivot?.rowField ? report.xAxisLabel : void 0;
23714
+ return {
23715
+ ...column,
23716
+ label: rowLabel || savedColumn?.label || column.label
23717
+ };
23718
+ });
23719
+ }
23708
23720
  function prepareStaticChartReport(report, { removePagination }) {
23709
- const config = report.pivot ? {
23721
+ const pivotData = report.pivot ? formattedPivotRowsAndColumns(report, [], { formatRows: false }) : void 0;
23722
+ const config = pivotData ? {
23710
23723
  ...report,
23711
- ...formattedPivotRowsAndColumns(report, [], { formatRows: false })
23724
+ ...pivotData,
23725
+ columns: applySavedPivotColumnLabels(report, pivotData.columns)
23712
23726
  } : { ...report };
23713
23727
  if (removePagination) {
23714
23728
  config.pagination = void 0;
@@ -64323,6 +64337,20 @@ function resolveTableColumnLabel(fieldRaw, labelRaw) {
64323
64337
  const label = String(labelRaw ?? "").trim();
64324
64338
  return !label || label === field ? toTitleCaseLabel(field) : label;
64325
64339
  }
64340
+ function reportColumnsContainPivotOutputFields(report) {
64341
+ if (!report?.pivot || String(report.chartType ?? "").toLowerCase() !== "table" || !Array.isArray(report.columns) || report.columns.length === 0) {
64342
+ return false;
64343
+ }
64344
+ const detailFields = new Set(
64345
+ [
64346
+ ...report.reportBuilderState?.columns ?? [],
64347
+ ...report.columnInternal ?? []
64348
+ ].flatMap((column) => [column.field, column.alias]).map((field) => String(field ?? "").trim()).filter(Boolean)
64349
+ );
64350
+ return report.columns.some(
64351
+ (column) => !detailFields.has(String(column.field ?? "").trim())
64352
+ );
64353
+ }
64326
64354
  function mergeDisplayAndSourceForTableFormats(args) {
64327
64355
  const {
64328
64356
  effectiveReportBuilderTableNames,
@@ -64332,7 +64360,8 @@ function mergeDisplayAndSourceForTableFormats(args) {
64332
64360
  includeSelectedSchemaFallback
64333
64361
  } = args;
64334
64362
  const selectedTableNames = new Set(effectiveReportBuilderTableNames);
64335
- const persistedReportColumns = Array.isArray(sourceReport?.columns) && sourceReport.columns.length > 0 ? sourceReport.columns : null;
64363
+ const savedColumnsArePivotDisplayColumns = reportColumnsContainPivotOutputFields(sourceReport);
64364
+ const persistedReportColumns = !savedColumnsArePivotDisplayColumns && Array.isArray(sourceReport?.columns) && sourceReport.columns.length > 0 ? sourceReport.columns : null;
64336
64365
  const pivotTableColumnsFromSchema = sourceReport?.pivot && !persistedReportColumns && scopedSchemaColumns.length > 0 && selectedTableNames.size > 0 ? scopedSchemaColumns.filter(
64337
64366
  (column) => selectedTableNames.has(String(column.table ?? "").trim())
64338
64367
  ) : [];
@@ -67716,7 +67745,8 @@ function useReport(reportIdArg, options = {}) {
67716
67745
  table: String(column.table ?? "").trim() || resolveColumnTableFromReportMetadata(sourceReport, column.field)
67717
67746
  }))
67718
67747
  );
67719
- const sourceDisplayColumns = savedDisplayColumns.length > 0 ? savedDisplayColumns : sourceDisplayColumnsFromSchema.length > 0 ? sourceDisplayColumnsFromSchema : sourceQueryColumns;
67748
+ const savedColumnsArePivotDisplayColumns = reportColumnsContainPivotOutputFields(sourceReport);
67749
+ const sourceDisplayColumns = savedDisplayColumns.length > 0 && !savedColumnsArePivotDisplayColumns ? savedDisplayColumns : sourceDisplayColumnsFromSchema.length > 0 ? sourceDisplayColumnsFromSchema : sourceQueryColumns;
67720
67750
  const shouldKeepLocalRowGroup = groupRowsBySetViaSetReportRef.current || groupColumnsBySetViaSetReportRef.current && prev.groupRowsBy !== void 0;
67721
67751
  const shouldKeepLocalColumnGroup = groupColumnsBySetViaSetReportRef.current || groupRowsBySetViaSetReportRef.current && prev.groupColumnsBy !== void 0;
67722
67752
  const nextGroupRowsBy = shouldTakePivotGroupsFromSource ? shouldKeepLocalRowGroup ? prev.groupRowsBy : sourceRowGroupOption : prev.groupRowsBy !== void 0 ? prev.groupRowsBy : groupRowsBySetViaSetReportRef.current ? prev.groupRowsBy : sourceRowGroupOption;
@@ -71144,6 +71174,28 @@ function useReport(reportIdArg, options = {}) {
71144
71174
  const hasReportFlagsOverride = overrides?.reportFlags !== void 0;
71145
71175
  const isFlatTable = String(resolvedChartType).toLowerCase() === "table" && !effectiveReportBuilderState.pivot;
71146
71176
  const isPivotTable = String(resolvedChartType).toLowerCase() === "table" && Boolean(effectiveReportBuilderState.pivot);
71177
+ const fallbackDetailColumns = effectiveReportBuilderState.columns.map(
71178
+ (column) => {
71179
+ const field = String(column.alias ?? "").trim() || String(column.field ?? "").trim();
71180
+ const tableName = String(column.table ?? "").trim();
71181
+ const metadata = [
71182
+ ...sourceReport.columnInternal ?? [],
71183
+ ...sourceReport.columns ?? []
71184
+ ].find((candidate) => {
71185
+ const candidateField = String(candidate.field ?? "").trim();
71186
+ const candidateTable = String(
71187
+ candidate.table ?? ""
71188
+ ).trim();
71189
+ return (candidateField === field || candidateField === String(column.field ?? "").trim()) && (!tableName || !candidateTable || candidateTable === tableName);
71190
+ });
71191
+ return {
71192
+ field,
71193
+ label: String(metadata?.label ?? "").trim() || toTitleCaseLabel(field),
71194
+ format: String(metadata?.format ?? "").trim() || "string"
71195
+ };
71196
+ }
71197
+ );
71198
+ const columnsSelectedForSave = table.columns.length > 0 ? table.columns : fallbackDetailColumns;
71147
71199
  const resp = await saveReport({
71148
71200
  report: {
71149
71201
  ...EMPTY_INTERNAL_REPORT,
@@ -71155,7 +71207,7 @@ function useReport(reportIdArg, options = {}) {
71155
71207
  dashboardName: resolvedDashboardName,
71156
71208
  ...isAdmin ? { adminMode: true } : {},
71157
71209
  ...hasSectionOverride ? { section: overrides.section } : {},
71158
- columns: isPivotTable ? chart?.columns ?? sourceReport.columns : table.columns,
71210
+ columns: columnsSelectedForSave,
71159
71211
  ...isFlatTable ? {
71160
71212
  sort: effectiveReportBuilderState.sort?.[0] ?? null
71161
71213
  } : {},
package/dist/index.js CHANGED
@@ -23687,10 +23687,24 @@ function hasPreformattedDateBucketLabels(report) {
23687
23687
  if (report.chartType?.toLowerCase() === "table") return false;
23688
23688
  return report.xAxisField?.trim() === pivot.rowField?.trim();
23689
23689
  }
23690
+ function applySavedPivotColumnLabels(report, pivotColumns) {
23691
+ return pivotColumns?.map((column) => {
23692
+ const savedColumn = report.columns?.find(
23693
+ ({ field }) => field === column.field
23694
+ );
23695
+ const rowLabel = column.field === report.pivot?.rowField ? report.xAxisLabel : void 0;
23696
+ return {
23697
+ ...column,
23698
+ label: rowLabel || savedColumn?.label || column.label
23699
+ };
23700
+ });
23701
+ }
23690
23702
  function prepareStaticChartReport(report, { removePagination }) {
23691
- const config = report.pivot ? {
23703
+ const pivotData = report.pivot ? formattedPivotRowsAndColumns(report, [], { formatRows: false }) : void 0;
23704
+ const config = pivotData ? {
23692
23705
  ...report,
23693
- ...formattedPivotRowsAndColumns(report, [], { formatRows: false })
23706
+ ...pivotData,
23707
+ columns: applySavedPivotColumnLabels(report, pivotData.columns)
23694
23708
  } : { ...report };
23695
23709
  if (removePagination) {
23696
23710
  config.pagination = void 0;
@@ -64531,6 +64545,20 @@ function resolveTableColumnLabel(fieldRaw, labelRaw) {
64531
64545
  const label = String(labelRaw ?? "").trim();
64532
64546
  return !label || label === field ? toTitleCaseLabel(field) : label;
64533
64547
  }
64548
+ function reportColumnsContainPivotOutputFields(report) {
64549
+ if (!report?.pivot || String(report.chartType ?? "").toLowerCase() !== "table" || !Array.isArray(report.columns) || report.columns.length === 0) {
64550
+ return false;
64551
+ }
64552
+ const detailFields = new Set(
64553
+ [
64554
+ ...report.reportBuilderState?.columns ?? [],
64555
+ ...report.columnInternal ?? []
64556
+ ].flatMap((column) => [column.field, column.alias]).map((field) => String(field ?? "").trim()).filter(Boolean)
64557
+ );
64558
+ return report.columns.some(
64559
+ (column) => !detailFields.has(String(column.field ?? "").trim())
64560
+ );
64561
+ }
64534
64562
  function mergeDisplayAndSourceForTableFormats(args) {
64535
64563
  const {
64536
64564
  effectiveReportBuilderTableNames,
@@ -64540,7 +64568,8 @@ function mergeDisplayAndSourceForTableFormats(args) {
64540
64568
  includeSelectedSchemaFallback
64541
64569
  } = args;
64542
64570
  const selectedTableNames = new Set(effectiveReportBuilderTableNames);
64543
- const persistedReportColumns = Array.isArray(sourceReport?.columns) && sourceReport.columns.length > 0 ? sourceReport.columns : null;
64571
+ const savedColumnsArePivotDisplayColumns = reportColumnsContainPivotOutputFields(sourceReport);
64572
+ const persistedReportColumns = !savedColumnsArePivotDisplayColumns && Array.isArray(sourceReport?.columns) && sourceReport.columns.length > 0 ? sourceReport.columns : null;
64544
64573
  const pivotTableColumnsFromSchema = sourceReport?.pivot && !persistedReportColumns && scopedSchemaColumns.length > 0 && selectedTableNames.size > 0 ? scopedSchemaColumns.filter(
64545
64574
  (column) => selectedTableNames.has(String(column.table ?? "").trim())
64546
64575
  ) : [];
@@ -67924,7 +67953,8 @@ function useReport(reportIdArg, options = {}) {
67924
67953
  table: String(column.table ?? "").trim() || resolveColumnTableFromReportMetadata(sourceReport, column.field)
67925
67954
  }))
67926
67955
  );
67927
- const sourceDisplayColumns = savedDisplayColumns.length > 0 ? savedDisplayColumns : sourceDisplayColumnsFromSchema.length > 0 ? sourceDisplayColumnsFromSchema : sourceQueryColumns;
67956
+ const savedColumnsArePivotDisplayColumns = reportColumnsContainPivotOutputFields(sourceReport);
67957
+ const sourceDisplayColumns = savedDisplayColumns.length > 0 && !savedColumnsArePivotDisplayColumns ? savedDisplayColumns : sourceDisplayColumnsFromSchema.length > 0 ? sourceDisplayColumnsFromSchema : sourceQueryColumns;
67928
67958
  const shouldKeepLocalRowGroup = groupRowsBySetViaSetReportRef.current || groupColumnsBySetViaSetReportRef.current && prev.groupRowsBy !== void 0;
67929
67959
  const shouldKeepLocalColumnGroup = groupColumnsBySetViaSetReportRef.current || groupRowsBySetViaSetReportRef.current && prev.groupColumnsBy !== void 0;
67930
67960
  const nextGroupRowsBy = shouldTakePivotGroupsFromSource ? shouldKeepLocalRowGroup ? prev.groupRowsBy : sourceRowGroupOption : prev.groupRowsBy !== void 0 ? prev.groupRowsBy : groupRowsBySetViaSetReportRef.current ? prev.groupRowsBy : sourceRowGroupOption;
@@ -71352,6 +71382,28 @@ function useReport(reportIdArg, options = {}) {
71352
71382
  const hasReportFlagsOverride = overrides?.reportFlags !== void 0;
71353
71383
  const isFlatTable = String(resolvedChartType).toLowerCase() === "table" && !effectiveReportBuilderState.pivot;
71354
71384
  const isPivotTable = String(resolvedChartType).toLowerCase() === "table" && Boolean(effectiveReportBuilderState.pivot);
71385
+ const fallbackDetailColumns = effectiveReportBuilderState.columns.map(
71386
+ (column) => {
71387
+ const field = String(column.alias ?? "").trim() || String(column.field ?? "").trim();
71388
+ const tableName = String(column.table ?? "").trim();
71389
+ const metadata = [
71390
+ ...sourceReport.columnInternal ?? [],
71391
+ ...sourceReport.columns ?? []
71392
+ ].find((candidate) => {
71393
+ const candidateField = String(candidate.field ?? "").trim();
71394
+ const candidateTable = String(
71395
+ candidate.table ?? ""
71396
+ ).trim();
71397
+ return (candidateField === field || candidateField === String(column.field ?? "").trim()) && (!tableName || !candidateTable || candidateTable === tableName);
71398
+ });
71399
+ return {
71400
+ field,
71401
+ label: String(metadata?.label ?? "").trim() || toTitleCaseLabel(field),
71402
+ format: String(metadata?.format ?? "").trim() || "string"
71403
+ };
71404
+ }
71405
+ );
71406
+ const columnsSelectedForSave = table.columns.length > 0 ? table.columns : fallbackDetailColumns;
71355
71407
  const resp = await saveReport({
71356
71408
  report: {
71357
71409
  ...EMPTY_INTERNAL_REPORT,
@@ -71363,7 +71415,7 @@ function useReport(reportIdArg, options = {}) {
71363
71415
  dashboardName: resolvedDashboardName,
71364
71416
  ...isAdmin ? { adminMode: true } : {},
71365
71417
  ...hasSectionOverride ? { section: overrides.section } : {},
71366
- columns: isPivotTable ? chart?.columns ?? sourceReport.columns : table.columns,
71418
+ columns: columnsSelectedForSave,
71367
71419
  ...isFlatTable ? {
71368
71420
  sort: effectiveReportBuilderState.sort?.[0] ?? null
71369
71421
  } : {},
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quillsql/react",
3
- "version": "2.16.88",
3
+ "version": "2.16.90",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {