@adventurelabs/scout-core 1.0.113 → 1.0.114
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.
|
@@ -113,6 +113,59 @@ export function useScoutRefresh(options = {}) {
|
|
|
113
113
|
return businessData;
|
|
114
114
|
});
|
|
115
115
|
}, []);
|
|
116
|
+
// Helper function to find what specifically changed for debugging
|
|
117
|
+
const findBusinessDataChanges = useCallback((newData, currentData) => {
|
|
118
|
+
if (!Array.isArray(newData) || !Array.isArray(currentData)) {
|
|
119
|
+
return `Array type mismatch: new=${Array.isArray(newData)}, current=${Array.isArray(currentData)}`;
|
|
120
|
+
}
|
|
121
|
+
if (newData.length !== currentData.length) {
|
|
122
|
+
return `Array length: ${currentData.length} → ${newData.length}`;
|
|
123
|
+
}
|
|
124
|
+
// Sort and normalize both for consistent comparison
|
|
125
|
+
const sortedNew = normalizeHerdModulesForComparison(sortHerdModulesById(newData));
|
|
126
|
+
const sortedCurrent = normalizeHerdModulesForComparison(sortHerdModulesById(currentData));
|
|
127
|
+
const changes = [];
|
|
128
|
+
for (let i = 0; i < sortedNew.length; i++) {
|
|
129
|
+
const newHerd = sortedNew[i];
|
|
130
|
+
const currentHerd = sortedCurrent[i];
|
|
131
|
+
if (!newHerd || !currentHerd)
|
|
132
|
+
continue;
|
|
133
|
+
const herdName = newHerd.herd?.name || newHerd.name || `herd-${newHerd.herd?.id || i}`;
|
|
134
|
+
// Check key business fields
|
|
135
|
+
const businessFields = [
|
|
136
|
+
"total_events",
|
|
137
|
+
"total_events_with_filters",
|
|
138
|
+
"events_page_index",
|
|
139
|
+
];
|
|
140
|
+
businessFields.forEach((field) => {
|
|
141
|
+
if (newHerd[field] !== currentHerd[field]) {
|
|
142
|
+
changes.push(`${herdName}.${field}: ${currentHerd[field]} → ${newHerd[field]}`);
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
// Check array lengths
|
|
146
|
+
const arrayFields = [
|
|
147
|
+
"devices",
|
|
148
|
+
"events",
|
|
149
|
+
"plans",
|
|
150
|
+
"zones",
|
|
151
|
+
"sessions",
|
|
152
|
+
"layers",
|
|
153
|
+
"providers",
|
|
154
|
+
];
|
|
155
|
+
arrayFields.forEach((field) => {
|
|
156
|
+
const newArray = newHerd[field];
|
|
157
|
+
const currentArray = currentHerd[field];
|
|
158
|
+
if (Array.isArray(newArray) && Array.isArray(currentArray)) {
|
|
159
|
+
if (newArray.length !== currentArray.length) {
|
|
160
|
+
changes.push(`${herdName}.${field}[]: ${currentArray.length} → ${newArray.length}`);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
return changes.length > 0
|
|
166
|
+
? changes.join(", ")
|
|
167
|
+
: "No specific changes identified";
|
|
168
|
+
}, [normalizeHerdModulesForComparison, sortHerdModulesById]);
|
|
116
169
|
// Helper function to conditionally dispatch only if business data has changed
|
|
117
170
|
const conditionalDispatch = useCallback((newData, currentData, actionCreator, dataType, skipTimestampOnlyUpdates = false) => {
|
|
118
171
|
// For herd modules, sort both datasets by ID before comparison
|
|
@@ -130,6 +183,11 @@ export function useScoutRefresh(options = {}) {
|
|
|
130
183
|
}
|
|
131
184
|
if (!deepEqual(dataToCompare, currentToCompare)) {
|
|
132
185
|
console.log(`[useScoutRefresh] ${dataType} business data changed, updating store`);
|
|
186
|
+
// Add debugging for unexpected business changes
|
|
187
|
+
if (skipTimestampOnlyUpdates && dataType.includes("Herd modules")) {
|
|
188
|
+
const changes = findBusinessDataChanges(newData, currentData);
|
|
189
|
+
console.log(`[useScoutRefresh] ${dataType} changes: ${changes}`);
|
|
190
|
+
}
|
|
133
191
|
dispatch(actionCreator(newData)); // Always dispatch original unsorted data
|
|
134
192
|
return true;
|
|
135
193
|
}
|
|
@@ -142,6 +200,7 @@ export function useScoutRefresh(options = {}) {
|
|
|
142
200
|
deepEqual,
|
|
143
201
|
sortHerdModulesById,
|
|
144
202
|
normalizeHerdModulesForComparison,
|
|
203
|
+
findBusinessDataChanges,
|
|
145
204
|
]);
|
|
146
205
|
// Helper function to handle IndexedDB errors - memoized for stability
|
|
147
206
|
const handleIndexedDbError = useCallback(async (error, operation, retryFn) => {
|