Skip to content

Commit c81470b

Browse files
mihowannavik
andauthored
Improve bulk identification workflow (#841)
* feat: extend list of recent labels * fix: do not invalidate queries until all ids are saved --------- Co-authored-by: Anna Viklund <annamariaviklund@gmail.com>
1 parent 660223f commit c81470b

3 files changed

Lines changed: 15 additions & 6 deletions

File tree

ui/src/data-services/hooks/identifications/useCreateIdentification.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ const convertToServerFieldValues = (
1515
comment: fieldValues.comment,
1616
})
1717

18-
export const useCreateIdentification = (onSuccess?: () => void) => {
18+
export const useCreateIdentification = (
19+
onSuccess?: () => void,
20+
invalidate: boolean = true
21+
) => {
1922
const { user } = useUser()
2023
const queryClient = useQueryClient()
2124

@@ -29,8 +32,10 @@ export const useCreateIdentification = (onSuccess?: () => void) => {
2932
}
3033
),
3134
onSuccess: () => {
32-
queryClient.invalidateQueries([API_ROUTES.IDENTIFICATIONS])
33-
queryClient.invalidateQueries([API_ROUTES.OCCURRENCES])
35+
if (invalidate) {
36+
queryClient.invalidateQueries([API_ROUTES.IDENTIFICATIONS])
37+
queryClient.invalidateQueries([API_ROUTES.OCCURRENCES])
38+
}
3439
onSuccess?.()
3540
},
3641
})

ui/src/data-services/hooks/identifications/useCreateIdentifications.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1-
import { SUCCESS_TIMEOUT } from 'data-services/constants'
1+
import { useQueryClient } from '@tanstack/react-query'
2+
import { API_ROUTES, SUCCESS_TIMEOUT } from 'data-services/constants'
23
import { useEffect, useState } from 'react'
34
import { IdentificationFieldValues } from './types'
45
import { useCreateIdentification } from './useCreateIdentification'
56

67
export const useCreateIdentifications = (
78
params: IdentificationFieldValues[]
89
) => {
10+
const queryClient = useQueryClient()
911
const [results, setResults] = useState<PromiseSettledResult<any>[]>()
1012
const { createIdentification, isLoading, isSuccess, reset } =
1113
useCreateIdentification(() => {
1214
setTimeout(() => {
1315
reset()
1416
}, SUCCESS_TIMEOUT)
15-
})
17+
}, false)
1618

1719
const numRejected = results?.filter(
1820
(result) => result.status === 'rejected'
@@ -47,6 +49,8 @@ export const useCreateIdentifications = (
4749
setResults(undefined)
4850
const result = await Promise.allSettled(promises)
4951
setResults(result)
52+
queryClient.invalidateQueries([API_ROUTES.IDENTIFICATIONS])
53+
queryClient.invalidateQueries([API_ROUTES.OCCURRENCES])
5054
},
5155
}
5256
}

ui/src/pages/occurrence-details/reject-id/useRecentOptions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useUserPreferences } from 'utils/userPreferences/userPreferencesContext'
22
import { REJECT_OPTIONS } from './constants'
33

4-
const DISPLAY_LIST_SIZE = 1 // Limit how many identifications are displayed
4+
const DISPLAY_LIST_SIZE = 5 // Limit how many identifications are displayed
55
const STORAGE_LIST_SIZE = 5 // Limit how many identifications are stored
66

77
export const useRecentIdentifications = () => {

0 commit comments

Comments
 (0)