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

UISACQCOMP-166: configure the plugin via props #726

Merged
merged 12 commits into from
Nov 9, 2023
10 changes: 9 additions & 1 deletion lib/Donors/DonorsList.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { isEmpty } from 'lodash';
import PropTypes from 'prop-types';

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

import {
alignRowProps,
defaultColumnMapping,
defaultVisibleColumns,
} from './constants';

import { getDonorsListFormatter } from './utils';

export const DonorsList = ({
columnMapping,
columnWidths,
Expand All @@ -16,12 +20,16 @@ export const DonorsList = ({
id,
visibleColumns,
}) => {
const stripes = useStripes();
const canViewOrganizations = stripes.hasPerm('ui-organizations.view');
const defaultFormatter = isEmpty(formatter) || getDonorsListFormatter({ canViewOrganizations });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need isEmpty here? Moreover:

isEmpty(undefined) || getDonorsListFormatter(..) // true ??
isEmpty({ foo: 'bar' }) || getDonorsListFormatter(..)  // default formatter even we passed one through the props ??

just:

export const DonorsList = ({
  ..
  formatter: formatterProp,
  ..
}) => {
..
const formatter = useMemo(() => formatterProp || getDonorsListFormatter({ canViewOrganizations }), [formatterProp, canViewOrganizations]);
..


return (
<MultiColumnList
id={id}
columnMapping={columnMapping}
contentData={contentData}
formatter={formatter}
formatter={defaultFormatter}
rowProps={alignRowProps}
visibleColumns={visibleColumns}
columnWidths={columnWidths}
Expand Down
2 changes: 2 additions & 0 deletions lib/Donors/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export { Donors } from './Donors';
export { DonorsList } from './DonorsList';
export { useFetchDonors } from './hooks/useFetchDonors';
Loading