feat: Add delete session in the sessions menu. (#1557)
Signed-off-by: Paolo Insogna <paolo@cowtech.it> Co-authored-by: Bohdan Triapitsyn <artmore@protonmail.com>
This commit is contained in:
committed by
GitHub
co-authored by
Bohdan Triapitsyn
parent
a0597b1065
commit
b1810013e5
@@ -81,7 +81,7 @@ type Props = {
|
|||||||
addSessionToFolder: (scopeKey: string, folderId: string, sessionId: string) => void;
|
addSessionToFolder: (scopeKey: string, folderId: string, sessionId: string) => void;
|
||||||
createFolderAndStartRename: (scopeKey: string, parentId?: string | null) => { id: string } | null;
|
createFolderAndStartRename: (scopeKey: string, parentId?: string | null) => { id: string } | null;
|
||||||
openContextPanelTab: (directory: string, options: { mode: 'chat'; dedupeKey: string; label: string; readOnly?: boolean }) => void;
|
openContextPanelTab: (directory: string, options: { mode: 'chat'; dedupeKey: string; label: string; readOnly?: boolean }) => void;
|
||||||
handleDeleteSession: (session: Session, source?: { archivedBucket?: boolean }) => void;
|
handleDeleteSession: (session: Session, source?: { archivedBucket?: boolean; hardDelete?: boolean }) => void;
|
||||||
mobileVariant: boolean;
|
mobileVariant: boolean;
|
||||||
alwaysShowActions: boolean;
|
alwaysShowActions: boolean;
|
||||||
renderSessionNode: (node: SessionNode, depth?: number, groupDirectory?: string | null, projectId?: string | null, archivedBucket?: boolean, secondaryMeta?: SecondaryMeta | null, renderContext?: 'project' | 'recent') => React.ReactNode;
|
renderSessionNode: (node: SessionNode, depth?: number, groupDirectory?: string | null, projectId?: string | null, archivedBucket?: boolean, secondaryMeta?: SecondaryMeta | null, renderContext?: 'project' | 'recent') => React.ReactNode;
|
||||||
@@ -849,9 +849,15 @@ function SessionNodeItemComponent(props: Props): React.ReactNode {
|
|||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
<Separator />
|
<Separator />
|
||||||
<Item className="text-destructive focus:text-destructive [&>svg]:mr-1" onClick={() => handleDeleteSession(session, { archivedBucket })}>
|
{!archivedBucket ? (
|
||||||
<Icon name={archivedBucket ? "delete-bin" : "archive"} className="mr-1 h-4 w-4" />
|
<Item className="[&>svg]:mr-1" onClick={() => handleDeleteSession(session, { archivedBucket })}>
|
||||||
{archivedBucket ? t('sessions.sidebar.bulkActions.delete') : t('sessions.sidebar.bulkActions.archive')}
|
<Icon name="inbox-archive" className="mr-1 h-4 w-4" />
|
||||||
|
{t('sessions.sidebar.bulkActions.archive')}
|
||||||
|
</Item>
|
||||||
|
) : null}
|
||||||
|
<Item className="text-destructive focus:text-destructive [&>svg]:mr-1" onClick={() => handleDeleteSession(session, { archivedBucket, hardDelete: true })}>
|
||||||
|
<Icon name="delete-bin" className="mr-1 h-4 w-4" />
|
||||||
|
{t('sessions.sidebar.bulkActions.delete')}
|
||||||
</Item>
|
</Item>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -12,6 +12,11 @@ type DeleteSessionConfirmSetter = React.Dispatch<React.SetStateAction<{
|
|||||||
archivedBucket: boolean;
|
archivedBucket: boolean;
|
||||||
} | null>>;
|
} | null>>;
|
||||||
|
|
||||||
|
type DeleteSessionSource = {
|
||||||
|
archivedBucket?: boolean;
|
||||||
|
hardDelete?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
type Args = {
|
type Args = {
|
||||||
activeProjectId: string | null;
|
activeProjectId: string | null;
|
||||||
currentDirectory: string | null;
|
currentDirectory: string | null;
|
||||||
@@ -187,10 +192,10 @@ export const useSessionActions = (args: Args) => {
|
|||||||
const executeDeleteSession = React.useCallback(
|
const executeDeleteSession = React.useCallback(
|
||||||
async (
|
async (
|
||||||
session: Session,
|
session: Session,
|
||||||
source?: { archivedBucket?: boolean },
|
source?: DeleteSessionSource,
|
||||||
precomputed?: { descendantIds: string[] },
|
precomputed?: { descendantIds: string[] },
|
||||||
) => {
|
) => {
|
||||||
const shouldHardDelete = source?.archivedBucket === true;
|
const shouldHardDelete = source?.archivedBucket === true || source?.hardDelete === true;
|
||||||
// Use the snapshot taken when the dialog opened (if any) so the
|
// Use the snapshot taken when the dialog opened (if any) so the
|
||||||
// executed list matches what the user was told. Fall back to a fresh
|
// executed list matches what the user was told. Fall back to a fresh
|
||||||
// collection for direct-execute (no-dialog) callers.
|
// collection for direct-execute (no-dialog) callers.
|
||||||
@@ -246,8 +251,8 @@ export const useSessionActions = (args: Args) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const handleDeleteSession = React.useCallback(
|
const handleDeleteSession = React.useCallback(
|
||||||
(session: Session, source?: { archivedBucket?: boolean }) => {
|
(session: Session, source?: DeleteSessionSource) => {
|
||||||
const shouldHardDelete = source?.archivedBucket === true;
|
const shouldHardDelete = source?.archivedBucket === true || source?.hardDelete === true;
|
||||||
const effectiveDescendantIds = filterDescendantsForAction(
|
const effectiveDescendantIds = filterDescendantsForAction(
|
||||||
collectDescendants(session.id),
|
collectDescendants(session.id),
|
||||||
shouldHardDelete,
|
shouldHardDelete,
|
||||||
|
|||||||
Reference in New Issue
Block a user