Skip to content

Commit c19adb8

Browse files
authored
fix: not all contributors are displayed in contributor merge form gf-550 (#551)
* feat: add separate handling for contributors table and contributor merge gf-550 * fix: remove is loading from contributor merge form gf-550
1 parent 85608cd commit c19adb8

File tree

6 files changed

+85
-12
lines changed

6 files changed

+85
-12
lines changed

apps/backend/src/modules/contributors/contributor.controller.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,17 +186,24 @@ class ContributorController extends BaseController {
186186
query: { projectId?: string } & PaginationQueryParameters;
187187
}>,
188188
): Promise<APIHandlerResponse> {
189-
if (options.query.projectId) {
190-
const projectId = Number(options.query.projectId);
189+
const { page, pageSize, projectId } = options.query;
191190

191+
if (projectId) {
192192
return {
193193
payload: await this.contributorService.findAllByProjectId({
194-
projectId,
194+
projectId: Number(projectId),
195195
}),
196196
status: HTTPCode.OK,
197197
};
198198
}
199199

200+
if (!page || !pageSize) {
201+
return {
202+
payload: await this.contributorService.findAllWithoutPagination({}),
203+
status: HTTPCode.OK,
204+
};
205+
}
206+
200207
return {
201208
payload: await this.contributorService.findAll(options.query),
202209
status: HTTPCode.OK,

apps/frontend/src/modules/contributors/contributors-api.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,18 @@ class ContributorApi extends BaseHTTPApi {
6060
return await response.json<ContributorGetAllResponseDto>();
6161
}
6262

63+
public async getAllWithoutPagination(): Promise<ContributorGetAllResponseDto> {
64+
const response = await this.load(
65+
this.getFullEndpoint(ContributorsApiPath.ROOT, {}),
66+
{
67+
hasAuth: true,
68+
method: "GET",
69+
},
70+
);
71+
72+
return await response.json<ContributorGetAllResponseDto>();
73+
}
74+
6375
public async merge(
6476
id: number,
6577
payload: ContributorMergeRequestDto,

apps/frontend/src/modules/contributors/slices/actions.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ const loadAll = createAsyncThunk<
2727
return await contributorApi.getAll(query);
2828
});
2929

30+
const loadAllWithoutPagination = createAsyncThunk<
31+
ContributorGetAllResponseDto,
32+
undefined,
33+
AsyncThunkConfig
34+
>(`${sliceName}/load-all-without-pagination`, async (_payload, { extra }) => {
35+
const { contributorApi } = extra;
36+
37+
return await contributorApi.getAllWithoutPagination();
38+
});
39+
3040
const merge = createAsyncThunk<
3141
ContributorGetAllItemResponseDto,
3242
{ id: number; payload: ContributorMergeRequestDto },
@@ -71,4 +81,4 @@ const patch = createAsyncThunk<
7181
},
7282
);
7383

74-
export { loadAll, merge, patch, split };
84+
export { loadAll, loadAllWithoutPagination, merge, patch, split };

apps/frontend/src/modules/contributors/slices/contributor.slice.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,18 @@ import { DataStatus } from "~/libs/enums/enums.js";
55
import { type ValueOf } from "~/libs/types/types.js";
66

77
import { type ContributorGetAllItemResponseDto } from "../libs/types/types.js";
8-
import { loadAll, merge, patch, split } from "./actions.js";
8+
import {
9+
loadAll,
10+
loadAllWithoutPagination,
11+
merge,
12+
patch,
13+
split,
14+
} from "./actions.js";
915

1016
type State = {
17+
allContributors: ContributorGetAllItemResponseDto[];
18+
allContributorsStatus: ValueOf<typeof DataStatus>;
19+
allContributorsTotalCount: number;
1120
contributors: ContributorGetAllItemResponseDto[];
1221
dataStatus: ValueOf<typeof DataStatus>;
1322
mergeContributorsStatus: ValueOf<typeof DataStatus>;
@@ -17,6 +26,9 @@ type State = {
1726
};
1827

1928
const initialState: State = {
29+
allContributors: [],
30+
allContributorsStatus: DataStatus.IDLE,
31+
allContributorsTotalCount: 0,
2032
contributors: [],
2133
dataStatus: DataStatus.IDLE,
2234
mergeContributorsStatus: DataStatus.IDLE,
@@ -39,6 +51,18 @@ const { actions, name, reducer } = createSlice({
3951
state.contributors = [];
4052
state.dataStatus = DataStatus.REJECTED;
4153
});
54+
builder.addCase(loadAllWithoutPagination.pending, (state) => {
55+
state.allContributorsStatus = DataStatus.PENDING;
56+
});
57+
builder.addCase(loadAllWithoutPagination.fulfilled, (state, action) => {
58+
state.allContributors = action.payload.items;
59+
state.allContributorsStatus = DataStatus.FULFILLED;
60+
state.allContributorsTotalCount = action.payload.totalItems;
61+
});
62+
builder.addCase(loadAllWithoutPagination.rejected, (state) => {
63+
state.allContributors = [];
64+
state.allContributorsStatus = DataStatus.REJECTED;
65+
});
4266

4367
builder.addCase(merge.pending, (state) => {
4468
state.mergeContributorsStatus = DataStatus.PENDING;
@@ -69,6 +93,7 @@ const { actions, name, reducer } = createSlice({
6993
(contributor) => contributor.id !== removedContributorId,
7094
);
7195
state.totalCount -= ITEMS_CHANGED_COUNT;
96+
state.allContributorsTotalCount -= ITEMS_CHANGED_COUNT;
7297
}
7398

7499
state.contributors = state.contributors.map((contributor) =>

apps/frontend/src/modules/contributors/slices/contributors.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1-
import { loadAll, merge, patch, split } from "./actions.js";
1+
import {
2+
loadAll,
3+
loadAllWithoutPagination,
4+
merge,
5+
patch,
6+
split,
7+
} from "./actions.js";
28
import { actions } from "./contributor.slice.js";
39

410
const allActions = {
511
...actions,
612
loadAll,
13+
loadAllWithoutPagination,
714
merge,
815
patch,
916
split,

apps/frontend/src/pages/contributors/contributors.tsx

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
Loader,
23
Modal,
34
PageLayout,
45
Table,
@@ -39,6 +40,8 @@ const Contributors = (): JSX.Element => {
3940
const dispatch = useAppDispatch();
4041

4142
const {
43+
allContributors,
44+
allContributorsStatus,
4245
contributors,
4346
dataStatus,
4447
mergeContributorsStatus,
@@ -93,10 +96,11 @@ const Contributors = (): JSX.Element => {
9396

9497
const openMergeModal = useCallback(
9598
(contributor: ContributorGetAllItemResponseDto | null) => {
99+
void dispatch(contributorActions.loadAllWithoutPagination());
96100
setContributorToMerge(contributor);
97101
onMergeModalOpen();
98102
},
99-
[setContributorToMerge, onMergeModalOpen],
103+
[dispatch, setContributorToMerge, onMergeModalOpen],
100104
);
101105

102106
const openSplitModal = useCallback(
@@ -218,6 +222,10 @@ const Contributors = (): JSX.Element => {
218222
const isLoading =
219223
dataStatus === DataStatus.IDLE || dataStatus === DataStatus.PENDING;
220224

225+
const isLoadingAllContributors =
226+
allContributorsStatus === DataStatus.IDLE ||
227+
allContributorsStatus === DataStatus.PENDING;
228+
221229
return (
222230
<PageLayout isLoading={isLoading}>
223231
<h1 className={styles["title"]}>Contributors</h1>
@@ -254,11 +262,15 @@ const Contributors = (): JSX.Element => {
254262
onClose={onMergeModalClose}
255263
title="Merge contributors"
256264
>
257-
<ContributorMergeForm
258-
allContributors={contributors}
259-
currentContributor={contributorToMerge}
260-
onSubmit={handleContributorMergeSubmit}
261-
/>
265+
{isLoadingAllContributors ? (
266+
<Loader />
267+
) : (
268+
<ContributorMergeForm
269+
allContributors={allContributors}
270+
currentContributor={contributorToMerge}
271+
onSubmit={handleContributorMergeSubmit}
272+
/>
273+
)}
262274
</Modal>
263275
)}
264276
{contributorToSplit && (

0 commit comments

Comments
 (0)