@quillsql/react 2.16.99 → 2.16.101

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
@@ -62437,14 +62437,67 @@ function createUseFormInitialLoadQueryKey(input) {
62437
62437
  ];
62438
62438
  }
62439
62439
  var DASHBOARD_REPORT_STALE_TIME_MS = 5 * 60 * 1e3;
62440
+ var DASHBOARD_REPORT_RESULT_FIELDS = [
62441
+ "rows",
62442
+ "compareRows",
62443
+ "pivotRows",
62444
+ "pivotColumns",
62445
+ "pivotRowCount"
62446
+ ];
62447
+ function pivotDimensionKey(pivot) {
62448
+ const value = pivot && typeof pivot === "object" ? pivot : {};
62449
+ return [
62450
+ String(value.rowField ?? "").trim(),
62451
+ String(value.rowFieldTable ?? "").trim(),
62452
+ String(value.columnField ?? "").trim(),
62453
+ String(value.columnFieldTable ?? "").trim()
62454
+ ].join("\0");
62455
+ }
62456
+ function pivotDimensionsChanged(previous, next) {
62457
+ return pivotDimensionKey(previous?.pivot) !== pivotDimensionKey(next.pivot);
62458
+ }
62459
+ function dashboardReportQueryKey(reportId) {
62460
+ return ["quill", "dashboard-report", reportId];
62461
+ }
62462
+ function mergeSavedReportIntoDashboardQueryData(previous, saved) {
62463
+ const previousReport = previous?.report && typeof previous.report === "object" ? previous.report : void 0;
62464
+ const savedId = String(saved.id ?? saved._id ?? "").trim();
62465
+ const merged = {
62466
+ ...previousReport,
62467
+ ...saved,
62468
+ ...savedId ? { id: savedId } : {}
62469
+ };
62470
+ const dimensionsChanged = pivotDimensionsChanged(previousReport, merged);
62471
+ for (const field of DASHBOARD_REPORT_RESULT_FIELDS) {
62472
+ const savedValue = saved[field];
62473
+ if (savedValue != null) continue;
62474
+ if (dimensionsChanged) {
62475
+ delete merged[field];
62476
+ continue;
62477
+ }
62478
+ if (previousReport?.[field] != null) {
62479
+ merged[field] = previousReport[field];
62480
+ }
62481
+ }
62482
+ return { report: merged, error: void 0 };
62483
+ }
62440
62484
  function findCachedDashboardReportQuery(queryClient, reportId) {
62441
62485
  const id = String(reportId ?? "").trim();
62442
62486
  if (!id) return void 0;
62443
- return queryClient.getQueryCache().findAll({ queryKey: ["quill", "dashboard-report", id] }).find((query) => {
62487
+ return queryClient.getQueryCache().findAll({ queryKey: dashboardReportQueryKey(id) }).find((query) => {
62488
+ if (query.state.isInvalidated) return false;
62444
62489
  const data = query.state.data;
62445
62490
  return Boolean(data?.report) && !data?.error;
62446
62491
  });
62447
62492
  }
62493
+ function syncDashboardReportQueryCacheAfterSave(queryClient, reportId, saved) {
62494
+ const id = String(reportId ?? "").trim();
62495
+ if (!id) return;
62496
+ queryClient.setQueriesData(
62497
+ { queryKey: dashboardReportQueryKey(id) },
62498
+ (previous) => mergeSavedReportIntoDashboardQueryData(previous, saved)
62499
+ );
62500
+ }
62448
62501
  function shouldBootstrapUseFormInitialLoad(input) {
62449
62502
  return !input.hasInitialReportBuilderState && input.previouslyBootstrappedIdentity !== input.currentIdentity;
62450
62503
  }
@@ -69408,6 +69461,7 @@ function useReport(reportIdArg, options = {}) {
69408
69461
  ...report,
69409
69462
  // Keep chart axis metadata from the pivot load; detail fetch is flat
69410
69463
  // (`pivot: null`) and must supply wide `columns` for the detail table.
69464
+ xAxisLabel: previousReport.xAxisLabel,
69411
69465
  xAxisFormat: previousReport.xAxisFormat,
69412
69466
  yAxisFields: previousReport.yAxisFields,
69413
69467
  pivot: previousReport.pivot,
@@ -71422,13 +71476,14 @@ function useReport(reportIdArg, options = {}) {
71422
71476
  }
71423
71477
  );
71424
71478
  const columnsSelectedForSave = table.columns.length > 0 ? table.columns : fallbackDetailColumns;
71479
+ const persistedName = overriddenName || (String(formReportName ?? "").trim() ? formReportName : String(sourceRest.name ?? "").trim() ? sourceRest.name : effectiveReportBuilderState.tables[0]?.name ? snakeAndCamelCaseToTitleCase(
71480
+ String(effectiveReportBuilderState.tables[0].name)
71481
+ ) : "New report");
71425
71482
  const resp = await saveReport({
71426
71483
  report: {
71427
71484
  ...EMPTY_INTERNAL_REPORT,
71428
71485
  ...sourceRest,
71429
- name: overriddenName || (String(formReportName ?? "").trim() ? formReportName : String(sourceRest.name ?? "").trim() ? sourceRest.name : effectiveReportBuilderState.tables[0]?.name ? snakeAndCamelCaseToTitleCase(
71430
- String(effectiveReportBuilderState.tables[0].name)
71431
- ) : "New report"),
71486
+ name: persistedName,
71432
71487
  chartType: resolvedChartType,
71433
71488
  dashboardName: resolvedDashboardName,
71434
71489
  ...isAdmin ? { adminMode: true } : {},
@@ -71466,11 +71521,32 @@ function useReport(reportIdArg, options = {}) {
71466
71521
  if (savedReportId && resp && resp.name !== "error" && !resp.error) {
71467
71522
  await cacheCab.evictReport(savedReportId, tenants);
71468
71523
  evictSharedReportRequests(savedReportId);
71469
- await queryClient.invalidateQueries({
71470
- queryKey: ["quill", "dashboard-report", savedReportId],
71471
- refetchType: "none"
71524
+ const savedReport = {
71525
+ id: savedReportId,
71526
+ name: persistedName,
71527
+ chartType: resolvedChartType,
71528
+ xAxisField: resolvedXAxisField,
71529
+ xAxisFormat: resolvedXAxisFormat,
71530
+ xAxisLabel: resolvedXAxisLabel,
71531
+ yAxisFields: yAxisMeasures,
71532
+ pivot: effectiveReportBuilderState.pivot ?? null,
71533
+ reportBuilderState: effectiveReportBuilderState,
71534
+ columns: columnsSelectedForSave,
71535
+ rows: sourceReport.rows,
71536
+ compareRows: sourceReport.compareRows,
71537
+ pivotRows: sourceReport.pivotRows,
71538
+ pivotColumns: sourceReport.pivotColumns,
71539
+ pivotRowCount: sourceReport.pivotRowCount
71540
+ };
71541
+ syncDashboardReportQueryCacheAfterSave(
71542
+ queryClient,
71543
+ savedReportId,
71544
+ savedReport
71545
+ );
71546
+ await loadDashboard(resolvedDashboardName, true, {
71547
+ report: { ...sourceRest, ...savedReport },
71548
+ action: "upsert"
71472
71549
  });
71473
- await loadDashboard(resolvedDashboardName, true);
71474
71550
  }
71475
71551
  return resp;
71476
71552
  },
package/dist/index.js CHANGED
@@ -62645,14 +62645,67 @@ function createUseFormInitialLoadQueryKey(input) {
62645
62645
  ];
62646
62646
  }
62647
62647
  var DASHBOARD_REPORT_STALE_TIME_MS = 5 * 60 * 1e3;
62648
+ var DASHBOARD_REPORT_RESULT_FIELDS = [
62649
+ "rows",
62650
+ "compareRows",
62651
+ "pivotRows",
62652
+ "pivotColumns",
62653
+ "pivotRowCount"
62654
+ ];
62655
+ function pivotDimensionKey(pivot) {
62656
+ const value = pivot && typeof pivot === "object" ? pivot : {};
62657
+ return [
62658
+ String(value.rowField ?? "").trim(),
62659
+ String(value.rowFieldTable ?? "").trim(),
62660
+ String(value.columnField ?? "").trim(),
62661
+ String(value.columnFieldTable ?? "").trim()
62662
+ ].join("\0");
62663
+ }
62664
+ function pivotDimensionsChanged(previous, next) {
62665
+ return pivotDimensionKey(previous?.pivot) !== pivotDimensionKey(next.pivot);
62666
+ }
62667
+ function dashboardReportQueryKey(reportId) {
62668
+ return ["quill", "dashboard-report", reportId];
62669
+ }
62670
+ function mergeSavedReportIntoDashboardQueryData(previous, saved) {
62671
+ const previousReport = previous?.report && typeof previous.report === "object" ? previous.report : void 0;
62672
+ const savedId = String(saved.id ?? saved._id ?? "").trim();
62673
+ const merged = {
62674
+ ...previousReport,
62675
+ ...saved,
62676
+ ...savedId ? { id: savedId } : {}
62677
+ };
62678
+ const dimensionsChanged = pivotDimensionsChanged(previousReport, merged);
62679
+ for (const field of DASHBOARD_REPORT_RESULT_FIELDS) {
62680
+ const savedValue = saved[field];
62681
+ if (savedValue != null) continue;
62682
+ if (dimensionsChanged) {
62683
+ delete merged[field];
62684
+ continue;
62685
+ }
62686
+ if (previousReport?.[field] != null) {
62687
+ merged[field] = previousReport[field];
62688
+ }
62689
+ }
62690
+ return { report: merged, error: void 0 };
62691
+ }
62648
62692
  function findCachedDashboardReportQuery(queryClient, reportId) {
62649
62693
  const id = String(reportId ?? "").trim();
62650
62694
  if (!id) return void 0;
62651
- return queryClient.getQueryCache().findAll({ queryKey: ["quill", "dashboard-report", id] }).find((query) => {
62695
+ return queryClient.getQueryCache().findAll({ queryKey: dashboardReportQueryKey(id) }).find((query) => {
62696
+ if (query.state.isInvalidated) return false;
62652
62697
  const data = query.state.data;
62653
62698
  return Boolean(data?.report) && !data?.error;
62654
62699
  });
62655
62700
  }
62701
+ function syncDashboardReportQueryCacheAfterSave(queryClient, reportId, saved) {
62702
+ const id = String(reportId ?? "").trim();
62703
+ if (!id) return;
62704
+ queryClient.setQueriesData(
62705
+ { queryKey: dashboardReportQueryKey(id) },
62706
+ (previous) => mergeSavedReportIntoDashboardQueryData(previous, saved)
62707
+ );
62708
+ }
62656
62709
  function shouldBootstrapUseFormInitialLoad(input) {
62657
62710
  return !input.hasInitialReportBuilderState && input.previouslyBootstrappedIdentity !== input.currentIdentity;
62658
62711
  }
@@ -69616,6 +69669,7 @@ function useReport(reportIdArg, options = {}) {
69616
69669
  ...report,
69617
69670
  // Keep chart axis metadata from the pivot load; detail fetch is flat
69618
69671
  // (`pivot: null`) and must supply wide `columns` for the detail table.
69672
+ xAxisLabel: previousReport.xAxisLabel,
69619
69673
  xAxisFormat: previousReport.xAxisFormat,
69620
69674
  yAxisFields: previousReport.yAxisFields,
69621
69675
  pivot: previousReport.pivot,
@@ -71630,13 +71684,14 @@ function useReport(reportIdArg, options = {}) {
71630
71684
  }
71631
71685
  );
71632
71686
  const columnsSelectedForSave = table.columns.length > 0 ? table.columns : fallbackDetailColumns;
71687
+ const persistedName = overriddenName || (String(formReportName ?? "").trim() ? formReportName : String(sourceRest.name ?? "").trim() ? sourceRest.name : effectiveReportBuilderState.tables[0]?.name ? snakeAndCamelCaseToTitleCase(
71688
+ String(effectiveReportBuilderState.tables[0].name)
71689
+ ) : "New report");
71633
71690
  const resp = await saveReport({
71634
71691
  report: {
71635
71692
  ...EMPTY_INTERNAL_REPORT,
71636
71693
  ...sourceRest,
71637
- name: overriddenName || (String(formReportName ?? "").trim() ? formReportName : String(sourceRest.name ?? "").trim() ? sourceRest.name : effectiveReportBuilderState.tables[0]?.name ? snakeAndCamelCaseToTitleCase(
71638
- String(effectiveReportBuilderState.tables[0].name)
71639
- ) : "New report"),
71694
+ name: persistedName,
71640
71695
  chartType: resolvedChartType,
71641
71696
  dashboardName: resolvedDashboardName,
71642
71697
  ...isAdmin ? { adminMode: true } : {},
@@ -71674,11 +71729,32 @@ function useReport(reportIdArg, options = {}) {
71674
71729
  if (savedReportId && resp && resp.name !== "error" && !resp.error) {
71675
71730
  await cacheCab.evictReport(savedReportId, tenants);
71676
71731
  evictSharedReportRequests(savedReportId);
71677
- await queryClient.invalidateQueries({
71678
- queryKey: ["quill", "dashboard-report", savedReportId],
71679
- refetchType: "none"
71732
+ const savedReport = {
71733
+ id: savedReportId,
71734
+ name: persistedName,
71735
+ chartType: resolvedChartType,
71736
+ xAxisField: resolvedXAxisField,
71737
+ xAxisFormat: resolvedXAxisFormat,
71738
+ xAxisLabel: resolvedXAxisLabel,
71739
+ yAxisFields: yAxisMeasures,
71740
+ pivot: effectiveReportBuilderState.pivot ?? null,
71741
+ reportBuilderState: effectiveReportBuilderState,
71742
+ columns: columnsSelectedForSave,
71743
+ rows: sourceReport.rows,
71744
+ compareRows: sourceReport.compareRows,
71745
+ pivotRows: sourceReport.pivotRows,
71746
+ pivotColumns: sourceReport.pivotColumns,
71747
+ pivotRowCount: sourceReport.pivotRowCount
71748
+ };
71749
+ syncDashboardReportQueryCacheAfterSave(
71750
+ queryClient,
71751
+ savedReportId,
71752
+ savedReport
71753
+ );
71754
+ await loadDashboard(resolvedDashboardName, true, {
71755
+ report: { ...sourceRest, ...savedReport },
71756
+ action: "upsert"
71680
71757
  });
71681
- await loadDashboard(resolvedDashboardName, true);
71682
71758
  }
71683
71759
  return resp;
71684
71760
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quillsql/react",
3
- "version": "2.16.99",
3
+ "version": "2.16.101",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {