Skip to content

Commit

Permalink
Use mutator.reset after fecthing records
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeTaylor committed Dec 20, 2024
1 parent eee92b5 commit daeb000
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/routes/RecordsRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const RecordsRoute = ({ stripes, resources, mutator, children }) => {
hasLoaded={hasLoaded}
error={error}
onNeedMoreData={handleNeedMoreData}
getMoreRecords={mutator.records.GET}
recordsMutator={mutator.records}
>
{children}
</Records>
Expand Down
18 changes: 11 additions & 7 deletions src/views/Records/Records.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ import ErrorMessage from '../../components/ErrorMessage';
import packageInfo from '../../../package';


function exportAllRecords(resultCount, getMoreRecords) {
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(getMoreRecords({ params: { offset, limit: 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),
Expand All @@ -31,15 +32,15 @@ function exportAllRecords(resultCount, getMoreRecords) {
}


function renderActionMenu(onToggle, intl, data, resultCount, getMoreRecords, renderedColumnsMenu) {
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={!resultCount}
buttonStyle="dropdownItem"
onClick={() => { exportAllRecords(resultCount, getMoreRecords); onToggle(); }}
onClick={() => { exportAllRecords(resultCount, recordsMutator); onToggle(); }}
>
<Icon icon="download">
<FormattedMessage id="ui-harvester-admin.export-csv" />
Expand All @@ -60,7 +61,7 @@ function Records({
error,
hasLoaded,
onNeedMoreData,
getMoreRecords,
recordsMutator,
children,
}) {
const intl = useIntl();
Expand Down Expand Up @@ -122,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, resultCount, getMoreRecords, renderColumnsMenu)}
actionMenu={({ onToggle }) => renderActionMenu(onToggle, intl, data, resultCount, recordsMutator, renderColumnsMenu)}
>
<MultiColumnList
autosize
Expand Down Expand Up @@ -178,7 +179,10 @@ Records.propTypes = {
error: PropTypes.string,
hasLoaded: PropTypes.bool.isRequired,
onNeedMoreData: PropTypes.func.isRequired,
getMoreRecords: 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 daeb000

Please sign in to comment.