Skip to content

Commit 4888e27

Browse files
committed
[5667] Extract the dynamic age indicator
This avoids re-rendering the whole results component on every 'tick', which can be an issue at the moment with large result sets. Also increase the tick from 10s to 1min: there is no need to update more frequently than that given the precision of the text message. Bug: #5667 Signed-off-by: Pierre-Charles David <[email protected]>
1 parent 802d728 commit 4888e27

File tree

1 file changed

+14
-9
lines changed
  • packages/sirius-web/frontend/sirius-web-application/src/views/edit-project/workbench-views/search

1 file changed

+14
-9
lines changed

packages/sirius-web/frontend/sirius-web-application/src/views/edit-project/workbench-views/search/SearchResults.tsx

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,8 @@ const useSecondsSince = (startTime: number, refreshDelay: number = 1000): number
6363
return secondsSince;
6464
};
6565

66-
export const SearchResults = ({ loading, query, result, timestamp }: SearchResultProps) => {
67-
const { classes } = useSearchResultStyles();
68-
const { setSelection } = useSelection();
69-
const { selectionTargets } = useSelectionTargets();
70-
71-
const resultsAge = useSecondsSince(timestamp, 10_000);
66+
const AgeIndicator = ({ timestamp }: { timestamp: number }) => {
67+
const resultsAge = useSecondsSince(timestamp, 60_000);
7268
const resultsAgeText =
7369
resultsAge < 60
7470
? `less than a minute`
@@ -77,6 +73,17 @@ export const SearchResults = ({ loading, query, result, timestamp }: SearchResul
7773
: resultsAge < 86_400
7874
? `${Math.floor(resultsAge / 3_600)}h`
7975
: `${Math.floor(resultsAge / 86_400)}d`;
76+
return (
77+
<Typography variant="caption" color="secondary">
78+
{`Performed ${resultsAgeText} ago`}
79+
</Typography>
80+
);
81+
};
82+
83+
export const SearchResults = ({ loading, query, result, timestamp }: SearchResultProps) => {
84+
const { classes } = useSearchResultStyles();
85+
const { setSelection } = useSelection();
86+
const { selectionTargets } = useSelectionTargets();
8087

8188
const matches = result?.matches || [];
8289

@@ -104,9 +111,7 @@ export const SearchResults = ({ loading, query, result, timestamp }: SearchResul
104111
<Typography variant="subtitle2" color="secondary">
105112
{`${matches.length} result${matches.length > 1 ? 's' : ''} for '${query.text}'`}
106113
</Typography>
107-
<Typography variant="caption" color="secondary">
108-
{`Performed ${resultsAgeText} ago`}
109-
</Typography>
114+
<AgeIndicator timestamp={timestamp} />
110115
</div>
111116
</>
112117
);

0 commit comments

Comments
 (0)