Skip to content

Commit 095f8d5

Browse files
committed
fixed duplicate finder frontend: store last job id
1 parent 5d52684 commit 095f8d5

File tree

3 files changed

+68
-17
lines changed

3 files changed

+68
-17
lines changed

frontend/src/store/store.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import searchReducer from "../views/search/DocumentSearch/searchSlice.ts";
2222
import imageSearchReducer from "../views/search/ImageSearch/imageSearchSlice.ts";
2323
import sentenceSearchReducer from "../views/search/SentenceSearch/sentenceSearchSlice.ts";
2424
import documentSamplerReducer from "../views/tools/DocumentSampler/documentSamplerSlice.ts";
25+
import duplicateFinderReducer from "../views/tools/DuplicateFinder/duplicateFinderSlice.ts";
2526

2627
export const store = configureStore({
2728
reducer: {
@@ -49,6 +50,7 @@ export const store = configureStore({
4950
dialog: dialogReducer,
5051
documentSampler: documentSamplerReducer,
5152
perspectives: perspectivesReducer,
53+
duplicateFinder: duplicateFinderReducer,
5254
},
5355
middleware: (getDefaultMiddleware) =>
5456
getDefaultMiddleware({

frontend/src/views/tools/DuplicateFinder/DuplicateFinder.tsx

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import SdocHooks from "../../../api/SdocHooks.ts";
1717
import SdocRenderer from "../../../components/SourceDocument/SdocRenderer.tsx";
1818
import SdocTagsRenderer from "../../../components/SourceDocument/SdocTagRenderer.tsx";
1919
import ContentContainerLayout from "../../../layouts/ContentLayouts/ContentContainerLayout.tsx";
20+
import { useAppDispatch, useAppSelector } from "../../../plugins/ReduxHooks.ts";
21+
import { DuplicateFinderActions } from "./duplicateFinderSlice.ts";
2022

2123
interface DuplicateDocumentData {
2224
sdocId: string;
@@ -47,15 +49,26 @@ function ProjectDuplicateDocuments() {
4749
const [maxDifferentWords, setMaxDifferentWords] = useState<number>(10);
4850
const [rowSelection, setRowSelection] = useState<MRT_RowSelectionState>({});
4951

52+
// global client state
53+
const dispatch = useAppDispatch();
54+
const lastDuplicateFinderJobId = useAppSelector((state) => state.duplicateFinder.lastDuplicateFinderJobId);
55+
5056
// actions
51-
const startDuplicateFinderJobMutation = JobHooks.useStartDuplicateFinderJob();
57+
const { mutate: startDuplicateFinderJob, isPending } = JobHooks.useStartDuplicateFinderJob();
5258
const handleClickFindDuplicateTextDocuments = () => {
53-
startDuplicateFinderJobMutation.mutate({
54-
requestBody: {
55-
project_id: projectId,
56-
max_different_words: maxDifferentWords,
59+
startDuplicateFinderJob(
60+
{
61+
requestBody: {
62+
project_id: projectId,
63+
max_different_words: maxDifferentWords,
64+
},
5765
},
58-
});
66+
{
67+
onSuccess: (data) => {
68+
dispatch(DuplicateFinderActions.setLastDuplicateFinderJobId(data.job_id));
69+
},
70+
},
71+
);
5972
};
6073
const deleteDocumentsMutation = SdocHooks.useDeleteDocuments();
6174
const handleDeleteClick = (sdocIds: number[]) => {
@@ -66,12 +79,19 @@ function ProjectDuplicateDocuments() {
6679
{
6780
onSuccess: () => {
6881
setRowSelection({});
69-
startDuplicateFinderJobMutation.mutate({
70-
requestBody: {
71-
project_id: projectId,
72-
max_different_words: maxDifferentWords,
82+
startDuplicateFinderJob(
83+
{
84+
requestBody: {
85+
project_id: projectId,
86+
max_different_words: maxDifferentWords,
87+
},
7388
},
74-
});
89+
{
90+
onSuccess: (data) => {
91+
dispatch(DuplicateFinderActions.setLastDuplicateFinderJobId(data.job_id));
92+
},
93+
},
94+
);
7595
},
7696
},
7797
);
@@ -89,10 +109,7 @@ function ProjectDuplicateDocuments() {
89109
};
90110

91111
// job data
92-
const duplicateFinderJob = JobHooks.usePollDuplicateFinderJob(
93-
startDuplicateFinderJobMutation.data?.job_id,
94-
undefined,
95-
);
112+
const duplicateFinderJob = JobHooks.usePollDuplicateFinderJob(lastDuplicateFinderJobId, undefined);
96113

97114
// computed
98115
const data = useMemo(() => {
@@ -139,7 +156,7 @@ function ProjectDuplicateDocuments() {
139156
state: {
140157
rowSelection, //pass our managed row selection state to the table to use
141158
isLoading:
142-
startDuplicateFinderJobMutation.isPending ||
159+
isPending ||
143160
duplicateFinderJob.isLoading ||
144161
(duplicateFinderJob.data && duplicateFinderJob.data.status !== JobStatus.FINISHED),
145162
},
@@ -227,7 +244,7 @@ function ProjectDuplicateDocuments() {
227244
sx={{ ml: 1 }}
228245
onClick={handleClickFindDuplicateTextDocuments}
229246
loading={
230-
startDuplicateFinderJobMutation.isPending ||
247+
isPending ||
231248
duplicateFinderJob.isLoading ||
232249
(duplicateFinderJob.data && duplicateFinderJob.data.status !== JobStatus.FINISHED)
233250
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { PayloadAction, createSlice } from "@reduxjs/toolkit";
2+
import { ProjectActions } from "../../../components/Project/projectSlice.ts";
3+
4+
interface DuplicateFinderState {
5+
// project state:
6+
lastDuplicateFinderJobId: string | undefined;
7+
}
8+
9+
const initialState: DuplicateFinderState = {
10+
lastDuplicateFinderJobId: undefined,
11+
};
12+
13+
export const duplicateFinderSlice = createSlice({
14+
name: "duplicateFinder",
15+
initialState,
16+
reducers: {
17+
setLastDuplicateFinderJobId: (state, action: PayloadAction<string>) => {
18+
state.lastDuplicateFinderJobId = action.payload;
19+
},
20+
},
21+
extraReducers(builder) {
22+
builder.addCase(ProjectActions.changeProject, (state) => {
23+
console.log("Project changed! Resetting 'duplicateFinder' state.");
24+
state.lastDuplicateFinderJobId = initialState.lastDuplicateFinderJobId;
25+
});
26+
},
27+
});
28+
29+
// actions
30+
export const DuplicateFinderActions = duplicateFinderSlice.actions;
31+
32+
export default duplicateFinderSlice.reducer;

0 commit comments

Comments
 (0)