-
Notifications
You must be signed in to change notification settings - Fork 5
Bulk actions #460
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Bulk actions #460
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
81aa999
Fix typo
annavik 958642e
Add more identification quick action options
annavik 5610ec4
Tweak trigger button appearance
annavik 6385461
Exclude applied rank from options and reverse list
annavik 0d4b8f6
Hide quick action section if no options
annavik 082738d
Add selectable feature to table component and use in occurrence view
annavik b468134
Prepare bulk action bar UI
annavik 6c6a902
Merge branch 'main' into feature/bulk-actions
annavik 02e506b
Make it possible to agree in bulk
annavik 13f83e2
Make it possible to apply id in bulk
annavik 04d51a2
Hide quick actions when in multi select mode
annavik 70c44ef
Merge branch 'main' into feature/bulk-actions
mihow d235a3a
Merge branch 'main' into feature/bulk-actions
annavik 133ccb8
Only show common ranks in list of apply options
annavik 1bd6412
Merge branch 'feature/bulk-actions' of github.com:RolnickLab/ami-plat…
annavik 04ea706
Add error handling to quick actions
annavik 3787f90
Cleanup
annavik cfa4a6d
Present recent identifications as apply options
annavik a02fd34
Cleanup logic for identification options
annavik cfd106f
Filter out items currently not visible from selected items
annavik 03a5142
Disable outside close for identifications options popover
annavik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export interface IdentificationFieldValues { | ||
agreeWith?: { | ||
identificationId?: string | ||
predictionId?: string | ||
} | ||
occurrenceId: string | ||
taxonId: string | ||
comment?: string | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
ui/src/data-services/hooks/identifications/useCreateIdentifications.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { SUCCESS_TIMEOUT } from 'data-services/constants' | ||
import { useEffect, useState } from 'react' | ||
import { IdentificationFieldValues } from './types' | ||
import { useCreateIdentification } from './useCreateIdentification' | ||
|
||
export const useCreateIdentifications = ( | ||
params: IdentificationFieldValues[] | ||
) => { | ||
const [results, setResults] = useState<PromiseSettledResult<any>[]>() | ||
const { createIdentification, isLoading, isSuccess, reset } = | ||
useCreateIdentification(() => { | ||
setTimeout(() => { | ||
reset() | ||
}, SUCCESS_TIMEOUT) | ||
}) | ||
|
||
const numRejected = results?.filter( | ||
(result) => result.status === 'rejected' | ||
).length | ||
|
||
const error = numRejected | ||
? results.length > 1 | ||
? `${numRejected}/${results.length} updates were rejected, please retry.` | ||
: 'The update was rejected, please retry.' | ||
: undefined | ||
|
||
useEffect(() => { | ||
setResults(undefined) | ||
}, [params.length]) | ||
|
||
return { | ||
isLoading, | ||
isSuccess, | ||
error, | ||
createIdentifications: async () => { | ||
const promises = params | ||
.filter((_, index) => { | ||
if (error) { | ||
// Only retry rejected requests | ||
return results?.[index]?.status === 'rejected' | ||
} | ||
|
||
return true | ||
}) | ||
.map((variables) => createIdentification(variables)) | ||
|
||
setResults(undefined) | ||
const result = await Promise.allSettled(promises) | ||
setResults(result) | ||
}, | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
ui/src/data-services/hooks/identifications/useDeleteIdentification copy.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { useMutation, useQueryClient } from '@tanstack/react-query' | ||
import axios from 'axios' | ||
import { API_ROUTES, API_URL } from 'data-services/constants' | ||
import { getAuthHeader } from 'data-services/utils' | ||
import { useUser } from 'utils/user/userContext' | ||
|
||
export const useDeleteIdentification = (onSuccess?: () => void) => { | ||
const { user } = useUser() | ||
const queryClient = useQueryClient() | ||
|
||
const { mutateAsync, isLoading, isSuccess, error } = useMutation({ | ||
mutationFn: (id: string) => | ||
axios.delete(`${API_URL}/${API_ROUTES.IDENTIFICATIONS}/${id}`, { | ||
headers: getAuthHeader(user), | ||
}), | ||
onSuccess: () => { | ||
queryClient.invalidateQueries([API_ROUTES.IDENTIFICATIONS]) | ||
queryClient.invalidateQueries([API_ROUTES.OCCURRENCES]) | ||
onSuccess?.() | ||
}, | ||
}) | ||
|
||
return { deleteIdentification: mutateAsync, isLoading, isSuccess, error } | ||
} |
23 changes: 23 additions & 0 deletions
23
ui/src/design-system/components/bulk-action-bar/bulk-action-bar.module.scss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
@import 'src/design-system/variables/colors.scss'; | ||
@import 'src/design-system/variables/typography.scss'; | ||
|
||
.wrapper { | ||
bottom: 72px; | ||
position: fixed; | ||
border-radius: 32px; | ||
height: 64px; | ||
padding: 0 32px; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
gap: 16px; | ||
background-color: $color-generic-white; | ||
box-shadow: 0px 4px 16px rgba(0, 0, 0, 0.1); | ||
} | ||
|
||
.infoLabel { | ||
display: block; | ||
@include paragraph-small(); | ||
font-weight: 600; | ||
color: $color-neutral-500; | ||
} |
26 changes: 26 additions & 0 deletions
26
ui/src/design-system/components/bulk-action-bar/bulk-action-bar.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { ReactNode } from 'react' | ||
import { IconButton, IconButtonTheme } from '../icon-button/icon-button' | ||
import { IconType } from '../icon/icon' | ||
import styles from './bulk-action-bar.module.scss' | ||
|
||
interface BulkActionBarProps { | ||
children: ReactNode | ||
selectedItems: string[] | ||
onClear: () => void | ||
} | ||
|
||
export const BulkActionBar = ({ | ||
children, | ||
selectedItems, | ||
onClear, | ||
}: BulkActionBarProps) => ( | ||
<div className={styles.wrapper}> | ||
<span className={styles.infoLabel}>{selectedItems.length} selected</span> | ||
{children} | ||
<IconButton | ||
icon={IconType.Cross} | ||
theme={IconButtonTheme.Plain} | ||
onClick={onClear} | ||
/> | ||
</div> | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great! The async really pays off here. I see all 16 requests fire off at once and the backend seems to respond quickly.