Skip to content

Commit 2809b9e

Browse files
authored
Merge pull request #38 from easeq/master
0.6.2
2 parents cb41b4e + 2f4484b commit 2809b9e

File tree

13 files changed

+413
-53
lines changed

13 files changed

+413
-53
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ import { reducer, epics } from '@flipbyte/redux-datatable';
6363
},
6464
...
6565
},
66+
entity: { // optional. Check example code in /demo.
67+
state: '{your state path}',
68+
responseSchema: // normalizr schema,
69+
schema: // normal;izr schema
70+
},
6671
layout: [
6772
['Editable'],
6873
['MassActions', 'SimpleButton', 'ResetFilters', 'Spacer', 'Print', 'Columns'],
@@ -316,6 +321,7 @@ const YourComponent = () =>
316321
| rowHeight | integer | true | - | The maximum height of each table body row |
317322
| routes | object | true | - | Routes definition to fetch data and other custom routes config for custom handling (Check below) |
318323
| components | object | true | - | All the components required for your table |
324+
| entity | object | false | - | [Normalizr](https://github.com/paularmstrong/normalizr) specification. Check below for details. |
319325
| layout | array | true | - | The layout of your table |
320326
| editing | boolean | false | false | Set the default state of the table to be in editing mode |
321327
| primaryKey | string | true | - | Set the primary key column of the table for actions like editing. |
@@ -342,6 +348,18 @@ Please check the example table config object above.
342348
An array of arrays where each inner array represents a row in the layout, within which components can be specified, which will be displayed in the frontend.
343349
Please check the example table config object above.
344350

351+
#### Entity array
352+
353+
All the fields are required when entity is defined. However, entity key itself is optional in the table config.
354+
355+
| Key | Type | Required | Default | Description |
356+
| -------------- | ------ | -------- | ------- | --------------------------------------------------------------------------------------- |
357+
| state | object | true | - | Path to sub state in your top level redux state where the normalized data will be saved |
358+
| responseSchema | object | true | - | Define how the data is represented in your fetch data api response |
359+
| schema | object | true | - | Define how the data is represented in each row item of the table fetch repsonse |
360+
361+
Note: Check the [example](https://github.com/flipbyte/redux-datatable/blob/master/demo/src/schema/normalized.js) code.
362+
345363
#### Available Components
346364

347365
**_Common Properties_**

demo/src/ExampleTableContainer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import { render } from 'react-dom';
33
import ReduxDatatable from '../../src';
44
import config from './config';
55

6-
const ExampleTableContainer = ({ title, className, id, ...tableProps }) =>
6+
const ExampleTableContainer = ({ title, className, id, ...tableProps }) => (
77
<div id={ id } className="form-container">
88
<h5 className="card-title">{ title }</h5>
99
<ReduxDatatable reducerName={ config.tableReducerName } { ...tableProps } />
1010
</div>
11+
);
1112

1213
export default ExampleTableContainer;

demo/src/config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { reducer, epics } from '../../src';
2+
import pagesReducer from './reducer';
23

34
export default {
45
tableReducerName: 'reduxDatatable',
56
reducers: {
6-
reduxDatatable: reducer
7+
reduxDatatable: reducer,
8+
pages: pagesReducer,
79
},
810
epics: {
911
pageTableFetchDataEpic: epics.fetchDataEpic,

demo/src/index.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Provider } from 'react-redux';
66
import configureStore from './store';
77
import config from './config';
88

9-
// import '../../node_modules/bootstrap/dist/css/bootstrap.css';
9+
import '../../node_modules/bootstrap/dist/css/bootstrap.css';
1010
import './css/simple-sidebar.css';
1111
import './css/styles.css';
1212

@@ -17,22 +17,24 @@ const Demo = () => (
1717
<div className="bg-light border-right sidenav" id="sidebar-wrapper">
1818
<div className="sidebar-heading"><strong>redux-datatable</strong></div>
1919
<div className="list-group list-group-flush">
20-
{ tables.map(({ id, title }, index) =>
20+
{ tables.map(({ id, title }, index) => (
2121
<a key={ index } href={ `#${id}` }
2222
className="list-group-item list-group-item-action bg-light">
2323
{ title }
2424
</a>
25-
) }
25+
))}
2626
</div>
2727
</div>
2828
<div id="page-content-wrapper">
2929
<div className="scrollmenu sticky">
30-
{ tables.map(({ id, title }, index) =>
31-
<a key={ index } href={ `#${id}` }>{ title }</a> ) }
30+
{ tables.map(({ id, title }, index) => (
31+
<a key={ index } href={ `#${id}` }>{ title }</a>
32+
))}
3233
</div>
3334
<div className="container-fluid p-4 content">
34-
{ tables.map((table, index) =>
35-
<ExampleTableContainer key={ index } { ...table }/> )}
35+
{ tables.map((table, index) => (
36+
<ExampleTableContainer key={ index } { ...table }/>
37+
))}
3638
</div>
3739
</div>
3840
</div>

demo/src/reducer.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import _ from 'lodash';
2+
import * as actions from '../../src/actions';
3+
4+
export default function reducer(state = {}, action) {
5+
if (!action.meta) {
6+
return state;
7+
}
8+
9+
const { payload, meta: { name } } = action;
10+
const acceptedActions = {
11+
[actions.RECEIVE_DATA]: () => ({
12+
...state,
13+
..._.get(payload, ['entities', 'pages'], {})
14+
})
15+
};
16+
17+
if (acceptedActions.hasOwnProperty(action.type) && name === 'pages') {
18+
return acceptedActions[action.type]();
19+
}
20+
21+
return state;
22+
}

demo/src/schema/basic.js

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -226,39 +226,7 @@ export default {
226226
// indexField: '@pageId',
227227
width: 50,
228228
extraData: 'selection',
229-
}, {
230-
label: 'ID',
231-
type: 'number',
232-
name: 'pageId',
233-
width: 150,
234-
filterable: true,
235-
sortable: true,
236-
// editable: true
237-
}, {
238-
label: 'ID',
239-
type: 'number',
240-
name: 'pageId',
241-
width: 150,
242-
filterable: true,
243-
sortable: true,
244-
// editable: true
245-
}, {
246-
label: 'ID',
247-
type: 'number',
248-
name: 'pageId',
249-
width: 150,
250-
filterable: true,
251-
sortable: true,
252-
// editable: true
253-
}, {
254-
label: 'ID',
255-
type: 'number',
256-
name: 'pageId',
257-
width: 150,
258-
filterable: true,
259-
sortable: true,
260-
// editable: true
261-
}, {
229+
}, {
262230
label: 'ID',
263231
type: 'number',
264232
name: 'pageId',

demo/src/schema/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import basic from './basic';
2+
import normalized from './normalized';
23

34
export default [
5+
{
6+
title: 'Normalized Table',
7+
id: 'normalized-table',
8+
className: 'mb-4',
9+
config: normalized
10+
},
411
{
512
title: 'Basic Table',
613
id: 'basic-table',

0 commit comments

Comments
 (0)