-
Notifications
You must be signed in to change notification settings - Fork 15
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
Conversation
minus graphql tests
Limited to success and not found. Quite limited and unsure of testing comprehensively here
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} | ||
> | ||
{t('button.delete-lines', { ns: 'distribution' })} | ||
</DropdownMenuItem> | ||
</DropdownMenu> | ||
); | ||
}; |
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.
Moved into its own file to duplicate RequestRequisition pattern
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 comment
The 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 comment
The 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?
if requisition_row.status != RequisitionStatus::Draft { | ||
return Err(OutError::CannotEditRequisition); | ||
} | ||
|
||
if requisition_row.r#type != RequisitionType::Request { | ||
return Err(OutError::NotARequestRequisition); | ||
} | ||
|
||
if requisition_row.status != RequisitionStatus::Draft { | ||
return Err(OutError::CannotEditRequisition); | ||
} |
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've rearranged error handling for mutating requisitions throughout.
To me this makes more sense returning the wrong type of requisition error before returning a status error.
Bundle size differenceComparing this PR to
|
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.
Thanks Ferg (: Excellent job on the deletes~
I just have a few comments below that need to be addressed before the PR can be approved (:
RE::StandUP: Create carryover issue to not allow deletion of lines if they are in a linked shipment (requires extra logic)
client/packages/requisitions/src/ResponseRequisition/DetailView/Toolbar/ToolbarDropDown.tsx
Outdated
Show resolved
Hide resolved
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 comment
The 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?
client/packages/requisitions/src/ResponseRequisition/api/hooks/line/useDeleteResponseLines.ts
Show resolved
Hide resolved
NotThisStoreRequisition, | ||
NotAResponseRequisition, | ||
RequisitionDoesNotExist, | ||
CannotEditRequisition, |
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.
Can you add a CannotDeleteTransferredRequisition
er or some better naming... This needs to check that the requisition is not created from an Internal Order
server/service/src/requisition_line/response_requisition_line/delete.rs
Outdated
Show resolved
Hide resolved
Oh! And the postgres tests are failing, can you fix this (: And can you change the deletion message when you cannot delete #5128 should be a small fix |
β¦delete.rs Co-authored-by: roxy-dao <[email protected]>
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.
Thanks for the changes Ferg! I just have a few more comments and have put them in this example branch (:
{t('button.delete-lines', { ns: 'distribution' })} | ||
</DropdownMenuItem> | ||
</DropdownMenu> | ||
<ToolbarDropDown isDisabled={isDisabled || !!theirReference} /> |
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.
The user can enter in theirReference, so we shouldn't be using this for the check. Their is a linkedRequisition
node that gets returned which will tell us if the Requisition was created as a result of an Internal Order.
import { useResponse } from '../../api'; | ||
|
||
interface ToolbarDropDownProps { | ||
isDisabled: boolean; |
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
onClick={onDelete} | ||
disabled={isDisabled} | ||
> | ||
{t('button.delete-lines', { ns: 'distribution' })} |
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.
We don't need to use namespace anymore since all the translations are in one common.json file
client/packages/requisitions/src/ResponseRequisition/api/hooks/line/useDeleteResponseLines.ts
Show resolved
Hide resolved
Awesome thank you Roxy! I have added those. |
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.
Awesome! Thanks for all the changes Ferg /o/
Fixes #5139
π©π»βπ» What does this PR do?
Adds delete response requisition lines & line back end service and graphql layers.
Adds front end api for batch delete requisition lines.
π Any notes for the reviewer?
Have added delete singular response requisition lines but doesn't expose this in API (similar to request requisition lines).
We have the singular delete, but all deletes are handled through the batch delete.
Adds tests, but graphql delete lines are a little limited.
π§ͺ Testing
π Documentation