Fleet UI: Dashboard > Software fix cached data not updating UI (#29288)

This commit is contained in:
RachelElysia 2025-05-20 13:34:08 -04:00 committed by GitHub
parent 030c61ca17
commit 7c69c69728
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -331,34 +331,38 @@ const DashboardPage = ({ router, location }: IDashboardProps): JSX.Element => {
enabled: isRouteOk && isSoftwareEnabled,
keepPreviousData: true,
staleTime: 30000, // stale time can be adjusted if fresher data is desired based on software inventory interval
onSuccess: (data) => {
const hasSoftwareResults = !!data.software && data.software.length > 0;
if (hasSoftwareResults) {
setSoftwareTitleDetail &&
setSoftwareTitleDetail(
<LastUpdatedText
lastUpdatedAt={data.counts_updated_at}
customTooltipText={
<>
Fleet periodically queries all hosts to
<br />
retrieve software. Click to view
<br />
hosts for the most up-to-date lists.
</>
}
/>
);
setShowSoftwareCard(true);
} else if (!isViewingVulnerableSoftware) {
setShowSoftwareCard(false);
}
// For vulnerable software with no results, the count query will handle showing the card.
},
// Don't use onSuccess for UI state: it won't run for cached data, only after a new fetch
}
);
// Keeps UI state in sync with both cached and freshly fetched query results
useEffect(() => {
const hasSoftwareResults =
!!software?.software && software.software.length > 0;
if (hasSoftwareResults) {
setShowSoftwareCard(true);
setSoftwareTitleDetail(
<LastUpdatedText
lastUpdatedAt={software.counts_updated_at}
customTooltipText={
<>
Fleet periodically queries all hosts to
<br />
retrieve software. Click to view
<br />
hosts for the most up-to-date lists.
</>
}
/>
);
} else if (!isViewingVulnerableSoftware) {
setShowSoftwareCard(false);
setSoftwareTitleDetail(null);
}
// For vulnerable software with no results, the count query will handle showing the card.
}, [software, isViewingVulnerableSoftware]);
// If viewing vulnerable software and no results are returned,
// fetch the count of non-vulnerable software to decide if the card should be shown.
const shouldFetchSoftwareCount =