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-246 Displaying and paginating through retrieved records #463

Merged
merged 9 commits into from
Jan 30, 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 @@ -39,6 +39,7 @@
* [UIBULKED-399](https://issues.folio.org/browse/UIBULKED-399) Update label verbiage on the Identifier tab.
* [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.

## [4.0.0](https://github.com/folio-org/ui-bulk-edit/tree/v4.0.0) (2023-10-12)

Expand Down
16 changes: 9 additions & 7 deletions src/components/BulkEditList/BulkEditList.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
logsTab: logsFilters,
}));
}
}, [history.location]);

Check warning on line 66 in src/components/BulkEditList/BulkEditList.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

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

Check warning on line 66 in src/components/BulkEditList/BulkEditList.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

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

const initialFiltersState = {
criteria: CRITERIA.IDENTIFIER,
Expand Down Expand Up @@ -143,7 +143,7 @@
/>
);
} else return <FormattedMessage id="ui-bulk-edit.meta.title" />;
}, [confirmedFileName, history.location.search]);

Check warning on line 146 in src/components/BulkEditList/BulkEditList.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

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

Check warning on line 146 in src/components/BulkEditList/BulkEditList.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

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

const changedPaneSubTitle = useMemo(() => (
step === EDITING_STEPS.UPLOAD ?
Expand Down Expand Up @@ -222,13 +222,15 @@
/>
</BulkEditInAppLayer>

<BulkEditInAppPreviewModal
bulkOperationId={bulkOperationId}
open={isPreviewModalOpened}
contentUpdates={contentUpdates}
onKeepEditing={handlePreviewModalClose}
onChangesCommited={handleChangesCommited}
/>
{isPreviewModalOpened && (
<BulkEditInAppPreviewModal
bulkOperationId={bulkOperationId}
open={isPreviewModalOpened}
contentUpdates={contentUpdates}
onKeepEditing={handlePreviewModalClose}
onChangesCommited={handleChangesCommited}
/>
)}
</Paneset>

<BulkEditManualUploadModal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@

import { MessageBanner, Modal, MultiColumnList } from '@folio/stripes/components';
import { Preloader } from '@folio/stripes-data-transfer-components';
import { useShowCallout } from '@folio/stripes-acq-components';
import { PrevNextPagination, useShowCallout } from '@folio/stripes-acq-components';

import { RootContext } from '../../../../context/RootContext';
import {
APPROACHES,
EDITING_STEPS,
FILE_KEYS,
FILE_SEARCH_PARAMS,
PAGINATION_CONFIG,
getFormattedFilePrefixDate,
} from '../../../../constants';
import {
Expand All @@ -25,6 +26,7 @@
useFileDownload,
QUERY_KEY_DOWNLOAD_IN_APP,
IN_APP_PREVIEW_KEY,
BULK_OPERATION_DETAILS_KEY,
} from '../../../../hooks/api';

import { getContentUpdatesBody } from '../BulkEditInApp/ContentUpdatesForm/helpers';
Expand All @@ -33,6 +35,7 @@
import css from './BulkEditInAppPreviewModal.css';
import { getVisibleColumnsKeys } from '../../../../utils/helpers';
import { PREVIEW_COLUMN_WIDTHS } from '../../../PermissionsModal/constants/lists';
import { usePagination } from '../../../../hooks/usePagination';

const BulkEditInAppPreviewModal = ({
open,
Expand All @@ -58,25 +61,34 @@

const { bulkDetails } = useBulkOperationDetails({ id: bulkOperationId });
const { contentUpdate } = useContentUpdate({ id: bulkOperationId });
const { bulkOperationStart } = useBulkOperationStart();
const { bulkOperationStart, startData } = useBulkOperationStart();

const totalRecords = bulkDetails?.totalNumOfRecords;

const {
pagination,
changePage,
} = usePagination(PAGINATION_CONFIG);

const [isPreviewLoading, setIsLoadingPreview] = useState(false);

const {
contentData,
columnMapping,
refetch: fetchPreview,
isFetching
} = useRecordsPreview({
key: IN_APP_PREVIEW_KEY,
id: bulkOperationId,
step: EDITING_STEPS.EDIT,
capabilities,
queryOptions: {
enabled: false,
enabled: !!startData,
onError: () => {
swwCallout();
onKeepEditing();
},
},
...pagination,
});

const { refetch } = useFileDownload({
Expand All @@ -86,15 +98,15 @@
fileInfo: {
fileContentType: FILE_SEARCH_PARAMS.PROPOSED_CHANGES_FILE,
},
onSuccess: data => {
onSuccess: fileData => {
const searchParams = new URLSearchParams(history.location.search);
let fileName = searchParams.get('fileName');

if (!fileName) {
fileName = `${capabilities}-${searchParams.get('criteria')}.csv`;
}

saveAs(new Blob([data]), `${getFormattedFilePrefixDate()}-Updates-Preview-${fileName}`);
saveAs(new Blob([fileData]), `${getFormattedFilePrefixDate()}-Updates-Preview-${fileName}`);
},
});

Expand Down Expand Up @@ -122,11 +134,11 @@
};

useEffect(() => {
if (contentUpdates && open) {
if (contentUpdates && open && totalRecords) {
const contentUpdatesBody = getContentUpdatesBody({
bulkOperationId,
contentUpdates,
totalRecords: bulkDetails.totalNumOfRecords,
totalRecords,
});

setIsLoadingPreview(true);
Expand All @@ -137,8 +149,10 @@
approach: APPROACHES.IN_APP,
step: EDITING_STEPS.EDIT,
}))
.then(() => fetchPreview())
.then(() => queryClient.invalidateQueries('bulkOperationDetails'))
.then(() => {
queryClient.invalidateQueries(BULK_OPERATION_DETAILS_KEY);
queryClient.invalidateQueries(IN_APP_PREVIEW_KEY);
})
.catch(() => {
swwCallout();
onKeepEditing();
Expand All @@ -147,7 +161,7 @@
setIsLoadingPreview(false);
});
}
}, [contentUpdates, open]);
}, [contentUpdates, open, totalRecords]);

Check warning on line 164 in src/components/BulkEditList/BulkEditListResult/BulkEditInAppPreviewModal/BulkEditInAppPreviewModal.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

React Hook useEffect has missing dependencies: 'bulkOperationId', 'bulkOperationStart', 'contentUpdate', 'onKeepEditing', 'queryClient', and 'swwCallout'. Either include them or remove the dependency array. If 'onKeepEditing' changes too often, find the parent component that defines it and wrap that definition in useCallback

Check warning on line 164 in src/components/BulkEditList/BulkEditListResult/BulkEditInAppPreviewModal/BulkEditInAppPreviewModal.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

React Hook useEffect has missing dependencies: 'bulkOperationId', 'bulkOperationStart', 'contentUpdate', 'onKeepEditing', 'queryClient', and 'swwCallout'. Either include them or remove the dependency array. If 'onKeepEditing' changes too often, find the parent component that defines it and wrap that definition in useCallback

return (
<Modal
Expand Down Expand Up @@ -182,7 +196,17 @@
maxHeight={300}
columnIdPrefix="in-app"
columnWidths={PREVIEW_COLUMN_WIDTHS}
loading={isFetching}
/>

{contentData.length > 0 && (
<PrevNextPagination
{...pagination}
totalCount={bulkDetails?.matchedNumOfRecords}
disabled={false}
onChange={changePage}
/>
)}
</>
) : <Preloader />}
</Modal>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ import {
} from '../../../../constants';
import {
useBulkOperationDetails,
useRecordsPreview,
} from '../../../../hooks/api';
import BulkEditInAppPreviewModal from './BulkEditInAppPreviewModal';

jest.mock('../../../../hooks/api', () => ({
...jest.requireActual('../../../../hooks/api'),
useBulkOperationDetails: jest.fn(),
useRecordsPreview: jest.fn(),
}));

const bulkOperation = bulkEditLogsData[0];
Expand Down Expand Up @@ -63,6 +65,15 @@ describe('BulkEditInAppPreviewModal', () => {
bulkDetails: bulkOperation,
});

useRecordsPreview.mockClear().mockReturnValue({
isLoading: false,
refetch: jest.fn(),
isFetching: false,
contentData: [],
columnMapping: {},
columns: [],
});

useOkapiKy
.mockClear()
.mockReturnValue({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const ErrorsAccordion = ({
}}
label={<FormattedMessage id="ui-bulk-edit.list.errors.title" />}
>
<div className={css.errorAccordionInner}>
<div className={css.errorAccordionOuter}>
<Headline size="medium" margin="small">
{headLine}
</Headline>
Expand Down
15 changes: 11 additions & 4 deletions src/components/BulkEditList/BulkEditListResult/Preview/Preview.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,32 @@
}

.previewAccordion,
.previewAccordionList,
.errorAccordionList {
flex-grow: 1;
}

.previewAccordion:first-child:has([aria-expanded="false"]) {
.previewAccordion:has([aria-expanded="false"]) {
flex-grow: 0;
}

.previewAccordion > * {
height: 100%;
}

.previewAccordionInner,
.errorAccordionInner {
.previewAccordionInner {
display: flex;
flex-direction: column;
height: 100%;
}

.previewAccordionOuter,
.errorAccordionOuter {
display: flex;
flex-direction: column;
flex-grow: 1;
}

.errorAccordionInner {
.errorAccordionOuter {
height: 100%;
}
52 changes: 25 additions & 27 deletions src/components/BulkEditList/BulkEditListResult/Preview/Preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
MessageBanner,
} from '@folio/stripes/components';
import PropTypes from 'prop-types';
import { useContext, useEffect, useState } from 'react';
import { useLocation } from 'react-router-dom';
import css from './Preview.css';
import { PreviewAccordion } from './PreviewAccordion';
Expand All @@ -15,45 +14,40 @@ import {
useErrorsPreview,
useRecordsPreview
} from '../../../../hooks/api';
import { RootContext } from '../../../../context/RootContext';

import { EDITING_STEPS } from '../../../../constants';
import { PAGINATION_CONFIG } from '../../../../constants';
import { usePagination } from '../../../../hooks/usePagination';
import { useBulkOperationStats } from '../../../../hooks/useBulkOperationStats';

export const Preview = ({ id, title, isInitial, bulkDetails }) => {
const location = useLocation();
const { countOfRecords, setCountOfRecords, visibleColumns } = useContext(RootContext);
const [countOfErrors, setCountOfErrors] = useState(0);
const [totalCount, setTotalCount] = useState(0);

const search = new URLSearchParams(location.search);
const step = search.get('step');
const capabilities = search.get('capabilities');

const { contentData, columns, columnMapping } = useRecordsPreview({
const {
countOfRecords,
countOfErrors,
totalCount,
visibleColumns,
} = useBulkOperationStats({ bulkDetails, step });

const {
pagination,
changePage,
} = usePagination(PAGINATION_CONFIG);

const { contentData, columns, columnMapping, isFetching } = useRecordsPreview({
key: RECORDS_PREVIEW_KEY,
id,
step,
capabilities
capabilities,
...pagination,
});
const { data } = useErrorsPreview({ id });
const errors = data?.errors || [];

useEffect(() => {
const isInitialPreview = step === EDITING_STEPS.UPLOAD;

const countRecords = isInitialPreview
? bulkDetails.matchedNumOfRecords
: bulkDetails.committedNumOfRecords;

const countErrors = isInitialPreview
? bulkDetails.matchedNumOfErrors
: bulkDetails.committedNumOfErrors;

setCountOfErrors(countErrors);
setCountOfRecords(countRecords);
setTotalCount(isInitialPreview ? bulkDetails.totalNumOfRecords : bulkDetails.matchedNumOfRecords);
}, [bulkDetails, step]);
const { data } = useErrorsPreview({ id });

const errors = data?.errors || [];

return (
<AccordionStatus>
Expand All @@ -73,15 +67,19 @@ export const Preview = ({ id, title, isInitial, bulkDetails }) => {
{title}
</Headline>
)}
<div className={css.previewAccordionInner}>
<div className={css.previewAccordionOuter}>
{Boolean(contentData?.length) && (
<PreviewAccordion
totalRecords={bulkDetails?.matchedNumOfRecords}
isInitial={isInitial}
columns={columns}
contentData={contentData}
columnMapping={columnMapping}
visibleColumns={visibleColumns}
step={step}
onChangePage={changePage}
pagination={pagination}
isFetching={isFetching}
/>
)}

Expand Down
Loading
Loading