Skip to content

Commit cd24783

Browse files
Merge pull request #11372 from gitbutlerapp/only-invalidate-pr-list
Only invalidate PR list
2 parents bfd2ee5 + aeee56f commit cd24783

File tree

10 files changed

+75
-34
lines changed

10 files changed

+75
-34
lines changed

apps/desktop/src/lib/branches/branchService.svelte.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export class BranchService {
2222
}
2323

2424
async refresh(): Promise<void> {
25+
// TODO: This doesn't do anything... should it??
2526
this.api.util.invalidateTags([invalidatesList(ReduxTag.BranchListing)]);
2627
}
2728
}

apps/desktop/src/lib/forge/forgeFactory.svelte.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,10 @@ export class DefaultForgeFactory implements Reactive<Forge> {
141141
};
142142

143143
if (forgeType === 'github') {
144-
const { gitHubClient, gitHubApi, posthog, backendApi } = this.params;
144+
const { gitHubClient, gitHubApi, posthog, backendApi, dispatch } = this.params;
145145
return new GitHub({
146146
...baseParams,
147+
dispatch,
147148
api: gitHubApi,
148149
backendApi,
149150
client: gitHubClient,
@@ -153,13 +154,14 @@ export class DefaultForgeFactory implements Reactive<Forge> {
153154
});
154155
}
155156
if (forgeType === 'gitlab') {
156-
const { gitLabClient, gitLabApi, posthog } = this.params;
157+
const { gitLabClient, gitLabApi, posthog, dispatch } = this.params;
157158
return new GitLab({
158159
...baseParams,
159160
api: gitLabApi,
160161
client: gitLabClient,
161162
posthog: posthog,
162-
authenticated: !!gitlabAuthenticated
163+
authenticated: !!gitlabAuthenticated,
164+
dispatch
163165
});
164166
}
165167
if (forgeType === 'bitbucket') {

apps/desktop/src/lib/forge/github/github.test.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ describe('GitHub', () => {
2525
repo,
2626
baseBranch: id,
2727
authenticated: true,
28-
isLoading: false
28+
isLoading: false,
29+
dispatch: () => {}
2930
});
3031
const url = gh.commitUrl(id);
3132
expect(url).toMatch(new RegExp(`/${id}$`));
@@ -44,7 +45,8 @@ describe('GitHub', () => {
4445
repo: sshRepo,
4546
baseBranch: id,
4647
authenticated: true,
47-
isLoading: false
48+
isLoading: false,
49+
dispatch: () => {}
4850
});
4951

5052
expect(gh.commitUrl('abc123')).toBe('https://github.com/test-owner/test-repo/commit/abc123');
@@ -63,7 +65,8 @@ describe('GitHub', () => {
6365
repo: sshRepo,
6466
baseBranch: 'main',
6567
authenticated: true,
66-
isLoading: false
68+
isLoading: false,
69+
dispatch: () => {}
6770
});
6871

6972
const branch = gh.branch('feature-branch');
@@ -85,7 +88,8 @@ describe('GitHub', () => {
8588
repo: sshRepo,
8689
baseBranch: id,
8790
authenticated: true,
88-
isLoading: false
91+
isLoading: false,
92+
dispatch: () => {}
8993
});
9094

9195
expect(gh.commitUrl('abc123')).toBe('https://github.com/test-owner/test-repo/commit/abc123');
@@ -106,7 +110,8 @@ describe('GitHub', () => {
106110
repo: enterpriseRepo,
107111
baseBranch: id,
108112
authenticated: true,
109-
isLoading: false
113+
isLoading: false,
114+
dispatch: () => {}
110115
});
111116

112117
expect(gh.commitUrl('abc123')).toBe(

apps/desktop/src/lib/forge/github/github.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type { Forge, ForgeName } from '$lib/forge/interface/forge';
1212
import type { ForgeArguments } from '$lib/forge/interface/types';
1313
import type { BackendApi, GitHubApi } from '$lib/state/clientState.svelte';
1414
import type { RestEndpointMethodTypes } from '@octokit/rest';
15+
import type { ThunkDispatch, UnknownAction } from '@reduxjs/toolkit';
1516
import type { TagDescription } from '@reduxjs/toolkit/query';
1617

1718
export const GITHUB_DOMAIN = 'github.com';
@@ -26,6 +27,7 @@ export class GitHub implements Forge {
2627

2728
constructor(
2829
private params: ForgeArguments & {
30+
dispatch: ThunkDispatch<any, any, UnknownAction>;
2931
posthog?: PostHogWrapper;
3032
client: GitHubClient;
3133
api: GitHubApi;
@@ -59,8 +61,8 @@ export class GitHub implements Forge {
5961

6062
get listService() {
6163
if (!this.authenticated) return;
62-
const { api: gitHubApi, backendApi } = this.params;
63-
return new GitHubListingService(gitHubApi, backendApi);
64+
const { api: gitHubApi, backendApi, dispatch } = this.params;
65+
return new GitHubListingService(gitHubApi, backendApi, dispatch);
6466
}
6567

6668
get prService() {

apps/desktop/src/lib/forge/github/githubBranch.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ describe('GitHubBranch', () => {
2727
repo,
2828
baseBranch,
2929
authenticated: true,
30-
isLoading: false
30+
isLoading: false,
31+
dispatch: () => {}
3132
});
3233
const branch = gh.branch(name);
3334
expect(branch?.url).toMatch(new RegExp(`...${name}$`));
@@ -43,7 +44,8 @@ describe('GitHubBranch', () => {
4344
baseBranch,
4445
forkStr,
4546
authenticated: true,
46-
isLoading: false
47+
isLoading: false,
48+
dispatch: () => {}
4749
});
4850
const branch = gh.branch(name);
4951
expect(branch?.url).toMatch(new RegExp(`...${forkStr}:${name}$`));

apps/desktop/src/lib/forge/github/githubListingService.svelte.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,26 @@ import {
66
type PullRequest
77
} from '$lib/forge/interface/types';
88
import { createSelectByIds } from '$lib/state/customSelectors';
9-
import { providesList, ReduxTag } from '$lib/state/tags';
9+
import { invalidatesList, providesList, ReduxTag } from '$lib/state/tags';
1010
import { isDefined } from '@gitbutler/ui/utils/typeguards';
11-
import { createEntityAdapter, type EntityState } from '@reduxjs/toolkit';
11+
import {
12+
createEntityAdapter,
13+
type EntityState,
14+
type ThunkDispatch,
15+
type UnknownAction
16+
} from '@reduxjs/toolkit';
1217
import type { ForgeListingService } from '$lib/forge/interface/forgeListingService';
1318
import type { BackendApi, GitHubApi } from '$lib/state/clientState.svelte';
1419

1520
export class GitHubListingService implements ForgeListingService {
1621
private api: ReturnType<typeof injectEndpoints>;
1722
private backendApi: ReturnType<typeof injectBackendEndpoints>;
1823

19-
constructor(gitHubApi: GitHubApi, backendApi: BackendApi) {
24+
constructor(
25+
gitHubApi: GitHubApi,
26+
backendApi: BackendApi,
27+
private readonly dispatch: ThunkDispatch<any, any, UnknownAction>
28+
) {
2029
this.api = injectEndpoints(gitHubApi);
2130
this.backendApi = injectBackendEndpoints(backendApi);
2231
}
@@ -52,8 +61,8 @@ export class GitHubListingService implements ForgeListingService {
5261
return results.filter(isDefined) ?? [];
5362
}
5463

55-
async refresh(projectId: string): Promise<void> {
56-
await this.backendApi.endpoints.listPrs.fetch(projectId, { forceRefetch: true });
64+
async refresh(_projectId: string): Promise<void> {
65+
this.dispatch(this.backendApi.util.invalidateTags([invalidatesList(ReduxTag.PullRequests)]));
5766
}
5867
}
5968

apps/desktop/src/lib/forge/github/githubPrService.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ describe('GitHubPrService', () => {
2828
api: gitHubApi,
2929
authenticated: true,
3030
isLoading: false,
31-
client: gitHubClient
31+
client: gitHubClient,
32+
dispatch: () => {}
3233
});
3334
service = gh.prService;
3435
});

apps/desktop/src/lib/forge/gitlab/gitlab.test.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ describe('GitLab', () => {
3030
client: gitLabClient,
3131
repo: baseRepo,
3232
baseBranch,
33-
authenticated: true
33+
authenticated: true,
34+
dispatch: () => {}
3435
});
3536

3637
expect(gitlab.commitUrl('abc123')).toBe(
@@ -49,7 +50,8 @@ describe('GitLab', () => {
4950
client: gitLabClient,
5051
repo,
5152
baseBranch,
52-
authenticated: true
53+
authenticated: true,
54+
dispatch: () => {}
5355
});
5456

5557
expect(gitlab.commitUrl('abc123')).toBe(
@@ -68,7 +70,8 @@ describe('GitLab', () => {
6870
client: gitLabClient,
6971
repo,
7072
baseBranch,
71-
authenticated: true
73+
authenticated: true,
74+
dispatch: () => {}
7275
});
7376

7477
expect(gitlab.commitUrl('abc123')).toBe(
@@ -87,7 +90,8 @@ describe('GitLab', () => {
8790
client: gitLabClient,
8891
repo,
8992
baseBranch,
90-
authenticated: true
93+
authenticated: true,
94+
dispatch: () => {}
9195
});
9296

9397
expect(gitlab.commitUrl('abc123')).toBe(
@@ -106,7 +110,8 @@ describe('GitLab', () => {
106110
client: gitLabClient,
107111
repo,
108112
baseBranch,
109-
authenticated: true
113+
authenticated: true,
114+
dispatch: () => {}
110115
});
111116

112117
const branch = gitlab.branch('feature-branch');
@@ -126,7 +131,8 @@ describe('GitLab', () => {
126131
client: gitLabClient,
127132
repo,
128133
baseBranch,
129-
authenticated: true
134+
authenticated: true,
135+
dispatch: () => {}
130136
});
131137

132138
expect(gitlab.commitUrl('abc123')).toBe(
@@ -145,7 +151,8 @@ describe('GitLab', () => {
145151
client: gitLabClient,
146152
repo,
147153
baseBranch,
148-
authenticated: true
154+
authenticated: true,
155+
dispatch: () => {}
149156
});
150157

151158
const branch = gitlab.branch('feature-branch');
@@ -165,7 +172,8 @@ describe('GitLab', () => {
165172
client: gitLabClient,
166173
repo,
167174
baseBranch,
168-
authenticated: true
175+
authenticated: true,
176+
dispatch: () => {}
169177
});
170178

171179
expect(gitlab.commitUrl('abc123')).toBe(
@@ -186,7 +194,8 @@ describe('GitLab', () => {
186194
client: gitLabClient,
187195
repo,
188196
baseBranch,
189-
authenticated: true
197+
authenticated: true,
198+
dispatch: () => {}
190199
});
191200

192201
expect(gitlab.commitUrl('abc123')).toBe(

apps/desktop/src/lib/forge/gitlab/gitlab.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type { PostHogWrapper } from '$lib/analytics/posthog';
88
import type { Forge, ForgeName } from '$lib/forge/interface/forge';
99
import type { ForgeArguments, ForgeUser } from '$lib/forge/interface/types';
1010
import type { GitLabApi } from '$lib/state/clientState.svelte';
11+
import type { ThunkDispatch, UnknownAction } from '@reduxjs/toolkit';
1112
import type { TagDescription } from '@reduxjs/toolkit/query';
1213

1314
export const GITLAB_DOMAIN = 'gitlab.com';
@@ -33,6 +34,7 @@ export class GitLab implements Forge {
3334
posthog?: PostHogWrapper;
3435
api: GitLabApi;
3536
client: GitLabClient;
37+
dispatch: ThunkDispatch<any, any, UnknownAction>;
3638
}
3739
) {
3840
const { api, client, baseBranch, forkStr, authenticated, repo } = this.params;
@@ -74,8 +76,8 @@ export class GitLab implements Forge {
7476

7577
get listService() {
7678
if (!this.authenticated) return;
77-
const { api: gitLabApi } = this.params;
78-
return new GitLabListingService(gitLabApi);
79+
const { api: gitLabApi, dispatch } = this.params;
80+
return new GitLabListingService(gitLabApi, dispatch);
7981
}
8082

8183
get issueService() {

apps/desktop/src/lib/forge/gitlab/gitlabListingService.svelte.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
11
import { gitlab } from '$lib/forge/gitlab/gitlabClient.svelte';
22
import { mrToInstance } from '$lib/forge/gitlab/types';
33
import { createSelectByIds } from '$lib/state/customSelectors';
4-
import { providesList, ReduxTag } from '$lib/state/tags';
4+
import { invalidatesList, providesList, ReduxTag } from '$lib/state/tags';
55
import { toSerializable } from '@gitbutler/shared/network/types';
66
import { isDefined } from '@gitbutler/ui/utils/typeguards';
7-
import { createEntityAdapter, type EntityState } from '@reduxjs/toolkit';
7+
import {
8+
createEntityAdapter,
9+
type EntityState,
10+
type ThunkDispatch,
11+
type UnknownAction
12+
} from '@reduxjs/toolkit';
813
import type { ForgeListingService } from '$lib/forge/interface/forgeListingService';
914
import type { PullRequest } from '$lib/forge/interface/types';
1015
import type { GitLabApi } from '$lib/state/clientState.svelte';
1116

1217
export class GitLabListingService implements ForgeListingService {
1318
private api: ReturnType<typeof injectEndpoints>;
1419

15-
constructor(gitLabApi: GitLabApi) {
20+
constructor(
21+
gitLabApi: GitLabApi,
22+
private readonly dispatch: ThunkDispatch<any, any, UnknownAction>
23+
) {
1624
this.api = injectEndpoints(gitLabApi);
1725
}
1826

@@ -44,8 +52,8 @@ export class GitLabListingService implements ForgeListingService {
4452
return results.filter(isDefined) ?? [];
4553
}
4654

47-
async refresh(projectId: string): Promise<void> {
48-
await this.api.endpoints.listPrs.fetch(projectId, { forceRefetch: true });
55+
async refresh(_projectId: string): Promise<void> {
56+
this.dispatch(this.api.util.invalidateTags([invalidatesList(ReduxTag.PullRequests)]));
4957
}
5058
}
5159

0 commit comments

Comments
 (0)