From e70e3618543dccf3049a8531b51d1c3cc1357bb8 Mon Sep 17 00:00:00 2001 From: Jack Golding Date: Tue, 7 Jan 2025 15:04:40 +0000 Subject: [PATCH 1/4] fix: Combination pieces do not get allocated a date * fix: Initial combination piece sorting work Added initial work for sorted combination piece's recurrence pieces (bit confusing) * refactor: New generate fetch handling Updated some functions to handle new generate predicted pieces fetch (Object) whilst still supporting older version (Array), also updated some variable names for easier parsing * revert: Array/Object endpoint handling Reverted work for generated piece set handling or new/deprectaed endpoint responses, this is in a new ticket so should be part of a new PR * fix: Piece list sort Fixed the piece list so that now the pieces are correctly sorted regardless of class, additionally all combination pieces recurrence pieces are correctly sorted * fix: Sorted pieces Moved piece sorting to pieceset view, may need to be used outside of this component in the future, also resolved issue with the internalPieceClasses constants * refactor: Implement internal piece classes constants Added internal piece class constants to areas where omissionOrigins or combinationOrigins were used previously * fix: First/last piece information First/last piece information within the genrate receiving modal should now correctly handle combination pieces * fix: Predicted pieces information labelling Fixed an issue in which predicted pieces first/last date were not displaying correctly * refactor: Piece publication date As we've implemented the internal piece classes, seemed like a good time to refactor the piece publication date to use them aswell * test: Fixed tests Due to updated backend logic, alot of the tests needed to be updated --- .../GenerateReceivingModal.js | 59 ++++++++++++++----- .../PiecePublicationDate.js | 54 ++++++++++------- .../PiecePublicationDate.test.js | 51 ++++++++-------- .../PieceSetSections/PiecesList/PiecesList.js | 7 ++- .../PiecesList/PiecesList.test.js | 8 +-- .../PiecesPreviewModal/PiecesPreviewModal.js | 6 +- .../views/PieceSetView/PieceSetView.js | 35 ++++++++++- src/constants/internalPieceClasses.js | 3 + test/resources/pieceSet.js | 12 ++++ 9 files changed, 161 insertions(+), 74 deletions(-) create mode 100644 src/constants/internalPieceClasses.js diff --git a/src/components/GenerateReceivingModal/GenerateReceivingModal.js b/src/components/GenerateReceivingModal/GenerateReceivingModal.js index d605d5fe..71c6d69e 100644 --- a/src/components/GenerateReceivingModal/GenerateReceivingModal.js +++ b/src/components/GenerateReceivingModal/GenerateReceivingModal.js @@ -29,6 +29,11 @@ import { PIECE_SET_ENDPOINT, RECEIVING_PIECES_ENDPOINT, } from '../../constants/endpoints'; +import { + INTERNAL_COMBINATION_PIECE, + INTERNAL_OMISSION_PIECE, + INTERNAL_RECURRENCE_PIECE, +} from '../../constants/internalPieceClasses'; import css from './GenerateReceivingModal.css'; @@ -64,7 +69,12 @@ const GenerateReceivingModal = ({ 'submitReceivingPiece', ], (data) => { - return ky.post(`${RECEIVING_PIECES_ENDPOINT}${data?.createItem ? '?createItem=true' : ''}`, { json: data?.receiving }).json(); + return ky + .post( + `${RECEIVING_PIECES_ENDPOINT}${data?.createItem ? '?createItem=true' : ''}`, + { json: data?.receiving } + ) + .json(); } ); @@ -145,19 +155,20 @@ const GenerateReceivingModal = ({ }; const formatReceivingPiece = (piece, values) => { - if (!piece?.omissionOrigins) { - const pieceInfo = piece?.combinationOrigins - ? { - date: addDays(piece?.recurrencePieces[0]?.date, values?.interval), - label: piece?.recurrencePieces[0]?.label, - } - : { - date: addDays(piece?.date, values?.interval), - label: piece?.label, - }; + if (piece?.class !== INTERNAL_OMISSION_PIECE) { + const pieceInfo = + piece?.class === INTERNAL_COMBINATION_PIECE + ? { + date: addDays(piece?.recurrencePieces[0]?.date, values?.interval), + label: piece?.recurrencePieces[0]?.label, + } + : { + date: addDays(piece?.date, values?.interval), + label: piece?.label, + }; return { - ...values?.createItem && { createItem: values.createItem }, + ...(values?.createItem && { createItem: values.createItem }), receiving: { poLineId: serial?.orderLine?.remoteId, titleId: serial?.orderLine?.titleId, @@ -222,6 +233,20 @@ const GenerateReceivingModal = ({ }; const renderPredictedPiecesInformation = () => { + // Format piece information based on class + const renderPieceDateLabel = (piece) => { + switch (piece?.class) { + case INTERNAL_RECURRENCE_PIECE: + return `${piece?.date}, ${piece?.label}`; + case INTERNAL_OMISSION_PIECE: + return `${piece?.date}`; + case INTERNAL_COMBINATION_PIECE: + return `${piece?.recurrencePieces[0]?.date}, ${piece?.label}`; + default: + return null; + } + }; + return ( <> {!serial?.orderLine?.remoteId_object?.locations?.length && ( @@ -278,7 +303,7 @@ const GenerateReceivingModal = ({ } > - {pieceSet?.pieces[0]?.date}, {pieceSet?.pieces[0]?.label} + {renderPieceDateLabel(pieceSet?.pieces[0])} @@ -287,8 +312,9 @@ const GenerateReceivingModal = ({ } > - {pieceSet?.pieces[pieceSet?.pieces?.length - 1]?.date},{' '} - {pieceSet?.pieces[pieceSet?.pieces?.length - 1]?.label} + {renderPieceDateLabel( + pieceSet?.pieces?.[pieceSet?.pieces?.length - 1] + )} @@ -354,7 +380,8 @@ const GenerateReceivingModal = ({ )} - {serial?.orderLine?.remoteId_object?.physical?.createInventory === 'Instance, Holding, Item' && ( + {serial?.orderLine?.remoteId_object?.physical?.createInventory === + 'Instance, Holding, Item' && (