Skip to content

Commit

Permalink
UIBULKED-367 Logs - Provide a link to file with identifiers of the re…
Browse files Browse the repository at this point in the history
…cords affected by query (#467)
  • Loading branch information
vashjs authored Feb 1, 2024
1 parent 4c0143e commit 876e6e1
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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,
Expand Down Expand Up @@ -70,7 +72,7 @@ export const Preview = ({ id, title, isInitial, bulkDetails }) => {
<div className={css.previewAccordionOuter}>
{Boolean(contentData?.length) && (
<PreviewAccordion
totalRecords={bulkDetails?.matchedNumOfRecords}
totalRecords={totalRecords}
isInitial={isInitial}
columns={columns}
contentData={contentData}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ import {
} from '@folio/stripes/components';
import { FormattedMessage } from 'react-intl';
import { QUERY_KEY_DOWNLOAD_LOGS, useFileDownload } from '../../../hooks/api';
import { CAPABILITIES, linkNamesMap } from '../../../constants';
import { APPROACHES, CAPABILITIES, linkNamesMap } from '../../../constants';
import { useBulkPermissions } from '../../../hooks';
import { getFileName } from '../../../utils/getFileName';

const BulkEditLogsActions = ({ item }) => {
const fileNamePostfix = item.approach === APPROACHES.QUERY ? `.${item.approach}` : '';

const {
hasUsersViewPerms,
hasInventoryInstanceViewPerms,
Expand All @@ -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);
},
});
Expand Down Expand Up @@ -76,7 +79,7 @@ const BulkEditLogsActions = ({ item }) => {
onClick={() => onLoadFile(file)}
>
<Icon icon="download">
<FormattedMessage id={`ui-bulk-edit.logs.actions.${file}`} />
<FormattedMessage id={`ui-bulk-edit.logs.actions.${file}${fileNamePostfix}`} />
</Icon>
</Button>
))}
Expand Down
15 changes: 15 additions & 0 deletions src/utils/getFileName.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { getFormattedFilePrefixDate } from '../constants';

export const getFileName = (item, triggeredFile) => {
if (item.fqlQueryId) {
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];
};
28 changes: 28 additions & 0 deletions src/utils/getFileName.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { getFileName } from './getFileName';

jest.mock('./date', () => ({
getFormattedFilePrefixDate: jest.fn(() => 'mockedDate'),
}));

describe('getFileName', () => {
it('should return the correct file name for Query approach - linkToTriggeringCsvFile', () => {
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 = { 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 = { fqlQueryId: null, linkToTriggeringCsvFile: 'somePath/someFile.csv' };
const triggeredFile = 'linkToTriggeringCsvFile';
const result = getFileName(item, triggeredFile);
expect(result).toBe('someFile.csv');
});
});
1 change: 1 addition & 0 deletions translations/ui-bulk-edit/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 876e6e1

Please sign in to comment.