Fix workspace actions in summary (#1986)
## Summary Fixed the "workspace not found" error when performing actions on non-selected workspaces. **Root cause**: The `getWorkspaceFromCache()` function only checked the React Query cache, but only the currently selected workspace had its full data cached. **Solution**: Modified the helper function to fetch from the API when data isn't in cache. **File modified**: `frontend/src/components/ui-new/actions/index.ts` **Changes**: 1. Renamed `getWorkspaceFromCache` → `getWorkspace` and made it async 2. Added fallback to `attemptsApi.get(workspaceId)` when cache miss occurs 3. Updated all 6 call sites to use `await getWorkspace()`: - `RenameWorkspace` (line 215) - `PinWorkspace` (line 229) - `ArchiveWorkspace` (line 246) - `DeleteWorkspace` (line 281) - `OpenInOldUI` (line 489) - `GitCreatePR` (line 630)
This commit is contained in:
committed by
GitHub
parent
b87fb13e87
commit
25c8ab29a9
@@ -161,18 +161,19 @@ export type ActionDefinition =
|
|||||||
| WorkspaceActionDefinition
|
| WorkspaceActionDefinition
|
||||||
| GitActionDefinition;
|
| GitActionDefinition;
|
||||||
|
|
||||||
// Helper to get workspace from query cache
|
// Helper to get workspace from query cache or fetch from API
|
||||||
function getWorkspaceFromCache(
|
async function getWorkspace(
|
||||||
queryClient: QueryClient,
|
queryClient: QueryClient,
|
||||||
workspaceId: string
|
workspaceId: string
|
||||||
): Workspace {
|
): Promise<Workspace> {
|
||||||
const workspace = queryClient.getQueryData<Workspace>(
|
const cached = queryClient.getQueryData<Workspace>(
|
||||||
attemptKeys.byId(workspaceId)
|
attemptKeys.byId(workspaceId)
|
||||||
);
|
);
|
||||||
if (!workspace) {
|
if (cached) {
|
||||||
throw new Error('Workspace not found');
|
return cached;
|
||||||
}
|
}
|
||||||
return workspace;
|
// Fetch from API if not in cache
|
||||||
|
return attemptsApi.get(workspaceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper to invalidate workspace-related queries
|
// Helper to invalidate workspace-related queries
|
||||||
@@ -211,7 +212,7 @@ export const Actions = {
|
|||||||
icon: PencilSimpleIcon,
|
icon: PencilSimpleIcon,
|
||||||
requiresTarget: true,
|
requiresTarget: true,
|
||||||
execute: async (ctx, workspaceId) => {
|
execute: async (ctx, workspaceId) => {
|
||||||
const workspace = getWorkspaceFromCache(ctx.queryClient, workspaceId);
|
const workspace = await getWorkspace(ctx.queryClient, workspaceId);
|
||||||
await RenameWorkspaceDialog.show({
|
await RenameWorkspaceDialog.show({
|
||||||
workspaceId,
|
workspaceId,
|
||||||
currentName: workspace.name || workspace.branch,
|
currentName: workspace.name || workspace.branch,
|
||||||
@@ -225,7 +226,7 @@ export const Actions = {
|
|||||||
icon: PushPinIcon,
|
icon: PushPinIcon,
|
||||||
requiresTarget: true,
|
requiresTarget: true,
|
||||||
execute: async (ctx, workspaceId) => {
|
execute: async (ctx, workspaceId) => {
|
||||||
const workspace = getWorkspaceFromCache(ctx.queryClient, workspaceId);
|
const workspace = await getWorkspace(ctx.queryClient, workspaceId);
|
||||||
await attemptsApi.update(workspaceId, {
|
await attemptsApi.update(workspaceId, {
|
||||||
pinned: !workspace.pinned,
|
pinned: !workspace.pinned,
|
||||||
});
|
});
|
||||||
@@ -242,7 +243,7 @@ export const Actions = {
|
|||||||
isVisible: (ctx) => ctx.hasWorkspace,
|
isVisible: (ctx) => ctx.hasWorkspace,
|
||||||
isActive: (ctx) => ctx.workspaceArchived,
|
isActive: (ctx) => ctx.workspaceArchived,
|
||||||
execute: async (ctx, workspaceId) => {
|
execute: async (ctx, workspaceId) => {
|
||||||
const workspace = getWorkspaceFromCache(ctx.queryClient, workspaceId);
|
const workspace = await getWorkspace(ctx.queryClient, workspaceId);
|
||||||
const wasArchived = workspace.archived;
|
const wasArchived = workspace.archived;
|
||||||
|
|
||||||
// Calculate next workspace before archiving
|
// Calculate next workspace before archiving
|
||||||
@@ -277,7 +278,7 @@ export const Actions = {
|
|||||||
variant: 'destructive',
|
variant: 'destructive',
|
||||||
requiresTarget: true,
|
requiresTarget: true,
|
||||||
execute: async (ctx, workspaceId) => {
|
execute: async (ctx, workspaceId) => {
|
||||||
const workspace = getWorkspaceFromCache(ctx.queryClient, workspaceId);
|
const workspace = await getWorkspace(ctx.queryClient, workspaceId);
|
||||||
const result = await ConfirmDialog.show({
|
const result = await ConfirmDialog.show({
|
||||||
title: 'Delete Workspace',
|
title: 'Delete Workspace',
|
||||||
message:
|
message:
|
||||||
@@ -485,7 +486,7 @@ export const Actions = {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const workspace = getWorkspaceFromCache(
|
const workspace = await getWorkspace(
|
||||||
ctx.queryClient,
|
ctx.queryClient,
|
||||||
ctx.currentWorkspaceId
|
ctx.currentWorkspaceId
|
||||||
);
|
);
|
||||||
@@ -626,7 +627,7 @@ export const Actions = {
|
|||||||
requiresTarget: 'git',
|
requiresTarget: 'git',
|
||||||
isVisible: (ctx) => ctx.hasWorkspace && ctx.hasGitRepos,
|
isVisible: (ctx) => ctx.hasWorkspace && ctx.hasGitRepos,
|
||||||
execute: async (ctx, workspaceId, repoId) => {
|
execute: async (ctx, workspaceId, repoId) => {
|
||||||
const workspace = getWorkspaceFromCache(ctx.queryClient, workspaceId);
|
const workspace = await getWorkspace(ctx.queryClient, workspaceId);
|
||||||
const task = await tasksApi.getById(workspace.task_id);
|
const task = await tasksApi.getById(workspace.task_id);
|
||||||
|
|
||||||
const repos = await attemptsApi.getRepos(workspaceId);
|
const repos = await attemptsApi.getRepos(workspaceId);
|
||||||
|
|||||||
Reference in New Issue
Block a user