Skip to content

Commit 933218c

Browse files
authored
fix: Fix corrupted view redirect, workspace cache flash and diff collapse (#1206)
1. Redirect to task input when task-detail view has no data or taskId 2. Optimistically update workspace cache on task create/open to prevent setup screen flash 3. Collapse unchanged lines in session diff viewer with 3-line margin 4. Replace direct ${{ steps.version.outputs.version }} interpolation in run: block with APP_VERSION env var 5. Fixed the sidebars per-folder plus button not pre-selecting the correct repo
1 parent 4078b8d commit 933218c

6 files changed

Lines changed: 28 additions & 4 deletions

File tree

.github/workflows/code-release.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,5 @@ jobs:
127127
- name: Publish GitHub release
128128
env:
129129
GH_TOKEN: ${{ steps.app-token.outputs.token }}
130-
run: gh release edit "v${{ steps.version.outputs.version }}" --repo PostHog/code --draft=false
130+
APP_VERSION: ${{ steps.version.outputs.version }}
131+
run: gh release edit "v$APP_VERSION" --repo PostHog/code --draft=false

apps/code/src/renderer/components/MainLayout.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { useTaskDeepLink } from "../hooks/useTaskDeepLink";
2424
import { GlobalEventHandlers } from "./GlobalEventHandlers";
2525

2626
export function MainLayout() {
27-
const { view, hydrateTask } = useNavigationStore();
27+
const { view, hydrateTask, navigateToTaskInput } = useNavigationStore();
2828
const {
2929
isOpen: commandMenuOpen,
3030
setOpen: setCommandMenuOpen,
@@ -47,6 +47,12 @@ export function MainLayout() {
4747
}
4848
}, [tasks, hydrateTask]);
4949

50+
useEffect(() => {
51+
if (view.type === "task-detail" && !view.data && !view.taskId) {
52+
navigateToTaskInput();
53+
}
54+
}, [view, navigateToTaskInput]);
55+
5056
const handleToggleCommandMenu = useCallback(() => {
5157
toggleCommandMenu();
5258
}, [toggleCommandMenu]);

apps/code/src/renderer/features/sessions/components/session-update/CodePreview.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export function CodePreview({
4949
highlightChanges: false,
5050
gutter: false,
5151
mergeControls: false,
52+
collapseUnchanged: { margin: 3, minSize: 4 },
5253
}),
5354
]
5455
: [];

apps/code/src/renderer/features/sidebar/components/TaskListView.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,8 @@ export function TaskListView({
318318
f.remoteUrl?.toLowerCase() === group.id.toLowerCase() ||
319319
f.path === group.id,
320320
);
321+
const groupFolderId =
322+
folder?.id ?? group.tasks.find((t) => t.folderId)?.folderId;
321323
return (
322324
<DraggableFolder key={group.id} id={group.id} index={index}>
323325
<SidebarSection
@@ -335,8 +337,8 @@ export function TaskListView({
335337
addSpacingBefore={false}
336338
tooltipContent={folder?.path ?? group.id}
337339
onNewTask={() => {
338-
if (folder) {
339-
navigateToTaskInput(folder.id);
340+
if (groupFolderId) {
341+
navigateToTaskInput(groupFolderId);
340342
} else {
341343
navigateToTaskInput();
342344
}

apps/code/src/renderer/features/sidebar/hooks/useSidebarData.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export interface TaskData {
2525
isPinned: boolean;
2626
needsPermission: boolean;
2727
repository: TaskRepositoryInfo | null;
28+
folderId?: string;
2829
taskRunStatus?:
2930
| "started"
3031
| "in_progress"
@@ -203,6 +204,7 @@ export function useSidebarData({
203204
isPinned: pinnedTaskIds.has(task.id),
204205
needsPermission: (session?.pendingPermissions?.size ?? 0) > 0,
205206
repository: getRepositoryInfo(task, workspace?.folderPath),
207+
folderId: workspace?.folderId || undefined,
206208
taskRunStatus: task.latest_run?.status,
207209
taskRunEnvironment: task.latest_run?.environment,
208210
};

apps/code/src/renderer/features/task-detail/service/service.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useAuthStore } from "@features/auth/stores/authStore";
22
import { useDraftStore } from "@features/message-editor/stores/draftStore";
33
import { useSettingsStore } from "@features/settings/stores/settingsStore";
44
import { workspaceApi } from "@features/workspace/hooks/useWorkspace";
5+
import type { Workspace } from "@main/services/workspace/schemas";
56
import type { SagaResult } from "@posthog/shared";
67
import {
78
type TaskCreationInput,
@@ -60,6 +61,7 @@ export class TaskService {
6061
const result = await saga.run(input);
6162

6263
if (result.success) {
64+
this.optimisticallyUpdateWorkspaceCache(result.data);
6365
this.updateStoresOnSuccess(result.data, input);
6466
void queryClient.invalidateQueries({
6567
queryKey: [["workspace", "getAll"]],
@@ -124,6 +126,7 @@ export class TaskService {
124126
const result = await saga.run({ taskId });
125127

126128
if (result.success) {
129+
this.optimisticallyUpdateWorkspaceCache(result.data);
127130
this.updateStoresOnSuccess(result.data);
128131
void queryClient.invalidateQueries({
129132
queryKey: [["workspace", "getAll"]],
@@ -151,6 +154,15 @@ export class TaskService {
151154
return result;
152155
}
153156

157+
private optimisticallyUpdateWorkspaceCache(output: TaskCreationOutput): void {
158+
if (!output.workspace) return;
159+
const workspace = output.workspace;
160+
queryClient.setQueriesData<Record<string, Workspace>>(
161+
{ queryKey: [["workspace", "getAll"]] },
162+
(old) => ({ ...old, [output.task.id]: workspace }),
163+
);
164+
}
165+
154166
/**
155167
* Batch update stores after successful task creation/open.
156168
*/

0 commit comments

Comments
 (0)