cleanup history page
This commit is contained in:
parent
326440f656
commit
815e51c721
3 changed files with 84 additions and 63 deletions
|
|
@ -65,7 +65,7 @@ export function HistoryTableRow({
|
|||
onMouseEnter={() => setHovered(true)}
|
||||
onMouseLeave={() => setHovered(false)}
|
||||
data-testid={`history-row-${index}`}
|
||||
className="hover:bg-list-hover relative box-border flex w-full cursor-pointer overflow-hidden rounded-lg p-3"
|
||||
className="border-border relative mb-2 box-border flex w-full cursor-pointer overflow-hidden rounded-lg border border-solid p-3"
|
||||
onClick={async () => {
|
||||
await dispatch(exitEdit({}));
|
||||
if (sessionMetadata.sessionId !== currentSessionId) {
|
||||
|
|
@ -117,7 +117,7 @@ export function HistoryTableRow({
|
|||
</div>
|
||||
|
||||
{hovered && !editing && (
|
||||
<div className="bg-vsc-background absolute right-2 top-1/2 ml-auto flex -translate-y-1/2 transform items-center gap-x-1 rounded-full px-2 py-1 shadow-md">
|
||||
<div className="bg-badge absolute right-2 top-1/2 ml-auto flex -translate-y-1/2 transform items-center gap-x-1 rounded-full px-2 py-1 shadow-md">
|
||||
<HeaderButtonWithToolTip
|
||||
text="Edit"
|
||||
onClick={async (e) => {
|
||||
|
|
|
|||
|
|
@ -21,20 +21,12 @@ import {
|
|||
import { setDialogMessage, setShowDialog } from "../../redux/slices/uiSlice";
|
||||
import { refreshSessionMetadata } from "../../redux/thunks/session";
|
||||
import { getFontSize, getPlatform } from "../../util";
|
||||
import { cn } from "../../util/cn";
|
||||
import { ROUTES } from "../../util/navigation";
|
||||
import ConfirmationDialog from "../dialogs/ConfirmationDialog";
|
||||
import { Button } from "../ui";
|
||||
import { HistoryTableRow } from "./HistoryTableRow";
|
||||
|
||||
const parseDate = (date: string): Date => {
|
||||
let dateObj = new Date(date);
|
||||
if (isNaN(dateObj.getTime())) {
|
||||
dateObj = new Date(parseInt(date));
|
||||
}
|
||||
return dateObj;
|
||||
};
|
||||
|
||||
const HEADER_CLASS =
|
||||
"flex user-select-none mt-1 opacity-75 text-center font-bold items-center justify-center sticky h-6";
|
||||
import { groupSessionsByDate, parseDate } from "./util";
|
||||
|
||||
export function History() {
|
||||
const dispatch = useAppDispatch();
|
||||
|
|
@ -124,10 +116,9 @@ export function History() {
|
|||
);
|
||||
}, [allSessionMetadata, searchTerm, minisearch]);
|
||||
|
||||
const yesterday = new Date(Date.now() - 1000 * 60 * 60 * 24);
|
||||
const lastWeek = new Date(Date.now() - 1000 * 60 * 60 * 24 * 7);
|
||||
const lastMonth = new Date(Date.now() - 1000 * 60 * 60 * 24 * 30);
|
||||
const earlier = new Date(0);
|
||||
const sessionGroups = useMemo(() => {
|
||||
return groupSessionsByDate(filteredAndSortedSessions);
|
||||
}, [filteredAndSortedSessions]);
|
||||
|
||||
const showClearSessionsDialog = () => {
|
||||
dispatch(
|
||||
|
|
@ -158,7 +149,7 @@ export function History() {
|
|||
style={{ fontSize: getFontSize() }}
|
||||
className="flex flex-1 flex-col overflow-auto px-1"
|
||||
>
|
||||
<div className="relative my-2 flex justify-center space-x-2">
|
||||
<div className="relative my-2 mt-4 flex justify-center space-x-2">
|
||||
<input
|
||||
className="bg-vsc-input-background text-vsc-foreground flex-1 rounded-md border border-none py-1 pl-2 pr-8 text-sm outline-none focus:outline-none"
|
||||
ref={searchInputRef}
|
||||
|
|
@ -196,61 +187,43 @@ export function History() {
|
|||
|
||||
<table className="flex flex-1 flex-col">
|
||||
<tbody className="">
|
||||
{filteredAndSortedSessions.map((session, index) => {
|
||||
const prevDate =
|
||||
index > 0
|
||||
? parseDate(filteredAndSortedSessions[index - 1].dateCreated)
|
||||
: earlier;
|
||||
const date = parseDate(session.dateCreated);
|
||||
return (
|
||||
<Fragment key={index}>
|
||||
{index === 0 && date > yesterday && (
|
||||
<tr className={HEADER_CLASS}>
|
||||
<td colSpan={3}>Today</td>
|
||||
</tr>
|
||||
{sessionGroups.map((group, groupIndex) => (
|
||||
<Fragment key={group.label}>
|
||||
<tr
|
||||
className={cn(
|
||||
"user-select-none sticky mb-3 ml-2 flex h-6 justify-start text-left text-base font-bold opacity-75",
|
||||
groupIndex === 0 ? "mt-2" : "mt-8",
|
||||
)}
|
||||
{date < yesterday &&
|
||||
date > lastWeek &&
|
||||
prevDate > yesterday && (
|
||||
<div className={HEADER_CLASS}>
|
||||
<td colSpan={3}>This Week</td>
|
||||
</div>
|
||||
)}
|
||||
{date < lastWeek &&
|
||||
date > lastMonth &&
|
||||
prevDate > lastWeek && (
|
||||
<div className={HEADER_CLASS}>
|
||||
<td colSpan={3}>This Month</td>
|
||||
</div>
|
||||
)}
|
||||
{date < lastMonth && prevDate > lastMonth && (
|
||||
<div className={HEADER_CLASS}>
|
||||
<td colSpan={3}>Older</td>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<HistoryTableRow sessionMetadata={session} index={index} />
|
||||
</Fragment>
|
||||
);
|
||||
})}
|
||||
>
|
||||
<td colSpan={3}>{group.label}</td>
|
||||
</tr>
|
||||
{group.sessions.map((session, sessionIndex) => (
|
||||
<HistoryTableRow
|
||||
key={session.sessionId}
|
||||
sessionMetadata={session}
|
||||
index={sessionIndex}
|
||||
/>
|
||||
))}
|
||||
</Fragment>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div className="border-border flex items-center justify-center border-0 border-t border-solid px-2 py-3 text-xs">
|
||||
<span data-testid="history-sessions-note">
|
||||
Data is saved in{" "}
|
||||
<div className="border-border flex flex-col items-end justify-center border-0 border-t border-solid px-2 py-3 text-xs">
|
||||
<Button variant="secondary" size="sm" onClick={showClearSessionsDialog}>
|
||||
Clear chats
|
||||
</Button>
|
||||
<span
|
||||
className="text-description text-2xs"
|
||||
data-testid="history-sessions-note"
|
||||
>
|
||||
Chat history is saved to{" "}
|
||||
<span className="italic">
|
||||
{platform === "windows"
|
||||
? "%USERPROFILE%/.continue"
|
||||
: "~/.continue/sessions"}
|
||||
</span>
|
||||
</span>
|
||||
<span
|
||||
className="text-2xs text-description-muted ml-1 cursor-pointer hover:underline"
|
||||
onClick={showClearSessionsDialog}
|
||||
>
|
||||
(Clear session history)
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
|
|
|||
48
gui/src/components/History/util.ts
Normal file
48
gui/src/components/History/util.ts
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
import { SessionMetadata } from "core";
|
||||
|
||||
export const parseDate = (date: string): Date => {
|
||||
let dateObj = new Date(date);
|
||||
if (isNaN(dateObj.getTime())) {
|
||||
dateObj = new Date(parseInt(date));
|
||||
}
|
||||
return dateObj;
|
||||
};
|
||||
|
||||
export interface SessionGroup {
|
||||
label: string;
|
||||
sessions: SessionMetadata[];
|
||||
}
|
||||
|
||||
export const groupSessionsByDate = (sessions: SessionMetadata[]): SessionGroup[] => {
|
||||
const yesterday = new Date(Date.now() - 1000 * 60 * 60 * 24);
|
||||
const lastWeek = new Date(Date.now() - 1000 * 60 * 60 * 24 * 7);
|
||||
const lastMonth = new Date(Date.now() - 1000 * 60 * 60 * 24 * 30);
|
||||
|
||||
const groups: SessionGroup[] = [];
|
||||
|
||||
const todaySessions = sessions.filter(
|
||||
(session) => parseDate(session.dateCreated) > yesterday,
|
||||
);
|
||||
const weekSessions = sessions.filter((session) => {
|
||||
const date = parseDate(session.dateCreated);
|
||||
return date <= yesterday && date > lastWeek;
|
||||
});
|
||||
const monthSessions = sessions.filter((session) => {
|
||||
const date = parseDate(session.dateCreated);
|
||||
return date <= lastWeek && date > lastMonth;
|
||||
});
|
||||
const olderSessions = sessions.filter(
|
||||
(session) => parseDate(session.dateCreated) <= lastMonth,
|
||||
);
|
||||
|
||||
if (todaySessions.length > 0)
|
||||
groups.push({ label: "Today", sessions: todaySessions });
|
||||
if (weekSessions.length > 0)
|
||||
groups.push({ label: "This Week", sessions: weekSessions });
|
||||
if (monthSessions.length > 0)
|
||||
groups.push({ label: "This Month", sessions: monthSessions });
|
||||
if (olderSessions.length > 0)
|
||||
groups.push({ label: "Older", sessions: olderSessions });
|
||||
|
||||
return groups;
|
||||
};
|
||||
Loading…
Add table
Reference in a new issue