Skip to content

Commit

Permalink
UIBULKED-411 [FE] Refactoring of ListFilters component
Browse files Browse the repository at this point in the history
  • Loading branch information
vashjs committed Feb 12, 2024
1 parent f7ef12f commit b7e8f8b
Show file tree
Hide file tree
Showing 26 changed files with 539 additions and 506 deletions.
74 changes: 30 additions & 44 deletions src/components/BulkEditList/BulkEditList.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { AppIcon } from '@folio/stripes/core';
import { noop } from 'lodash/util';

import { useHistory } from 'react-router';
import { BulkEditListFilters } from './BulkEditListFilters/BulkEditListFilters';
import { BulkEditListResult } from './BulkEditListResult';
import { BulkEditActionMenu } from '../BulkEditActionMenu';
import { BulkEditManualUploadModal } from './BulkEditListResult/BulkEditManualUploadModal';
Expand All @@ -22,7 +21,9 @@ import {
CRITERIA,
APPROACHES,
EDITING_STEPS,
FILTERS,
LOGS_FILTERS,
IDENTIFIER_FILTERS,
QUERY_FILTERS,
} from '../../constants';
import { BulkEditInApp } from './BulkEditListResult/BulkEditInApp/BulkEditInApp';
import BulkEditInAppPreviewModal from './BulkEditListResult/BulkEditInAppPreviewModal/BulkEditInAppPreviewModal';
Expand All @@ -31,6 +32,8 @@ import { RootContext } from '../../context/RootContext';
import BulkEditLogs from '../BulkEditLogs/BulkEditLogs';
import { useResetAppState } from '../../hooks/useResetAppState';
import BulkEditInAppLayer from './BulkEditListResult/BulkEditInAppLayer/BulkEditInAppLayer';
import { BulkEditListSidebar } from './BulkEditListSidebar/BulkEditListSidebar';
import { useSearchParams } from '../../hooks/useSearchParams';

export const BulkEditList = () => {
const history = useHistory();
Expand All @@ -46,37 +49,30 @@ export const BulkEditList = () => {
const [confirmedFileName, setConfirmedFileName] = useState(null);
const [inAppCommitted, setInAppCommitted] = useState(false);
const [filtersTab, setFiltersTab] = useState({
identifierTab: [],
queryTab: [],
logsTab: [],
});

const { isActionMenuShown } = useBulkPermissions();
const { id: bulkOperationId } = usePathParams('/bulk-edit/:id');
const step = search.get('step');
const capabilities = search.get('capabilities');
const criteria = search.get('criteria');
const logsFilters = Object.values(FILTERS).map((el) => search.getAll(el));
const { step, capabilities, criteria, initialFileName } = useSearchParams();
const identifierFilters = Object.values(IDENTIFIER_FILTERS).map((el) => search.getAll(el));
const queryFilters = Object.values(QUERY_FILTERS).map((el) => search.getAll(el));
const logsFilters = Object.values(LOGS_FILTERS).map((el) => search.getAll(el));

useEffect(() => {
if (history.location.search) {
setFiltersTab(prevState => ({
...prevState,
queryTab: queryFilters,
identifierTab: identifierFilters,
logsTab: logsFilters,
}));
}
}, [history.location]);

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

View workflow job for this annotation

GitHub Actions / github-actions-ci

React Hook useEffect has missing dependencies: 'identifierFilters', 'logsFilters', and 'queryFilters'. Either include them or remove the dependency array

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

View workflow job for this annotation

GitHub Actions / github-actions-ci

React Hook useEffect has missing dependencies: 'identifierFilters', 'logsFilters', and 'queryFilters'. Either include them or remove the dependency array

const initialFiltersState = {
criteria: CRITERIA.IDENTIFIER,
capabilities: '',
queryText: '',
recordIdentifier: '',
};

const [filters, setFilters] = useState(initialFiltersState);

useResetAppState({
initialFiltersState,
setFilters,
setConfirmedFileName,
setCountOfRecords,
setVisibleColumns,
Expand Down Expand Up @@ -133,17 +129,15 @@ export const BulkEditList = () => {
};

const paneTitle = useMemo(() => {
const fileUploadedName = search.get('fileName');

if (confirmedFileName || fileUploadedName) {
if (confirmedFileName || initialFileName) {
return (
<FormattedMessage
id="ui-bulk-edit.meta.title.uploadedFile"
values={{ fileName: confirmedFileName || fileUploadedName }}
values={{ fileName: confirmedFileName || initialFileName }}
/>
);
} else return <FormattedMessage id="ui-bulk-edit.meta.title" />;
}, [confirmedFileName, history.location.search]);
}, [confirmedFileName, initialFileName, history.location.search]);

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

View workflow job for this annotation

GitHub Actions / github-actions-ci

React Hook useMemo has an unnecessary dependency: 'history.location.search'. Either exclude it or remove the dependency array

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

View workflow job for this annotation

GitHub Actions / github-actions-ci

React Hook useMemo has an unnecessary dependency: 'history.location.search'. Either exclude it or remove the dependency array

const changedPaneSubTitle = useMemo(() => (
step === EDITING_STEPS.UPLOAD ?
Expand Down Expand Up @@ -176,37 +170,30 @@ export const BulkEditList = () => {
confirmedFileName,
inAppCommitted,
setInAppCommitted,
isFileUploaded,
setIsFileUploaded,
}}
>
<Paneset>
{/* FILTERS PANE */}
{/* LOGS_FILTERS PANE */}
<Pane
defaultWidth="300px"
paneTitle={<FormattedMessage id="ui-bulk-edit.list.criteriaTitle" />}
>
<BulkEditListFilters
filters={filters}
setFilters={setFilters}
setIsFileUploaded={setIsFileUploaded}
isFileUploaded={isFileUploaded}
setVisibleColumns={setVisibleColumns}
/>
<BulkEditListSidebar />
</Pane>

{/* RESULT PANES */}
{
isLogsTab && <BulkEditLogs />
}
{
!isLogsTab && (
<Pane
{...defaultPaneProps}
actionMenu={actionMenu}
>
<BulkEditListResult />
</Pane>
)
}
{ isLogsTab && <BulkEditLogs /> }

{ !isLogsTab && (
<Pane
{...defaultPaneProps}
actionMenu={actionMenu}
>
<BulkEditListResult />
</Pane>
)}

{/* IN_APP APPROACH */}
<BulkEditInAppLayer
Expand Down Expand Up @@ -235,7 +222,6 @@ export const BulkEditList = () => {

<BulkEditManualUploadModal
operationId={bulkOperationId}
identifier={filters.recordIdentifier}
open={isBulkEditModalOpen}
onCancel={cancelBulkEditStart}
countOfRecords={countOfRecords}
Expand Down
Loading

0 comments on commit b7e8f8b

Please sign in to comment.