-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add config properties for plugin to implement donors
- Loading branch information
1 parent
acb730f
commit 5474b1a
Showing
4 changed files
with
129 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { map } from 'lodash'; | ||
import PropTypes from 'prop-types'; | ||
import { FormattedMessage } from 'react-intl'; | ||
|
||
import { Pluggable } from '@folio/stripes/core'; | ||
|
||
import { | ||
initialFilters, | ||
modalLabel, | ||
pluginVisibleColumns, | ||
resultsPaneTitle, | ||
searchableIndexes, | ||
visibleFilters, | ||
} from './constants'; | ||
|
||
const AddDonorButton = ({ fetchDonors, fields, stripes, name }) => { | ||
const addDonors = (donors = []) => { | ||
const addedDonorIds = new Set(fields.value); | ||
const newDonorsIds = map(donors.filter(({ id }) => !addedDonorIds.has(id)), 'id'); | ||
|
||
if (newDonorsIds.length) { | ||
fetchDonors([...addedDonorIds, ...newDonorsIds]); | ||
newDonorsIds.forEach(contactId => fields.push(contactId)); | ||
} | ||
}; | ||
|
||
return ( | ||
<Pluggable | ||
id={`${name}-plugin`} | ||
aria-haspopup="true" | ||
type="find-organization" | ||
dataKey="organization" | ||
searchLabel={<FormattedMessage id="stripes-acq-components.donors.button.addDonor" />} | ||
searchButtonStyle="default" | ||
disableRecordCreation | ||
stripes={stripes} | ||
selectVendor={addDonors} | ||
modalLabel={modalLabel} | ||
resultsPaneTitle={resultsPaneTitle} | ||
visibleColumns={pluginVisibleColumns} | ||
initialFilters={initialFilters} | ||
searchableIndexes={searchableIndexes} | ||
visibleFilters={visibleFilters} | ||
isMultiSelect | ||
> | ||
<span data-test-add-donor> | ||
<FormattedMessage id="stripes-acq-components.donors.noFindOrganizationPlugin" /> | ||
</span> | ||
</Pluggable> | ||
); | ||
}; | ||
|
||
AddDonorButton.propTypes = { | ||
fetchDonors: PropTypes.func.isRequired, | ||
fields: PropTypes.object, | ||
stripes: PropTypes.object, | ||
name: PropTypes.string.isRequired, | ||
}; | ||
|
||
export default AddDonorButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { FormattedMessage } from 'react-intl'; | ||
|
||
export const columnMapping = { | ||
name: <FormattedMessage id="stripes-acq-components.donors.column.name" />, | ||
code: <FormattedMessage id="stripes-acq-components.donors.column.code" />, | ||
unassignDonor: null, | ||
}; | ||
|
||
export const visibleColumns = [ | ||
'name', | ||
'code', | ||
'unassignDonor', | ||
]; | ||
|
||
export const alignRowProps = { alignLastColToEnd: true }; | ||
|
||
export const columnWidths = { | ||
name: '45%', | ||
code: '45%', | ||
unassignDonor: '10%', | ||
}; | ||
|
||
export const modalLabel = <FormattedMessage id="stripes-acq-components.donors.modal.title" />; | ||
export const resultsPaneTitle = <FormattedMessage id="stripes-acq-components.donors.modal.resultsTitle" />; | ||
|
||
export const pluginVisibleColumns = ['name', 'code']; | ||
|
||
export const DONORS_SORT_MAP = { | ||
name: 'name', | ||
code: 'code', | ||
}; | ||
|
||
const ORGANIZATION_STATUS = { | ||
active: 'Active', | ||
inactive: 'Inactive', | ||
pending: 'Pending', | ||
}; | ||
|
||
const FILTERS = { | ||
IS_VENDOR: 'isVendor', | ||
STATUS: 'status', | ||
TAGS: 'tags', | ||
TYPES: 'organizationTypes', | ||
}; | ||
|
||
export const visibleFilters = [ | ||
FILTERS.IS_VENDOR, | ||
FILTERS.TAGS, | ||
FILTERS.TYPES, | ||
]; | ||
|
||
export const initialFilters = { | ||
[FILTERS.IS_DONOR]: ['true'], | ||
[FILTERS.STATUS]: [ORGANIZATION_STATUS.active], | ||
}; | ||
|
||
export const searchableIndexes = pluginVisibleColumns.map(column => ({ | ||
labelId: `ui-organizations.search.${column}`, | ||
value: column, | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters