Skip to content

Commit 60e11f5

Browse files
authored
feat: add button to control sorting of task history (#155)
1 parent 34461a2 commit 60e11f5

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

src/common/TaskHistory.tsx

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useState } from "react";
12
import {
23
Alert,
34
AlertIcon,
@@ -11,11 +12,13 @@ import {
1112
AccordionButton,
1213
AccordionPanel,
1314
AccordionIcon,
15+
Icon,
1416
Spacer,
1517
ColorProps,
1618
BackgroundProps,
1719
} from "@chakra-ui/react";
1820
import { TaskHistoryEntry } from "../state/currentTask";
21+
import { BsSortNumericDown, BsSortNumericUp } from "react-icons/bs";
1922
import { useAppState } from "../state/store";
2023
import CopyButton from "./CopyButton";
2124
import Notes from "./CustomKnowledgeBase/Notes";
@@ -155,8 +158,19 @@ export default function TaskHistory() {
155158
taskStatus: state.currentTask.status,
156159
taskHistory: state.currentTask.history,
157160
}));
161+
const [sortNumericDown, setSortNumericDown] = useState(false);
162+
const toggleSort = () => {
163+
setSortNumericDown(!sortNumericDown);
164+
};
158165

159166
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+
}
160174

161175
return (
162176
<VStack mt={8}>
@@ -165,13 +179,17 @@ export default function TaskHistory() {
165179
Action History
166180
</Heading>
167181
<Spacer />
182+
<Icon
183+
as={sortNumericDown ? BsSortNumericDown : BsSortNumericUp}
184+
cursor="pointer"
185+
color="gray.500"
186+
_hover={{ color: "gray.700" }}
187+
onClick={toggleSort}
188+
/>
168189
<CopyButton text={JSON.stringify(taskHistory, null, 2)} />
169190
</HStack>
170191
<Accordion allowMultiple w="full" pb="4">
171-
<MatchedNotes />
172-
{taskHistory.map((entry, index) => (
173-
<TaskHistoryItem key={index} index={index} entry={entry} />
174-
))}
192+
{historyItems}
175193
</Accordion>
176194
</VStack>
177195
);

0 commit comments

Comments
 (0)