1
+ import { useState } from "react" ;
1
2
import {
2
3
Alert ,
3
4
AlertIcon ,
@@ -11,11 +12,13 @@ import {
11
12
AccordionButton ,
12
13
AccordionPanel ,
13
14
AccordionIcon ,
15
+ Icon ,
14
16
Spacer ,
15
17
ColorProps ,
16
18
BackgroundProps ,
17
19
} from "@chakra-ui/react" ;
18
20
import { TaskHistoryEntry } from "../state/currentTask" ;
21
+ import { BsSortNumericDown , BsSortNumericUp } from "react-icons/bs" ;
19
22
import { useAppState } from "../state/store" ;
20
23
import CopyButton from "./CopyButton" ;
21
24
import Notes from "./CustomKnowledgeBase/Notes" ;
@@ -155,8 +158,19 @@ export default function TaskHistory() {
155
158
taskStatus : state . currentTask . status ,
156
159
taskHistory : state . currentTask . history ,
157
160
} ) ) ;
161
+ const [ sortNumericDown , setSortNumericDown ] = useState ( false ) ;
162
+ const toggleSort = ( ) => {
163
+ setSortNumericDown ( ! sortNumericDown ) ;
164
+ } ;
158
165
159
166
if ( taskHistory . length === 0 && taskStatus !== "running" ) return null ;
167
+ const historyItems = taskHistory . map ( ( entry , index ) => (
168
+ < TaskHistoryItem key = { index } index = { index } entry = { entry } />
169
+ ) ) ;
170
+ historyItems . unshift ( < MatchedNotes key = "matched-notes" /> ) ;
171
+ if ( ! sortNumericDown ) {
172
+ historyItems . reverse ( ) ;
173
+ }
160
174
161
175
return (
162
176
< VStack mt = { 8 } >
@@ -165,13 +179,17 @@ export default function TaskHistory() {
165
179
Action History
166
180
</ Heading >
167
181
< Spacer />
182
+ < Icon
183
+ as = { sortNumericDown ? BsSortNumericDown : BsSortNumericUp }
184
+ cursor = "pointer"
185
+ color = "gray.500"
186
+ _hover = { { color : "gray.700" } }
187
+ onClick = { toggleSort }
188
+ />
168
189
< CopyButton text = { JSON . stringify ( taskHistory , null , 2 ) } />
169
190
</ HStack >
170
191
< Accordion allowMultiple w = "full" pb = "4" >
171
- < MatchedNotes />
172
- { taskHistory . map ( ( entry , index ) => (
173
- < TaskHistoryItem key = { index } index = { index } entry = { entry } />
174
- ) ) }
192
+ { historyItems }
175
193
</ Accordion >
176
194
</ VStack >
177
195
) ;
0 commit comments