Skip to content

Commit

Permalink
chore: fix last scale banner
Browse files Browse the repository at this point in the history
We cannot always find the last (2) scale operations in order to render
the from and to container profile and sizes.  This change makes it so we
do not show inaccurate information to the user.
  • Loading branch information
neurosnap committed Nov 4, 2024
1 parent beab704 commit ea55037
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions src/ui/pages/app-detail-service-scale.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ const LastScaleBanner = ({ serviceId }: { serviceId: string }) => {
const prev = useSelector((s) =>
selectPreviousServiceScale(s, { id: serviceId }),
);
const neverScaled = current.status === "unknown";
const noScaleFound = current.status === "unknown";
const currentComplete = current.status === "succeeded";
const action = pollServiceOperations({ id: serviceId });
const loader = useLoader(action);
Expand All @@ -868,23 +868,30 @@ const LastScaleBanner = ({ serviceId }: { serviceId: string }) => {
const cancel = useMemo(() => cancelServicesOpsPoll(), []);
usePoller({ action: poller, cancel });

let tail = getScaleText(current);
if (prev.id !== "") {
tail = `from ${getScaleText(prev)} to ${tail}`;
}

if (loader.isInitialLoading) {
return null;
}

if (noScaleFound) {
return null;
}

if (!currentComplete) {
return (
<Banner variant="progress">
<strong>Scale in Progress</strong> {getScaleText(current)}
</Banner>
);
}

return (
<Banner variant={currentComplete || neverScaled ? "info" : "progress"}>
{neverScaled ? (
"Never Scaled"
) : (
<>
<strong>
{currentComplete ? "Last Scale" : "Scale in Progress"}:
</strong>{" "}
{prettyDateTime(current.createdAt)} from {getScaleText(prev)} to{" "}
{getScaleText(current)}
</>
)}
<Banner variant="info">
<strong>Last Scale</strong> {prettyDateTime(current.createdAt)} {tail}
</Banner>
);
};
Expand Down

0 comments on commit ea55037

Please sign in to comment.