Skip to content

Commit 425919b

Browse files
author
Bogdan Tsechoev
committed
fix(ui): Correct edge snapshots sorting by dataStateAt
1 parent 78f396a commit 425919b

File tree

1 file changed

+18
-5
lines changed
  • ui/packages/shared/pages/Instance/Info/Snapshots

1 file changed

+18
-5
lines changed

ui/packages/shared/pages/Instance/Info/Snapshots/utils.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,24 @@
88
import { Snapshot } from '@postgres.ai/shared/types/api/entities/snapshot'
99

1010
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+
1427
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
1730
}
1831
}

0 commit comments

Comments
 (0)