@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.js CHANGED
@@ -444,7 +444,9 @@ function usePivotTable(data) {
444
444
  }
445
445
  }, [availableFields, requirePro]);
446
446
  const addCalculatedField = useCallback3((field) => {
447
+ console.log("[usePivotTable] addCalculatedField called with:", field);
447
448
  setCalculatedFields((prev) => {
449
+ console.log("[usePivotTable] Previous calculatedFields:", prev);
448
450
  const existing = prev.findIndex((f) => f.id === field.id);
449
451
  let updated;
450
452
  if (existing >= 0) {
@@ -452,6 +454,7 @@ function usePivotTable(data) {
452
454
  } else {
453
455
  updated = [...prev, field];
454
456
  }
457
+ console.log("[usePivotTable] Updated calculatedFields:", updated);
455
458
  saveCalculatedFields(updated);
456
459
  return updated;
457
460
  });
@@ -1026,11 +1029,15 @@ function CalculatedFieldModal({
1026
1029
  });
1027
1030
  }, []);
1028
1031
  const handleSave = useCallback6(() => {
1032
+ console.log("[CalculatedFieldModal] handleSave called");
1033
+ console.log("[CalculatedFieldModal] name:", name, "formula:", formula);
1034
+ console.log("[CalculatedFieldModal] availableFields:", availableFields);
1029
1035
  if (!name.trim()) {
1030
1036
  setError("Name is required");
1031
1037
  return;
1032
1038
  }
1033
1039
  const validationResult = validateSimpleFormula(formula, availableFields);
1040
+ console.log("[CalculatedFieldModal] validationResult:", validationResult);
1034
1041
  if (validationResult) {
1035
1042
  setError(validationResult);
1036
1043
  return;
@@ -1042,6 +1049,7 @@ function CalculatedFieldModal({
1042
1049
  formatAs,
1043
1050
  decimals
1044
1051
  };
1052
+ console.log("[CalculatedFieldModal] Calling onSave with:", field);
1045
1053
  onSave(field);
1046
1054
  onClose();
1047
1055
  }, [name, formula, formatAs, decimals, existingField, availableFields, onSave, onClose]);
@@ -1194,7 +1202,6 @@ function PivotConfig({
1194
1202
  onRemoveCalculatedField,
1195
1203
  onUpdateCalculatedField
1196
1204
  }) {
1197
- const { showWatermark } = useLicense();
1198
1205
  const [fieldSearch, setFieldSearch] = useState7("");
1199
1206
  const [showCalcModal, setShowCalcModal] = useState7(false);
1200
1207
  const [editingCalcField, setEditingCalcField] = useState7(null);
@@ -1203,8 +1210,9 @@ function PivotConfig({
1203
1210
  [availableFields]
1204
1211
  );
1205
1212
  const calculatedFieldsAsStats = useMemo7(() => {
1213
+ console.log("[PivotConfig] calculatedFields prop:", calculatedFields);
1206
1214
  if (!calculatedFields) return [];
1207
- return calculatedFields.map((calc) => ({
1215
+ const stats = calculatedFields.map((calc) => ({
1208
1216
  field: `calc:${calc.id}`,
1209
1217
  type: "number",
1210
1218
  uniqueCount: 0,
@@ -1214,11 +1222,17 @@ function PivotConfig({
1214
1222
  calcName: calc.name,
1215
1223
  calcFormula: calc.formula
1216
1224
  }));
1225
+ console.log("[PivotConfig] calculatedFieldsAsStats:", stats);
1226
+ return stats;
1217
1227
  }, [calculatedFields]);
1218
- const allAvailableFields = useMemo7(() => [
1219
- ...availableFields.map((f) => ({ ...f, isCalculated: false })),
1220
- ...calculatedFieldsAsStats
1221
- ], [availableFields, calculatedFieldsAsStats]);
1228
+ const allAvailableFields = useMemo7(() => {
1229
+ const all = [
1230
+ ...availableFields.map((f) => ({ ...f, isCalculated: false })),
1231
+ ...calculatedFieldsAsStats
1232
+ ];
1233
+ console.log("[PivotConfig] allAvailableFields:", all.length, "items, calc fields:", calculatedFieldsAsStats.length);
1234
+ return all;
1235
+ }, [availableFields, calculatedFieldsAsStats]);
1222
1236
  const assignedFields = useMemo7(() => {
1223
1237
  const rowSet = new Set(rowFields);
1224
1238
  const colSet = new Set(columnFields);
@@ -1300,9 +1314,14 @@ function PivotConfig({
1300
1314
  setShowCalcModal(true);
1301
1315
  }, []);
1302
1316
  const handleSaveCalcField = useCallback7((field) => {
1317
+ console.log("[PivotConfig] handleSaveCalcField called with:", field);
1318
+ console.log("[PivotConfig] editingCalcField:", editingCalcField);
1319
+ console.log("[PivotConfig] onAddCalculatedField exists:", !!onAddCalculatedField);
1303
1320
  if (editingCalcField && onUpdateCalculatedField) {
1321
+ console.log("[PivotConfig] Calling onUpdateCalculatedField");
1304
1322
  onUpdateCalculatedField(field);
1305
1323
  } else if (onAddCalculatedField) {
1324
+ console.log("[PivotConfig] Calling onAddCalculatedField");
1306
1325
  onAddCalculatedField(field);
1307
1326
  }
1308
1327
  setShowCalcModal(false);
@@ -1533,7 +1552,6 @@ function PivotConfig({
1533
1552
  /* @__PURE__ */ jsx3("span", { children: "+ Calc" })
1534
1553
  ] })
1535
1554
  ] }),
1536
- showWatermark && /* @__PURE__ */ jsx3("div", { className: "vpg-watermark", children: /* @__PURE__ */ jsx3("a", { href: "https://tiny-pivot.com", target: "_blank", rel: "noopener noreferrer", children: "TinyPivot" }) }),
1537
1555
  /* @__PURE__ */ jsx3(
1538
1556
  CalculatedFieldModal,
1539
1557
  {
@@ -2197,6 +2215,7 @@ function DataGrid({
2197
2215
  valueFields: pivotValueFields,
2198
2216
  showRowTotals: pivotShowRowTotals,
2199
2217
  showColumnTotals: pivotShowColumnTotals,
2218
+ calculatedFields: pivotCalculatedFields,
2200
2219
  availableFields: pivotAvailableFields,
2201
2220
  isConfigured: pivotIsConfigured,
2202
2221
  pivotResult,
@@ -2212,7 +2231,9 @@ function DataGrid({
2212
2231
  setShowRowTotals: setPivotShowRowTotals,
2213
2232
  setShowColumnTotals: setPivotShowColumnTotals,
2214
2233
  setRowFields,
2215
- setColumnFields
2234
+ setColumnFields,
2235
+ addCalculatedField,
2236
+ removeCalculatedField
2216
2237
  } = usePivotTable(filteredDataForPivot);
2217
2238
  const activeFilterInfo = useMemo9(() => {
2218
2239
  if (activeFilters.length === 0) return null;
@@ -2993,6 +3014,7 @@ function DataGrid({
2993
3014
  valueFields: pivotValueFields,
2994
3015
  showRowTotals: pivotShowRowTotals,
2995
3016
  showColumnTotals: pivotShowColumnTotals,
3017
+ calculatedFields: pivotCalculatedFields,
2996
3018
  onShowRowTotalsChange: setPivotShowRowTotals,
2997
3019
  onShowColumnTotalsChange: setPivotShowColumnTotals,
2998
3020
  onClearConfig: clearPivotConfig,
@@ -3005,7 +3027,10 @@ function DataGrid({
3005
3027
  onAddColumnField: addColumnField,
3006
3028
  onRemoveColumnField: removeColumnField,
3007
3029
  onAddValueField: addValueField,
3008
- onRemoveValueField: removeValueField
3030
+ onRemoveValueField: removeValueField,
3031
+ onAddCalculatedField: addCalculatedField,
3032
+ onRemoveCalculatedField: removeCalculatedField,
3033
+ onUpdateCalculatedField: addCalculatedField
3009
3034
  }
3010
3035
  ) }),
3011
3036
  /* @__PURE__ */ jsx5("div", { className: `vpg-pivot-main ${!showPivotConfig ? "vpg-full-width" : ""}`, children: /* @__PURE__ */ jsx5(