Skip to content

Commit

Permalink
UIOR-1256: Add additional order filters to support reporting requirem…
Browse files Browse the repository at this point in the history
…ents (#1588)
  • Loading branch information
alisher-epam authored and NikitaSedyx committed Apr 18, 2024
1 parent 1b21f49 commit 6c19c93
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 21 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
},
{
Expand Down
48 changes: 32 additions & 16 deletions src/OrdersList/OrdersListFilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,22 +97,6 @@ function OrdersListFilters({
onChange={onChange}
disabled={disabled}
/>
<PluggableUserFilter
id={FILTERS.CREATED_BY}
activeFilters={activeFilters[FILTERS.CREATED_BY]}
labelId="ui-orders.orderDetails.createdBy"
name={FILTERS.CREATED_BY}
onChange={onChange}
disabled={disabled}
/>
<AcqDateRangeFilter
id={FILTERS.DATE_CREATED}
activeFilters={activeFilters[FILTERS.DATE_CREATED]}
labelId="ui-orders.filter.dateCreated"
name={FILTERS.DATE_CREATED}
onChange={onChange}
disabled={disabled}
/>
<AcqDateRangeFilter
id={FILTERS.DATE_ORDERED}
activeFilters={activeFilters[FILTERS.DATE_ORDERED]}
Expand Down Expand Up @@ -221,6 +205,38 @@ function OrdersListFilters({
name={FILTERS.CUSTOM_FIELDS}
onChange={onChange}
/>
<PluggableUserFilter
id={FILTERS.CREATED_BY}
activeFilters={activeFilters[FILTERS.CREATED_BY]}
labelId="ui-orders.orderDetails.createdBy"
name={FILTERS.CREATED_BY}
onChange={onChange}
disabled={disabled}
/>
<AcqDateRangeFilter
id={FILTERS.DATE_CREATED}
activeFilters={activeFilters[FILTERS.DATE_CREATED]}
labelId="ui-orders.filter.dateCreated"
name={FILTERS.DATE_CREATED}
onChange={onChange}
disabled={disabled}
/>
<PluggableUserFilter
id={FILTERS.UPDATED_BY}
activeFilters={activeFilters[FILTERS.UPDATED_BY]}
labelId="ui-orders.filter.updatedBy"
name={FILTERS.UPDATED_BY}
onChange={onChange}
disabled={disabled}
/>
<AcqDateRangeFilter
id={FILTERS.DATE_UPDATED}
activeFilters={activeFilters[FILTERS.DATE_UPDATED]}
labelId="ui-orders.filter.dateUpdated"
name={FILTERS.DATE_UPDATED}
onChange={onChange}
disabled={disabled}
/>
</AccordionSet>
);
}
Expand Down
2 changes: 2 additions & 0 deletions src/OrdersList/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => ({
Expand Down
1 change: 1 addition & 0 deletions src/OrdersList/hooks/useBuildQuery/useBuildQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
8 changes: 8 additions & 0 deletions src/common/ExportSettingsModal/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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 => ({
Expand Down
10 changes: 10 additions & 0 deletions src/common/ExportSettingsModal/utils/createExportReport.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};
};

Expand All @@ -132,6 +136,7 @@ const getOrderLineExportData = ({
locationMap,
materialTypeMap,
poLinesMap,
userMap,
vendorMap,
}) => {
const invalidReference = intl.formatMessage({ id: 'ui-orders.export.invalidReference' });
Expand Down Expand Up @@ -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),
};
};

Expand Down Expand Up @@ -244,6 +253,7 @@ const getExportRow = ({
materialTypeMap,
poLinesMap,
vendorMap,
userMap,
})
: {};

Expand Down
16 changes: 12 additions & 4 deletions src/common/ExportSettingsModal/utils/getExportData.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => ([
Expand All @@ -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 }) => ([
Expand Down
9 changes: 9 additions & 0 deletions test/jest/fixtures/exportReport.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
];
4 changes: 4 additions & 0 deletions translations/ui-orders/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 6c19c93

Please sign in to comment.