@@ -11,16 +11,33 @@ interface LastUsedProps {
11
11
}
12
12
13
13
export const LastUsed : FC < LastUsedProps > = ( { lastUsedAt } ) => {
14
- /**
15
- * @todo Verify that this is equivalent
16
- */
17
14
const [ circle , message ] = useTimeSync ( {
18
15
idealRefreshIntervalMs : IDEAL_REFRESH_ONE_MINUTE ,
19
16
select : ( date ) => {
17
+ /**
18
+ * @todo Verify that t.from(now) is equivalent to t.fromNow()
19
+ */
20
20
const t = dayjs ( lastUsedAt ) ;
21
- const deltaMsg = t . from ( dayjs ( date ) ) ;
22
- const circle = < StatusIndicatorDot variant = "inactive" /> ;
23
- return [ circle , deltaMsg ] as const ;
21
+ const now = dayjs ( date ) ;
22
+ let message = t . from ( now ) ;
23
+ let circle = < StatusIndicatorDot variant = "inactive" /> ;
24
+
25
+ if ( t . isAfter ( now . subtract ( 1 , "hour" ) ) ) {
26
+ circle = < StatusIndicatorDot variant = "success" /> ;
27
+ // Since the agent reports on a 10m interval,
28
+ // the last_used_at can be inaccurate when recent.
29
+ message = "Now" ;
30
+ } else if ( t . isAfter ( now . subtract ( 3 , "day" ) ) ) {
31
+ circle = < StatusIndicatorDot variant = "pending" /> ;
32
+ } else if ( t . isAfter ( now . subtract ( 1 , "month" ) ) ) {
33
+ circle = < StatusIndicatorDot variant = "warning" /> ;
34
+ } else if ( t . isAfter ( now . subtract ( 100 , "year" ) ) ) {
35
+ circle = < StatusIndicatorDot variant = "failed" /> ;
36
+ } else {
37
+ message = "Never" ;
38
+ }
39
+
40
+ return [ circle , message ] as const ;
24
41
} ,
25
42
} ) ;
26
43
0 commit comments