@adventurelabs/scout-core 1.0.112 → 1.0.113
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/hooks/useScoutRefresh.js +29 -75
- package/package.json +1 -1
|
@@ -101,94 +101,48 @@ export function useScoutRefresh(options = {}) {
|
|
|
101
101
|
return aId - bId;
|
|
102
102
|
});
|
|
103
103
|
}, []);
|
|
104
|
-
// Helper function to
|
|
105
|
-
const
|
|
106
|
-
if (!Array.isArray(
|
|
107
|
-
return
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
const differences = [];
|
|
116
|
-
for (let i = 0; i < sortedNew.length; i++) {
|
|
117
|
-
const newHerd = sortedNew[i];
|
|
118
|
-
const currentHerd = sortedCurrent[i];
|
|
119
|
-
if (!newHerd || !currentHerd) {
|
|
120
|
-
differences.push(`Herd ${i}: null/undefined mismatch`);
|
|
121
|
-
continue;
|
|
122
|
-
}
|
|
123
|
-
// Get herd identifiers for better debugging
|
|
124
|
-
const newHerdId = newHerd.herd?.id || "unknown";
|
|
125
|
-
const currentHerdId = currentHerd.herd?.id || "unknown";
|
|
126
|
-
const newHerdName = newHerd.herd?.name || "unknown";
|
|
127
|
-
const currentHerdName = currentHerd.herd?.name || "unknown";
|
|
128
|
-
// Check if herd IDs match (data shuffling detection)
|
|
129
|
-
if (newHerdId !== currentHerdId) {
|
|
130
|
-
differences.push(`Herd ${i}: ID mismatch - expected ${currentHerdId}(${currentHerdName}) got ${newHerdId}(${newHerdName})`);
|
|
131
|
-
}
|
|
132
|
-
// Check top-level fields
|
|
133
|
-
const fieldsToCheck = [
|
|
134
|
-
"timestamp_last_refreshed",
|
|
135
|
-
"total_events",
|
|
136
|
-
"total_events_with_filters",
|
|
137
|
-
"events_page_index",
|
|
138
|
-
];
|
|
139
|
-
fieldsToCheck.forEach((field) => {
|
|
140
|
-
if (newHerd[field] !== currentHerd[field]) {
|
|
141
|
-
differences.push(`Herd ${i}(${newHerdName}).${field}: ${currentHerd[field]} → ${newHerd[field]}`);
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
// Check array lengths for nested data
|
|
145
|
-
const arrayFields = [
|
|
146
|
-
"devices",
|
|
147
|
-
"events",
|
|
148
|
-
"plans",
|
|
149
|
-
"zones",
|
|
150
|
-
"sessions",
|
|
151
|
-
"layers",
|
|
152
|
-
"providers",
|
|
153
|
-
];
|
|
154
|
-
arrayFields.forEach((field) => {
|
|
155
|
-
const newArray = newHerd[field];
|
|
156
|
-
const currentArray = currentHerd[field];
|
|
157
|
-
if (Array.isArray(newArray) && Array.isArray(currentArray)) {
|
|
158
|
-
if (newArray.length !== currentArray.length) {
|
|
159
|
-
differences.push(`Herd ${i}(${newHerdName}).${field}[]: length ${currentArray.length} → ${newArray.length}`);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
return differences.length > 0
|
|
165
|
-
? differences.join(", ")
|
|
166
|
-
: "No significant differences found";
|
|
104
|
+
// Helper function to normalize herd modules for comparison (excludes timestamp metadata)
|
|
105
|
+
const normalizeHerdModulesForComparison = useCallback((herdModules) => {
|
|
106
|
+
if (!Array.isArray(herdModules))
|
|
107
|
+
return herdModules;
|
|
108
|
+
return herdModules.map((hm) => {
|
|
109
|
+
if (!hm || typeof hm !== "object")
|
|
110
|
+
return hm;
|
|
111
|
+
// Create a copy without timestamp metadata that doesn't represent business data changes
|
|
112
|
+
const { timestamp_last_refreshed, ...businessData } = hm;
|
|
113
|
+
return businessData;
|
|
114
|
+
});
|
|
167
115
|
}, []);
|
|
168
|
-
// Helper function to conditionally dispatch only if data has changed
|
|
169
|
-
const conditionalDispatch = useCallback((newData, currentData, actionCreator, dataType,
|
|
116
|
+
// Helper function to conditionally dispatch only if business data has changed
|
|
117
|
+
const conditionalDispatch = useCallback((newData, currentData, actionCreator, dataType, skipTimestampOnlyUpdates = false) => {
|
|
170
118
|
// For herd modules, sort both datasets by ID before comparison
|
|
171
119
|
let dataToCompare = newData;
|
|
172
120
|
let currentToCompare = currentData;
|
|
173
121
|
if (dataType.includes("Herd modules")) {
|
|
174
122
|
dataToCompare = sortHerdModulesById(newData);
|
|
175
123
|
currentToCompare = sortHerdModulesById(currentData);
|
|
124
|
+
// If we want to skip timestamp-only updates, normalize the data for comparison
|
|
125
|
+
if (skipTimestampOnlyUpdates) {
|
|
126
|
+
dataToCompare = normalizeHerdModulesForComparison(dataToCompare);
|
|
127
|
+
currentToCompare =
|
|
128
|
+
normalizeHerdModulesForComparison(currentToCompare);
|
|
129
|
+
}
|
|
176
130
|
}
|
|
177
131
|
if (!deepEqual(dataToCompare, currentToCompare)) {
|
|
178
|
-
console.log(`[useScoutRefresh] ${dataType} data changed, updating store`);
|
|
179
|
-
// Add debugging for herd modules to see what actually changed
|
|
180
|
-
if (enableDebugging && dataType.includes("Herd modules")) {
|
|
181
|
-
const differences = findHerdModulesDifferences(newData, currentData);
|
|
182
|
-
console.log(`[useScoutRefresh] ${dataType} differences: ${differences}`);
|
|
183
|
-
}
|
|
132
|
+
console.log(`[useScoutRefresh] ${dataType} business data changed, updating store`);
|
|
184
133
|
dispatch(actionCreator(newData)); // Always dispatch original unsorted data
|
|
185
134
|
return true;
|
|
186
135
|
}
|
|
187
136
|
else {
|
|
188
|
-
console.log(`[useScoutRefresh] ${dataType} data unchanged, skipping store update`);
|
|
137
|
+
console.log(`[useScoutRefresh] ${dataType} business data unchanged, skipping store update`);
|
|
189
138
|
return false;
|
|
190
139
|
}
|
|
191
|
-
}, [
|
|
140
|
+
}, [
|
|
141
|
+
dispatch,
|
|
142
|
+
deepEqual,
|
|
143
|
+
sortHerdModulesById,
|
|
144
|
+
normalizeHerdModulesForComparison,
|
|
145
|
+
]);
|
|
192
146
|
// Helper function to handle IndexedDB errors - memoized for stability
|
|
193
147
|
const handleIndexedDbError = useCallback(async (error, operation, retryFn) => {
|
|
194
148
|
if (error instanceof Error &&
|
|
@@ -295,7 +249,7 @@ export function useScoutRefresh(options = {}) {
|
|
|
295
249
|
}
|
|
296
250
|
});
|
|
297
251
|
}
|
|
298
|
-
// Conditionally update store with fresh background data
|
|
252
|
+
// Conditionally update store with fresh background data, skip timestamp-only changes
|
|
299
253
|
const currentHerdModules = store.getState().scout.herd_modules;
|
|
300
254
|
const currentUser = store.getState().scout.user;
|
|
301
255
|
conditionalDispatch(backgroundHerdModulesResult.data, currentHerdModules, setHerdModules, "Herd modules (background)", true);
|
|
@@ -407,7 +361,7 @@ export function useScoutRefresh(options = {}) {
|
|
|
407
361
|
await scoutCache.setHerdModules(compatible_new_herd_modules, cacheTtlMs);
|
|
408
362
|
});
|
|
409
363
|
}
|
|
410
|
-
// Step 4: Conditionally update store with fresh data
|
|
364
|
+
// Step 4: Conditionally update store with fresh data, skip timestamp-only changes
|
|
411
365
|
const dataProcessingStartTime = Date.now();
|
|
412
366
|
const currentHerdModules = store.getState().scout.herd_modules;
|
|
413
367
|
const currentUser = store.getState().scout.user;
|