@smallwebco/tinypivot-react 1.0.26 → 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]);
@@ -1217,8 +1225,9 @@ function PivotConfig({
1217
1225
  [availableFields]
1218
1226
  );
1219
1227
  const calculatedFieldsAsStats = (0, import_react7.useMemo)(() => {
1228
+ console.log("[PivotConfig] calculatedFields prop:", calculatedFields);
1220
1229
  if (!calculatedFields) return [];
1221
- return calculatedFields.map((calc) => ({
1230
+ const stats = calculatedFields.map((calc) => ({
1222
1231
  field: `calc:${calc.id}`,
1223
1232
  type: "number",
1224
1233
  uniqueCount: 0,
@@ -1228,11 +1237,17 @@ function PivotConfig({
1228
1237
  calcName: calc.name,
1229
1238
  calcFormula: calc.formula
1230
1239
  }));
1240
+ console.log("[PivotConfig] calculatedFieldsAsStats:", stats);
1241
+ return stats;
1231
1242
  }, [calculatedFields]);
1232
- const allAvailableFields = (0, import_react7.useMemo)(() => [
1233
- ...availableFields.map((f) => ({ ...f, isCalculated: false })),
1234
- ...calculatedFieldsAsStats
1235
- ], [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]);
1236
1251
  const assignedFields = (0, import_react7.useMemo)(() => {
1237
1252
  const rowSet = new Set(rowFields);
1238
1253
  const colSet = new Set(columnFields);
@@ -1314,9 +1329,14 @@ function PivotConfig({
1314
1329
  setShowCalcModal(true);
1315
1330
  }, []);
1316
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);
1317
1335
  if (editingCalcField && onUpdateCalculatedField) {
1336
+ console.log("[PivotConfig] Calling onUpdateCalculatedField");
1318
1337
  onUpdateCalculatedField(field);
1319
1338
  } else if (onAddCalculatedField) {
1339
+ console.log("[PivotConfig] Calling onAddCalculatedField");
1320
1340
  onAddCalculatedField(field);
1321
1341
  }
1322
1342
  setShowCalcModal(false);