Skip to content

Commit 1bfea14

Browse files
CopilotByron
andcommitted
Fix stackId null handling in frontend API calls
- Fix URL parameter parsing converting null to "null" string - Update branchChanges methods to convert "null" string to null - Update type signatures to accept string | null for stackId - Update mock backend validation to accept null stackId values Co-authored-by: Byron <[email protected]>
1 parent 24a4aa3 commit 1bfea14

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

apps/desktop/cypress/e2e/support/mock/changes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ export function isGetCommitChangesParams(args: unknown): args is GetCommitChange
147147

148148
export type GetBranchChangesParams = {
149149
projectId: string;
150-
stackId?: string;
150+
stackId?: string | null;
151151
branch: string;
152152
};
153153

@@ -157,7 +157,7 @@ export function isGetBranchChangesParams(args: unknown): args is GetBranchChange
157157
args !== null &&
158158
'projectId' in args &&
159159
typeof args['projectId'] === 'string' &&
160-
(typeof (args as any).stackId === 'string' || (args as any).stackId === undefined) &&
160+
(typeof (args as any).stackId === 'string' || (args as any).stackId === undefined || (args as any).stackId === null) &&
161161
'branch' in args &&
162162
typeof args['branch'] === 'string'
163163
);

apps/desktop/src/lib/stacks/stackService.svelte.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -602,11 +602,11 @@ export class StackService {
602602
* If the branch is part of a stack and if the stackId is provided, this will include only the changes up to the next branch in the stack.
603603
* Otherwise, if stackId is not provided, this will include all changes as compared to the target branch
604604
*/
605-
branchChanges(args: { projectId: string; stackId?: string; branch: BranchRef }) {
605+
branchChanges(args: { projectId: string; stackId?: string | null; branch: BranchRef }) {
606606
return this.api.endpoints.branchChanges.useQuery(
607607
{
608608
projectId: args.projectId,
609-
stackId: args.stackId,
609+
stackId: args.stackId === 'null' ? null : args.stackId,
610610
branch: args.branch
611611
},
612612
{
@@ -618,11 +618,11 @@ export class StackService {
618618
);
619619
}
620620

621-
branchChange(args: { projectId: string; stackId?: string; branch: BranchRef; path: string }) {
621+
branchChange(args: { projectId: string; stackId?: string | null; branch: BranchRef; path: string }) {
622622
return this.api.endpoints.branchChanges.useQuery(
623623
{
624624
projectId: args.projectId,
625-
stackId: args.stackId,
625+
stackId: args.stackId === 'null' ? null : args.stackId,
626626
branch: args.branch
627627
},
628628
{ transform: (result) => changesSelectors.selectById(result.changes, args.path) }
@@ -631,14 +631,14 @@ export class StackService {
631631

632632
async branchChangesByPaths(args: {
633633
projectId: string;
634-
stackId?: string;
634+
stackId?: string | null;
635635
branch: BranchRef;
636636
paths: string[];
637637
}) {
638638
const result = await this.api.endpoints.branchChanges.fetch(
639639
{
640640
projectId: args.projectId,
641-
stackId: args.stackId,
641+
stackId: args.stackId === 'null' ? null : args.stackId,
642642
branch: args.branch
643643
},
644644
{ transform: (result) => selectChangesByPaths(result.changes, args.paths) }
@@ -1185,7 +1185,7 @@ function injectEndpoints(api: ClientState['backendApi'], uiState: UiState) {
11851185
}),
11861186
branchChanges: build.query<
11871187
{ changes: EntityState<TreeChange, string>; stats: TreeStats },
1188-
{ projectId: string; stackId?: string; branch: BranchRef }
1188+
{ projectId: string; stackId?: string | null; branch: BranchRef }
11891189
>({
11901190
extraOptions: { command: 'changes_in_branch' },
11911191
query: (args) => args,

apps/desktop/src/routes/[projectId]/workspace/+page.svelte

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717
const stackId = $derived(projectState.stackId.current);
1818
1919
// Check for stackId in URL query parameters
20-
const urlStackId = $derived(page.url.searchParams.get('stackId'));
20+
const urlStackId = $derived((() => {
21+
const param = page.url.searchParams.get('stackId');
22+
// Convert string "null" back to actual null
23+
return param === 'null' ? null : param;
24+
})());
2125
let scrollToStackId = $state<string | undefined>(undefined);
2226
2327
const firstStackResult = $derived(stackService.stackAt(projectId, 0));
@@ -29,7 +33,7 @@
2933
});
3034
3135
$effect(() => {
32-
if (urlStackId) {
36+
if (urlStackId !== null) {
3337
projectState.stackId.set(urlStackId);
3438
scrollToStackId = urlStackId;
3539
} else if (stackId === undefined && firstStack) {

0 commit comments

Comments
 (0)