@smallwebco/tinypivot-react 1.0.25 → 1.0.27

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
@@ -464,7 +464,9 @@ function usePivotTable(data) {
464
464
  }
465
465
  }, [availableFields, requirePro]);
466
466
  const addCalculatedField = (0, import_react3.useCallback)((field) => {
467
+ console.log("[usePivotTable] addCalculatedField called with:", field);
467
468
  setCalculatedFields((prev) => {
469
+ console.log("[usePivotTable] Previous calculatedFields:", prev);
468
470
  const existing = prev.findIndex((f) => f.id === field.id);
469
471
  let updated;
470
472
  if (existing >= 0) {
@@ -472,6 +474,7 @@ function usePivotTable(data) {
472
474
  } else {
473
475
  updated = [...prev, field];
474
476
  }
477
+ console.log("[usePivotTable] Updated calculatedFields:", updated);
475
478
  (0, import_tinypivot_core3.saveCalculatedFields)(updated);
476
479
  return updated;
477
480
  });
@@ -1041,11 +1044,15 @@ function CalculatedFieldModal({
1041
1044
  });
1042
1045
  }, []);
1043
1046
  const handleSave = (0, import_react6.useCallback)(() => {
1047
+ console.log("[CalculatedFieldModal] handleSave called");
1048
+ console.log("[CalculatedFieldModal] name:", name, "formula:", formula);
1049
+ console.log("[CalculatedFieldModal] availableFields:", availableFields);
1044
1050
  if (!name.trim()) {
1045
1051
  setError("Name is required");
1046
1052
  return;
1047
1053
  }
1048
1054
  const validationResult = (0, import_tinypivot_core5.validateSimpleFormula)(formula, availableFields);
1055
+ console.log("[CalculatedFieldModal] validationResult:", validationResult);
1049
1056
  if (validationResult) {
1050
1057
  setError(validationResult);
1051
1058
  return;
@@ -1057,6 +1064,7 @@ function CalculatedFieldModal({
1057
1064
  formatAs,
1058
1065
  decimals
1059
1066
  };
1067
+ console.log("[CalculatedFieldModal] Calling onSave with:", field);
1060
1068
  onSave(field);
1061
1069
  onClose();
1062
1070
  }, [name, formula, formatAs, decimals, existingField, availableFields, onSave, onClose]);
@@ -1209,7 +1217,6 @@ function PivotConfig({
1209
1217
  onRemoveCalculatedField,
1210
1218
  onUpdateCalculatedField
1211
1219
  }) {
1212
- const { showWatermark } = useLicense();
1213
1220
  const [fieldSearch, setFieldSearch] = (0, import_react7.useState)("");
1214
1221
  const [showCalcModal, setShowCalcModal] = (0, import_react7.useState)(false);
1215
1222
  const [editingCalcField, setEditingCalcField] = (0, import_react7.useState)(null);
@@ -1218,8 +1225,9 @@ function PivotConfig({
1218
1225
  [availableFields]
1219
1226
  );
1220
1227
  const calculatedFieldsAsStats = (0, import_react7.useMemo)(() => {
1228
+ console.log("[PivotConfig] calculatedFields prop:", calculatedFields);
1221
1229
  if (!calculatedFields) return [];
1222
- return calculatedFields.map((calc) => ({
1230
+ const stats = calculatedFields.map((calc) => ({
1223
1231
  field: `calc:${calc.id}`,
1224
1232
  type: "number",
1225
1233
  uniqueCount: 0,
@@ -1229,11 +1237,17 @@ function PivotConfig({
1229
1237
  calcName: calc.name,
1230
1238
  calcFormula: calc.formula
1231
1239
  }));
1240
+ console.log("[PivotConfig] calculatedFieldsAsStats:", stats);
1241
+ return stats;
1232
1242
  }, [calculatedFields]);
1233
- const allAvailableFields = (0, import_react7.useMemo)(() => [
1234
- ...availableFields.map((f) => ({ ...f, isCalculated: false })),
1235
- ...calculatedFieldsAsStats
1236
- ], [availableFields, calculatedFieldsAsStats]);
1243
+ const allAvailableFields = (0, import_react7.useMemo)(() => {
1244
+ const all = [
1245
+ ...availableFields.map((f) => ({ ...f, isCalculated: false })),
1246
+ ...calculatedFieldsAsStats
1247
+ ];
1248
+ console.log("[PivotConfig] allAvailableFields:", all.length, "items, calc fields:", calculatedFieldsAsStats.length);
1249
+ return all;
1250
+ }, [availableFields, calculatedFieldsAsStats]);
1237
1251
  const assignedFields = (0, import_react7.useMemo)(() => {
1238
1252
  const rowSet = new Set(rowFields);
1239
1253
  const colSet = new Set(columnFields);
@@ -1315,9 +1329,14 @@ function PivotConfig({
1315
1329
  setShowCalcModal(true);
1316
1330
  }, []);
1317
1331
  const handleSaveCalcField = (0, import_react7.useCallback)((field) => {
1332
+ console.log("[PivotConfig] handleSaveCalcField called with:", field);
1333
+ console.log("[PivotConfig] editingCalcField:", editingCalcField);
1334
+ console.log("[PivotConfig] onAddCalculatedField exists:", !!onAddCalculatedField);
1318
1335
  if (editingCalcField && onUpdateCalculatedField) {
1336
+ console.log("[PivotConfig] Calling onUpdateCalculatedField");
1319
1337
  onUpdateCalculatedField(field);
1320
1338
  } else if (onAddCalculatedField) {
1339
+ console.log("[PivotConfig] Calling onAddCalculatedField");
1321
1340
  onAddCalculatedField(field);
1322
1341
  }
1323
1342
  setShowCalcModal(false);
@@ -1548,7 +1567,6 @@ function PivotConfig({
1548
1567
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: "+ Calc" })
1549
1568
  ] })
1550
1569
  ] }),
1551
- showWatermark && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "vpg-watermark", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("a", { href: "https://tiny-pivot.com", target: "_blank", rel: "noopener noreferrer", children: "TinyPivot" }) }),
1552
1570
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1553
1571
  CalculatedFieldModal,
1554
1572
  {
@@ -2212,6 +2230,7 @@ function DataGrid({
2212
2230
  valueFields: pivotValueFields,
2213
2231
  showRowTotals: pivotShowRowTotals,
2214
2232
  showColumnTotals: pivotShowColumnTotals,
2233
+ calculatedFields: pivotCalculatedFields,
2215
2234
  availableFields: pivotAvailableFields,
2216
2235
  isConfigured: pivotIsConfigured,
2217
2236
  pivotResult,
@@ -2227,7 +2246,9 @@ function DataGrid({
2227
2246
  setShowRowTotals: setPivotShowRowTotals,
2228
2247
  setShowColumnTotals: setPivotShowColumnTotals,
2229
2248
  setRowFields,
2230
- setColumnFields
2249
+ setColumnFields,
2250
+ addCalculatedField,
2251
+ removeCalculatedField
2231
2252
  } = usePivotTable(filteredDataForPivot);
2232
2253
  const activeFilterInfo = (0, import_react9.useMemo)(() => {
2233
2254
  if (activeFilters.length === 0) return null;
@@ -3008,6 +3029,7 @@ function DataGrid({
3008
3029
  valueFields: pivotValueFields,
3009
3030
  showRowTotals: pivotShowRowTotals,
3010
3031
  showColumnTotals: pivotShowColumnTotals,
3032
+ calculatedFields: pivotCalculatedFields,
3011
3033
  onShowRowTotalsChange: setPivotShowRowTotals,
3012
3034
  onShowColumnTotalsChange: setPivotShowColumnTotals,
3013
3035
  onClearConfig: clearPivotConfig,
@@ -3020,7 +3042,10 @@ function DataGrid({
3020
3042
  onAddColumnField: addColumnField,
3021
3043
  onRemoveColumnField: removeColumnField,
3022
3044
  onAddValueField: addValueField,
3023
- onRemoveValueField: removeValueField
3045
+ onRemoveValueField: removeValueField,
3046
+ onAddCalculatedField: addCalculatedField,
3047
+ onRemoveCalculatedField: removeCalculatedField,
3048
+ onUpdateCalculatedField: addCalculatedField
3024
3049
  }
3025
3050
  ) }),
3026
3051
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: `vpg-pivot-main ${!showPivotConfig ? "vpg-full-width" : ""}`, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(