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
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
949d692
Add delete response requisition service layer
fergie-nz Oct 23, 2024
18a745b
Add service layer tests
fergie-nz Oct 24, 2024
a9bb801
Add graphql layer delete response requisition line
fergie-nz Oct 24, 2024
88953a6
Add check for status as per update response requisition line
fergie-nz Oct 24, 2024
32c14fb
Add tests to graphql layer
fergie-nz Oct 24, 2024
fcad1b2
Add front end deleteResponseLines
fergie-nz Oct 24, 2024
f743641
Add batch mutations service layer
fergie-nz Oct 24, 2024
5772374
Add batch mutations graphql layer
fergie-nz Oct 24, 2024
ccb8f4b
Add individual line delete (using batch mutation on back end)
fergie-nz Oct 24, 2024
e6ec2a2
Add graphql tests
fergie-nz Oct 24, 2024
b5d434e
Merge branch 'develop' into 5139-delete-response-requisition
fergie-nz Oct 24, 2024
e6406a7
Regenerate schema
fergie-nz Oct 24, 2024
322715b
Fix tests
fergie-nz Oct 24, 2024
1d668b0
Restructure order of errors
fergie-nz Oct 24, 2024
07df943
Remove redundant delete line from api
fergie-nz Oct 24, 2024
c5f479b
Add check for request requisition reference
fergie-nz Oct 25, 2024
d933c3b
Update server/service/src/requisition_line/response_requisition_line/…
fergie-nz Oct 25, 2024
49c32da
Add check for transferred requisition
fergie-nz Oct 25, 2024
206d377
Don't make map_response public
roxy-dao Oct 28, 2024
8e8b2bb
Passing in wrong type for isResponseDisabled check
roxy-dao Oct 28, 2024
be7022a
Expose linkedRequisition node
roxy-dao Oct 28, 2024
010e33c
Use linkedRequisition for disabled check
roxy-dao Oct 28, 2024
e1c3e4d
Disambiguiating map_errors
fergie-nz Oct 28, 2024
83d98e2
Fix test
roxy-dao Oct 28, 2024
b685bb2
Merge branch '5139-example' into 5139-delete-response-requisition
fergie-nz Oct 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 50 additions & 3 deletions client/packages/common/src/types/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,16 @@ export type BatchRequestRequisitionResponse = {
updateRequestRequisitions?: Maybe<Array<UpdateRequestRequisitionResponseWithId>>;
};

export type BatchResponseRequisitionInput = {
continueOnError?: InputMaybe<Scalars['Boolean']['input']>;
deleteResponseRequisitionLines?: InputMaybe<Array<DeleteResponseRequisitionLineInput>>;
};

export type BatchResponseRequisitionResponse = {
__typename: 'BatchResponseRequisitionResponse';
deleteResponseRequisitionLines?: Maybe<Array<DeleteResponseRequisitionLineResponseWithId>>;
};

export type BatchStocktakeInput = {
continueOnError?: InputMaybe<Scalars['Boolean']['input']>;
deleteStocktakeLines?: InputMaybe<Array<DeleteStocktakeLineInput>>;
Expand Down Expand Up @@ -823,7 +833,7 @@ export type CannotEditInvoice = AddToInboundShipmentFromMasterListErrorInterface
description: Scalars['String']['output'];
};

export type CannotEditRequisition = AddFromMasterListErrorInterface & CreateRequisitionShipmentErrorInterface & DeleteRequestRequisitionErrorInterface & DeleteRequestRequisitionLineErrorInterface & InsertRequestRequisitionLineErrorInterface & InsertResponseRequisitionLineErrorInterface & SupplyRequestedQuantityErrorInterface & UpdateRequestRequisitionErrorInterface & UpdateRequestRequisitionLineErrorInterface & UpdateResponseRequisitionErrorInterface & UpdateResponseRequisitionLineErrorInterface & UseSuggestedQuantityErrorInterface & {
export type CannotEditRequisition = AddFromMasterListErrorInterface & CreateRequisitionShipmentErrorInterface & DeleteRequestRequisitionErrorInterface & DeleteRequestRequisitionLineErrorInterface & DeleteResponseRequisitionLineErrorInterface & InsertRequestRequisitionLineErrorInterface & InsertResponseRequisitionLineErrorInterface & SupplyRequestedQuantityErrorInterface & UpdateRequestRequisitionErrorInterface & UpdateRequestRequisitionLineErrorInterface & UpdateResponseRequisitionErrorInterface & UpdateResponseRequisitionLineErrorInterface & UseSuggestedQuantityErrorInterface & {
__typename: 'CannotEditRequisition';
description: Scalars['String']['output'];
};
Expand Down Expand Up @@ -1511,6 +1521,27 @@ export type DeleteResponse = {
id: Scalars['String']['output'];
};

export type DeleteResponseRequisitionLineError = {
__typename: 'DeleteResponseRequisitionLineError';
error: DeleteResponseRequisitionLineErrorInterface;
};

export type DeleteResponseRequisitionLineErrorInterface = {
description: Scalars['String']['output'];
};

export type DeleteResponseRequisitionLineInput = {
id: Scalars['String']['input'];
};

export type DeleteResponseRequisitionLineResponse = DeleteResponse | DeleteResponseRequisitionLineError;

export type DeleteResponseRequisitionLineResponseWithId = {
__typename: 'DeleteResponseRequisitionLineResponseWithId';
id: Scalars['String']['output'];
response: DeleteResponseRequisitionLineResponse;
};

export type DeleteStocktakeError = {
__typename: 'DeleteStocktakeError';
error: DeleteStocktakeErrorInterface;
Expand Down Expand Up @@ -2120,7 +2151,7 @@ export enum ForeignKey {
StockLineId = 'stockLineId'
}

export type ForeignKeyError = DeleteInboundShipmentLineErrorInterface & DeleteInboundShipmentServiceLineErrorInterface & DeleteOutboundShipmentLineErrorInterface & DeleteOutboundShipmentServiceLineErrorInterface & DeleteOutboundShipmentUnallocatedLineErrorInterface & DeletePrescriptionLineErrorInterface & InsertInboundShipmentLineErrorInterface & InsertInboundShipmentServiceLineErrorInterface & InsertOutboundShipmentLineErrorInterface & InsertOutboundShipmentServiceLineErrorInterface & InsertOutboundShipmentUnallocatedLineErrorInterface & InsertPrescriptionLineErrorInterface & InsertRequestRequisitionLineErrorInterface & InsertResponseRequisitionLineErrorInterface & UpdateInboundShipmentLineErrorInterface & UpdateInboundShipmentServiceLineErrorInterface & UpdateOutboundShipmentLineErrorInterface & UpdateOutboundShipmentServiceLineErrorInterface & UpdateOutboundShipmentUnallocatedLineErrorInterface & UpdatePrescriptionLineErrorInterface & UpdateRequestRequisitionLineErrorInterface & UpdateResponseRequisitionLineErrorInterface & {
export type ForeignKeyError = DeleteInboundShipmentLineErrorInterface & DeleteInboundShipmentServiceLineErrorInterface & DeleteOutboundShipmentLineErrorInterface & DeleteOutboundShipmentServiceLineErrorInterface & DeleteOutboundShipmentUnallocatedLineErrorInterface & DeletePrescriptionLineErrorInterface & DeleteResponseRequisitionLineErrorInterface & InsertInboundShipmentLineErrorInterface & InsertInboundShipmentServiceLineErrorInterface & InsertOutboundShipmentLineErrorInterface & InsertOutboundShipmentServiceLineErrorInterface & InsertOutboundShipmentUnallocatedLineErrorInterface & InsertPrescriptionLineErrorInterface & InsertRequestRequisitionLineErrorInterface & InsertResponseRequisitionLineErrorInterface & UpdateInboundShipmentLineErrorInterface & UpdateInboundShipmentServiceLineErrorInterface & UpdateOutboundShipmentLineErrorInterface & UpdateOutboundShipmentServiceLineErrorInterface & UpdateOutboundShipmentUnallocatedLineErrorInterface & UpdatePrescriptionLineErrorInterface & UpdateRequestRequisitionLineErrorInterface & UpdateResponseRequisitionLineErrorInterface & {
__typename: 'ForeignKeyError';
description: Scalars['String']['output'];
key: ForeignKey;
Expand Down Expand Up @@ -3826,6 +3857,7 @@ export type Mutations = {
batchOutboundShipment: BatchOutboundShipmentResponse;
batchPrescription: BatchPrescriptionResponse;
batchRequestRequisition: BatchRequestRequisitionResponse;
batchResponseRequisition: BatchResponseRequisitionResponse;
batchStocktake: BatchStocktakeResponse;
centralServer: CentralServerMutationNode;
createInventoryAdjustment: CreateInventoryAdjustmentResponse;
Expand All @@ -3850,6 +3882,7 @@ export type Mutations = {
deletePrescriptionLine: DeletePrescriptionLineResponse;
deleteRequestRequisition: DeleteRequestRequisitionResponse;
deleteRequestRequisitionLine: DeleteRequestRequisitionLineResponse;
deleteResponseRequisitionLine: DeleteResponseRequisitionLineResponse;
deleteStocktake: DeleteStocktakeResponse;
deleteStocktakeLine: DeleteStocktakeLineResponse;
deleteSupplierReturn: DeleteSupplierReturnResponse;
Expand Down Expand Up @@ -4009,6 +4042,12 @@ export type MutationsBatchRequestRequisitionArgs = {
};


export type MutationsBatchResponseRequisitionArgs = {
input: BatchResponseRequisitionInput;
storeId: Scalars['String']['input'];
};


export type MutationsBatchStocktakeArgs = {
input: BatchStocktakeInput;
storeId: Scalars['String']['input'];
Expand Down Expand Up @@ -4111,6 +4150,12 @@ export type MutationsDeleteRequestRequisitionLineArgs = {
};


export type MutationsDeleteResponseRequisitionLineArgs = {
input: DeleteResponseRequisitionLineInput;
storeId: Scalars['String']['input'];
};


export type MutationsDeleteStocktakeArgs = {
input: DeleteStocktakeInput;
storeId: Scalars['String']['input'];
Expand Down Expand Up @@ -6186,7 +6231,7 @@ export type RecordBelongsToAnotherStore = DeleteAssetErrorInterface & DeleteAsse
description: Scalars['String']['output'];
};

export type RecordNotFound = AddFromMasterListErrorInterface & AddToInboundShipmentFromMasterListErrorInterface & AddToOutboundShipmentFromMasterListErrorInterface & AllocateOutboundShipmentUnallocatedLineErrorInterface & CreateRequisitionShipmentErrorInterface & DeleteAssetCatalogueItemErrorInterface & DeleteAssetErrorInterface & DeleteAssetLogReasonErrorInterface & DeleteCustomerReturnErrorInterface & DeleteErrorInterface & DeleteInboundShipmentErrorInterface & DeleteInboundShipmentLineErrorInterface & DeleteInboundShipmentServiceLineErrorInterface & DeleteLocationErrorInterface & DeleteOutboundShipmentLineErrorInterface & DeleteOutboundShipmentServiceLineErrorInterface & DeleteOutboundShipmentUnallocatedLineErrorInterface & DeletePrescriptionErrorInterface & DeletePrescriptionLineErrorInterface & DeleteRequestRequisitionErrorInterface & DeleteRequestRequisitionLineErrorInterface & DeleteSupplierReturnErrorInterface & DeleteVaccineCourseErrorInterface & NodeErrorInterface & RequisitionLineChartErrorInterface & RequisitionLineStatsErrorInterface & SupplyRequestedQuantityErrorInterface & UpdateAssetErrorInterface & UpdateErrorInterface & UpdateInboundShipmentErrorInterface & UpdateInboundShipmentLineErrorInterface & UpdateInboundShipmentServiceLineErrorInterface & UpdateLocationErrorInterface & UpdateNameErrorInterface & UpdateNamePropertiesErrorInterface & UpdateOutboundShipmentLineErrorInterface & UpdateOutboundShipmentServiceLineErrorInterface & UpdateOutboundShipmentUnallocatedLineErrorInterface & UpdatePrescriptionErrorInterface & UpdatePrescriptionLineErrorInterface & UpdateRequestRequisitionErrorInterface & UpdateRequestRequisitionLineErrorInterface & UpdateResponseRequisitionErrorInterface & UpdateResponseRequisitionLineErrorInterface & UpdateReturnOtherPartyErrorInterface & UpdateSensorErrorInterface & UpdateStockLineErrorInterface & UseSuggestedQuantityErrorInterface & {
export type RecordNotFound = AddFromMasterListErrorInterface & AddToInboundShipmentFromMasterListErrorInterface & AddToOutboundShipmentFromMasterListErrorInterface & AllocateOutboundShipmentUnallocatedLineErrorInterface & CreateRequisitionShipmentErrorInterface & DeleteAssetCatalogueItemErrorInterface & DeleteAssetErrorInterface & DeleteAssetLogReasonErrorInterface & DeleteCustomerReturnErrorInterface & DeleteErrorInterface & DeleteInboundShipmentErrorInterface & DeleteInboundShipmentLineErrorInterface & DeleteInboundShipmentServiceLineErrorInterface & DeleteLocationErrorInterface & DeleteOutboundShipmentLineErrorInterface & DeleteOutboundShipmentServiceLineErrorInterface & DeleteOutboundShipmentUnallocatedLineErrorInterface & DeletePrescriptionErrorInterface & DeletePrescriptionLineErrorInterface & DeleteRequestRequisitionErrorInterface & DeleteRequestRequisitionLineErrorInterface & DeleteResponseRequisitionLineErrorInterface & DeleteSupplierReturnErrorInterface & DeleteVaccineCourseErrorInterface & NodeErrorInterface & RequisitionLineChartErrorInterface & RequisitionLineStatsErrorInterface & SupplyRequestedQuantityErrorInterface & UpdateAssetErrorInterface & UpdateErrorInterface & UpdateInboundShipmentErrorInterface & UpdateInboundShipmentLineErrorInterface & UpdateInboundShipmentServiceLineErrorInterface & UpdateLocationErrorInterface & UpdateNameErrorInterface & UpdateNamePropertiesErrorInterface & UpdateOutboundShipmentLineErrorInterface & UpdateOutboundShipmentServiceLineErrorInterface & UpdateOutboundShipmentUnallocatedLineErrorInterface & UpdatePrescriptionErrorInterface & UpdatePrescriptionLineErrorInterface & UpdateRequestRequisitionErrorInterface & UpdateRequestRequisitionLineErrorInterface & UpdateResponseRequisitionErrorInterface & UpdateResponseRequisitionLineErrorInterface & UpdateReturnOtherPartyErrorInterface & UpdateSensorErrorInterface & UpdateStockLineErrorInterface & UseSuggestedQuantityErrorInterface & {
__typename: 'RecordNotFound';
description: Scalars['String']['output'];
};
Expand Down Expand Up @@ -8042,7 +8087,9 @@ export type UpdateResponseRequisitionLineErrorInterface = {
export type UpdateResponseRequisitionLineInput = {
comment?: InputMaybe<Scalars['String']['input']>;
id: Scalars['String']['input'];
requestedQuantity?: InputMaybe<Scalars['Float']['input']>;
supplyQuantity?: InputMaybe<Scalars['Float']['input']>;
theirStockOnHand?: InputMaybe<Scalars['Float']['input']>;
};

export type UpdateResponseRequisitionLineResponse = RequisitionLineNode | UpdateResponseRequisitionLineError;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from '@openmsupply-client/common';
import { AppRoute } from '@openmsupply-client/config';
import { ActivityLogList } from '@openmsupply-client/system';
import { Toolbar } from './Toolbar';
import { Toolbar } from './Toolbar/Toolbar';
import { Footer } from './Footer';
import { AppBarButtons } from './AppBarButtons';
import { SidePanel } from './SidePanel';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import {
Box,
InputWithLabelRow,
Grid,
DropdownMenu,
DropdownMenuItem,
DeleteIcon,
useTranslation,
SearchBar,
Typography,
Expand All @@ -16,8 +13,9 @@ import {
} from '@openmsupply-client/common';
import { CustomerSearchInput } from '@openmsupply-client/system';

import { useResponse } from '../api';
import { getApprovalStatusKey } from '../../utils';
import { useResponse } from '../../api';
import { getApprovalStatusKey } from '../../../utils';
import { ToolbarDropDown } from './ToolbarDropDown';

export const Toolbar: FC = () => {
const t = useTranslation();
Expand All @@ -42,7 +40,6 @@ export const Toolbar: FC = () => {
'period',
'orderType',
]);
const { onDelete } = useResponse.line.delete();
const noLinkedShipments = (shipments?.totalCount ?? 0) === 0;
const showInfo = noLinkedShipments && !isDisabled;
const { isRemoteAuthorisation } = useResponse.utils.isRemoteAuthorisation();
Expand Down Expand Up @@ -132,16 +129,7 @@ export const Toolbar: FC = () => {
}}
debounceTime={0}
/>

<DropdownMenu label={t('label.actions')}>
<DropdownMenuItem
IconComponent={DeleteIcon}
onClick={onDelete}
disabled={isDisabled}
>
{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.

</Grid>
</AppBarContentPortal>
);
Expand Down
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;
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

}

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' })}
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

</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

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './Toolbar';
30 changes: 14 additions & 16 deletions client/packages/requisitions/src/ResponseRequisition/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,22 +191,20 @@ 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;
// }
// }
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!');
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export const useResponse = {
line: {
list: Lines.useResponseLines,
stats: Lines.useResponseLineStatsData,

delete: Lines.useDeleteResponseLines,
save: Lines.useSaveResponseLines,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ export const Lines = {
useDeleteResponseLines,
useResponseLines,
useSaveResponseLines,
useResponseLineStatsData
useResponseLineStatsData,
};
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import {
useQueryClient,
useMutation,
useNotification,
useTranslation,
useTableStore,
useDeleteConfirmation,
} from '@openmsupply-client/common';
import { useResponse } from '..';
import { useResponseNumber } from '../document/useResponse';
import { useResponseApi } from '../utils/useResponseApi';
import { useResponseLines } from './useResponseLines';

export const useDeleteResponseLines = () => {
const { success, info } = useNotification();
const { lines } = useResponseLines();
const api = useResponseApi();
const requestNumber = useResponseNumber();
const isDisabled = useResponse.utils.isDisabled();
const queryClient = useQueryClient();
const { mutate } = useMutation(api.deleteLines, {
const { mutateAsync } = useMutation(api.deleteLines, {
onSettled: () =>
queryClient.invalidateQueries(api.keys.detail(requestNumber)),
});
Expand All @@ -28,21 +27,25 @@ export const useDeleteResponseLines = () => {
);

const onDelete = async () => {
if (isDisabled) {
info(t('label.cant-delete-disabled-requisition'))();
return;
}
info('Deleting response lines not yet implemented in API')();
return;
const number = selectedRows?.length;
if (selectedRows && number) {
mutate(selectedRows, {
onSuccess: success(t('messages.deleted-lines', { count: number })),
});
} else {
info(t('messages.select-rows-to-delete-them'))();
}
mutateAsync(selectedRows).catch(err => {
throw err;
});
};

return { onDelete };
const confirmAndDelete = useDeleteConfirmation({
selectedRows,
deleteAction: onDelete,
canDelete: !isDisabled,
fergie-nz marked this conversation as resolved.
Show resolved Hide resolved
messages: {
confirmMessage: t('messages.confirm-delete-requisition-lines', {
count: selectedRows.length,
}),
deleteSuccess: t('messages.deleted-lines', {
count: selectedRows.length,
}),
cantDelete: t('label.cant-delete-disabled-requisition'),
},
});

return confirmAndDelete;
};
Loading
Loading