From 3212eea0e0961144657ec3b90bec80de4968e2a9 Mon Sep 17 00:00:00 2001 From: Yury Saukou Date: Mon, 9 Dec 2024 21:44:23 +0400 Subject: [PATCH 1/3] UIORGS-356 Properly display mapped ref values --- .../OrganizationSummaryVersionView.js | 2 +- .../useSelectedOrganizationVersion.js | 41 +++++++++++++------ 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/Organizations/OrganizationVersion/components/OrganizationSummaryVersionView/OrganizationSummaryVersionView.js b/src/Organizations/OrganizationVersion/components/OrganizationSummaryVersionView/OrganizationSummaryVersionView.js index d3cd65f8..f3ccc00c 100644 --- a/src/Organizations/OrganizationVersion/components/OrganizationSummaryVersionView/OrganizationSummaryVersionView.js +++ b/src/Organizations/OrganizationVersion/components/OrganizationSummaryVersionView/OrganizationSummaryVersionView.js @@ -84,7 +84,7 @@ export const OrganizationSummaryVersionView = ({ version }) => { } - value={version?.organizationTypes?.join(', ') || } + value={version?.organizationTypesResolved || } multiple /> diff --git a/src/Organizations/OrganizationVersion/hooks/useSelectedOrganizationVersion/useSelectedOrganizationVersion.js b/src/Organizations/OrganizationVersion/hooks/useSelectedOrganizationVersion/useSelectedOrganizationVersion.js index b8f285e8..65f0c12f 100644 --- a/src/Organizations/OrganizationVersion/hooks/useSelectedOrganizationVersion/useSelectedOrganizationVersion.js +++ b/src/Organizations/OrganizationVersion/hooks/useSelectedOrganizationVersion/useSelectedOrganizationVersion.js @@ -5,25 +5,25 @@ import get from 'lodash/fp/get'; import keyBy from 'lodash/fp/keyBy'; import uniq from 'lodash/fp/uniq'; import { useMemo } from 'react'; -import { useIntl } from 'react-intl'; import { useQuery } from 'react-query'; import { useNamespace, useOkapiKy, } from '@folio/stripes/core'; -import { getFullName } from '@folio/stripes/util'; import { fetchAcqUnitsByIds, getVersionMetadata, useOrganization, useUsersBatch, + useVersionHistoryValueResolvers, } from '@folio/stripes-acq-components'; import { currenciesByCode } from '@folio/stripes/components'; import { useContactsByIds, useInterfacesByIds, + useTypes, } from '../../../../common/hooks'; const getUniqItems = (arr) => ( @@ -34,11 +34,13 @@ const getUniqItems = (arr) => ( ); export const useSelectedOrganizationVersion = ({ versionId, versions, snapshotPath }, options = {}) => { - const intl = useIntl(); const ky = useOkapiKy(); const [namespace] = useNamespace({ key: 'organization-version-data' }); - const deletedRecordLabel = intl.formatMessage({ id: 'stripes-acq-components.versionHistory.deletedRecord' }); + const { + getObjectPropertyById, + getUserFullNameById, + } = useVersionHistoryValueResolvers(); const currentVersion = useMemo(() => ( versions?.find(({ id }) => id === versionId) @@ -72,6 +74,11 @@ export const useSelectedOrganizationVersion = ({ versionId, versions, snapshotPa isLoading: isInterfacesLoading, } = useInterfacesByIds(versionSnapshot?.interfaces); + const { + organizationTypes, + isLoading: isOrganizationTypesLoading, + } = useTypes(); + const { isLoading: isVersionDataLoading, data = {}, @@ -101,9 +108,9 @@ export const useSelectedOrganizationVersion = ({ versionId, versions, snapshotPa ...versionSnapshot, accounts: versionSnapshot?.accounts?.map((account) => ({ ...account, - acqUnits: account?.acqUnitIds?.map((acqUnitId) => acqUnitsMap[acqUnitId]?.name || deletedRecordLabel), + acqUnits: account?.acqUnitIds?.map((id) => getObjectPropertyById(id, 'name', acqUnitsMap)), })), - acqUnits: acqUnitsIds.map(acqUnitsId => acqUnitsMap[acqUnitsId]?.name || deletedRecordLabel).join(', '), + acqUnits: acqUnitsIds.map((id) => getObjectPropertyById(id, 'name', acqUnitsMap)).join(', '), vendorCurrenciesValue, metadata, }; @@ -113,19 +120,26 @@ export const useSelectedOrganizationVersion = ({ versionId, versions, snapshotPa }); const selectedVersion = useMemo(() => { - const versionUsersMap = keyBy('id', users); - - const createdByUser = versionUsersMap[createdByUserId] - ? getFullName(versionUsersMap[createdByUserId]) - : deletedRecordLabel; + const versionUsersDict = keyBy('id', users); + const organizationTypesDict = keyBy('id', organizationTypes); return { ...data, - createdByUser: createdByUserId && createdByUser, + organizationTypesResolved: data.organizationTypes?.map((id) => getObjectPropertyById(id, 'name', organizationTypesDict))?.join(', '), + createdByUser: getUserFullNameById(createdByUserId, versionUsersDict), contactsList: contacts, interfacesList: interfaces, }; - }, [users, createdByUserId, deletedRecordLabel, data, contacts, interfaces]); + }, [ + getObjectPropertyById, + getUserFullNameById, + users, + createdByUserId, + data, + contacts, + interfaces, + organizationTypes, + ]); const isLoading = ( isOrganizationLoading @@ -133,6 +147,7 @@ export const useSelectedOrganizationVersion = ({ versionId, versions, snapshotPa || isVersionDataLoading || isContactsLoading || isInterfacesLoading + || isOrganizationTypesLoading ); return { From 7351634cf0c9d09e5b8256e216a23776ac73ab56 Mon Sep 17 00:00:00 2001 From: Yury Saukou Date: Mon, 9 Dec 2024 21:55:26 +0400 Subject: [PATCH 2/3] update tests --- .../useSelectedOrganizationVersion.test.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Organizations/OrganizationVersion/hooks/useSelectedOrganizationVersion/useSelectedOrganizationVersion.test.js b/src/Organizations/OrganizationVersion/hooks/useSelectedOrganizationVersion/useSelectedOrganizationVersion.test.js index 73809bb2..cbcc6484 100644 --- a/src/Organizations/OrganizationVersion/hooks/useSelectedOrganizationVersion/useSelectedOrganizationVersion.test.js +++ b/src/Organizations/OrganizationVersion/hooks/useSelectedOrganizationVersion/useSelectedOrganizationVersion.test.js @@ -19,6 +19,7 @@ import { organizationAuditEvent } from 'fixtures'; import { useContactsByIds, useInterfacesByIds, + useTypes, } from '../../../../common/hooks'; import { useSelectedOrganizationVersion } from './useSelectedOrganizationVersion'; @@ -33,6 +34,7 @@ jest.mock('../../../../common/hooks', () => ({ ...jest.requireActual('../../../../common/hooks'), useContactsByIds: jest.fn(), useInterfacesByIds: jest.fn(), + useTypes: jest.fn(), })); const versionId = organizationAuditEvent.id; @@ -43,6 +45,10 @@ const contacts = [{ id: 'contact1' }]; const interfaces = [{ id: 'interface1' }]; const organization = { id: 'org1' }; const users = [{ id: 'user1', personal: { firstName: 'John', lastName: 'Doe' } }]; +const organizationTypes = [{ + id: 'e7e9af00-c12c-448f-8ad1-d15ff209605a', + name: 'Type name', +}]; const queryClient = new QueryClient(); const wrapper = ({ children }) => ( @@ -58,6 +64,7 @@ describe('useSelectedOrganizationVersion', () => { useUsersBatch.mockReturnValue({ users, isLoading: false }); useContactsByIds.mockReturnValue({ contacts, isLoading: false }); useInterfacesByIds.mockReturnValue({ interfaces, isLoading: false }); + useTypes.mockReturnValue({ organizationTypes, isLoading: false }); }); afterEach(() => { @@ -81,6 +88,7 @@ describe('useSelectedOrganizationVersion', () => { acqUnits: '', contactsList: contacts, interfacesList: interfaces, + organizationTypesResolved: 'Type name', vendorCurrenciesValue: 'US Dollar (USD)', metadata: getVersionMetadata(organizationAuditEvent, organization), }); From 6df826df6a99e7ca4ff45142e93d633fc01a08ce Mon Sep 17 00:00:00 2001 From: Yury Saukou Date: Mon, 9 Dec 2024 22:33:58 +0400 Subject: [PATCH 3/3] update --- .../useSelectedOrganizationVersion.test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Organizations/OrganizationVersion/hooks/useSelectedOrganizationVersion/useSelectedOrganizationVersion.test.js b/src/Organizations/OrganizationVersion/hooks/useSelectedOrganizationVersion/useSelectedOrganizationVersion.test.js index cbcc6484..5e65ff6f 100644 --- a/src/Organizations/OrganizationVersion/hooks/useSelectedOrganizationVersion/useSelectedOrganizationVersion.test.js +++ b/src/Organizations/OrganizationVersion/hooks/useSelectedOrganizationVersion/useSelectedOrganizationVersion.test.js @@ -86,6 +86,7 @@ describe('useSelectedOrganizationVersion', () => { acqUnits: [], })), acqUnits: '', + createdByUser: null, contactsList: contacts, interfacesList: interfaces, organizationTypesResolved: 'Type name',