Add session forking capability (#5882)
Co-authored-by: Zane Staggs <zane@squareup.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { AppEvents } from '../constants/events';
|
||||
import React, { useRef, useState, useEffect, useMemo, useCallback } from 'react';
|
||||
import { Bug, ScrollText, ChefHat } from 'lucide-react';
|
||||
import { Bug, ChefHat, ScrollText } from 'lucide-react';
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from './ui/Tooltip';
|
||||
import { Button } from './ui/button';
|
||||
import type { View } from '../utils/navigationUtils';
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
Download,
|
||||
Upload,
|
||||
ExternalLink,
|
||||
Copy,
|
||||
Puzzle,
|
||||
} from 'lucide-react';
|
||||
import { Card } from '../ui/card';
|
||||
@@ -28,6 +29,7 @@ import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '../ui/
|
||||
import {
|
||||
deleteSession,
|
||||
exportSession,
|
||||
forkSession,
|
||||
importSession,
|
||||
listSessions,
|
||||
Session,
|
||||
@@ -436,6 +438,25 @@ const SessionListView: React.FC<SessionListViewProps> = React.memo(
|
||||
setShowDeleteConfirmation(true);
|
||||
}, []);
|
||||
|
||||
const handleDuplicateSession = useCallback(
|
||||
async (session: Session) => {
|
||||
try {
|
||||
await forkSession({
|
||||
path: { session_id: session.id },
|
||||
body: { truncate: false, copy: true },
|
||||
throwOnError: true,
|
||||
});
|
||||
toast.success(`Session "${session.name}" duplicated successfully`);
|
||||
await loadSessions();
|
||||
} catch (error) {
|
||||
console.error('Error duplicating session:', error);
|
||||
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
||||
toast.error(`Failed to duplicate session: ${errorMessage}`);
|
||||
}
|
||||
},
|
||||
[loadSessions]
|
||||
);
|
||||
|
||||
const handleConfirmDelete = useCallback(async () => {
|
||||
if (!sessionToDelete) return;
|
||||
|
||||
@@ -530,27 +551,37 @@ const SessionListView: React.FC<SessionListViewProps> = React.memo(
|
||||
const SessionItem = React.memo(function SessionItem({
|
||||
session,
|
||||
onEditClick,
|
||||
onDuplicateClick,
|
||||
onDeleteClick,
|
||||
onExportClick,
|
||||
onOpenInNewWindow,
|
||||
}: {
|
||||
session: Session;
|
||||
onEditClick: (session: Session) => void;
|
||||
onDuplicateClick: (session: Session) => void;
|
||||
onDeleteClick: (session: Session) => void;
|
||||
onExportClick: (session: Session, e: React.MouseEvent) => void;
|
||||
onOpenInNewWindow: (session: Session, e: React.MouseEvent) => void;
|
||||
}) {
|
||||
const handleEditClick = useCallback(
|
||||
(e: React.MouseEvent) => {
|
||||
e.stopPropagation(); // Prevent card click
|
||||
e.stopPropagation();
|
||||
onEditClick(session);
|
||||
},
|
||||
[onEditClick, session]
|
||||
);
|
||||
|
||||
const handleDuplicateClick = useCallback(
|
||||
(e: React.MouseEvent) => {
|
||||
e.stopPropagation();
|
||||
onDuplicateClick(session);
|
||||
},
|
||||
[onDuplicateClick, session]
|
||||
);
|
||||
|
||||
const handleDeleteClick = useCallback(
|
||||
(e: React.MouseEvent) => {
|
||||
e.stopPropagation(); // Prevent card click
|
||||
e.stopPropagation();
|
||||
onDeleteClick(session);
|
||||
},
|
||||
[onDeleteClick, session]
|
||||
@@ -605,6 +636,13 @@ const SessionListView: React.FC<SessionListViewProps> = React.memo(
|
||||
>
|
||||
<Edit2 className="w-3 h-3 text-textSubtle hover:text-textStandard" />
|
||||
</button>
|
||||
<button
|
||||
onClick={handleDuplicateClick}
|
||||
className="p-2 rounded hover:bg-gray-100 dark:hover:bg-gray-700 cursor-pointer"
|
||||
title="Duplicate session"
|
||||
>
|
||||
<Copy className="w-3 h-3 text-textSubtle hover:text-textStandard" />
|
||||
</button>
|
||||
<button
|
||||
onClick={handleDeleteClick}
|
||||
className="p-2 rounded hover:bg-red-50 dark:hover:bg-red-900/20 cursor-pointer transition-colors"
|
||||
@@ -757,6 +795,7 @@ const SessionListView: React.FC<SessionListViewProps> = React.memo(
|
||||
key={session.id}
|
||||
session={session}
|
||||
onEditClick={handleEditSession}
|
||||
onDuplicateClick={handleDuplicateSession}
|
||||
onDeleteClick={handleDeleteSession}
|
||||
onExportClick={handleExportSession}
|
||||
onOpenInNewWindow={handleOpenInNewWindow}
|
||||
|
||||
Reference in New Issue
Block a user