Skip to content

Commit

Permalink
feat: add button to control sorting of task history (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
mondaychen authored May 6, 2024
1 parent 34461a2 commit 60e11f5
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/common/TaskHistory.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useState } from "react";
import {
Alert,
AlertIcon,
Expand All @@ -11,11 +12,13 @@ import {
AccordionButton,
AccordionPanel,
AccordionIcon,
Icon,
Spacer,
ColorProps,
BackgroundProps,
} from "@chakra-ui/react";
import { TaskHistoryEntry } from "../state/currentTask";
import { BsSortNumericDown, BsSortNumericUp } from "react-icons/bs";
import { useAppState } from "../state/store";
import CopyButton from "./CopyButton";
import Notes from "./CustomKnowledgeBase/Notes";
Expand Down Expand Up @@ -155,8 +158,19 @@ export default function TaskHistory() {
taskStatus: state.currentTask.status,
taskHistory: state.currentTask.history,
}));
const [sortNumericDown, setSortNumericDown] = useState(false);
const toggleSort = () => {
setSortNumericDown(!sortNumericDown);
};

if (taskHistory.length === 0 && taskStatus !== "running") return null;
const historyItems = taskHistory.map((entry, index) => (
<TaskHistoryItem key={index} index={index} entry={entry} />
));
historyItems.unshift(<MatchedNotes key="matched-notes" />);
if (!sortNumericDown) {
historyItems.reverse();
}

return (
<VStack mt={8}>
Expand All @@ -165,13 +179,17 @@ export default function TaskHistory() {
Action History
</Heading>
<Spacer />
<Icon
as={sortNumericDown ? BsSortNumericDown : BsSortNumericUp}
cursor="pointer"
color="gray.500"
_hover={{ color: "gray.700" }}
onClick={toggleSort}
/>
<CopyButton text={JSON.stringify(taskHistory, null, 2)} />
</HStack>
<Accordion allowMultiple w="full" pb="4">
<MatchedNotes />
{taskHistory.map((entry, index) => (
<TaskHistoryItem key={index} index={index} entry={entry} />
))}
{historyItems}
</Accordion>
</VStack>
);
Expand Down

0 comments on commit 60e11f5

Please sign in to comment.