| 1 |
import {__} from '@wordpress/i18n'; |
| 2 |
import CustomFilter from '../CustomFilter'; |
| 3 |
import styles from './BulkActionSelect.module.scss'; |
| 4 |
import pageStyles from '../ListTablePage/ListTablePage.module.scss'; |
| 5 |
|
| 6 |
export const BulkActionSelect = ({bulkActions = null, selectedState, showModal, data, parameters}) => { |
| 7 |
const [selectedAction, setSelectedAction] = selectedState; |
| 8 |
|
| 9 |
if (window.GiveDonations && window.GiveDonations.addonsBulkActions) { |
| 10 |
bulkActions = [...bulkActions, ...window.GiveDonations.addonsBulkActions]; |
| 11 |
} |
| 12 |
|
| 13 |
if (!bulkActions) { |
| 14 |
return null; |
| 15 |
} |
| 16 |
|
| 17 |
// Format bulkActions for Custom Select |
| 18 |
const filteredOptions = bulkActions |
| 19 |
.filter(action => { |
| 20 |
if (typeof action?.isVisible == 'function' && !action.isVisible(data, parameters)) { |
| 21 |
return false; |
| 22 |
} |
| 23 |
return true; |
| 24 |
}) |
| 25 |
.map(action => ({ |
| 26 |
value: action.value, |
| 27 |
text: action.label |
| 28 |
})); |
| 29 |
|
| 30 |
const changeSelected = (name, value) => { |
| 31 |
setSelectedAction(value); |
| 32 |
}; |
| 33 |
|
| 34 |
return ( |
| 35 |
<div id={styles.bulkActionsForm}> |
| 36 |
<CustomFilter |
| 37 |
name="bulkActions" |
| 38 |
options={filteredOptions} |
| 39 |
ariaLabel={__('Bulk Actions', 'give')} |
| 40 |
placeholder={__('Bulk Actions', 'give')} |
| 41 |
onChange={changeSelected} |
| 42 |
value={selectedAction} |
| 43 |
isSearchable={false} |
| 44 |
isSelectable={true} |
| 45 |
isClearable={true} |
| 46 |
/> |
| 47 |
<button |
| 48 |
onClick={showModal} |
| 49 |
className={`button button-tertiary ${pageStyles.secondaryActionButton}`} |
| 50 |
disabled={!selectedAction} |
| 51 |
> |
| 52 |
{__('Apply', 'give')} |
| 53 |
</button> |
| 54 |
</div> |
| 55 |
); |
| 56 |
}; |
| 57 |
|