Skip to content

Commit

Permalink
Add basic functionality for managing missing data
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-blazhko committed Nov 26, 2024
1 parent 21f2a60 commit 66ec3e8
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Add circulation-storage.staff-slips.collection.get for get staff-slips on Send item in transit. Refs UIREQMED-55.
* Add Decline Action for Mediated request with status of New - Awaiting confirmation. Refs UIREQMED-42.
* Fix DOMPurify import. Refs UIREQMED-56.
* Add functionality for managing missing data related to item, instance, requester. Refs UIREQMED-51.

## [1.1.0](https://github.com/folio-org/ui-requests-mediated/tree/v1.1.0) (2024-10-30)
* Update github actions. Refs UIREQMED-14.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class InstanceInformation extends Component {
isLoading: PropTypes.bool.isRequired,
enterButtonClass: PropTypes.string.isRequired,
isInstancePreselected: PropTypes.bool.isRequired,
isEditMode: PropTypes.bool.isRequired,
request: PropTypes.object.isRequired,
stripes: PropTypes.object.isRequired,
selectedInstance: PropTypes.object,
};
Expand All @@ -58,11 +60,22 @@ class InstanceInformation extends Component {
const {
isInstancePreselected,
selectedInstance,
isEditMode,
triggerValidation,
request,
} = this.props;
const isNewPreselectedValue = isInstancePreselected && isInstancePreselected !== prevProps.isInstancePreselected;

if (selectedInstance && isInstancePreselected && isInstancePreselected !== prevProps.isInstancePreselected) {
if (selectedInstance && isNewPreselectedValue) {
this.setState({ validatedId: selectedInstance.hrid });
}

if (isEditMode && !selectedInstance && isNewPreselectedValue) {
this.setState({
validatedId: request?.instance?.hrid,
shouldValidate: true,
}, triggerValidation);
}
}

validate = memoizeValidation(async (instanceId) => {
Expand Down Expand Up @@ -183,6 +196,7 @@ class InstanceInformation extends Component {
isLoading,
enterButtonClass,
stripes,
isEditMode,
} = this.props;
const {
isInstanceClicked,
Expand Down Expand Up @@ -211,7 +225,7 @@ class InstanceInformation extends Component {
>
{({ input, meta }) => {
const selectInstanceError = meta.touched && meta.error;
const instanceDoesntExistError = (isInstanceClicked || isInstanceBlurred) && meta.error;
const instanceDoesntExistError = (isInstanceClicked || isInstanceBlurred || (isEditMode && !selectedInstance)) && meta.error;
const error = selectInstanceError || instanceDoesntExistError || null;

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class ItemInformation extends Component {
isItemIdRequest: PropTypes.bool.isRequired,
enterButtonClass: PropTypes.string.isRequired,
isItemPreselected: PropTypes.bool.isRequired,
isEditMode: PropTypes.bool.isRequired,
stripes: PropTypes.shape({
hasPerm: PropTypes.func,
}).isRequired,
Expand All @@ -59,11 +60,22 @@ class ItemInformation extends Component {
const {
isItemPreselected,
selectedItem,
isEditMode,
triggerValidation,
request,
} = this.props;
const isNewPreselectedValue = isItemPreselected && isItemPreselected !== prevProps.isItemPreselected;

if (selectedItem && isItemPreselected && isItemPreselected !== prevProps.isItemPreselected) {
if (selectedItem && isNewPreselectedValue) {
this.setState({ validatedBarcode: selectedItem.barcode });
}

if (isEditMode && !selectedItem && isNewPreselectedValue) {
this.setState({
shouldValidate: true,
validatedBarcode: request?.item?.barcode,
}, triggerValidation);
}
}

validate = memoizeValidation(async (barcode) => {
Expand Down Expand Up @@ -186,6 +198,7 @@ class ItemInformation extends Component {
selectedLoan,
enterButtonClass,
stripes,
isEditMode,
} = this.props;
const {
isItemClicked,
Expand Down Expand Up @@ -213,7 +226,7 @@ class ItemInformation extends Component {
>
{({ input, meta }) => {
const selectItemError = meta.touched && meta.error;
const itemDoesntExistError = (isItemClicked || isItemBlurred) && meta.error;
const itemDoesntExistError = (isItemClicked || isItemBlurred || (isEditMode && !selectedItem)) && meta.error;
const error = selectItemError || itemDoesntExistError || null;

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class RequestForm extends React.Component {
form.change(MEDIATED_REQUEST_FORM_FIELD_NAMES.ITEM_BARCODE, request.item.barcode);
}

form.change(MEDIATED_REQUEST_FORM_FIELD_NAMES.REQUESTER_BARCODE, request.requester.barcode);
form.change(MEDIATED_REQUEST_FORM_FIELD_NAMES.REQUESTER_BARCODE, request.requester?.barcode);
form.change(MEDIATED_REQUEST_FORM_FIELD_NAMES.PATRON_COMMENTS, request.patronComments);

Promise.allSettled([
Expand Down Expand Up @@ -648,20 +648,22 @@ class RequestForm extends React.Component {
const { requestPreferences } = await findResource(RESOURCE_TYPES.REQUEST_PREFERENCES, userId);
const preferences = requestPreferences[0];
const fulfillmentPreference = getFulfillmentPreference(preferences, initialValues);
const defaultDeliveryAddressTypeId = preferences?.defaultDeliveryAddressTypeId;
const defaultServicePointId = preferences?.defaultServicePointId;

this.setState({
defaultDeliveryAddressTypeId: preferences.defaultDeliveryAddressTypeId,
defaultServicePointId: preferences.defaultServicePointId,
defaultDeliveryAddressTypeId,
defaultServicePointId,
fulfillmentPreference,
});

return {
...defaultPreferences,
defaultDeliveryAddressTypeId: preferences.defaultDeliveryAddressTypeId,
defaultServicePointId: preferences.defaultServicePointId,
hasDelivery: Boolean(preferences.delivery),
hasDelivery: Boolean(preferences?.delivery),
isDeliverySelected: isDelivery(fulfillmentPreference),
selectedAddress: preferences.defaultDeliveryAddressTypeId,
selectedAddress: defaultDeliveryAddressTypeId,
defaultDeliveryAddressTypeId,
defaultServicePointId,
fulfillmentPreference,
};
} catch (e) {
Expand Down Expand Up @@ -952,6 +954,8 @@ class RequestForm extends React.Component {
onSetSelectedInstance={onSetSelectedInstance}
isLoading={isItemOrInstanceLoading}
enterButtonClass={css.enterButton}
isEditMode={isEditMode}
request={request}
/>
</Accordion>
)
Expand All @@ -975,6 +979,7 @@ class RequestForm extends React.Component {
selectedLoan={selectedLoan}
isLoading={isItemOrInstanceLoading}
enterButtonClass={css.enterButton}
isEditMode={isEditMode}
/>
</Accordion>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,22 @@ class RequesterInformation extends Component {
const {
isUserPreselected,
selectedUser,
triggerUserBarcodeValidation,
isEditMode,
request,
} = this.props;
const isNewPreselectedValue = isUserPreselected && isUserPreselected !== prevProps.isUserPreselected;

if (selectedUser && isUserPreselected && isUserPreselected !== prevProps.isUserPreselected) {
if (selectedUser && isNewPreselectedValue) {
this.setState({ validatedBarcode: selectedUser.barcode });
}

if (isEditMode && !selectedUser && isNewPreselectedValue) {
this.setState({
validatedBarcode: request?.requester?.barcode,
shouldValidate: true,
}, triggerUserBarcodeValidation);
}
}

validate = memoizeValidation(async (barcode) => {
Expand Down Expand Up @@ -246,7 +257,7 @@ class RequesterInformation extends Component {
>
{({ input, meta }) => {
const selectUserError = meta.touched && !selectedUser?.id && meta.error;
const userDoesntExistError = (isUserClicked || isUserBlurred) && meta.error;
const userDoesntExistError = (isUserClicked || isUserBlurred || (isEditMode && !selectedUser)) && meta.error;
const error = selectUserError || userDoesntExistError || null;

return (
Expand Down

0 comments on commit 66ec3e8

Please sign in to comment.