Skip to content

Commit 385e10c

Browse files
committed
updated duplicate finder frontend
1 parent df3fac0 commit 385e10c

File tree

11 files changed

+471
-93
lines changed

11 files changed

+471
-93
lines changed

frontend/src/api/JobHooks.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { useMutation, useQuery } from "@tanstack/react-query";
2+
import { QueryKey } from "./QueryKey.ts";
3+
import { DuplicateFinderJobRead } from "./openapi/models/DuplicateFinderJobRead.ts";
4+
import { JobStatus } from "./openapi/models/JobStatus.ts";
5+
import { JobService } from "./openapi/services/JobService.ts";
6+
7+
const useStartDuplicateFinderJob = () =>
8+
useMutation({
9+
mutationFn: JobService.startDuplicateFinderJob,
10+
meta: {
11+
successMessage: () => `Started Duplicate Finder Job. Please wait & do not leave this page!`,
12+
},
13+
});
14+
15+
const usePollDuplicateFinderJob = (
16+
duplicateFinderJobId: string | undefined,
17+
initialData: DuplicateFinderJobRead | undefined,
18+
) => {
19+
return useQuery<DuplicateFinderJobRead, Error>({
20+
queryKey: [QueryKey.DUPLICATE_FINDER_JOB, duplicateFinderJobId],
21+
queryFn: () =>
22+
JobService.getDuplicateFinderJobById({
23+
jobId: duplicateFinderJobId!,
24+
}),
25+
enabled: !!duplicateFinderJobId,
26+
refetchInterval: (query) => {
27+
if (!query.state.data) {
28+
return 1000;
29+
}
30+
if (query.state.data.status) {
31+
switch (query.state.data.status) {
32+
case JobStatus.CANCELED:
33+
case JobStatus.FAILED:
34+
case JobStatus.FINISHED:
35+
case JobStatus.STOPPED:
36+
return false;
37+
case JobStatus.DEFERRED:
38+
case JobStatus.QUEUED:
39+
case JobStatus.SCHEDULED:
40+
case JobStatus.STARTED:
41+
return 1000;
42+
}
43+
}
44+
return false;
45+
},
46+
initialData,
47+
});
48+
};
49+
50+
const JobHooks = {
51+
usePollDuplicateFinderJob,
52+
useStartDuplicateFinderJob,
53+
};
54+
55+
export default JobHooks;

frontend/src/api/ProjectHooks.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { QueryKey } from "./QueryKey.ts";
55
import { PreprocessingJobRead } from "./openapi/models/PreprocessingJobRead.ts";
66
import { ProjectCreate } from "./openapi/models/ProjectCreate.ts";
77
import { ProjectRead } from "./openapi/models/ProjectRead.ts";
8-
import { AnalysisService } from "./openapi/services/AnalysisService.ts";
98
import { ProjectService } from "./openapi/services/ProjectService.ts";
109

1110
// PROJECT QUERIES
@@ -87,15 +86,6 @@ const useUploadDocument = () =>
8786
},
8887
});
8988

90-
// duplicates
91-
const useFindDuplicateTextDocuments = () =>
92-
useMutation({
93-
mutationFn: AnalysisService.findDuplicateTextSdocs,
94-
meta: {
95-
successMessage: () => "Document duplicate search completed",
96-
},
97-
});
98-
9989
const ProjectHooks = {
10090
// project
10191
useGetAllProjects,
@@ -105,8 +95,6 @@ const ProjectHooks = {
10595
useDeleteProject,
10696
// sdoc
10797
useUploadDocument,
108-
// duplicates
109-
useFindDuplicateTextDocuments,
11098
};
11199

112100
export default ProjectHooks;

frontend/src/api/QueryKey.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ export const QueryKey = {
131131
// all DocumentTagRecommendationLinkRead[] of a MLJob (by ml job id)
132132
TAG_RECOMMENDATIONS: "tagRecommendations",
133133

134+
// managed by JobHooks
135+
// a single DuplicateFinderJobRead (by duplicate finder job id)
136+
DUPLICATE_FINDER_JOB: "duplicateFinderJob",
137+
134138
// tables
135139
SEARCH_TABLE: "search-document-table-data",
136140
SDOC_TABLE: "document-table-data",
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* generated using openapi-typescript-codegen -- do not edit */
2+
/* istanbul ignore file */
3+
/* tslint:disable */
4+
/* eslint-disable */
5+
export type DuplicateFinderInput = {
6+
/**
7+
* Project ID to search for duplicates
8+
*/
9+
project_id: number;
10+
/**
11+
* Number of different words allowed between duplicates
12+
*/
13+
max_different_words: number;
14+
};
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/* generated using openapi-typescript-codegen -- do not edit */
2+
/* istanbul ignore file */
3+
/* tslint:disable */
4+
/* eslint-disable */
5+
import type { DuplicateFinderInput } from "./DuplicateFinderInput";
6+
import type { DuplicateFinderOutput } from "./DuplicateFinderOutput";
7+
import type { JobStatus } from "./JobStatus";
8+
export type DuplicateFinderJobRead = {
9+
/**
10+
* RQ job ID
11+
*/
12+
job_id: string;
13+
/**
14+
* Type of the job
15+
*/
16+
job_type: string;
17+
/**
18+
* Project ID associated with the job
19+
*/
20+
project_id: number;
21+
/**
22+
* Current status of the job
23+
*/
24+
status: JobStatus;
25+
/**
26+
* Status message
27+
*/
28+
status_message?: string | null;
29+
/**
30+
* Input for the job
31+
*/
32+
input: DuplicateFinderInput;
33+
/**
34+
* Output for the job
35+
*/
36+
output?: DuplicateFinderOutput | null;
37+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* generated using openapi-typescript-codegen -- do not edit */
2+
/* istanbul ignore file */
3+
/* tslint:disable */
4+
/* eslint-disable */
5+
export type DuplicateFinderOutput = {
6+
/**
7+
* List of found duplicate clusters
8+
*/
9+
duplicates: Array<Array<number>>;
10+
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* generated using openapi-typescript-codegen -- do not edit */
2+
/* istanbul ignore file */
3+
/* tslint:disable */
4+
/* eslint-disable */
5+
export enum JobStatus {
6+
QUEUED = "queued",
7+
FINISHED = "finished",
8+
FAILED = "failed",
9+
STARTED = "started",
10+
DEFERRED = "deferred",
11+
SCHEDULED = "scheduled",
12+
STOPPED = "stopped",
13+
CANCELED = "canceled",
14+
}

frontend/src/api/openapi/services/AnalysisService.ts

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -118,30 +118,4 @@ export class AnalysisService {
118118
},
119119
});
120120
}
121-
/**
122-
* Returns groups of duplicate sdoc ids.
123-
* @returns number Successful Response
124-
* @throws ApiError
125-
*/
126-
public static findDuplicateTextSdocs({
127-
projId,
128-
maxDifferentWords,
129-
}: {
130-
projId: number;
131-
maxDifferentWords: number;
132-
}): CancelablePromise<Array<Array<number>>> {
133-
return __request(OpenAPI, {
134-
method: "POST",
135-
url: "/analysis/{proj_id}/find_duplicate_text_sdocs",
136-
path: {
137-
proj_id: projId,
138-
},
139-
query: {
140-
max_different_words: maxDifferentWords,
141-
},
142-
errors: {
143-
422: `Validation Error`,
144-
},
145-
});
146-
}
147121
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/* generated using openapi-typescript-codegen -- do not edit */
2+
/* istanbul ignore file */
3+
/* tslint:disable */
4+
/* eslint-disable */
5+
import type { DuplicateFinderInput } from "../models/DuplicateFinderInput";
6+
import type { DuplicateFinderJobRead } from "../models/DuplicateFinderJobRead";
7+
import type { CancelablePromise } from "../core/CancelablePromise";
8+
import { OpenAPI } from "../core/OpenAPI";
9+
import { request as __request } from "../core/request";
10+
export class JobService {
11+
/**
12+
* Start DuplicateFinder job
13+
* @returns DuplicateFinderJobRead Successful Response
14+
* @throws ApiError
15+
*/
16+
public static startDuplicateFinderJob({
17+
requestBody,
18+
}: {
19+
requestBody: DuplicateFinderInput;
20+
}): CancelablePromise<DuplicateFinderJobRead> {
21+
return __request(OpenAPI, {
22+
method: "POST",
23+
url: "/job/duplicate_finder",
24+
body: requestBody,
25+
mediaType: "application/json",
26+
errors: {
27+
422: `Validation Error`,
28+
},
29+
});
30+
}
31+
/**
32+
* Get DuplicateFinder job result
33+
* @returns DuplicateFinderJobRead Successful Response
34+
* @throws ApiError
35+
*/
36+
public static getDuplicateFinderJobById({ jobId }: { jobId: string }): CancelablePromise<DuplicateFinderJobRead> {
37+
return __request(OpenAPI, {
38+
method: "GET",
39+
url: "/job/duplicate_finder/{job_id}",
40+
path: {
41+
job_id: jobId,
42+
},
43+
errors: {
44+
422: `Validation Error`,
45+
},
46+
});
47+
}
48+
/**
49+
* Abort DuplicateFinder job
50+
* @returns boolean Successful Response
51+
* @throws ApiError
52+
*/
53+
public static abortDuplicateFinderJob({ jobId }: { jobId: string }): CancelablePromise<boolean> {
54+
return __request(OpenAPI, {
55+
method: "POST",
56+
url: "/job/duplicate_finder/{job_id}/abort",
57+
path: {
58+
job_id: jobId,
59+
},
60+
errors: {
61+
422: `Validation Error`,
62+
},
63+
});
64+
}
65+
/**
66+
* Retry DuplicateFinder job
67+
* @returns boolean Successful Response
68+
* @throws ApiError
69+
*/
70+
public static retryDuplicateFinderJob({ jobId }: { jobId: string }): CancelablePromise<boolean> {
71+
return __request(OpenAPI, {
72+
method: "POST",
73+
url: "/job/duplicate_finder/{job_id}/retry",
74+
path: {
75+
job_id: jobId,
76+
},
77+
errors: {
78+
422: `Validation Error`,
79+
},
80+
});
81+
}
82+
/**
83+
* Get all DuplicateFinder jobs by project
84+
* @returns DuplicateFinderJobRead Successful Response
85+
* @throws ApiError
86+
*/
87+
public static getDuplicateFinderJobsByProject({
88+
projectId,
89+
}: {
90+
projectId: number;
91+
}): CancelablePromise<Array<DuplicateFinderJobRead>> {
92+
return __request(OpenAPI, {
93+
method: "GET",
94+
url: "/job/duplicate_finder/project/{project_id}",
95+
path: {
96+
project_id: projectId,
97+
},
98+
errors: {
99+
422: `Validation Error`,
100+
},
101+
});
102+
}
103+
}

0 commit comments

Comments
 (0)