From 00f3f79c93325f03d0adfa93d82b3691294b5e42 Mon Sep 17 00:00:00 2001 From: jasonhsieh Date: Mon, 21 Jan 2019 22:13:55 +0800 Subject: [PATCH 1/3] update fix/836_columnDefIsArray --- src/utils/columnUtils.js | 26 +++++++++++++------------- stories/index.tsx | 17 ++++++++++++++++- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/utils/columnUtils.js b/src/utils/columnUtils.js index 3786c25c..5a41667c 100644 --- a/src/utils/columnUtils.js +++ b/src/utils/columnUtils.js @@ -1,3 +1,4 @@ +import _ from 'lodash'; const offset = 1000; /** Gets a column properties object from an array of columnNames @@ -7,8 +8,7 @@ function getColumnPropertiesFromColumnArray(columnProperties, columns) { return columns.reduce((previous, current, i) => { previous[current] = { id: current, order: offset + i }; return previous; - }, - columnProperties); + }, columnProperties); } /** Gets the column properties object from a react component (rowProperties) that contains child component(s) for columnProperties. @@ -16,28 +16,28 @@ function getColumnPropertiesFromColumnArray(columnProperties, columns) { * @param {Object} rowProperties - An React component that contains the rowProperties and child columnProperties components * @param {Array optional} allColumns - An optional array of colummn names. This will be used to generate the columnProperties when they are not defined in rowProperties */ -export function getColumnProperties(rowProperties, allColumns=[]) { +export function getColumnProperties(rowProperties, allColumns = []) { const children = rowProperties && rowProperties.props && rowProperties.props.children; const columnProperties = {}; // Working against an array of columnProperties if (Array.isArray(children)) { // build one object that contains all of the column properties keyed by id - children.reduce((previous, current, i) => { - if (current) { - previous[current.props.id] = {order: offset + i, ...current.props}; - } - return previous; - }, columnProperties); - - // Working against a lone, columnProperties object + _.reduce(_.flatten(children),(previous, current, i) => { + if (current) { + previous[current.props.id] = { order: offset + i, ...current.props }; + } + return previous; + }, columnProperties); + + // Working against a lone, columnProperties object } else if (children && children.props) { columnProperties[children.props.id] = { order: offset, ...children.props }; } - if(Object.keys(columnProperties).length === 0 && allColumns) { + if (Object.keys(columnProperties).length === 0 && allColumns) { getColumnPropertiesFromColumnArray(columnProperties, allColumns); } - return columnProperties; + return columnProperties; } diff --git a/stories/index.tsx b/stories/index.tsx index fbe503ce..f0b649a1 100644 --- a/stories/index.tsx +++ b/stories/index.tsx @@ -265,6 +265,21 @@ storiesOf('Griddle main', module) ) }) + .add("with filterable set by array of ", () => { + const ids = ["name", "city", "state"]; + return ( +
+ Name is not filterable + + + {ids.map(id => ( + + ))} + + +
+ ); + }) .add('with local and sort set', () => { const sortProperties = [ { id: 'name', sortAscending: true } @@ -1768,4 +1783,4 @@ storiesOf('TypeScript', module) ); - }) + }) \ No newline at end of file From fd88b7889fc6c9cc75799bfa68dcbe12c727d052 Mon Sep 17 00:00:00 2001 From: jasonhsieh Date: Mon, 21 Jan 2019 22:17:57 +0800 Subject: [PATCH 2/3] indent adjust --- src/utils/columnUtils.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/utils/columnUtils.js b/src/utils/columnUtils.js index 5a41667c..8799c10f 100644 --- a/src/utils/columnUtils.js +++ b/src/utils/columnUtils.js @@ -23,14 +23,14 @@ export function getColumnProperties(rowProperties, allColumns = []) { // Working against an array of columnProperties if (Array.isArray(children)) { // build one object that contains all of the column properties keyed by id - _.reduce(_.flatten(children),(previous, current, i) => { - if (current) { - previous[current.props.id] = { order: offset + i, ...current.props }; - } - return previous; - }, columnProperties); - - // Working against a lone, columnProperties object + _.reduce(_.flatten(children),(previous, current, i) => { + if (current) { + previous[current.props.id] = { order: offset + i, ...current.props }; + } + return previous; + }, columnProperties); + + // Working against a lone, columnProperties object } else if (children && children.props) { columnProperties[children.props.id] = { order: offset, ...children.props }; } From 195c8ff5e5538d85b4f365eed697f1684bb14890 Mon Sep 17 00:00:00 2001 From: jasonhsieh Date: Mon, 21 Jan 2019 22:19:54 +0800 Subject: [PATCH 3/3] format adjust --- src/utils/columnUtils.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/utils/columnUtils.js b/src/utils/columnUtils.js index 8799c10f..6d0aadc7 100644 --- a/src/utils/columnUtils.js +++ b/src/utils/columnUtils.js @@ -8,7 +8,8 @@ function getColumnPropertiesFromColumnArray(columnProperties, columns) { return columns.reduce((previous, current, i) => { previous[current] = { id: current, order: offset + i }; return previous; - }, columnProperties); + }, + columnProperties); } /** Gets the column properties object from a react component (rowProperties) that contains child component(s) for columnProperties. @@ -16,7 +17,7 @@ function getColumnPropertiesFromColumnArray(columnProperties, columns) { * @param {Object} rowProperties - An React component that contains the rowProperties and child columnProperties components * @param {Array optional} allColumns - An optional array of colummn names. This will be used to generate the columnProperties when they are not defined in rowProperties */ -export function getColumnProperties(rowProperties, allColumns = []) { +export function getColumnProperties(rowProperties, allColumns=[]) { const children = rowProperties && rowProperties.props && rowProperties.props.children; const columnProperties = {}; @@ -25,17 +26,17 @@ export function getColumnProperties(rowProperties, allColumns = []) { // build one object that contains all of the column properties keyed by id _.reduce(_.flatten(children),(previous, current, i) => { if (current) { - previous[current.props.id] = { order: offset + i, ...current.props }; + previous[current.props.id] = {order: offset + i, ...current.props}; } return previous; }, columnProperties); - + // Working against a lone, columnProperties object } else if (children && children.props) { columnProperties[children.props.id] = { order: offset, ...children.props }; } - if (Object.keys(columnProperties).length === 0 && allColumns) { + if(Object.keys(columnProperties).length === 0 && allColumns) { getColumnPropertiesFromColumnArray(columnProperties, allColumns); }