Skip to content

Commit b7b6f3c

Browse files
authored
Merge branch 'main' into release
2 parents 99429e0 + e501a4b commit b7b6f3c

File tree

29 files changed

+740
-78
lines changed

29 files changed

+740
-78
lines changed

apps/frontend/src/api/constant.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ export const ErrorMessages = {
2222
[TASK_INIT_CODE + 1000]: i18n.t('fileUploadFailed'),
2323
[TASK_INIT_CODE + 1001]: i18n.t('fileNotFound'),
2424
[TASK_INIT_CODE + 1002]: i18n.t('duplicatedFile'),
25-
[TASK_INIT_CODE + 5000]: i18n.t('参数错误:after,before,pageNo,只能选一个,pageNo 可以说是0'),
2625
[TASK_INIT_CODE + 5001]: i18n.t('noSample'),
2726
[TASK_INIT_CODE + 5003]: i18n.t('sampleNameExists'),
2827
[EXPORT_INIT_CODE + 1000]: i18n.t('noDataExport'),

apps/frontend/src/api/mutations/task.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import { useMutation } from '@tanstack/react-query';
22

3-
import { createTaskWithBasicConfig, updateTaskConfig } from '@/api/services/task';
3+
import {
4+
addCollaborator,
5+
batchAddCollaborators,
6+
batchRemoveCollaborators,
7+
createTaskWithBasicConfig,
8+
removeCollaborator,
9+
updateTaskConfig,
10+
} from '@/api/services/task';
411

512
import type { UpdateCommand } from '../types';
613

@@ -15,3 +22,27 @@ export function useUpdateTaskConfigMutation(taskId: number | string) {
1522
mutationFn: (payload: UpdateCommand) => updateTaskConfig(+taskId, payload),
1623
});
1724
}
25+
26+
export function useAddCollaborator(taskId: number) {
27+
return useMutation({
28+
mutationFn: (userId: number) => addCollaborator(taskId, userId),
29+
});
30+
}
31+
32+
export function useRemoveCollaborator(taskId: number) {
33+
return useMutation({
34+
mutationFn: (userId: number) => removeCollaborator(taskId, userId),
35+
});
36+
}
37+
38+
export function useBatchAddCollaborators(taskId: number) {
39+
return useMutation({
40+
mutationFn: (userIds: number[]) => batchAddCollaborators(taskId, userIds),
41+
});
42+
}
43+
44+
export function useBatchRemoveCollaborators(taskId: number) {
45+
return useMutation({
46+
mutationFn: (userIds: number[]) => batchRemoveCollaborators(taskId, userIds),
47+
});
48+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { useQuery } from '@tanstack/react-query';
2+
3+
import { getTaskCollaborators } from '../services/task';
4+
import { taskKey } from '../queryKeyFactories';
5+
6+
export function useCollaborators(taskId: number, enabled: boolean) {
7+
return useQuery({
8+
queryKey: taskKey.collaborators(),
9+
queryFn: () => getTaskCollaborators(taskId),
10+
enabled: enabled && taskId > 0,
11+
select: (data) => data?.data,
12+
});
13+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { useQuery } from '@tanstack/react-query';
2+
3+
import { userKey } from '../queryKeyFactories/user';
4+
import { getUsers } from '../services/user';
5+
import type { GetUsersApiV1UsersGetParams } from '../types';
6+
7+
export function useUsers(params: GetUsersApiV1UsersGetParams) {
8+
return useQuery({
9+
queryKey: userKey.list(params),
10+
queryFn: () => getUsers(params),
11+
});
12+
}

apps/frontend/src/api/queryKeyFactories/task.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ export const taskKey = {
77
list: (filter: ListByApiV1TasksGetParams) => [...taskKey.lists(), filter] as const,
88
details: () => [...taskKey.all, 'details'] as const,
99
detail: (id: string | number) => [...taskKey.details(), id] as const,
10+
collaborators: () => [...taskKey.all, 'collaborators'] as const,
1011
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import type { GetUsersApiV1UsersGetParams } from '../types';
2+
3+
export const userKey = {
4+
all: ['user'] as const,
5+
me: () => [...userKey.all, 'me'] as const,
6+
lists: () => [...userKey.all, 'list'] as const,
7+
list: (filter: GetUsersApiV1UsersGetParams) => [...userKey.lists(), filter] as const,
8+
};

apps/frontend/src/api/services/preAnnotations.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export async function getPreAnnotationFiles({
2727
return await request.get(`/v1/tasks/${task_id}/pre_annotations/files`, {
2828
params: {
2929
...params,
30-
pageNo: typeof params.pageNo === 'undefined' ? 0 : params.pageNo - 1,
30+
page: typeof params.page === 'undefined' ? 0 : params.page - 1,
3131
},
3232
});
3333
}
@@ -41,7 +41,7 @@ export async function getPreAnnotations({
4141
return await request.get(`/v1/tasks/${task_id}/pre_annotations`, {
4242
params: {
4343
...params,
44-
pageNo: typeof params.pageNo === 'undefined' ? 0 : params.pageNo - 1,
44+
page: typeof params.page === 'undefined' ? 0 : params.page - 1,
4545
},
4646
});
4747
}

apps/frontend/src/api/services/samples.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export async function getSamples({
3636
return await request.get(`/v1/tasks/${task_id}/samples`, {
3737
params: {
3838
...params,
39-
pageNo: typeof params.pageNo === 'undefined' ? 0 : params.pageNo - 1,
39+
page: typeof params.page === 'undefined' ? 0 : params.page - 1,
4040
},
4141
});
4242
}
@@ -138,7 +138,7 @@ export async function outputSample(taskId: number, sampleIds: number[], activeTx
138138
}
139139

140140
export async function outputSamples(taskId: number, activeTxt: ExportType) {
141-
const samplesRes = await getSamples({ task_id: taskId, pageNo: 1, pageSize: 100000 });
141+
const samplesRes = await getSamples({ task_id: taskId, page: 1, size: 100000 });
142142
const sampleIdArrays = samplesRes.data;
143143
const sampleIds = [];
144144

apps/frontend/src/api/services/task.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import type {
1111
CreateApiV1TasksTaskIdAttachmentsPostParams,
1212
DeleteApiV1TasksTaskIdAttachmentsDeleteParams,
1313
AttachmentDeleteCommand,
14+
ListResponseWithMeta,
15+
UserResponse,
16+
OkResponse,
1417
} from '../types';
1518

1619
export async function getTask(taskId: number): Promise<OkRespTaskResponseWithStatics> {
@@ -21,6 +24,32 @@ export async function getTask(taskId: number): Promise<OkRespTaskResponseWithSta
2124
});
2225
}
2326

27+
export async function getTaskCollaborators(taskId: number): Promise<ListResponseWithMeta<UserResponse>> {
28+
return await request.get(`/v1/tasks/${taskId}/collaborators`);
29+
}
30+
31+
export async function removeCollaborator(taskId: number, userId: number) {
32+
return await request.delete(`/v1/tasks/${taskId}/collaborators/${userId}`);
33+
}
34+
35+
export async function addCollaborator(taskId: number, userId: number) {
36+
return await request.post(`/v1/tasks/${taskId}/collaborators`, {
37+
user_id: userId,
38+
});
39+
}
40+
41+
export async function batchAddCollaborators(taskId: number, userIds: number[]): Promise<OkResponse<UserResponse>> {
42+
return await request.post(`/v1/tasks/${taskId}/collaborators/batch_add`, {
43+
user_ids: userIds,
44+
});
45+
}
46+
47+
export async function batchRemoveCollaborators(taskId: number, userIds: number[]): Promise<OkRespCommonDataResp> {
48+
return await request.post(`/v1/tasks/${taskId}/collaborators/batch_remove`, {
49+
user_ids: userIds,
50+
});
51+
}
52+
2453
export async function createTaskWithBasicConfig(data: BasicConfigCommand): Promise<OkRespTaskResponse> {
2554
return await request.post('/v1/tasks', data);
2655
}

apps/frontend/src/api/services/user.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@ import * as storage from '@/utils/storage';
22

33
import request from '../request';
44
import type {
5+
GetUsersApiV1UsersGetParams,
6+
ListResponseWithMeta,
57
LoginCommand,
68
OkRespLoginResponse,
79
OkRespLogoutResponse,
810
OkRespSignupResponse,
911
OkRespUserInfo,
1012
SignupCommand,
13+
UserResponse,
1114
} from '../types';
1215

1316
export async function login(params: LoginCommand): Promise<OkRespLoginResponse> {
@@ -28,7 +31,13 @@ export async function ssoLogin(code: string) {
2831
}
2932

3033
export async function getUserInfo(): Promise<OkRespUserInfo> {
31-
return await request.post('/v1/users/me');
34+
return await request.get('/v1/users/me');
35+
}
36+
37+
export async function getUsers(params: GetUsersApiV1UsersGetParams): Promise<ListResponseWithMeta<UserResponse>> {
38+
return await request.get('/v1/users', {
39+
params,
40+
});
3241
}
3342

3443
export async function logout(): Promise<OkRespLogoutResponse> {

0 commit comments

Comments
 (0)