From f0ad07c715452d485d488e6c525fe2b5f3bf7434 Mon Sep 17 00:00:00 2001 From: vashjs Date: Wed, 31 Jan 2024 13:50:17 +0100 Subject: [PATCH 1/3] UIBULKED-367 Logs - Provide a link to file with identifiers of the records affected by query --- CHANGELOG.md | 1 + .../BulkEditListFilters.js | 23 ++++++++------- .../BulkEditListResult/Preview/Preview.js | 6 ++-- .../BulkEditLogsActions.js | 9 ++++-- src/utils/getFileName.js | 15 ++++++++++ src/utils/getFileName.test.js | 29 +++++++++++++++++++ translations/ui-bulk-edit/en.json | 1 + 7 files changed, 69 insertions(+), 15 deletions(-) create mode 100644 src/utils/getFileName.js create mode 100644 src/utils/getFileName.test.js diff --git a/CHANGELOG.md b/CHANGELOG.md index f15e6d82..fcf618c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,7 @@ * [UIBULKED-407](https://issues.folio.org/browse/UIBULKED-407) When selecting action "Find" in Bulk Edit, the last dropdown on the row moves to the right. * [UIBULKED-403](https://issues.folio.org/browse/UIBULKED-403) Integrate query-plugin with bulk-edit API. * [UIBULKED-246](https://issues.folio.org/browse/UIBULKED-246) Enabling Build query button on Query tab. +* [UIBULKED-367](https://issues.folio.org/browse/UIBULKED-367) Logs - Provide a link to file with identifiers of the records affected by query. ## [4.0.0](https://github.com/folio-org/ui-bulk-edit/tree/v4.0.0) (2023-10-12) diff --git a/src/components/BulkEditList/BulkEditListFilters/BulkEditListFilters.js b/src/components/BulkEditList/BulkEditListFilters/BulkEditListFilters.js index 7610adfc..dc4fe399 100644 --- a/src/components/BulkEditList/BulkEditListFilters/BulkEditListFilters.js +++ b/src/components/BulkEditList/BulkEditListFilters/BulkEditListFilters.js @@ -151,7 +151,7 @@ export const BulkEditListFilters = ({ }; const handleCriteriaChange = (value) => { - const newFilterValue = { capabilities: null, recordTypes: null, criteria: value }; + const newFilterValue = { capabilities: '', recordTypes: '', criteria: value }; setFilters(prev => ({ ...prev, ...newFilterValue })); @@ -265,15 +265,18 @@ export const BulkEditListFilters = ({ ); const renderListSelect = () => ( - + <> + {JSON.stringify(capabilities)} + + ); const renderListFileUploader = () => ( diff --git a/src/components/BulkEditList/BulkEditListResult/Preview/Preview.js b/src/components/BulkEditList/BulkEditListResult/Preview/Preview.js index e86f0edd..9b4ec17c 100644 --- a/src/components/BulkEditList/BulkEditListResult/Preview/Preview.js +++ b/src/components/BulkEditList/BulkEditListResult/Preview/Preview.js @@ -15,7 +15,7 @@ import { useRecordsPreview } from '../../../../hooks/api'; -import { PAGINATION_CONFIG } from '../../../../constants'; +import { EDITING_STEPS, PAGINATION_CONFIG } from '../../../../constants'; import { usePagination } from '../../../../hooks/usePagination'; import { useBulkOperationStats } from '../../../../hooks/useBulkOperationStats'; @@ -25,6 +25,8 @@ export const Preview = ({ id, title, isInitial, bulkDetails }) => { const step = search.get('step'); const capabilities = search.get('capabilities'); + const totalRecords = step === EDITING_STEPS.COMMIT ? bulkDetails?.processedNumOfRecords : bulkDetails?.matchedNumOfRecords; + const { countOfRecords, countOfErrors, @@ -70,7 +72,7 @@ export const Preview = ({ id, title, isInitial, bulkDetails }) => {
{Boolean(contentData?.length) && ( { + const fileNamePostfix = item.approach === APPROACHES.QUERY ? `.${item.approach}` : ''; + const { hasUsersViewPerms, hasInventoryInstanceViewPerms, @@ -34,7 +37,7 @@ const BulkEditLogsActions = ({ item }) => { fileContentType: linkNamesMap[triggeredFile], }, onSuccess: data => { - saveAs(new Blob([data]), item[triggeredFile].split('/')[1]); + saveAs(new Blob([data]), getFileName(item, triggeredFile)); setTriggeredFile(null); }, }); @@ -76,7 +79,7 @@ const BulkEditLogsActions = ({ item }) => { onClick={() => onLoadFile(file)} > - + ))} diff --git a/src/utils/getFileName.js b/src/utils/getFileName.js new file mode 100644 index 00000000..3459863f --- /dev/null +++ b/src/utils/getFileName.js @@ -0,0 +1,15 @@ +import { APPROACHES, getFormattedFilePrefixDate } from '../constants'; + +export const getFileName = (item, triggeredFile) => { + if (item.approach === APPROACHES.QUERY) { + return { + linkToTriggeringCsvFile: `Query-${item.id}.csv`, + linkToMatchedRecordsCsvFile: `${getFormattedFilePrefixDate()}-Matched-Records-Query-${item.id}.csv`, + linkToModifiedRecordsCsvFile: `${getFormattedFilePrefixDate()}-Updates-Preview-Query-${item.id}.csv`, + linkToCommittedRecordsCsvFile: `${getFormattedFilePrefixDate()}-Changed-Records-Query-${item.id}.csv`, + linkToCommittedRecordsErrorsCsvFile: `${getFormattedFilePrefixDate()}-Committing-changes-Errors-Query-${item.id}.csv` + }[triggeredFile]; + } + + return item[triggeredFile].split('/')[1]; +}; diff --git a/src/utils/getFileName.test.js b/src/utils/getFileName.test.js new file mode 100644 index 00000000..326a7b6f --- /dev/null +++ b/src/utils/getFileName.test.js @@ -0,0 +1,29 @@ +import { getFileName } from './getFileName'; +import { APPROACHES } from '../constants'; + +jest.mock('./date', () => ({ + getFormattedFilePrefixDate: jest.fn(() => 'mockedDate'), +})); + +describe('getFileName', () => { + it('should return the correct file name for Query approach - linkToTriggeringCsvFile', () => { + const item = { approach: APPROACHES.QUERY, id: 123 }; + const triggeredFile = 'linkToTriggeringCsvFile'; + const result = getFileName(item, triggeredFile); + expect(result).toBe('Query-123.csv'); + }); + + it('should return the correct file name for Query approach - linkToMatchedRecordsCsvFile', () => { + const item = { approach: APPROACHES.QUERY, id: 123 }; + const triggeredFile = 'linkToMatchedRecordsCsvFile'; + const result = getFileName(item, triggeredFile); + expect(result).toBe('mockedDate-Matched-Records-Query-123.csv'); + }); + + it('should return the correct file name for non-Query approach', () => { + const item = { approach: APPROACHES.IN_APP, linkToTriggeringCsvFile: 'somePath/someFile.csv' }; + const triggeredFile = 'linkToTriggeringCsvFile'; + const result = getFileName(item, triggeredFile); + expect(result).toBe('someFile.csv'); + }); +}); diff --git a/translations/ui-bulk-edit/en.json b/translations/ui-bulk-edit/en.json index 31b127ed..f9512bc8 100644 --- a/translations/ui-bulk-edit/en.json +++ b/translations/ui-bulk-edit/en.json @@ -392,6 +392,7 @@ "logs.actions.linkToModifiedRecordsCsvFile": "File with the preview of proposed changes", "logs.actions.linkToCommittedRecordsCsvFile": "File with updated records", "logs.actions.linkToCommittedRecordsErrorsCsvFile": "File with errors encountered when committing the changes", + "logs.actions.linkToTriggeringCsvFile.QUERY": "File with identifiers of the records affected by bulk update", "logs.filter.title.status": "Statuses", "logs.filter.title.capability": "Record types", "logs.filter.title.types": "Bulk operation type", From 908cc83581e5515e47719b9dfc23b66f3df0ddec Mon Sep 17 00:00:00 2001 From: vashjs Date: Wed, 31 Jan 2024 14:06:47 +0100 Subject: [PATCH 2/3] remove JSON.stringify --- .../BulkEditListFilters.js | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/components/BulkEditList/BulkEditListFilters/BulkEditListFilters.js b/src/components/BulkEditList/BulkEditListFilters/BulkEditListFilters.js index dc4fe399..2277c66c 100644 --- a/src/components/BulkEditList/BulkEditListFilters/BulkEditListFilters.js +++ b/src/components/BulkEditList/BulkEditListFilters/BulkEditListFilters.js @@ -265,18 +265,15 @@ export const BulkEditListFilters = ({ ); const renderListSelect = () => ( - <> - {JSON.stringify(capabilities)} - - + ); const renderListFileUploader = () => ( From 437d305304f988b68e8dbe008ead9fc0a3169d0e Mon Sep 17 00:00:00 2001 From: vashjs Date: Thu, 1 Feb 2024 09:42:40 +0100 Subject: [PATCH 3/3] replace approach with fqlQueryId --- src/utils/getFileName.js | 4 ++-- src/utils/getFileName.test.js | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/utils/getFileName.js b/src/utils/getFileName.js index 3459863f..8b98c490 100644 --- a/src/utils/getFileName.js +++ b/src/utils/getFileName.js @@ -1,7 +1,7 @@ -import { APPROACHES, getFormattedFilePrefixDate } from '../constants'; +import { getFormattedFilePrefixDate } from '../constants'; export const getFileName = (item, triggeredFile) => { - if (item.approach === APPROACHES.QUERY) { + if (item.fqlQueryId) { return { linkToTriggeringCsvFile: `Query-${item.id}.csv`, linkToMatchedRecordsCsvFile: `${getFormattedFilePrefixDate()}-Matched-Records-Query-${item.id}.csv`, diff --git a/src/utils/getFileName.test.js b/src/utils/getFileName.test.js index 326a7b6f..277a3fdf 100644 --- a/src/utils/getFileName.test.js +++ b/src/utils/getFileName.test.js @@ -1,5 +1,4 @@ import { getFileName } from './getFileName'; -import { APPROACHES } from '../constants'; jest.mock('./date', () => ({ getFormattedFilePrefixDate: jest.fn(() => 'mockedDate'), @@ -7,21 +6,21 @@ jest.mock('./date', () => ({ describe('getFileName', () => { it('should return the correct file name for Query approach - linkToTriggeringCsvFile', () => { - const item = { approach: APPROACHES.QUERY, id: 123 }; + const item = { fqlQueryId: '111', id: 123 }; const triggeredFile = 'linkToTriggeringCsvFile'; const result = getFileName(item, triggeredFile); expect(result).toBe('Query-123.csv'); }); it('should return the correct file name for Query approach - linkToMatchedRecordsCsvFile', () => { - const item = { approach: APPROACHES.QUERY, id: 123 }; + const item = { fqlQueryId: '111', id: 123 }; const triggeredFile = 'linkToMatchedRecordsCsvFile'; const result = getFileName(item, triggeredFile); expect(result).toBe('mockedDate-Matched-Records-Query-123.csv'); }); it('should return the correct file name for non-Query approach', () => { - const item = { approach: APPROACHES.IN_APP, linkToTriggeringCsvFile: 'somePath/someFile.csv' }; + const item = { fqlQueryId: null, linkToTriggeringCsvFile: 'somePath/someFile.csv' }; const triggeredFile = 'linkToTriggeringCsvFile'; const result = getFileName(item, triggeredFile); expect(result).toBe('someFile.csv');