Skip to content

Commit 00f3f79

Browse files
committed
update fix/836_columnDefIsArray
1 parent 49306e7 commit 00f3f79

File tree

2 files changed

+29
-14
lines changed

2 files changed

+29
-14
lines changed

src/utils/columnUtils.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import _ from 'lodash';
12
const offset = 1000;
23

34
/** Gets a column properties object from an array of columnNames
@@ -7,37 +8,36 @@ function getColumnPropertiesFromColumnArray(columnProperties, columns) {
78
return columns.reduce((previous, current, i) => {
89
previous[current] = { id: current, order: offset + i };
910
return previous;
10-
},
11-
columnProperties);
11+
}, columnProperties);
1212
}
1313

1414
/** Gets the column properties object from a react component (rowProperties) that contains child component(s) for columnProperties.
1515
* If no properties are found, it will work return a column properties object based on the all columns array
1616
* @param {Object} rowProperties - An React component that contains the rowProperties and child columnProperties components
1717
* @param {Array<string> optional} allColumns - An optional array of colummn names. This will be used to generate the columnProperties when they are not defined in rowProperties
1818
*/
19-
export function getColumnProperties(rowProperties, allColumns=[]) {
19+
export function getColumnProperties(rowProperties, allColumns = []) {
2020
const children = rowProperties && rowProperties.props && rowProperties.props.children;
2121
const columnProperties = {};
2222

2323
// Working against an array of columnProperties
2424
if (Array.isArray(children)) {
2525
// build one object that contains all of the column properties keyed by id
26-
children.reduce((previous, current, i) => {
27-
if (current) {
28-
previous[current.props.id] = {order: offset + i, ...current.props};
29-
}
30-
return previous;
31-
}, columnProperties);
32-
33-
// Working against a lone, columnProperties object
26+
_.reduce(_.flatten(children),(previous, current, i) => {
27+
if (current) {
28+
previous[current.props.id] = { order: offset + i, ...current.props };
29+
}
30+
return previous;
31+
}, columnProperties);
32+
33+
// Working against a lone, columnProperties object
3434
} else if (children && children.props) {
3535
columnProperties[children.props.id] = { order: offset, ...children.props };
3636
}
3737

38-
if(Object.keys(columnProperties).length === 0 && allColumns) {
38+
if (Object.keys(columnProperties).length === 0 && allColumns) {
3939
getColumnPropertiesFromColumnArray(columnProperties, allColumns);
4040
}
4141

42-
return columnProperties;
42+
return columnProperties;
4343
}

stories/index.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,21 @@ storiesOf('Griddle main', module)
265265
</div>
266266
)
267267
})
268+
.add("with filterable set by array of <ColumnDefinition />", () => {
269+
const ids = ["name", "city", "state"];
270+
return (
271+
<div>
272+
<small>Name is not filterable</small>
273+
<Griddle data={fakeData} plugins={[LocalPlugin]}>
274+
<RowDefinition>
275+
{ids.map(id => (
276+
<ColumnDefinition id={id} filterable />
277+
))}
278+
</RowDefinition>
279+
</Griddle>
280+
</div>
281+
);
282+
})
268283
.add('with local and sort set', () => {
269284
const sortProperties = [
270285
{ id: 'name', sortAscending: true }
@@ -1768,4 +1783,4 @@ storiesOf('TypeScript', module)
17681783
</RowDefinition>
17691784
</Griddle>
17701785
);
1771-
})
1786+
})

0 commit comments

Comments
 (0)