Skip to content

Commit

Permalink
improve useFetchDonors hook
Browse files Browse the repository at this point in the history
  • Loading branch information
alisher-epam committed Nov 16, 2023
1 parent 00d15f7 commit 6344233
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 14 deletions.
2 changes: 1 addition & 1 deletion lib/Donors/Donors.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { useFetchDonors } from './hooks';

export function Donors({ name, donorOrganizationIds, onChange, ...rest }) {
const [donorIds, setDonorIds] = useState(donorOrganizationIds);
const { donors, isLoading } = useFetchDonors(donorIds);
const { donors, isLoading } = useFetchDonors(donorIds, { keepPreviousData: true });

useEffect(() => {
setDonorIds(donorOrganizationIds);
Expand Down
10 changes: 1 addition & 9 deletions lib/Donors/DonorsContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import { useIntl } from 'react-intl';

import { useStripes } from '@folio/stripes/core';

import {
defaultContainerVisibleColumns,
pluginVisibleColumns,
} from './constants';
import { defaultContainerVisibleColumns } from './constants';
import { DonorsList } from './DonorsList';
import { DonorsLookup } from './DonorsLookup';
import { getDonorsFormatter } from './utils';
Expand All @@ -21,7 +18,6 @@ export function DonorsContainer({
formatter,
id,
onRemove,
pluginVisibleColumns: pluginVisibleColumnsProp,
setDonorIds,
searchLabel,
showTriggerButton,
Expand Down Expand Up @@ -84,8 +80,6 @@ export function DonorsContainer({
onAddDonors={onAddDonors}
name={id}
searchLabel={searchLabel}
visibleColumns={pluginVisibleColumnsProp}
{...rest}
/>
)
}
Expand All @@ -105,12 +99,10 @@ DonorsContainer.propTypes = {
setDonorIds: PropTypes.func.isRequired,
showTriggerButton: PropTypes.bool,
visibleColumns: PropTypes.arrayOf(PropTypes.string),
pluginVisibleColumns: PropTypes.arrayOf(PropTypes.string),
};

DonorsContainer.defaultProps = {
onRemove: noop,
showTriggerButton: true,
visibleColumns: defaultContainerVisibleColumns,
pluginVisibleColumns,
};
2 changes: 0 additions & 2 deletions lib/Donors/DonorsLookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export const DonorsLookup = ({
onAddDonors,
searchLabel,
visibleColumns,
...rest
}) => {
const stripes = useStripes();

Expand All @@ -44,7 +43,6 @@ export const DonorsLookup = ({
visibleFilters={visibleFilters}
isMultiSelect
sortableColumns={sortableColumns}
{...rest}
>
<span data-test-add-donor>
<FormattedMessage id="stripes-acq-components.donors.noFindOrganizationPlugin" />
Expand Down
7 changes: 5 additions & 2 deletions lib/Donors/hooks/useFetchDonors/useFetchDonors.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { VENDORS_API } from '../../../constants';
import { batchRequest } from '../../../utils';
import { DEFAULT_DATA } from './constants';

export const useFetchDonors = (donorOrganizationIds = DEFAULT_DATA) => {
export const useFetchDonors = (donorOrganizationIds = DEFAULT_DATA, options = {}) => {
const ky = useOkapiKy();
const namespace = useNamespace({ key: 'fetch-donors-list' });

Expand All @@ -24,7 +24,10 @@ export const useFetchDonors = (donorOrganizationIds = DEFAULT_DATA) => {
donorOrganizationIds,
);
},
{ enabled: Boolean(donorOrganizationIds.length) },
{
enabled: Boolean(donorOrganizationIds.length),
...options,
},
);

return ({
Expand Down

0 comments on commit 6344233

Please sign in to comment.