Skip to content

Commit 8936b15

Browse files
jmatayaJeff Mataya
authored andcommitted
Add bulk action support
1 parent c674c0f commit 8936b15

File tree

3 files changed

+76
-23
lines changed

3 files changed

+76
-23
lines changed

ashes/src/components/bulk-actions/bulk-actions.jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ import { getStore } from 'lib/store-creator';
1414

1515
import SelectAdminsModal from '../users/select-modal';
1616

17-
const mapDispatchToProps = (dispatch, {module}) => {
18-
const {actions} = getStore(`${module}.bulk`);
17+
const mapDispatchToProps = (dispatch, {bulkModule, module}) => {
18+
const { actions } = bulkModule
19+
? getStore(bulkModule)
20+
: getStore(`${module}.bulk`);
1921

2022
return {
2123
bulkActions: bindActionCreators(actions, dispatch),
@@ -25,6 +27,7 @@ const mapDispatchToProps = (dispatch, {module}) => {
2527
@connect(void 0, mapDispatchToProps)
2628
export default class BulkActions extends Component {
2729
static propTypes = {
30+
bulkModule: PropTypes.string,
2831
module: PropTypes.string.isRequired,
2932
entity: PropTypes.string.isRequired,
3033
actions: PropTypes.arrayOf(PropTypes.array).isRequired,

ashes/src/components/bulk-actions/bulk-messages.jsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import ErrorAlerts from '../alerts/error-alerts';
1515

1616
type Props = {
1717
storePath: string,
18+
bulkModule?: string,
1819
module: string,
1920
entity: string,
2021
renderDetail: () => ReactElement,
@@ -95,8 +96,11 @@ const mapState = (state, { storePath }) => ({
9596
bulk: get(state, storePath, {}),
9697
});
9798

98-
const mapActions = (dispatch, { module }) => ({
99-
bulkActions: bindActionCreators(getStore(`${module}.bulk`).actions, dispatch),
100-
});
99+
const mapActions = (dispatch, { bulkModule, module }) => {
100+
const { actions } = bulkModule ? getStore(bulkModule) : getStore(`${module}.bulk`);
101+
return {
102+
bulkActions: bindActionCreators(actions, dispatch),
103+
};
104+
};
101105

102106
export default connect(mapState, mapActions)(BulkMessages);

ashes/src/components/catalog/products.jsx

Lines changed: 64 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import { Button } from 'components/core/button';
2525
import BulkActions from 'components/bulk-actions/bulk-actions';
2626
import BulkMessages from 'components/bulk-actions/bulk-messages';
2727
import { Link } from 'components/link';
28-
import Content from 'components/core/content/content';
2928

3029
// styles
3130
import styles from './products.css';
@@ -41,7 +40,11 @@ type Props = {
4140
unlinkProduct: Function,
4241
setExtraFilters: Function,
4342
},
44-
list: ?Object,
43+
bulkActions: {
44+
exportByIds: Function,
45+
},
46+
bulkExportAction: Function,
47+
list: Object,
4548
linkState: Object,
4649
unlinkState: Object,
4750
}
@@ -61,14 +64,20 @@ class CatalogProducts extends Component {
6164

6265
componentDidMount() {
6366
const { catalogId } = this.props.params;
64-
67+
6568
this.props.actions.setExtraFilters([
6669
dsl.nestedTermFilter('catalogs.id', catalogId),
6770
]);
68-
71+
6972
this.props.actions.fetch();
7073
}
71-
74+
75+
get bulkActions(): Array<any> {
76+
return [
77+
bulkExportBulkAction(this.bulkExport, 'Products'),
78+
];
79+
}
80+
7281
get tableColumns(): Columns {
7382
return [
7483
{ field: 'productId', text: 'ID' },
@@ -80,6 +89,27 @@ class CatalogProducts extends Component {
8089
];
8190
}
8291

92+
bulkExport = (allChecked: boolean, toggledIds: Array<number>) => {
93+
const { exportByIds } = this.props.bulkActions;
94+
const modalTitle = 'Products';
95+
const entity = 'products';
96+
97+
return renderExportModal(this.tableColumns, entity, modalTitle, exportByIds, toggledIds);
98+
};
99+
100+
renderBulkDetails = (context: string, id: number) => {
101+
const { list } = this.props;
102+
const results = list.currentSearch().results.rows;
103+
const filteredProduct = _.filter(results, (product) => product.id.toString() === id)[0];
104+
const productId = filteredProduct.productId;
105+
106+
return (
107+
<span key={id}>
108+
Product <Link to="product-details" params={{ productId, context }}>{productId}</Link>
109+
</span>
110+
);
111+
};
112+
83113
unlinkButton = (children: any, row: Product) => {
84114
const inProgress = this.props.unlinkState.inProgress
85115
&& this.state.deletedProductId === row.productId;
@@ -130,7 +160,7 @@ class CatalogProducts extends Component {
130160
}
131161

132162
addSearchFilters = (filters: Array<SearchFilter>, initial: boolean = false) => {
133-
return this.props.actions.addSearchFilters(filterArchived(filters), initial)
163+
return this.props.actions.addSearchFilters(filterArchived(filters), initial);
134164
};
135165

136166
render() {
@@ -152,18 +182,34 @@ class CatalogProducts extends Component {
152182
addTitle="Product"
153183
onAddClick={this.openModal}
154184
/>
155-
<SelectableSearchList
156-
exportEntity="products"
157-
exportTitle="Products"
158-
entity="catalogs.products"
159-
emptyMessage="No products found."
160-
list={list}
161-
renderRow={this.renderRow}
162-
tableColumns={this.tableColumns}
163-
searchOptions={{ singleSearch: true }}
164-
searchActions={searchActions}
165-
predicate={({ id }) => id}
185+
<BulkMessages
186+
bulkModule="catalogs.bulk"
187+
storePath="catalogs.bulk"
188+
module="catalogs.details"
189+
entity="product"
190+
renderDetail={this.renderBulkDetails}
191+
/>
192+
<BulkActions
193+
bulkModule="catalogs.bulk"
194+
module="catalogs.details"
195+
entity="product"
196+
actions={this.bulkActions}
197+
>
198+
<SelectableSearchList
199+
exportEntity="products"
200+
exportTitle="Products"
201+
bulkExport
202+
bulkExportAction={this.props.bulkExportAction}
203+
entity="catalogs.products"
204+
emptyMessage="No products found."
205+
list={list}
206+
renderRow={this.renderRow}
207+
tableColumns={this.tableColumns}
208+
searchOptions={{ singleSearch: true }}
209+
searchActions={searchActions}
210+
predicate={({ id }) => id}
166211
/>
212+
</BulkActions>
167213
<ProductsAddModal
168214
isVisible={this.state.modalVisible}
169215
onCancel={this.closeModal}
@@ -192,7 +238,7 @@ const mapDispatchToProps = (dispatch) => {
192238
linkProducts: bindActionCreators(linkProducts, dispatch),
193239
unlinkProduct: bindActionCreators(unlinkProduct, dispatch),
194240
},
195-
bulkActionExport: bindActionCreators(bulkExport, dispatch),
241+
bulkExportAction: bindActionCreators(bulkExport, dispatch),
196242
bulkActions: bindActionCreators(bulkActions, dispatch),
197243
};
198244
};

0 commit comments

Comments
 (0)