Skip to content

Commit 147af10

Browse files
fix: dataset TTL sync, toast failures, and retention persistence (#268) d34a2cc
1 parent 0d68206 commit 147af10

File tree

4 files changed

+34
-7
lines changed

4 files changed

+34
-7
lines changed

src/App.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,20 @@ class App extends React.Component {
808808

809809
try {
810810
const data = await getUploadedData(index);
811-
if (!data || !data.retentionDate) return "Valid";
811+
if (!data) {
812+
log(`Dataset ${index + 1} not found in storage. It may have expired or been deleted.`, "error");
813+
this.setState((prevState) => {
814+
const newUploadedDatasets = [...prevState.uploadedDatasets];
815+
newUploadedDatasets[index] = null;
816+
return {
817+
uploadedDatasets: newUploadedDatasets,
818+
activeDatasetIndex: prevState.activeDatasetIndex === index ? null : prevState.activeDatasetIndex,
819+
};
820+
});
821+
return "Expired";
822+
}
823+
824+
if (!data.retentionDate) return "Valid";
812825

813826
const retentionDate = new Date(data.retentionDate);
814827
const now = new Date();

src/DatasetLoading.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import { useState, useEffect } from "react";
33
import { GoogleOAuthProvider } from "@react-oauth/google";
44
import ExtraDataSource from "./ExtraDataSource";
55
import { log } from "./Utils";
6-
import { toast, ToastContainer } from "react-toastify";
7-
import "react-toastify/dist/ReactToastify.css";
6+
import { toast } from "react-toastify";
87
import { isTokenValid, fetchLogsWithToken, useCloudLoggingLogin, buildQueryFilter } from "./CloudLogging";
98
import { HAS_EXTRA_DATA_SOURCE } from "./constants";
109

@@ -206,7 +205,6 @@ export default function DatasetLoading(props) {
206205

207206
return (
208207
<>
209-
<ToastContainer position="top-right" autoClose={5000} />
210208
<div className="data-source-toggle">{renderSourceSelection()}</div>
211209

212210
{isExtra ? (

src/localStorage.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,10 @@ export function ensureCorrectFormat(data) {
260260
if (!Array.isArray(data)) {
261261
// If it's already in the correct format, return it as is, BUT RE-CALCULATE TTL for grace period.
262262
if (data && data.rawLogs && Array.isArray(data.rawLogs)) {
263+
const calculatedTTL = calculateRetentionDate(data.rawLogs);
263264
return {
264265
...data,
265-
retentionDate: calculateRetentionDate(data.rawLogs),
266+
retentionDate: data.retentionDate > calculatedTTL ? data.retentionDate : calculatedTTL,
266267
APIKEY: data.APIKEY || DEFAULT_API_KEY,
267268
};
268269
} else {
@@ -364,7 +365,7 @@ export function ensureCorrectFormat(data) {
364365
if (!hasPoints) log("Bounds Calculation Failed: Could not find vehicle location data in any row.");
365366

366367
// Calculate retention date using the helper
367-
const retentionDateIdentifier = calculateRetentionDate(logsArray);
368+
const calculatedTTL = calculateRetentionDate(logsArray);
368369

369370
return {
370371
APIKEY: DEFAULT_API_KEY,
@@ -374,7 +375,7 @@ export function ensureCorrectFormat(data) {
374375
solutionType: solutionType,
375376
rawLogs: fullyNormalizedLogs,
376377
bounds: hasPoints ? bounds : null,
377-
retentionDate: retentionDateIdentifier,
378+
retentionDate: data.retentionDate > calculatedTTL ? data.retentionDate : calculatedTTL,
378379
};
379380
}
380381

src/localStorage.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,4 +274,19 @@ describe("ensureCorrectFormat TTL Logic", () => {
274274
expect(result.retentionDate).not.toBe(staleDate);
275275
expect(retention).toBeGreaterThanOrEqual(expectedMin - 1000);
276276
});
277+
278+
it("should pick the 1h grace period if existing future TTL is less than 1h", () => {
279+
const thirtyMinFuture = new Date(Date.now() + 30 * 60 * 1000).toISOString();
280+
const mockExportedFile = {
281+
rawLogs: [{ timestamp: new Date(Date.now() - 100 * ONE_DAY_MS).toISOString(), jsonPayload: { test: 1 } }],
282+
retentionDate: thirtyMinFuture,
283+
};
284+
285+
const result = ensureCorrectFormat(mockExportedFile);
286+
const retention = new Date(result.retentionDate).getTime();
287+
const expectedMin = Date.now() + ONE_HOUR_MS;
288+
289+
expect(result.retentionDate).not.toBe(thirtyMinFuture);
290+
expect(retention).toBeGreaterThanOrEqual(expectedMin - 1000);
291+
});
277292
});

0 commit comments

Comments
 (0)