From 6c19c93015de3879cb662ecbe3bbbcf8823f3896 Mon Sep 17 00:00:00 2001 From: Alisher Musurmonov Date: Wed, 17 Apr 2024 17:03:41 +0500 Subject: [PATCH] UIOR-1256: Add additional order filters to support reporting requirements (#1588) --- CHANGELOG.md | 2 + package.json | 4 +- src/OrdersList/OrdersListFilters.js | 48 ++++++++++++------- src/OrdersList/constants.js | 2 + .../hooks/useBuildQuery/useBuildQuery.js | 1 + src/common/ExportSettingsModal/constants.js | 8 ++++ .../utils/createExportReport.js | 10 ++++ .../utils/getExportData.js | 16 +++++-- test/jest/fixtures/exportReport.js | 9 ++++ translations/ui-orders/en.json | 4 ++ 10 files changed, 83 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 69338d294..f04a3ea4f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Change history for ui-orders +* Add additional order filters to support reporting requirements. Refs UIOR- + ## [6.0.2](https://github.com/folio-org/ui-orders/tree/v6.0.2) (2024-04-01) [Full Changelog](https://github.com/folio-org/ui-orders/compare/v6.0.1...v6.0.2) diff --git a/package.json b/package.json index 3e05aa1d8..ceb4bfe0e 100644 --- a/package.json +++ b/package.json @@ -125,7 +125,9 @@ "search.facets.collection.get", "tags.collection.get", "tags.item.post", - "users.collection.get" + "usergroups.collection.get", + "users.collection.get", + "users.item.get" ] }, { diff --git a/src/OrdersList/OrdersListFilters.js b/src/OrdersList/OrdersListFilters.js index e9ad64d55..db9d3eadb 100644 --- a/src/OrdersList/OrdersListFilters.js +++ b/src/OrdersList/OrdersListFilters.js @@ -97,22 +97,6 @@ function OrdersListFilters({ onChange={onChange} disabled={disabled} /> - - + + + + ); } diff --git a/src/OrdersList/constants.js b/src/OrdersList/constants.js index f4c04d006..62946842b 100644 --- a/src/OrdersList/constants.js +++ b/src/OrdersList/constants.js @@ -36,6 +36,8 @@ export const FILTERS = { SUFFIX: 'poNumberSuffix', VENDOR: 'vendor', TAGS: 'tags.tagList', + DATE_UPDATED: 'metadata.updatedDate', + UPDATED_BY: 'metadata.updatedByUserId', }; export const STATUS_FILTER_OPTIONS = Object.keys(WORKFLOW_STATUS).map(status => ({ diff --git a/src/OrdersList/hooks/useBuildQuery/useBuildQuery.js b/src/OrdersList/hooks/useBuildQuery/useBuildQuery.js index a3770c90a..b2b78ca79 100644 --- a/src/OrdersList/hooks/useBuildQuery/useBuildQuery.js +++ b/src/OrdersList/hooks/useBuildQuery/useBuildQuery.js @@ -45,6 +45,7 @@ export function useBuildQuery(customFields) { 'sortby metadata.updatedDate/sort.descending', { [FILTERS.DATE_CREATED]: buildDateTimeRangeQuery.bind(null, [FILTERS.DATE_CREATED]), + [FILTERS.DATE_UPDATED]: buildDateTimeRangeQuery.bind(null, [FILTERS.DATE_UPDATED]), [FILTERS.RENEWAL_DATE]: buildDateRangeQuery.bind(null, [FILTERS.RENEWAL_DATE]), [FILTERS.DATE_ORDERED]: buildDateTimeRangeQuery.bind(null, [FILTERS.DATE_ORDERED]), [FILTERS.CLOSE_REASON]: (filterValue) => { diff --git a/src/common/ExportSettingsModal/constants.js b/src/common/ExportSettingsModal/constants.js index c0a9e4814..95d8286a3 100644 --- a/src/common/ExportSettingsModal/constants.js +++ b/src/common/ExportSettingsModal/constants.js @@ -25,6 +25,10 @@ export const EXPORT_ORDER_FIELDS = { renewalDate: 'Renewal date', reviewDate: 'Review date', poTags: 'PO tags', + createdBy: 'Created by', + dateCreated: 'Date created', + updatedBy: 'Updated by', + dateUpdated: 'Date updated', }; export const EXPORT_LINE_FIELDS = { @@ -86,6 +90,10 @@ export const EXPORT_LINE_FIELDS = { poLineTags: 'POLine tags', renewalNote: 'Renewal note', exchangeRate: 'Exchange rate', + poLineCreatedBy: 'Created by (POL)', + poLineDateCreated: 'Date created (POL)', + poLineUpdatedBy: 'Updated by (POL)', + poLineDateUpdated: 'Date updated (POL)', }; export const EXPORT_ORDER_FIELDS_OPTIONS = Object.keys(EXPORT_ORDER_FIELDS).map(field => ({ diff --git a/src/common/ExportSettingsModal/utils/createExportReport.js b/src/common/ExportSettingsModal/utils/createExportReport.js index bf503c068..652ad9dbd 100644 --- a/src/common/ExportSettingsModal/utils/createExportReport.js +++ b/src/common/ExportSettingsModal/utils/createExportReport.js @@ -118,6 +118,10 @@ const getOrderExportData = ({ renewalDate: formatDate(order.ongoing?.renewalDate, intl), reviewDate: formatDate(order.ongoing?.reviewDate, intl), poTags: order.tags?.tagList?.join('|'), + createdBy: userMap[order.metadata?.createdByUserId]?.username ?? invalidReference, + dateCreated: formatDate(order.metadata?.createdDate, intl), + updatedBy: userMap[order.metadata?.updatedByUserId]?.username ?? invalidReference, + dateUpdated: formatDate(order.metadata?.updatedDate, intl), }; }; @@ -132,6 +136,7 @@ const getOrderLineExportData = ({ locationMap, materialTypeMap, poLinesMap, + userMap, vendorMap, }) => { const invalidReference = intl.formatMessage({ id: 'ui-orders.export.invalidReference' }); @@ -200,6 +205,10 @@ const getOrderLineExportData = ({ resourceUrl: lineRecord.eresource?.resourceUrl, poLineTags: lineRecord.tags?.tagList?.join('|'), exchangeRate: lineRecord.cost?.exchangeRate, + poLineCreatedBy: userMap[lineRecord.metadata?.createdByUserId]?.username ?? invalidReference, + poLineDateCreated: formatDate(lineRecord.metadata?.createdDate, intl), + poLineUpdatedBy: userMap[lineRecord.metadata?.updatedByUserId]?.username ?? invalidReference, + poLineDateUpdated: formatDate(lineRecord.metadata?.updatedDate, intl), }; }; @@ -244,6 +253,7 @@ const getExportRow = ({ materialTypeMap, poLinesMap, vendorMap, + userMap, }) : {}; diff --git a/src/common/ExportSettingsModal/utils/getExportData.js b/src/common/ExportSettingsModal/utils/getExportData.js index 39dea2e7c..0e9b9768c 100644 --- a/src/common/ExportSettingsModal/utils/getExportData.js +++ b/src/common/ExportSettingsModal/utils/getExportData.js @@ -11,6 +11,17 @@ import { fetchExportDataByIds } from '../../utils'; import { getAddresses } from '../../utils/getAddresses'; import { createExportReport } from './createExportReport'; +const getExportUseIds = (lines = [], orders = []) => { + const lineUserIds = lines.map(({ metadata }) => { + return [metadata?.createdByUserId, metadata?.updatedByUserId]; + }); + const orderUserIds = orders.map(({ metadata, assignedTo, approvedBy }) => ([ + metadata?.createdByUserId, metadata?.updatedByUserId, assignedTo, approvedBy, + ])); + + return uniq(flatten([...lineUserIds, ...orderUserIds])).filter(Boolean); +}; + export const getExportData = async (mutator, lines, orders, intl) => { const orderVendorIds = uniq(orders.map(({ vendor }) => vendor)); const lineVendorIds = uniq(flatten((lines.map(({ physical, eresource }) => ([ @@ -22,10 +33,7 @@ export const getExportData = async (mutator, lines, orders, intl) => { ({ organizationTypes }) => organizationTypes, ))).filter(Boolean); const orgTypes = await fetchExportDataByIds(mutator.organizationTypes, organizationTypeIds); - const userIds = uniq(flatten((orders.map(({ metadata, assignedTo, approvedBy }) => ([ - metadata?.createdByUserId, metadata?.updatedByUserId, assignedTo, approvedBy, - ]))))).filter(Boolean); - const users = await fetchExportDataByIds(mutator.exportUsers, userIds); + const users = await fetchExportDataByIds(mutator.exportUsers, getExportUseIds(lines, orders)); const acqUnitsIds = uniq(flatten((orders.map(({ acqUnitIds }) => acqUnitIds)))); const acqUnits = await fetchExportDataByIds(mutator.exportAcqUnits, acqUnitsIds); const mTypeIds = uniq(flatten(lines.map(({ physical, eresource }) => ([ diff --git a/test/jest/fixtures/exportReport.js b/test/jest/fixtures/exportReport.js index fb401b333..28d6cf9d5 100644 --- a/test/jest/fixtures/exportReport.js +++ b/test/jest/fixtures/exportReport.js @@ -332,5 +332,14 @@ export const exportReport = [ 'volumes': 'vol. 1', 'workflowStatus': 'Pending', 'exchangeRate': 22, + 'poLineCreatedBy': 'ui-orders.export.invalidReference', + 'poLineDateCreated': '2021-08-15', + 'poLineDateUpdated': '2021-08-15', + 'poLineUpdatedBy': 'ui-orders.export.invalidReference', + 'createdBy': 'ui-orders.export.invalidReference', + 'dateCreated': '2021-08-15', + 'dateUpdated': '2021-08-15', + 'renewalNote': undefined, + 'updatedBy': 'ui-orders.export.invalidReference', }, ]; diff --git a/translations/ui-orders/en.json b/translations/ui-orders/en.json index b57c33355..81f364b7d 100644 --- a/translations/ui-orders/en.json +++ b/translations/ui-orders/en.json @@ -285,6 +285,10 @@ "filter.rush": "Rush", "filter.trial": "Trial", "filter.true": "Yes", + "filter.createdBy": "Created by", + "filter.updatedBy": "Updated by", + "filter.dateUpdated": "Date updated", + "fund.fundIdentifier": "Fund ID", "fund.selectAdjustment": "Select adjustment", "fund.value": "Value",