Files
opencode-manager/frontend/src/components/repo/ResetPermissionsDialog.tsx
T
Chris Scott eedbbfb94e feat(session): paginated session list with infinite scroll and assistant mode improvements (#243)
* feat(session): paginated session list with infinite scroll and search

Replace per-directory useQueries session listing with a combined
cursor-based useInfiniteQuery (25 per page, loads more on scroll) and
move search into the API query instead of client-side filtering.

Add OpenCodeClient.listSessionsPage backed by the v2 /api/session
endpoint plus a toLegacySession adapter. Add invalidateSessionListCaches
to centralize session-list cache invalidation for infinite queries, and
update EventContext and useSSE to handle the new infinite-query cache
shape.

* fix(session): centralize and debounce session-list cache invalidation

Migrate ResetPermissionsDialog off the stale per-directory cache key
(which no longer matches the infinite-query key shape and hardcoded the
opencode URL) to the shared invalidateSessionListCaches helper, and drop
the now-unused repoDirectory prop and its call sites.

Debounce session-list invalidation on SSE session.updated events in
EventContext and useSSE so a burst of updates coalesces into a single
refetch instead of one per event. Fix the directory fallback in
EventContext getClient so it never returns the joined directory key.

* fix(permissions): scope instance dispose to the repo directory

Drop the session-list cache invalidation from ResetPermissionsDialog:
disposing the OpenCode instance does not change the persisted session
list, so the refetch was unnecessary, and the prior cache key no longer
matched the paginated shape.

Guard the reset-permissions route against an empty repo directory so it
never forwards /instance/dispose without a directory, which would
dispose the entire server instead of only the repo's instance.
2026-05-31 10:32:14 -04:00

75 lines
2.1 KiB
TypeScript

import { useMutation } from "@tanstack/react-query";
import { resetRepoPermissions } from "@/api/repos";
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog";
import { Button } from "@/components/ui/button";
import { Loader2 } from "lucide-react";
import { showToast } from "@/lib/toast";
interface ResetPermissionsDialogProps {
open: boolean;
onOpenChange: (open: boolean) => void;
repoId: number;
}
export function ResetPermissionsDialog({
open,
onOpenChange,
repoId,
}: ResetPermissionsDialogProps) {
const resetPermissionsMutation = useMutation({
mutationFn: () => resetRepoPermissions(repoId),
onSuccess: () => {
showToast.success("Permissions reset successfully");
onOpenChange(false);
},
onError: () => {
showToast.error("Failed to reset permissions");
},
});
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent>
<DialogHeader>
<DialogTitle>Reset Permissions</DialogTitle>
<DialogDescription>
This will clear all "Allow Always" permissions for this repository.
You will be prompted again for permission when opencode needs to perform
actions like running commands or editing files.
</DialogDescription>
</DialogHeader>
<DialogFooter>
<Button
variant="outline"
onClick={() => onOpenChange(false)}
disabled={resetPermissionsMutation.isPending}
>
Cancel
</Button>
<Button
variant="destructive"
onClick={() => resetPermissionsMutation.mutate()}
disabled={resetPermissionsMutation.isPending}
>
{resetPermissionsMutation.isPending ? (
<>
<Loader2 className="w-4 h-4 mr-2 animate-spin" />
Resetting...
</>
) : (
"Reset Permissions"
)}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
}