Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add button to control sorting of task history #155

Merged
merged 1 commit into from
May 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading