Skip to content

Commit a4644aa

Browse files
authored
Merge pull request #46 from easeq/master
Minor changes and fixes
2 parents 41cad0e + 5652eb2 commit a4644aa

File tree

8 files changed

+36
-21
lines changed

8 files changed

+36
-21
lines changed

demo/src/schema/basic.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,13 @@ export default {
125125
SimpleButton: {
126126
type: 'button',
127127
label: 'Simple Button',
128-
thunk: ( config ) => ( dispatch, getState ) => {
128+
thunk: ( config, action ) => ( dispatch, getState ) => {
129129
const tableState = getState()[config.reducerName][config.name];
130130
console.log('toolbar button click', config, tableState);
131-
config.action(REQUEST_DATA)();
132-
config.action(SET_IS_LOADING)({ value: true });
131+
action(REQUEST_DATA)();
132+
action(SET_IS_LOADING)({ value: true });
133133
setTimeout(function() {
134-
config.action(SET_IS_LOADING)({ value: false });
134+
action(SET_IS_LOADING)({ value: false });
135135
}, 1000);
136136
},
137137
// styles: {

demo/src/schema/normalized.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,13 @@ export default {
159159
type: 'button',
160160
label: 'Simple Button',
161161
state: false,
162-
thunk: ( config ) => ( dispatch, getState ) => {
162+
thunk: ( config, action ) => ( dispatch, getState ) => {
163163
const tableState = getState()[config.reducerName][config.name];
164164
console.log('toolbar button click', config, tableState);
165-
config.action(REQUEST_DATA)();
166-
config.action(SET_IS_LOADING)({ value: true });
165+
action(REQUEST_DATA)();
166+
action(SET_IS_LOADING)({ value: true });
167167
setTimeout(function() {
168-
config.action(SET_IS_LOADING)({ value: false });
168+
action(SET_IS_LOADING)({ value: false });
169169
}, 1000);
170170
},
171171
// styles: {
@@ -258,12 +258,13 @@ export default {
258258
type: 'selection',
259259
width: 50
260260
}, {
261-
label: 'ID',
261+
label: 'ID 1',
262262
type: 'number',
263263
name: 'pageId',
264264
width: 150,
265265
filterable: true,
266266
sortable: true,
267+
visible: false,
267268
// editable: true
268269
}, {
269270
label: 'ID',

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@flipbyte/redux-datatable",
3-
"version": "0.7.3",
3+
"version": "0.7.4",
44
"description": "React-Redux data table",
55
"main": "lib/index.js",
66
"module": "es/index.js",

src/createTable.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,15 @@ const ReduxDatatable = ( props ) => {
4343

4444
const minWidth = calculateWidth(columns);
4545
const dispatch = useDispatch();
46-
const preparePayload = prepareActionPayload(props, action);
46+
const preparePayload = prepareActionPayload(props);
4747
const action = useCallback(
4848
( type ) => ( payload ) => dispatch(createActionCreator(type)(preparePayload(payload))),
4949
[ dispatch ]
5050
);
51-
const thunk = useCallback(( thunk, payload ) => dispatch(thunk(preparePayload(payload))), [ dispatch ]);
51+
const thunk = useCallback(( thunk, payload ) => (
52+
dispatch(thunk(preparePayload({ ...payload }), action)),
53+
[ dispatch ]
54+
));
5255
const loadData = useCallback(() => {
5356
action(SET_PAGE)({ page: 1 });
5457
action(SET_LIMIT)({ limit: Limiter.default || 10 });
@@ -57,7 +60,9 @@ const ReduxDatatable = ( props ) => {
5760
action(SET_VISIBLE_COLUMN_IDS)({ ids: getInitialVisibleColumns(columns) });
5861
action(SET_TABLE_WIDTH)({ width: minWidth, widthAdjustment: 1 });
5962
action(SET_COLUMN_WIDTHS)(columns.reduce((acc, column) => {
60-
acc.push(column.width);
63+
if (column.visible !== false) {
64+
acc.push(column.width);
65+
}
6166
return acc;
6267
}, []));
6368
}, [ dispatch ]);

src/hoc/withScrollSpy.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import _ from 'lodash';
22
import React, { Component, useRef, useState, useEffect, useContext } from 'react';
33
import { useSelector } from 'react-redux';
44
import ConfigContext from '../context';
5+
import { isUndefined } from '../utils';
56

67
export let scrollerMap = {};
78

@@ -10,10 +11,14 @@ const withScrollSpy = WrappedComponent => (props) => {
1011
const id = _.uniqueId(name);
1112
const ref = useRef(null);
1213
const [ scrollData, setScrollData ] = useState({ top: 0, pointerEvents: 'none' });
13-
const { getData, minWidth, config: { height } } = useContext(ConfigContext);
14+
const { getData, minWidth, config: { name: tableName, height } } = useContext(ConfigContext);
1415

1516
const handleScroll = (event) => {
16-
_.map(scrollerMap, (ref, key, index) => (
17+
if (isUndefined(scrollerMap[tableName])) {
18+
return;
19+
}
20+
21+
_.map(scrollerMap[tableName], (ref, key, index) => (
1722
ref.current.scrollLeft = event.target.scrollLeft
1823
));
1924

@@ -27,14 +32,18 @@ const withScrollSpy = WrappedComponent => (props) => {
2732
ref.current.removeEventListener('scroll', handleScroll, true);
2833
ref.current.addEventListener('scroll', handleScroll, true);
2934
} else {
30-
scrollerMap[id] = ref;
35+
if (isUndefined(scrollerMap[tableName])) {
36+
scrollerMap[tableName] = {};
37+
}
38+
39+
scrollerMap[tableName][id] = ref;
3140
}
3241

3342
return () => {
3443
if (name === 'Body') {
3544
ref.current.removeEventListener('scroll', handleScroll, true);
3645
} else {
37-
delete scrollerMap[id];
46+
delete scrollerMap[tableName][id];
3847
}
3948
};
4049
}, [ handleScroll ]);

src/reducer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ let initialTableState = {
3333
}
3434
};
3535

36-
const calculateTableWidth = (columnWidths, clientWidth ) => {
36+
const calculateTableWidth = (columnWidths, clientWidth) => {
3737
const totalColWidth = columnWidths.reduce((a, b) => a + b, 0);
3838
const innerWidth = totalColWidth > clientWidth ? totalColWidth : clientWidth;
3939
const widthAdjustment = innerWidth / totalColWidth;

src/utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,6 @@ export const getRenderer = ( config, Renderers ) => {
111111
export const prepareActionPayload = ({
112112
reducerName,
113113
config: { name, routes, entity, primaryKey }
114-
}, action) => (
115-
( payload = {} ) => ({ name, reducerName, routes, entity, payload, action, primaryKey })
114+
}) => (
115+
( payload = {} ) => ({ name, reducerName, routes, entity, payload, primaryKey })
116116
);

0 commit comments

Comments
 (0)