Fix date mutation bug causing 'Today' selector to return no data

- Create new Date objects instead of mutating original DateRangePicker dates
- Fixes issue where first API call would mutate dateValue.from/to causing
  subsequent calls to use corrupted date ranges
- Updated usage.tsx, cache_dashboard.tsx, and model_dashboard.tsx
- Minimal change preserving original timezone logic
This commit is contained in:
Cole McIntosh 2025-06-24 14:28:52 -06:00
parent a5ce1cd49b
commit c42a876735
3 changed files with 47 additions and 31 deletions

View file

@ -161,16 +161,20 @@ const CacheDashboard: React.FC<CachePageProps> = ({
return;
}
// Create new Date objects to avoid mutating the original dates
const adjustedStartTime = new Date(startTime);
const adjustedEndTime = new Date(endTime);
// the endTime put it to the last hour of the selected date
endTime.setHours(23, 59, 59, 999);
adjustedEndTime.setHours(23, 59, 59, 999);
// startTime put it to the first hour of the selected date
startTime.setHours(0, 0, 0, 0);
adjustedStartTime.setHours(0, 0, 0, 0);
let new_cache_data = await adminGlobalCacheActivity(
accessToken,
formatDateWithoutTZ(startTime),
formatDateWithoutTZ(endTime)
formatDateWithoutTZ(adjustedStartTime),
formatDateWithoutTZ(adjustedEndTime)
)
setData(new_cache_data);

View file

@ -306,14 +306,18 @@ const ModelDashboard: React.FC<ModelDashboardProps> = ({
selected_customer = null;
}
// make startTime and endTime to last hour of the day
startTime.setHours(0);
startTime.setMinutes(0);
startTime.setSeconds(0);
// Create new Date objects to avoid mutating the original dates
const adjustedStartTime = new Date(startTime);
const adjustedEndTime = new Date(endTime);
endTime.setHours(23);
endTime.setMinutes(59);
endTime.setSeconds(59);
// make startTime and endTime to last hour of the day
adjustedStartTime.setHours(0);
adjustedStartTime.setMinutes(0);
adjustedStartTime.setSeconds(0);
adjustedEndTime.setHours(23);
adjustedEndTime.setMinutes(59);
adjustedEndTime.setSeconds(59);
try {
const modelMetricsResponse = await modelMetricsCall(
@ -321,8 +325,8 @@ const ModelDashboard: React.FC<ModelDashboardProps> = ({
userID,
userRole,
modelGroup,
startTime.toISOString(),
endTime.toISOString(),
adjustedStartTime.toISOString(),
adjustedEndTime.toISOString(),
selected_token,
selected_customer
);
@ -335,8 +339,8 @@ const ModelDashboard: React.FC<ModelDashboardProps> = ({
const streamingModelMetricsResponse = await streamingModelMetricsCall(
accessToken,
modelGroup,
startTime.toISOString(),
endTime.toISOString()
adjustedStartTime.toISOString(),
adjustedEndTime.toISOString()
);
// Assuming modelMetricsResponse now contains the metric data for the specified model group
@ -350,8 +354,8 @@ const ModelDashboard: React.FC<ModelDashboardProps> = ({
userID,
userRole,
modelGroup,
startTime.toISOString(),
endTime.toISOString(),
adjustedStartTime.toISOString(),
adjustedEndTime.toISOString(),
selected_token,
selected_customer
);
@ -364,8 +368,8 @@ const ModelDashboard: React.FC<ModelDashboardProps> = ({
userID,
userRole,
modelGroup,
startTime.toISOString(),
endTime.toISOString(),
adjustedStartTime.toISOString(),
adjustedEndTime.toISOString(),
selected_token,
selected_customer
);
@ -378,8 +382,8 @@ const ModelDashboard: React.FC<ModelDashboardProps> = ({
if (modelGroup) {
const dailyExceptions = await adminGlobalActivityExceptions(
accessToken,
startTime?.toISOString().split('T')[0],
endTime?.toISOString().split('T')[0],
adjustedStartTime?.toISOString().split('T')[0],
adjustedEndTime?.toISOString().split('T')[0],
modelGroup,
);
@ -387,8 +391,8 @@ const ModelDashboard: React.FC<ModelDashboardProps> = ({
const dailyExceptionsPerDeplyment = await adminGlobalActivityExceptionsPerDeployment(
accessToken,
startTime?.toISOString().split('T')[0],
endTime?.toISOString().split('T')[0],
adjustedStartTime?.toISOString().split('T')[0],
adjustedEndTime?.toISOString().split('T')[0],
modelGroup,
)

View file

@ -213,19 +213,23 @@ const UsagePage: React.FC<UsagePageProps> = ({
return;
}
// Create new Date objects to avoid mutating the original dates
const adjustedStartTime = new Date(startTime);
const adjustedEndTime = new Date(endTime);
// the endTime put it to the last hour of the selected date
endTime.setHours(23, 59, 59, 999);
adjustedEndTime.setHours(23, 59, 59, 999);
// startTime put it to the first hour of the selected date
startTime.setHours(0, 0, 0, 0);
adjustedStartTime.setHours(0, 0, 0, 0);
console.log("uiSelectedKey", uiSelectedKey);
let newTopUserData = await adminTopEndUsersCall(
accessToken,
uiSelectedKey,
startTime.toISOString(),
endTime.toISOString()
adjustedStartTime.toISOString(),
adjustedEndTime.toISOString()
)
console.log("End user data updated successfully", newTopUserData);
setTopUsers(newTopUserData);
@ -245,16 +249,20 @@ const UsagePage: React.FC<UsagePageProps> = ({
return; // Don't run expensive DB queries - return out when SpendLogs has more than 1M rows
}
// Create new Date objects to avoid mutating the original dates
const adjustedStartTime = new Date(startTime);
const adjustedEndTime = new Date(endTime);
// the endTime put it to the last hour of the selected date
endTime.setHours(23, 59, 59, 999);
adjustedEndTime.setHours(23, 59, 59, 999);
// startTime put it to the first hour of the selected date
startTime.setHours(0, 0, 0, 0);
adjustedStartTime.setHours(0, 0, 0, 0);
let top_tags = await tagsSpendLogsCall(
accessToken,
startTime.toISOString(),
endTime.toISOString(),
adjustedStartTime.toISOString(),
adjustedEndTime.toISOString(),
selectedTags.length === 0 ? undefined : selectedTags
);
setTopTagsData(top_tags.spend_per_tag);