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

UIBULKED-367 Logs - Provide a link to file with identifiers of the records affected by query #467

Merged
merged 3 commits into from
Feb 1, 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 @@ -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 @@ -97,7 +97,7 @@

const applyFiltersAdapter = (callBack) => ({ name, values }) => callBack(name, values);

const adaptedApplyFilters = useCallback(

Check warning on line 100 in src/components/BulkEditList/BulkEditListFilters/BulkEditListFilters.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

React Hook useCallback received a function whose dependencies are unknown. Pass an inline function instead

Check warning on line 100 in src/components/BulkEditList/BulkEditListFilters/BulkEditListFilters.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

React Hook useCallback received a function whose dependencies are unknown. Pass an inline function instead
applyFiltersAdapter(applyFilters),
[applyFilters],
);
Expand Down Expand Up @@ -151,7 +151,7 @@
};

const handleCriteriaChange = (value) => {
const newFilterValue = { capabilities: null, recordTypes: null, criteria: value };
const newFilterValue = { capabilities: '', recordTypes: '', criteria: value };

setFilters(prev => ({ ...prev, ...newFilterValue }));

Expand Down Expand Up @@ -190,7 +190,7 @@
setVisibleColumns(null);
setIsFileUploaded(false);
setInAppCommitted(false);
}, [location.search]);

Check warning on line 193 in src/components/BulkEditList/BulkEditListFilters/BulkEditListFilters.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

React Hook useCallback has missing dependencies: 'criteria', 'handleChange', 'history', 'initialCapabilities', 'logFilters', 'setInAppCommitted', 'setIsFileUploaded', and 'setVisibleColumns'. Either include them or remove the dependency array. If 'setIsFileUploaded' changes too often, find the parent component that defines it and wrap that definition in useCallback

Check warning on line 193 in src/components/BulkEditList/BulkEditListFilters/BulkEditListFilters.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

React Hook useCallback has missing dependencies: 'criteria', 'handleChange', 'history', 'initialCapabilities', 'logFilters', 'setInAppCommitted', 'setIsFileUploaded', and 'setVisibleColumns'. Either include them or remove the dependency array. If 'setIsFileUploaded' changes too often, find the parent component that defines it and wrap that definition in useCallback

const uploadFileFlow = async (fileToUpload) => {
try {
Expand Down Expand Up @@ -233,7 +233,7 @@
const messagePrefix = recordIdentifier ? `.${recordIdentifier}` : '';

return <FormattedMessage id={`ui-bulk-edit.uploaderSubTitle${TRANSLATION_SUFFIX[capabilities]}${messagePrefix}`} />;
}, [recordIdentifier]);

Check warning on line 236 in src/components/BulkEditList/BulkEditListFilters/BulkEditListFilters.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

React Hook useMemo has a missing dependency: 'capabilities'. Either include it or remove the dependency array

Check warning on line 236 in src/components/BulkEditList/BulkEditListFilters/BulkEditListFilters.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

React Hook useMemo has a missing dependency: 'capabilities'. Either include it or remove the dependency array

useEffect(() => {
if (isFileUploaded || !recordIdentifier || initialFileName) {
Expand All @@ -241,7 +241,7 @@
} else {
setIsDropZoneDisabled(false);
}
}, [isFileUploaded, recordIdentifier]);

Check warning on line 244 in src/components/BulkEditList/BulkEditListFilters/BulkEditListFilters.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

React Hook useEffect has a missing dependency: 'initialFileName'. Either include it or remove the dependency array

Check warning on line 244 in src/components/BulkEditList/BulkEditListFilters/BulkEditListFilters.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

React Hook useEffect has a missing dependency: 'initialFileName'. Either include it or remove the dependency array

useEffect(() => {
const identifier = search.get('identifier');
Expand All @@ -253,7 +253,7 @@
if (initialCapabilities) {
handleChange(initialCapabilities, 'capabilities');
}
}, [location.search]);

Check warning on line 256 in src/components/BulkEditList/BulkEditListFilters/BulkEditListFilters.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

React Hook useEffect has missing dependencies: 'handleChange', 'initialCapabilities', and 'search'. Either include them or remove the dependency array

Check warning on line 256 in src/components/BulkEditList/BulkEditListFilters/BulkEditListFilters.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

React Hook useEffect has missing dependencies: 'handleChange', 'initialCapabilities', and 'search'. Either include them or remove the dependency array

const renderCapabilities = () => (
<Capabilities
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
Loading