Skip to content
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

Merged
merged 25 commits into from
Oct 29, 2024

Conversation

fergie-nz
Copy link
Contributor

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

  • Go to distribution -> requisitions
  • select some lines
  • delete via drop down
  • (You might need to create lines in the DB as no create lines method currently exists. Or you can reassign lines from another (request) requisition for data to delete.

πŸ“ƒ Documentation

  • Part of an epic: documentation will be completed for the feature as a whole

Comment on lines 1 to 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}
>
{t('button.delete-lines', { ns: 'distribution' })}
</DropdownMenuItem>
</DropdownMenu>
);
};
Copy link
Contributor Author

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

@roxy-dao roxy-dao self-assigned this Oct 24, 2024
Comment on lines 194 to 207
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;
}
}
Copy link
Contributor Author

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

Copy link
Contributor

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?

Comment on lines -97 to +103
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);
}
Copy link
Contributor Author

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.

Copy link

github-actions bot commented Oct 24, 2024

Bundle size difference

Comparing this PR to main

Old size New size Diff
4.87 MB 4.87 MB 1.46 KB (0.03%)

Copy link
Contributor

@roxy-dao roxy-dao left a 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)

Comment on lines 194 to 207
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;
}
}
Copy link
Contributor

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?

server/graphql/requisition_line/src/lib.rs Outdated Show resolved Hide resolved
NotThisStoreRequisition,
NotAResponseRequisition,
RequisitionDoesNotExist,
CannotEditRequisition,
Copy link
Contributor

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

@roxy-dao roxy-dao linked an issue Oct 24, 2024 that may be closed by this pull request
@roxy-dao roxy-dao changed the title 5139 delete response requisition 5139 delete response requisition lines Oct 24, 2024
@github-actions github-actions bot added this to the V2.4.0 milestone Oct 24, 2024
@github-actions github-actions bot added bug Something is borken Severity: Low Bugs that don't block workflows. UX like wrong fonts, bad layout labels Oct 24, 2024
@roxy-dao
Copy link
Contributor

roxy-dao commented Oct 24, 2024

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

Copy link
Contributor

@roxy-dao roxy-dao left a 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} />
Copy link
Contributor

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;
Copy link
Contributor

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' })}
Copy link
Contributor

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

@fergie-nz
Copy link
Contributor Author

Thanks for the changes Ferg! I just have a few more comments and have put them in this example branch (:

Awesome thank you Roxy! I have added those.

@fergie-nz fergie-nz requested a review from roxy-dao October 29, 2024 01:03
Copy link
Contributor

@roxy-dao roxy-dao left a 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/

@fergie-nz fergie-nz merged commit 8e94318 into develop Oct 29, 2024
6 checks passed
@fergie-nz fergie-nz deleted the 5139-delete-response-requisition branch October 29, 2024 03:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is borken enhancement New feature or request feature: manual requisition Severity: Low Bugs that don't block workflows. UX like wrong fonts, bad layout Team Ruru πŸ¦‰ Roxy, Ferg, Noel
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Delete response requisition lines Cannot delete lines - error message could be clearer
2 participants