Skip to content

Commit

Permalink
UISACQCOMP-232: Move reusable helper function to support version hist…
Browse files Browse the repository at this point in the history
…ory functionality
  • Loading branch information
alisher-epam committed Nov 21, 2024
1 parent e8132c3 commit 99aaaa4
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

* Add more reusable hooks and utilities. Refs UISACQCOMP-228.
* Move reusable version history components to the ACQ lib. Refs UISACQCOMP-230.
* Move reusable helper function to support version history functionality. Refs UISACQCOMP-232.

## [6.0.1](https://github.com/folio-org/stripes-acq-components/tree/v6.0.1) (2024-11-14)
[Full Changelog](https://github.com/folio-org/stripes-acq-components/compare/v6.0.0...v6.0.1)
Expand Down
7 changes: 7 additions & 0 deletions lib/VersionHistory/getVersionMetadata.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import get from 'lodash/get';

export const getVersionMetadata = (version, entity) => ({
...get(entity, 'metadata', {}),
updatedByUserId: version?.userId,
updatedDate: version?.actionDate,
});
38 changes: 38 additions & 0 deletions lib/VersionHistory/getVersionMetadata.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { getVersionMetadata } from './getVersionMetadata';

const version = {
userId: 'userId',
actionDate: '2024-11-21T05:14:30.510+00:00',
eventDate: '2024-11-21T05:14:30.510+00:00',
};

describe('getVersionMetadata', () => {
it('should return metadata from entity and updatedByUserId and updatedDate from version', () => {
const entity = {
metadata: {
metadataKey: 'metadataValue',
createdDate: '2024-11-21T01:55:55.066+00:00',
},
};

expect(getVersionMetadata(version, entity)).toEqual({
metadataKey: 'metadataValue',
updatedByUserId: 'userId',
updatedDate: 'actionDate',
});
});

it('should return empty object if entity is not provided', () => {
expect(getVersionMetadata(version)).toEqual({});
});

it('should return empty object if version is not provided', () => {
const entity = {
metadata: {
metadataKey: 'metadataValue',
},
};

expect(getVersionMetadata(null, entity)).toEqual({});
});
});
1 change: 1 addition & 0 deletions lib/VersionHistory/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from './components';
export { getFieldLabels } from './getFieldLabels';
export { getHighlightedFields } from './getHighlightedFields';
export { getVersionMetadata } from './getVersionMetadata';
export * from './hooks';
export { VersionCard } from './VersionCard';
export { VersionHistoryPane } from './VersionHistoryPane';
Expand Down
2 changes: 1 addition & 1 deletion lib/hooks/useAddresses/useAddresses.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const useAddresses = (options = {}) => {
...queryOptions
} = options;

const [namespace] = useNamespace({ key: 'acquisitions-units' });
const [namespace] = useNamespace({ key: 'tenant-addresses' });
const ky = useOkapiKy({ tenant: tenantId });

const searchParams = {
Expand Down
11 changes: 11 additions & 0 deletions lib/utils/getAcqUnitsByIds.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { ACQUISITIONS_UNITS_API } from '../constants';
import { fetchExportDataByIds } from './fetchExportDataByIds';

export const getAcqUnitsByIds = (ky) => async (acquisitionUnitIds) => {
return fetchExportDataByIds({
api: ACQUISITIONS_UNITS_API,
ids: acquisitionUnitIds,
ky,
records: 'acquisitionsUnits',
});
};
1 change: 1 addition & 0 deletions lib/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export * from './filterSelectValues';
export * from './formatDate';
export * from './formatDateTime';
export * from './generateQueryTemplate';
export * from './getAcqUnitsByIds';
export * from './getAcqUnitsOptions';
export * from './getAddresses';
export * from './getAddressOptions';
Expand Down

0 comments on commit 99aaaa4

Please sign in to comment.