-
Notifications
You must be signed in to change notification settings - Fork 16
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
5139 delete response requisition lines #5226
Changes from 13 commits
949d692
18a745b
a9bb801
88953a6
32c14fb
fcad1b2
f743641
5772374
ccb8f4b
e6ec2a2
b5d434e
e6406a7
322715b
1d668b0
07df943
c5f479b
d933c3b
49c32da
206d377
8e8b2bb
be7022a
010e33c
e1c3e4d
83d98e2
b685bb2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React from 'react'; | ||
import { | ||
DropdownMenu, | ||
DropdownMenuItem, | ||
DeleteIcon, | ||
useTranslation, | ||
} from '@openmsupply-client/common'; | ||
import { useResponse } from '../../api'; | ||
|
||
interface ToolbarDropDownProps { | ||
isDisabled: boolean; | ||
} | ||
|
||
export const ToolbarDropDown = ({ isDisabled }: ToolbarDropDownProps) => { | ||
const t = useTranslation(); | ||
const onDelete = useResponse.line.delete(); | ||
|
||
return ( | ||
<DropdownMenu label={t('label.actions')}> | ||
<DropdownMenuItem | ||
IconComponent={DeleteIcon} | ||
onClick={onDelete} | ||
disabled={isDisabled} | ||
fergie-nz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
> | ||
{t('button.delete-lines', { ns: 'distribution' })} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need to use namespace anymore since all the translations are in one common.json file |
||
</DropdownMenuItem> | ||
</DropdownMenu> | ||
); | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved into its own file to duplicate RequestRequisition pattern |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './Toolbar'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -191,22 +191,37 @@ export const getResponseQueries = (sdk: Sdk, storeId: string) => ({ | |
|
||
throw new Error('Unable to update requisition'); | ||
}, | ||
deleteLines: async (_: ResponseLineFragment[]) => { | ||
// NOT YET IMPLEMENTED IN SERVER API | ||
|
||
// const ids = responseLines.map(responseParser.toDeleteLine); | ||
// const result = await sdk.deleteRequestLines({ ids, storeId }); | ||
|
||
// if (result.batchRequestRequisition.deleteRequestRequisitionLines) { | ||
// const failedLines = | ||
// result.batchRequestRequisition.deleteRequestRequisitionLines.filter( | ||
// line => | ||
// line.response.__typename === 'DeleteRequestRequisitionLineError' | ||
// ); | ||
// if (failedLines.length === 0) { | ||
// return result.batchRequestRequisition.deleteRequestRequisitionLines; | ||
// } | ||
// } | ||
deleteLine: async (responseLineId: string) => { | ||
const ids = [{ id: responseLineId }]; | ||
const result = await sdk.deleteResponseLines({ ids, storeId }); | ||
|
||
if (result.batchResponseRequisition.deleteResponseRequisitionLines) { | ||
const failedLines = | ||
result.batchResponseRequisition.deleteResponseRequisitionLines.filter( | ||
line => | ||
line.response.__typename === 'DeleteResponseRequisitionLineError' | ||
); | ||
if (failedLines.length === 0) { | ||
return result.batchResponseRequisition.deleteResponseRequisitionLines; | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This uses the batch delete api even for singular. Not currently used, but will be used for edit single line in future There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need this. It's fine to use the deleteLines batch deletion to delete singular lines as well. Can you remove it? |
||
|
||
throw new Error('Could not delete requisition lines!'); | ||
}, | ||
deleteLines: async (responseLines: ResponseLineFragment[]) => { | ||
const ids = responseLines.map(responseParser.toDeleteLine); | ||
const result = await sdk.deleteResponseLines({ ids, storeId }); | ||
|
||
if (result.batchResponseRequisition.deleteResponseRequisitionLines) { | ||
const failedLines = | ||
result.batchResponseRequisition.deleteResponseRequisitionLines.filter( | ||
line => | ||
line.response.__typename === 'DeleteResponseRequisitionLineError' | ||
); | ||
if (failedLines.length === 0) { | ||
return result.batchResponseRequisition.deleteResponseRequisitionLines; | ||
} | ||
} | ||
|
||
throw new Error('Could not delete requisition lines!'); | ||
}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { useQueryClient, useMutation } from '@openmsupply-client/common'; | ||
import { useResponseApi } from '../utils/useResponseApi'; | ||
import { useResponseNumber } from '../document/useResponse'; | ||
|
||
export const useDeleteResponseLine = () => { | ||
const api = useResponseApi(); | ||
const responseNumber = useResponseNumber(); | ||
|
||
const queryClient = useQueryClient(); | ||
const { mutate } = useMutation(api.deleteLine, { | ||
onSettled: () => | ||
queryClient.invalidateQueries(api.keys.detail(responseNumber)), | ||
}); | ||
return mutate; | ||
}; |
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.
I would pass in the linkedRequisition here as a check just in case we add other actions to Requisition and having it this way will help differentiate between the two