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

UIOR-1355: Do not displayed “record deleted” when address field is not specified in "version history" for order #1680

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this correct that I am expecting null after current changes?

expect(billTo).toBeNull();
expect(shipTo).toEqual('stripes-acq-components.versionHistory.deletedRecord');
expect(createdByUser).toEqual(getFullName(user));
});
Expand Down
Loading