Skip to content

Commit

Permalink
improve code quality regarding to the comments
Browse files Browse the repository at this point in the history
  • Loading branch information
alisher-epam committed Nov 2, 2023
1 parent f12b1bc commit e54369b
Showing 1 changed file with 21 additions and 27 deletions.
48 changes: 21 additions & 27 deletions lib/DonorsList/DonorsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,38 @@ import {
Button,
Icon,
MultiColumnList,
TextLink,
} from '@folio/stripes/components';
import { useStripes } from '@folio/stripes/core';

import { acqRowFormatter } from '../utils';
import AddDonorButton from './AddDonorButton';
import { alignRowProps, columnMapping, columnWidths, visibleColumns } from './constants';
import {
alignRowProps,
columnMapping,
columnWidths,
visibleColumns,
} from './constants';

const getDonorUrl = (orgId) => {
if (orgId) {
return `/organizations/view/${orgId}`;
}

return undefined;
};

const getResultsFormatter = ({
intl,
canViewOrganizations,
fields,
intl,
}) => ({
name: donor => donor.name,
name: donor => <TextLink to={getDonorUrl(canViewOrganizations && donor.id)}>{donor.name}</TextLink>,
code: donor => donor.code,
unassignDonor: (donor) => (
unassignDonor: donor => (
<Button
align="end"
aria-label={intl.formatMessage({ id: 'stripes-acq-components.donors.button.unassign' })}
buttonStyle="fieldControl"
data-test-unassign-donor
type="button"
onClick={(e) => {
e.preventDefault();
Expand All @@ -37,14 +50,6 @@ const getResultsFormatter = ({
),
});

const getDonorUrl = (orgId) => {
if (orgId) {
return `/organizations/view/${orgId}`;
}

return undefined;
};

const DonorsList = ({ fetchDonors, fields, donorsMap, id }) => {
const intl = useIntl();
const stripes = useStripes();
Expand All @@ -60,19 +65,9 @@ const DonorsList = ({ fetchDonors, fields, donorsMap, id }) => {
});
const contentData = sortBy(donors, [({ lastName }) => lastName?.toLowerCase()]);

const anchoredRowFormatter = ({ rowProps, ...rest }) => {
return acqRowFormatter({
...rest,
rowProps: {
...rowProps,
to: getDonorUrl(canViewOrganizations && rest.rowData.id),
},
});
};

const resultsFormatter = useMemo(() => {
return getResultsFormatter({ intl, fields });
}, [fields, intl]);
return getResultsFormatter({ intl, fields, canViewOrganizations });
}, [canViewOrganizations, fields, intl]);

return (
<>
Expand All @@ -81,7 +76,6 @@ const DonorsList = ({ fetchDonors, fields, donorsMap, id }) => {
columnMapping={columnMapping}
contentData={contentData}
formatter={resultsFormatter}
rowFormatter={anchoredRowFormatter}
rowProps={alignRowProps}
visibleColumns={visibleColumns}
columnWidths={columnWidths}
Expand Down

0 comments on commit e54369b

Please sign in to comment.