Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,20 @@ class App extends React.Component {

try {
const data = await getUploadedData(index);
if (!data || !data.retentionDate) return "Valid";
if (!data) {
log(`Dataset ${index + 1} not found in storage. It may have expired or been deleted.`, "error");
this.setState((prevState) => {
const newUploadedDatasets = [...prevState.uploadedDatasets];
newUploadedDatasets[index] = null;
return {
uploadedDatasets: newUploadedDatasets,
activeDatasetIndex: prevState.activeDatasetIndex === index ? null : prevState.activeDatasetIndex,
};
});
return "Expired";
}

if (!data.retentionDate) return "Valid";

const retentionDate = new Date(data.retentionDate);
const now = new Date();
Expand Down
4 changes: 1 addition & 3 deletions src/DatasetLoading.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { useState, useEffect } from "react";
import { GoogleOAuthProvider } from "@react-oauth/google";
import ExtraDataSource from "./ExtraDataSource";
import { log } from "./Utils";
import { toast, ToastContainer } from "react-toastify";
import "react-toastify/dist/ReactToastify.css";
import { toast } from "react-toastify";
import { isTokenValid, fetchLogsWithToken, useCloudLoggingLogin, buildQueryFilter } from "./CloudLogging";
import { HAS_EXTRA_DATA_SOURCE } from "./constants";

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

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

{isExtra ? (
Expand Down
7 changes: 4 additions & 3 deletions src/localStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,10 @@ export function ensureCorrectFormat(data) {
if (!Array.isArray(data)) {
// If it's already in the correct format, return it as is, BUT RE-CALCULATE TTL for grace period.
if (data && data.rawLogs && Array.isArray(data.rawLogs)) {
const calculatedTTL = calculateRetentionDate(data.rawLogs);
return {
...data,
retentionDate: calculateRetentionDate(data.rawLogs),
retentionDate: data.retentionDate > calculatedTTL ? data.retentionDate : calculatedTTL,
APIKEY: data.APIKEY || DEFAULT_API_KEY,
};
} else {
Expand Down Expand Up @@ -364,7 +365,7 @@ export function ensureCorrectFormat(data) {
if (!hasPoints) log("Bounds Calculation Failed: Could not find vehicle location data in any row.");

// Calculate retention date using the helper
const retentionDateIdentifier = calculateRetentionDate(logsArray);
const calculatedTTL = calculateRetentionDate(logsArray);

return {
APIKEY: DEFAULT_API_KEY,
Expand All @@ -374,7 +375,7 @@ export function ensureCorrectFormat(data) {
solutionType: solutionType,
rawLogs: fullyNormalizedLogs,
bounds: hasPoints ? bounds : null,
retentionDate: retentionDateIdentifier,
retentionDate: data.retentionDate > calculatedTTL ? data.retentionDate : calculatedTTL,
};
}

Expand Down
15 changes: 15 additions & 0 deletions src/localStorage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,4 +274,19 @@ describe("ensureCorrectFormat TTL Logic", () => {
expect(result.retentionDate).not.toBe(staleDate);
expect(retention).toBeGreaterThanOrEqual(expectedMin - 1000);
});

it("should pick the 1h grace period if existing future TTL is less than 1h", () => {
const thirtyMinFuture = new Date(Date.now() + 30 * 60 * 1000).toISOString();
const mockExportedFile = {
rawLogs: [{ timestamp: new Date(Date.now() - 100 * ONE_DAY_MS).toISOString(), jsonPayload: { test: 1 } }],
retentionDate: thirtyMinFuture,
};

const result = ensureCorrectFormat(mockExportedFile);
const retention = new Date(result.retentionDate).getTime();
const expectedMin = Date.now() + ONE_HOUR_MS;

expect(result.retentionDate).not.toBe(thirtyMinFuture);
expect(retention).toBeGreaterThanOrEqual(expectedMin - 1000);
});
});
Loading