Skip to content

Commit

Permalink
updated default formatters
Browse files Browse the repository at this point in the history
  • Loading branch information
alisher-epam committed Nov 9, 2023
1 parent be0e6f9 commit da8a1c2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 19 deletions.
18 changes: 3 additions & 15 deletions lib/Donors/DonorsContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ import { useStripes } from '@folio/stripes/core';
import { defaultVisibleColumns } from './constants';
import { DonorsList } from './DonorsList';
import { DonorsLookup } from './DonorsLookup';
import {
getDonorsListFormatter,
getUnAssignDonorFormatter,
} from './utils';
import { getDonorsFormatter } from './utils';

export function DonorsContainer({
columnMapping,
Expand Down Expand Up @@ -50,17 +47,8 @@ export function DonorsContainer({
const contentData = useMemo(() => sortBy(listOfDonors, [({ lastName }) => lastName?.toLowerCase()]), [listOfDonors]);

const resultsFormatter = useMemo(() => {
const defaultFormatter = formatter || getDonorsListFormatter({ intl, fields, canViewOrganizations });

if (visibleColumns.includes('unassignDonor')) {
return {
...getUnAssignDonorFormatter({ intl, fields }),
...defaultFormatter,
};
}

return defaultFormatter;
}, [canViewOrganizations, fields, formatter, intl, visibleColumns]);
return formatter || getDonorsFormatter({ intl, fields, canViewOrganizations });
}, [canViewOrganizations, fields, formatter, intl]);

const onAddDonors = (values = []) => {
const addedDonorIds = new Set(fields.value);
Expand Down
3 changes: 2 additions & 1 deletion lib/Donors/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export const getDonorsListFormatter = ({ canViewOrganizations }) => ({
code: donor => donor.code,
});

export const getUnAssignDonorFormatter = ({ fields, intl }) => ({
export const getDonorsFormatter = ({ canViewOrganizations, fields, intl }) => ({
...getDonorsListFormatter({ canViewOrganizations }),
unassignDonor: donor => (
<Button
align="end"
Expand Down
6 changes: 3 additions & 3 deletions lib/Donors/utils.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
getDonorsListFormatter,
getUnAssignDonorFormatter,
getDonorsFormatter,
} from './utils';

const defaultProps = {
Expand All @@ -24,9 +24,9 @@ describe('getDonorsListFormatter', () => {
});
});

describe('getUnAssignDonorFormatter', () => {
describe('getDonorsFormatter', () => {
it('should return object with name, code and unassignDonor functions', () => {
const result = getUnAssignDonorFormatter(defaultProps);
const result = getDonorsFormatter(defaultProps);

expect(result).toEqual(expect.objectContaining({
unassignDonor: expect.any(Function),
Expand Down

0 comments on commit da8a1c2

Please sign in to comment.