Skip to content

Commit

Permalink
UIOR-1355: Do not displayed “record deleted” when address field is no…
Browse files Browse the repository at this point in the history
…t specified in "version history" for order (#1680)

* Add new useSelectedPOVersionMethods hook

* Do not displayed “Record-deleted” when address field is not specified in "Version-history" for Order

* Fix previous test expectation

* Add change log

* Fix minor mistakes

* Change getObjectPropertyById method argumets order

* Rename useSelectedPOVersionMethods to useVersionHistoryFormatters

* Add comments that AI assisted with code

* Update CHANGELOG.md

Co-authored-by: Yury Saukou <[email protected]>

* Fix import ordered and change text() to it()

* Rename useVersionHistoryFormatters to useVersionHistoryValueResolvers, Apply import guideline, FIx camelCase

* Move change log to 7.1.0 release

* Extract useVersionHistoryValueResolvers hook to stripes-acq-components

---------

Co-authored-by: Yury Saukou <[email protected]>
  • Loading branch information
azizjonnurov and usavkov-epam authored Dec 6, 2024
1 parent ed3d9e5 commit a2475dc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## 7.1.0 (IN PROGRESS)

* Display the “Record deleted” label in version history only if the UUID no longer exists. Refs UIOR-1355.

## [7.0.3](https://github.com/folio-org/ui-orders/tree/v7.0.3) (2024-12-06)
[Full Changelog](https://github.com/folio-org/ui-orders/compare/v7.0.2...v7.0.3)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useMemo } from 'react';
import { useQuery } from 'react-query';
import { useIntl } from 'react-intl';
import {
filter,
flow,
Expand All @@ -13,10 +12,10 @@ import {
useNamespace,
useOkapiKy,
} from '@folio/stripes/core';
import { getFullName } from '@folio/stripes/util';
import {
getAddresses,
useUsersBatch,
useVersionHistoryValueResolvers,
} from '@folio/stripes-acq-components';

import { useOrder } from '../../../../common/hooks';
Expand All @@ -35,11 +34,8 @@ const getUniqItems = (arr) => (
);

export const useSelectedPOVersion = ({ versionId, versions, snapshotPath }, options = {}) => {
const intl = useIntl();
const ky = useOkapiKy();
const [namespace] = useNamespace({ key: 'order-version-data' });

const deletedRecordLabel = intl.formatMessage({ id: 'stripes-acq-components.versionHistory.deletedRecord' });
const currentVersion = useMemo(() => (
versions?.find(({ id }) => id === versionId)
), [versionId, versions]);
Expand All @@ -52,6 +48,11 @@ export const useSelectedPOVersion = ({ versionId, versions, snapshotPath }, opti
isLoading: isOrderLoading,
} = useOrder(currentVersion?.orderId);

const {
getObjectPropertyById,
getUserFullNameById,
} = useVersionHistoryValueResolvers();

const metadata = useMemo(() => getVersionMetadata(currentVersion, order), [currentVersion, order]);
const assignedToId = versionSnapshot?.assignedTo;
const createdByUserId = metadata?.createdByUserId;
Expand Down Expand Up @@ -87,22 +88,14 @@ export const useSelectedPOVersion = ({ versionId, versions, snapshotPath }, opti
.then(keyBy('id')),
]);

const assignedTo = versionUsersMap[assignedToId]
? getFullName(versionUsersMap[assignedToId])
: deletedRecordLabel;

const createdByUser = versionUsersMap[createdByUserId]
? getFullName(versionUsersMap[createdByUserId])
: deletedRecordLabel;

return {
...versionSnapshot,
acqUnits: acqUnitsIds.map(acqUnitsId => acqUnitsMap[acqUnitsId]?.name || deletedRecordLabel).join(', '),
assignedTo: assignedToId && assignedTo,
vendor: organizationsMap[vendorId]?.name || deletedRecordLabel,
createdByUser: createdByUserId && createdByUser,
billTo: billToId && (addressesMap[billToId]?.address || deletedRecordLabel),
shipTo: shipToId && (addressesMap[shipToId]?.address || deletedRecordLabel),
acqUnits: acqUnitsIds.map((id) => getObjectPropertyById(id, 'name', acqUnitsMap)).join(', '),
assignedTo: getUserFullNameById(assignedToId, versionUsersMap),
createdByUser: getUserFullNameById(createdByUserId, versionUsersMap),
vendor: getObjectPropertyById(vendorId, 'name', organizationsMap),
billTo: getObjectPropertyById(billToId, 'address', addressesMap),
shipTo: getObjectPropertyById(shipToId, 'address', addressesMap),
metadata,
};
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe('useSelectedPOVersion', () => {

expect(id).toEqual(order.id);
expect(vendorField).toEqual(vendor.name);
expect(billTo).toEqual('stripes-acq-components.versionHistory.deletedRecord');
expect(billTo).toBeNull();
expect(shipTo).toEqual('stripes-acq-components.versionHistory.deletedRecord');
expect(createdByUser).toEqual(getFullName(user));
});
Expand Down

0 comments on commit a2475dc

Please sign in to comment.