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

UISACQCOMP-232: Move reusable helper function to support version history functionality #833

Merged
merged 4 commits into from
Nov 21, 2024
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
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,
});
29 changes: 29 additions & 0 deletions lib/VersionHistory/getVersionMetadata.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
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: version.actionDate,
...entity.metadata,
});
});

it('should return empty object if version is not provided', () => {
expect(getVersionMetadata(null, {})).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
10 changes: 10 additions & 0 deletions lib/utils/api/api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
SEARCH_PARAMETER,
} from '../../AcqList/constants';
import {
ACQUISITIONS_UNITS_API,
LIMIT_MAX,
LINES_API,
ORDER_PIECES_API,
Expand All @@ -11,6 +12,7 @@ import {
VENDORS_API,
} from '../../constants';

import { fetchAcqUnitsByIds } from './fetchAcqUnitsByIds';
import { fetchOrderLines } from './fetchOrderLines';
import { fetchOrderLinesByIds } from './fetchOrderLinesByIds';
import { fetchOrders } from './fetchOrders';
Expand Down Expand Up @@ -110,4 +112,12 @@ describe('API utils', () => {
expect(httpClient.get).toHaveBeenCalledWith(RECEIVING_TITLES_API, { searchParams });
});
});

describe('fetchAcqUnitsByIds', () => {
it('should fetch acquisitions units by ids', async () => {
await fetchAcqUnitsByIds(httpClient)(ids);

expect(httpClient.get).toHaveBeenCalledWith(ACQUISITIONS_UNITS_API, { searchParams });
});
});
});
11 changes: 11 additions & 0 deletions lib/utils/api/fetchAcqUnitsByIds.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 fetchAcqUnitsByIds = (ky) => async (acquisitionUnitIds) => {
return fetchExportDataByIds({
api: ACQUISITIONS_UNITS_API,
ids: acquisitionUnitIds,
ky,
records: 'acquisitionsUnits',
});
};
1 change: 1 addition & 0 deletions lib/utils/api/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { fetchAcqUnitsByIds } from './fetchAcqUnitsByIds';
export { fetchOrderLines } from './fetchOrderLines';
export { fetchOrderLinesByIds } from './fetchOrderLinesByIds';
export { fetchOrders } from './fetchOrders';
Expand Down
Loading