Skip to content

Commit

Permalink
sigh
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeTaylor committed Dec 20, 2024
1 parent 8f8e84c commit bd573c9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 22 deletions.
4 changes: 0 additions & 4 deletions src/routes/RecordsRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ const RecordsRoute = ({ stripes, resources, mutator, children }) => {
hasLoaded={hasLoaded}
error={error}
onNeedMoreData={handleNeedMoreData}
recordsMutator={mutator.records}
>
{children}
</Records>
Expand Down Expand Up @@ -103,9 +102,6 @@ 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
35 changes: 17 additions & 18 deletions src/views/Records/Records.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState } from 'react';
import PropTypes from 'prop-types';
import { FormattedMessage, useIntl } from 'react-intl';
import { AppIcon } from '@folio/stripes/core';
import { AppIcon, useOkapiKy } from '@folio/stripes/core';
import { MenuSection, Button, Icon, LoadingPane, Paneset, Pane, MultiColumnList, ErrorModal, exportToCsv, MCLPagingTypes } from '@folio/stripes/components';
import { ColumnManager, SearchAndSortQuery } from '@folio/stripes/smart-components';
import parseSort from '../../util/parseSort';
Expand All @@ -11,36 +11,39 @@ import ErrorMessage from '../../components/ErrorMessage';
import packageInfo from '../../../package';


function exportAllRecords(resultCount, recordsMutator) {
function exportAllRecords(resultCount, okapiKy) {
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 } }));
p.push(okapiKy(`harvester-admin/previous-jobs/failed-records?offset=${offset}&limit=${RCI}`)
.then(res => res.json()));
}

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

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


function renderActionMenu(onToggle, intl, data, resultCount, recordsMutator, renderedColumnsMenu) {
function renderActionMenu(onToggle, intl, data, resultCount, okapiKy, renderedColumnsMenu) {
return (
<div>
<MenuSection label={intl.formatMessage({ id: 'ui-harvester-admin.reports' })}>
<Button
aria-label={intl.formatMessage({ id: 'ui-harvester-admin.export-csv' })}
disabled={!resultCount}
buttonStyle="dropdownItem"
onClick={() => { exportAllRecords(resultCount, recordsMutator); onToggle(); }}
onClick={() => { exportAllRecords(resultCount, okapiKy); onToggle(); }}
>
<Icon icon="download">
<FormattedMessage id="ui-harvester-admin.export-csv" />
Expand All @@ -61,11 +64,11 @@ function Records({
error,
hasLoaded,
onNeedMoreData,
recordsMutator,
children,
}) {
const intl = useIntl();
const [invalidSortKey, setInvalidSortKey] = useState();
const okapiKy = useOkapiKy();

const columnMapping = {
recordNumber: <FormattedMessage id="ui-harvester-admin.failed-records.recordNumber" />,
Expand Down Expand Up @@ -123,7 +126,7 @@ function Records({
padContent={false}
paneTitle={paneTitle}
paneSub={<FormattedMessage id="ui-harvester-admin.resultCount" values={{ count: resultCount }} />}
actionMenu={({ onToggle }) => renderActionMenu(onToggle, intl, data, resultCount, recordsMutator, renderColumnsMenu)}
actionMenu={({ onToggle }) => renderActionMenu(onToggle, intl, data, resultCount, okapiKy, renderColumnsMenu)}
>
<MultiColumnList
autosize
Expand Down Expand Up @@ -179,10 +182,6 @@ 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

0 comments on commit bd573c9

Please sign in to comment.