1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Fix ReactiveDuration to update as frequently as necessary (#6375)

- When used in non compact mode (eg KubeObjectMeta's age) the seconds
  can be displayed but previously between 10m and 180m of age, the
  display would only update every minute

Signed-off-by: Sebastian Malton <sebastian@malton.name>

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2022-10-11 10:58:46 -04:00 committed by GitHub
parent 51af8f8aa4
commit 4e02ccb1c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 13 deletions

View File

@ -18,19 +18,29 @@ export interface ReactiveDurationProps {
compact?: boolean; compact?: boolean;
} }
const everySecond = 1000;
const everyMinute = 60 * 1000;
/** /**
* This function computes a resonable update * This function computes a resonable update interval, matching `formatDuration`'s rules on when to display seconds
*/ */
function computeUpdateInterval(creationTimestampEpoch: number): number { function computeUpdateInterval(creationTimestampEpoch: number, compact: boolean): number {
const seconds = Math.floor((Date.now() - creationTimestampEpoch) / 1000); const seconds = Math.floor((Date.now() - creationTimestampEpoch) / 1000);
const minutes = Math.floor(seconds / 60); const minutes = Math.floor(seconds / 60);
if (minutes < 10) { if (minutes < 10) {
// Update every second return everySecond;
return 1000;
} }
return 60 * 1000; if (compact) {
return everyMinute;
}
if (minutes < (60 * 3)) {
return everySecond;
}
return everyMinute;
} }
export const ReactiveDuration = observer(({ timestamp, compact = true }: ReactiveDurationProps) => { export const ReactiveDuration = observer(({ timestamp, compact = true }: ReactiveDurationProps) => {
@ -42,7 +52,7 @@ export const ReactiveDuration = observer(({ timestamp, compact = true }: Reactiv
return ( return (
<> <>
{formatDuration(reactiveNow(computeUpdateInterval(timestampSeconds)) - timestampSeconds, compact)} {formatDuration(reactiveNow(computeUpdateInterval(timestampSeconds, compact)) - timestampSeconds, compact)}
</> </>
); );
}); });

View File

@ -62,13 +62,7 @@ const NonInjectedKubeObjectMeta = observer(({
<DrawerItem name="Created" hidden={isHidden("creationTimestamp")}> <DrawerItem name="Created" hidden={isHidden("creationTimestamp")}>
<KubeObjectAge object={object} compact={false} /> <KubeObjectAge object={object} compact={false} />
{" ago "} {" ago "}
{creationTimestamp && ( {creationTimestamp && <LocaleDate date={creationTimestamp} />}
<>
(
<LocaleDate date={creationTimestamp} />
)
</>
)}
</DrawerItem> </DrawerItem>
<DrawerItem name="Name" hidden={isHidden("name")}> <DrawerItem name="Name" hidden={isHidden("name")}>
{getName()} {getName()}