File tree Expand file tree Collapse file tree 1 file changed +18
-5
lines changed
ui/packages/shared/pages/Instance/Info/Snapshots Expand file tree Collapse file tree 1 file changed +18
-5
lines changed Original file line number Diff line number Diff line change 8
8
import { Snapshot } from '@postgres.ai/shared/types/api/entities/snapshot'
9
9
10
10
export const getEdgeSnapshots = ( snapshots : Snapshot [ ] ) => {
11
- const list = [ ...snapshots ]
12
- const [ first ] = list
13
- const [ last ] = list . reverse ( )
11
+ if ( ! snapshots . length ) {
12
+ return {
13
+ firstSnapshot : null ,
14
+ lastSnapshot : null
15
+ }
16
+ }
17
+
18
+ const sortedList = [ ...snapshots ] . sort ( ( a , b ) => {
19
+ const aTime = a . dataStateAtDate ?. getTime ( ) ?? 0
20
+ const bTime = b . dataStateAtDate ?. getTime ( ) ?? 0
21
+ return bTime - aTime
22
+ } )
23
+
24
+ const [ first ] = sortedList
25
+ const [ last ] = sortedList . slice ( - 1 )
26
+
14
27
return {
15
- firstSnapshot : ( first as Snapshot | undefined ) ?? null ,
16
- lastSnapshot : ( last as Snapshot | undefined ) ?? null
28
+ firstSnapshot : first ?? null , // newest
29
+ lastSnapshot : last ?? null // oldest
17
30
}
18
31
}
You can’t perform that action at this time.
0 commit comments