Skip to content

Commit 8f9b43b

Browse files
committed
Fix recent activity rerender
1 parent 1659125 commit 8f9b43b

File tree

21 files changed

+195
-154
lines changed

21 files changed

+195
-154
lines changed

src/components/Admin/Header/Greeting/index.tsx

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect, useState } from "react";
1+
import { useNow } from "../../../../hooks/useNow";
22
import { useGetUserProfileQuery } from "../../../../redux/services/digma";
33
import * as s from "./styles";
44

@@ -19,17 +19,9 @@ const getGreetingText = (dateTime: number) => {
1919
};
2020

2121
export const Greeting = () => {
22+
const now = useNow(REFRESH_INTERVAL);
2223
const { data: userProfile } = useGetUserProfileQuery();
23-
const [currentDateTime, setCurrentDateTime] = useState(Date.now());
24-
const greetingText = getGreetingText(currentDateTime);
25-
26-
useEffect(() => {
27-
const intervalId = setInterval(() => {
28-
setCurrentDateTime(Date.now());
29-
}, REFRESH_INTERVAL);
30-
31-
return () => clearInterval(intervalId);
32-
}, []);
24+
const greetingText = getGreetingText(now);
3325

3426
if (!userProfile) {
3527
return null;

src/components/Admin/Header/HeaderContent/FilterMenu/FilterButton/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ const FilterButtonComponent = (
2020
</Tooltip>
2121
</div>
2222
);
23+
2324
export const FilterButton = forwardRef(FilterButtonComponent);

src/components/Assets/AssetList/AssetEntry/index.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { getFeatureFlagValue } from "../../../../featureFlags";
2+
import { useNow } from "../../../../hooks/useNow";
23
import { AssetsSortingCriterion } from "../../../../redux/services/types";
34
import { useConfigSelector } from "../../../../store/config/useConfigSelector";
45
import { isNumber } from "../../../../typeGuards/isNumber";
@@ -25,6 +26,7 @@ export const AssetEntry = ({
2526
sortingCriterion
2627
}: AssetEntryProps) => {
2728
const { backendInfo } = useConfigSelector();
29+
const now = useNow();
2830
const isNewImpactScoreCalculationEnabled = getFeatureFlagValue(
2931
backendInfo,
3032
FeatureFlag.IsNewImpactScoreCalculationEnabled
@@ -62,14 +64,14 @@ export const AssetEntry = ({
6264

6365
const servicesTitle = entry.services.join(", ");
6466

65-
const timeDistanceString = formatTimeDistance(lastSeenDateTime, {
67+
const timeDistanceString = formatTimeDistance(lastSeenDateTime, now, {
6668
format: "short",
6769
withDescriptiveWords: false
6870
}).replace(" ", "");
6971
const timeDistanceTitle = new Date(lastSeenDateTime).toString();
7072

7173
const isNew = isString(entry.firstDetected)
72-
? Date.now() - new Date(entry.firstDetected).valueOf() < IS_NEW_TIME_LIMIT
74+
? now - new Date(entry.firstDetected).valueOf() < IS_NEW_TIME_LIMIT
7375
: false;
7476

7577
return (

src/components/Errors/ErrorCard/TimestampKeyValue/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1+
import { useNow } from "../../../../hooks/useNow";
12
import { formatTimeDistance } from "../../../../utils/formatTimeDistance";
23
import { Tooltip } from "../../../common/v3/Tooltip";
34
import * as s from "./styles";
45
import type { TimestampProps } from "./types";
56

67
export const TimestampKeyValue = ({ label, timestamp }: TimestampProps) => {
78
const dateTimeString = new Date(timestamp).toString();
9+
const now = useNow();
810

911
return (
1012
<Tooltip title={dateTimeString} key={label}>
1113
<s.Container>
1214
<s.Label>{label}:</s.Label>
13-
<s.TimeDistance>{formatTimeDistance(timestamp)}</s.TimeDistance>
15+
<s.TimeDistance>{formatTimeDistance(timestamp, now)}</s.TimeDistance>
1416
</s.Container>
1517
</Tooltip>
1618
);

src/components/Errors/ErrorDetails/ErrorDetailsCardContent/index.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useEffect, useState } from "react";
2+
import { useNow } from "../../../../hooks/useNow";
23
import { usePrevious } from "../../../../hooks/usePrevious";
34
import { isNull } from "../../../../typeGuards/isNull";
45
import { isNumber } from "../../../../typeGuards/isNumber";
@@ -24,6 +25,7 @@ export const ErrorDetailsCardContent = ({
2425
}: ErrorDetailsCardContentProps) => {
2526
const previousId = usePrevious(id);
2627
const [currentFlowStack, setCurrentFlowStack] = useState(0);
28+
const now = useNow();
2729

2830
useEffect(() => {
2931
if (isString(previousId) && previousId !== id) {
@@ -35,9 +37,9 @@ export const ErrorDetailsCardContent = ({
3537
.filter(isServiceInfoWithName)
3638
.map((x) => x.serviceName);
3739
const startedTooltip = new Date(data.firstOccurenceTime).toString();
38-
const startedString = formatTimeDistance(data.firstOccurenceTime);
40+
const startedString = formatTimeDistance(data.firstOccurenceTime, now);
3941
const lastTooltip = new Date(data.lastOccurenceTime).toString();
40-
const lastString = formatTimeDistance(data.lastOccurenceTime);
42+
const lastString = formatTimeDistance(data.lastOccurenceTime, now);
4143
const avgPerDay = data.dayAvg;
4244

4345
const flows = data.errors.filter((x) => !isNull(x));

src/components/Highlights/Performance/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { Row } from "@tanstack/react-table";
22
import { createColumnHelper } from "@tanstack/react-table";
33
import { useMemo } from "react";
44
import { getFeatureFlagValue } from "../../../featureFlags";
5+
import { useNow } from "../../../hooks/useNow";
56
import {
67
useGetPerformanceHighlightsQuery,
78
useGetPerformanceHighlightsV2Query
@@ -28,6 +29,7 @@ import * as s from "./styles";
2829

2930
export const Performance = () => {
3031
const { scope, environments, backendInfo } = useConfigSelector();
32+
const now = useNow();
3133

3234
const areImpactHighlightsEnabled = getFeatureFlagValue(
3335
backendInfo,
@@ -125,7 +127,7 @@ export const Performance = () => {
125127
return null;
126128
}
127129

128-
const value = formatTimeDistance(lastCallDateTime, {
130+
const value = formatTimeDistance(lastCallDateTime, now, {
129131
format: "short",
130132
withDescriptiveWords: false
131133
}).replace(" ", "");

src/components/Insights/InsightsCatalog/InsightsPage/InsightCardRenderer/insightCards/SpanDurationsInsightCard/index.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
import type { DefaultTheme } from "styled-components";
1212
import { useTheme } from "styled-components";
1313
import { PERCENTILES } from "../../../../../../../constants";
14+
import { useNow } from "../../../../../../../hooks/useNow";
1415
import type { Duration } from "../../../../../../../redux/services/types";
1516
import { isNumber } from "../../../../../../../typeGuards/isNumber";
1617
import { convertToDuration } from "../../../../../../../utils/convertToDuration";
@@ -37,7 +38,7 @@ import { DIVIDER, LABEL_HEIGHT } from "./constants";
3738
import * as s from "./styles";
3839
import type { SpanDurationsInsightCardProps, TickData } from "./types";
3940

40-
const LAST_CALL_TIME_DISTANCE_LIMIT = 60 * 1000; // in milliseconds
41+
const LAST_CALL_TIME_LIMIT = 60 * 1000; // in milliseconds
4142

4243
// in pixels
4344
const MIN_BAR_HEIGHT = 5;
@@ -142,6 +143,7 @@ export const SpanDurationsInsightCard = ({
142143
tooltipBoundaryRef
143144
}: SpanDurationsInsightCardProps) => {
144145
const theme = useTheme();
146+
const now = useNow();
145147
const { observe, width } = useDimensions();
146148

147149
const sortedPercentiles = [...insight.percentiles].sort(
@@ -168,8 +170,7 @@ ${getDurationString(insight.average)}${
168170
const traces: Trace[] = [];
169171

170172
const isLastCallRecent = spanLastCall
171-
? Date.now() - new Date(spanLastCall.startTime).valueOf() <
172-
LAST_CALL_TIME_DISTANCE_LIMIT
173+
? now - new Date(spanLastCall.startTime).valueOf() < LAST_CALL_TIME_LIMIT
173174
: false;
174175

175176
const chartData = insight.histogramPlot
@@ -299,7 +300,7 @@ ${getDurationString(insight.average)}${
299300
title={
300301
isLastCallRecent
301302
? "Moments ago"
302-
: formatTimeDistance(spanLastCall.startTime)
303+
: formatTimeDistance(spanLastCall.startTime, now)
303304
}
304305
>
305306
<Tag

src/components/Insights/InsightsCatalog/InsightsPage/InsightCardRenderer/insightCards/common/DurationChange/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { formatDuration, intervalToDuration } from "date-fns";
2+
import { useNow } from "../../../../../../../../hooks/useNow";
23
import type { Duration } from "../../../../../../../../redux/services/types";
34
import { formatTimeDistance } from "../../../../../../../../utils/formatTimeDistance";
45
import { roundTo } from "../../../../../../../../utils/roundTo";
@@ -74,6 +75,8 @@ export const DurationChange = ({
7475
previousDuration,
7576
changeTime
7677
}: DurationChangeProps) => {
78+
const now = useNow();
79+
7780
const isChangeMeaningful = isChangeMeaningfulEnough(
7881
currentDuration,
7982
previousDuration,
@@ -90,7 +93,7 @@ export const DurationChange = ({
9093
{previousDuration && changeTime && isChangeMeaningful && (
9194
<Tag
9295
type={getTagType(direction)}
93-
title={formatTimeDistance(changeTime)}
96+
title={formatTimeDistance(changeTime, now)}
9497
content={
9598
<s.Container>
9699
<s.ArrowContainer>
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useNow } from "../../../../../../../../../../../hooks/useNow";
12
import { isString } from "../../../../../../../../../../../typeGuards/isString";
23
import { formatTimeDistance } from "../../../../../../../../../../../utils/formatTimeDistance";
34
import { KeyValue } from "../KeyValue";
@@ -6,7 +7,10 @@ import type { TimestampKeyValueProps } from "./types";
67
export const TimestampKeyValue = ({
78
label,
89
children
9-
}: TimestampKeyValueProps) =>
10-
isString(children) ? (
11-
<KeyValue label={label}>{formatTimeDistance(children)}</KeyValue>
10+
}: TimestampKeyValueProps) => {
11+
const now = useNow();
12+
13+
return isString(children) ? (
14+
<KeyValue label={label}>{formatTimeDistance(children, now)}</KeyValue>
1215
) : null;
16+
};

src/components/Insights/InsightsCatalog/InsightsPage/InsightCardRenderer/insightCards/common/InsightCard/InsightHeader/index.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useNow } from "../../../../../../../../../hooks/useNow";
12
import { useConfigSelector } from "../../../../../../../../../store/config/useConfigSelector";
23
import { isString } from "../../../../../../../../../typeGuards/isString";
34
import { formatTimeDistance } from "../../../../../../../../../utils/formatTimeDistance";
@@ -43,8 +44,9 @@ export const InsightHeader = ({
4344

4445
const insightTypeInfo = getInsightTypeInfo(insight.type, insight.subType);
4546
const statusTooltipContent = renderInsightStatusTooltipContent(insight);
47+
const now = useNow();
4648
const isNew = isString(insight.firstDetected)
47-
? Date.now() - new Date(insight.firstDetected).valueOf() < IS_NEW_TIME_LIMIT
49+
? now - new Date(insight.firstDetected).valueOf() < IS_NEW_TIME_LIMIT
4850
: false;
4951
const spanInfo =
5052
isSpanInsight(insight) || isEndpointInsight(insight)
@@ -74,7 +76,7 @@ export const InsightHeader = ({
7476
<s.Description>
7577
Updated:
7678
<Tooltip title={new Date(lastUpdateTimer).toString()}>
77-
<span>{formatTimeDistance(lastUpdateTimer)}</span>
79+
<span>{formatTimeDistance(lastUpdateTimer, now)}</span>
7880
</Tooltip>
7981
</s.Description>
8082
)}

0 commit comments

Comments
 (0)