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

First attempt at full-set-of-failed-records CSV export #86

Merged
merged 3 commits into from
Dec 20, 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 @@ -4,6 +4,7 @@

* Explicit paging for list of failed records. Fixes UIHAADM-141.
* Explicit paging for list of harvestables. Fixes UIHAADM-142.
* When downloading Failed Records, provide all records in the result set, not just the currently visible page. Fixes UIHAADM-140.

## [2.2.0](https://github.com/folio-org/ui-harvester-admin/tree/v2.2.0) (2024-10-23)

Expand Down
4 changes: 4 additions & 0 deletions src/routes/RecordsRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const RecordsRoute = ({ stripes, resources, mutator, children }) => {
hasLoaded={hasLoaded}
error={error}
onNeedMoreData={handleNeedMoreData}
recordsMutator={mutator.records}
>
{children}
</Records>
Expand Down Expand Up @@ -102,6 +103,9 @@ RecordsRoute.propTypes = {
query: PropTypes.shape({
update: PropTypes.func.isRequired,
}).isRequired,
records: PropTypes.shape({
GET: PropTypes.func.isRequired,
}).isRequired,
}).isRequired,
children: PropTypes.object, // XXX may need to add .isRequired later
};
Expand Down
41 changes: 30 additions & 11 deletions src/views/Records/Records.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,36 @@ import ErrorMessage from '../../components/ErrorMessage';
import packageInfo from '../../../package';


function renderActionMenu(onToggle, intl, data, renderedColumnsMenu) {
function exportAllRecords(resultCount, recordsMutator) {
const RCI = 100; // Probably keep in sync with RESULT_COUNT_INCREMENT from RecordsRoute.js

const p = [];
for (let offset = 0; offset < resultCount; offset += RCI) {
p.push(recordsMutator.GET({ params: { offset, limit: RCI } }));
}

Promise.all(p).then(res => {
recordsMutator.reset();
const records = res.flat().filter(r => r !== undefined).map(r => ({
...r,
errors: errors2string(r.recordErrors),
originalRecord: undefined,
}));

exportToCsv(records, {});
});
}


function renderActionMenu(onToggle, intl, data, resultCount, recordsMutator, renderedColumnsMenu) {
return (
<div>
<MenuSection label={intl.formatMessage({ id: 'ui-harvester-admin.reports' })}>
<Button
aria-label={intl.formatMessage({ id: 'ui-harvester-admin.export-csv' })}
disabled={data.records.length === 0}
disabled={!resultCount}
buttonStyle="dropdownItem"
onClick={() => {
const expanded = data.records.map(r => ({
...r,
errors: errors2string(r.recordErrors),
}));
exportToCsv(expanded, {});
onToggle();
}}
onClick={() => { exportAllRecords(resultCount, recordsMutator); onToggle(); }}
>
<Icon icon="download">
<FormattedMessage id="ui-harvester-admin.export-csv" />
Expand All @@ -47,6 +61,7 @@ function Records({
error,
hasLoaded,
onNeedMoreData,
recordsMutator,
children,
}) {
const intl = useIntl();
Expand Down Expand Up @@ -108,7 +123,7 @@ function Records({
padContent={false}
paneTitle={paneTitle}
paneSub={<FormattedMessage id="ui-harvester-admin.resultCount" values={{ count: resultCount }} />}
actionMenu={({ onToggle }) => renderActionMenu(onToggle, intl, data, renderColumnsMenu)}
actionMenu={({ onToggle }) => renderActionMenu(onToggle, intl, data, resultCount, recordsMutator, renderColumnsMenu)}
>
<MultiColumnList
autosize
Expand Down Expand Up @@ -164,6 +179,10 @@ Records.propTypes = {
error: PropTypes.string,
hasLoaded: PropTypes.bool.isRequired,
onNeedMoreData: PropTypes.func.isRequired,
recordsMutator: PropTypes.shape({
GET: PropTypes.func.isRequired,
reset: PropTypes.func.isRequired,
}).isRequired,
children: PropTypes.oneOfType([
PropTypes.object.isRequired,
PropTypes.arrayOf(PropTypes.object.isRequired).isRequired,
Expand Down
Loading