From 3d751c0c181b3fff8ddb5cf0161da3646ee8e343 Mon Sep 17 00:00:00 2001 From: dlowder-salesforce Date: Tue, 7 Jun 2016 13:58:40 -0700 Subject: [PATCH 01/13] Remove unneeded dependencies --- package.json | 5 ----- 1 file changed, 5 deletions(-) diff --git a/package.json b/package.json index 4e6690f..8ddb6e2 100644 --- a/package.json +++ b/package.json @@ -16,11 +16,6 @@ "url": "https://github.com/ForceDotComLabs/react.force.datacontainer/issues" }, "homepage": "https://github.com/ForceDotComLabs/react.force.datacontainer#readme", - "peerDependencies": { - "react-native": ">=0.20.0", - "react.force": "git+ssh://git@github.com/ForceDotComLabs/react.force.git", - "react.force.data": "git+ssh://git@github.com/ForceDotComLabs/react.force.data.git" - }, "dependencies": { "lodash.findindex": "^4.4.0", "lodash.keys": "^4.0.7", From ed0351689eadfcabc5f9d749a737aa0aba6ebcb9 Mon Sep 17 00:00:00 2001 From: dlowder-salesforce Date: Tue, 7 Jun 2016 14:03:22 -0700 Subject: [PATCH 02/13] Update for latest react-native --- src/List/index.js | 4 +++- src/RelevantItems/index.js | 4 +++- src/ScrollRefresh/index.js | 4 +++- src/SobjContainer/index.js | 4 +++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/List/index.js b/src/List/index.js index 17ca854..508f3ce 100644 --- a/src/List/index.js +++ b/src/List/index.js @@ -26,7 +26,9 @@ 'use strict'; -import React, { +import React from 'react'; + +import ReactNative, { Text, View, ListView diff --git a/src/RelevantItems/index.js b/src/RelevantItems/index.js index 17fe1ab..443fae8 100644 --- a/src/RelevantItems/index.js +++ b/src/RelevantItems/index.js @@ -26,7 +26,9 @@ 'use strict'; -import React, { +import React from 'react'; + +import ReactNative, { View, ListView } from 'react-native'; diff --git a/src/ScrollRefresh/index.js b/src/ScrollRefresh/index.js index 959210c..70d0c89 100644 --- a/src/ScrollRefresh/index.js +++ b/src/ScrollRefresh/index.js @@ -26,7 +26,9 @@ 'use strict'; -import React, { +import React from 'react'; + +import ReactNative, { View, ScrollView, RefreshControl diff --git a/src/SobjContainer/index.js b/src/SobjContainer/index.js index b54dd5b..cc883fe 100644 --- a/src/SobjContainer/index.js +++ b/src/SobjContainer/index.js @@ -26,7 +26,9 @@ 'use strict'; -import React, { +import React from 'react'; + +import ReactNative, { Text, View } from 'react-native'; From 992ef7cfc1ca94a58e242273fb6e220c471fb9ae Mon Sep 17 00:00:00 2001 From: dlowder-salesforce Date: Tue, 7 Jun 2016 16:58:00 -0700 Subject: [PATCH 03/13] ScrollView may only have one child --- src/ScrollRefresh/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ScrollRefresh/index.js b/src/ScrollRefresh/index.js index 70d0c89..9f5ed15 100644 --- a/src/ScrollRefresh/index.js +++ b/src/ScrollRefresh/index.js @@ -70,7 +70,9 @@ module.exports = React.createClass ({ /> } > + {this.props.children} + ) }, From ad8fea1d5c9770c632039f8bced3fe03a14ba8f5 Mon Sep 17 00:00:00 2001 From: Kapil Date: Thu, 9 Jun 2016 23:09:51 -0700 Subject: [PATCH 04/13] chatter user container --- src/ChatterUserContainer/index.js | 170 ++++++++++++++++++++++++++++++ src/index.js | 6 +- 2 files changed, 174 insertions(+), 2 deletions(-) create mode 100644 src/ChatterUserContainer/index.js diff --git a/src/ChatterUserContainer/index.js b/src/ChatterUserContainer/index.js new file mode 100644 index 0000000..7418a2f --- /dev/null +++ b/src/ChatterUserContainer/index.js @@ -0,0 +1,170 @@ +'use strict'; + +import React from 'react'; + +import ReactNative, { + Text, + View +} from 'react-native'; + +import shallowEqual from 'shallowequal'; +import findIndex from 'lodash.findindex'; + +import { + chatterQuery, + getByChatterUserId +} from 'react.force.data'; + +const subscribers = []; + +const subscribe = (comp)=>{ + subscribers.push(comp) +}; + +const unsubscribe = (comp) => { + const i = subscribers.indexOf(comp); + if(i != -1) { + subscribers.splice(i, 1); + } +}; + +const notify = (ids, records) => { + if(subscribers && subscribers.length){ + subscribers.forEach((subscriber)=>{ + if(subscriber && subscriber.props && subscriber.props.id){ + const searchId = subscriber.props.id; + const index = findIndex(ids, (id) => { + return id.indexOf(searchId)>-1; + }); +// const index = ids.indexOf(subscriber.props.id); + if(index>-1){ + const record = records[index]; + /* + subscriber.setState({ + sobj:sobj, + loading:false, + compactLayout:compactLayout, + defaultLayout:defaultLayout + }); + */ + subscriber.updateChatterData(record); + } + } + }); + } +}; + +chatterQuery.addListener(notify); + + +module.exports = React.createClass ({ + getDefaultProps(){ + return { + type:null, + id:null, + refreshDate:new Date(), + update:true + }; + }, + childContextTypes: { + chatterData: React.PropTypes.object, + // compactLayout: React.PropTypes.object, + // defaultLayout: React.PropTypes.object + }, + getInitialState(){ + return { + chatterData:this.props.chatterData?this.props.chatterData:{Name:' ',attributes:{}}, + // compactLayout:{}, + // defaultLayout:{}, + loading:false + }; + }, + getChildContext() { + return { + chatterData: this.state.chatterData, + // compactLayout:this.state.compactLayout, + // defaultLayout:this.state.defaultLayout + }; + }, + componentDidMount(){ + this.getInfo(); + subscribe(this); + }, + componentWillUnmount(){ + unsubscribe(this); + }, + updateChatterData(chatterData){ + this.setState({ + chatterData:chatterData, + // loading:false, + // compactLayout:compactLayout, + // defaultLayout:defaultLayout + }); + }, + handleDataLoad(){ + if(this.props.onData){ + this.props.onData({ + chatterData:this.state.chatterData + // compactLayout:this.state.compactLayout + }); + } + }, + getInfo() { + this.setState({loading:true}); + if(!this.props.type || !this.props.id){ + return; + } + getByChatterUserId(this.props.id) + .then((opts)=>{ + if(opts.cachedChatterData){ + this.setState({ + chatterData: opts.chatterData + }); + } + }); + // getByTypeAndId(this.props.type,this.props.id) + // .then((opts)=>{ + // if(opts.cachedSobj){ + // this.setState({ + // sobj:opts.cachedSobj, + // compactTitle: opts.cachedSobj.attributes.compactTitle, + // compactLayout:opts.compactLayout, + // defaultLayout:opts.defaultLayout, + // }); + // } + // }); + }, + + render() { + return ( + + {this.props.children} + + ) + }, + componentWillReceiveProps(newProps){ + if(this.props.refreshDate !== newProps.refreshDate){ + this.getInfo(); + } + }, +/* + shouldComponentUpdate(nextProps, nextState){ + if(!this.props.update){ +// return false; + } + if(this.props.type !== nextProps.type){ + return true; + } + if(this.props.type !== nextProps.type){ + return true; + } + if(!shallowEqual(this.state.sobj, nextProps.sobj)){ + return true; + } + if(this.state.loading !== nextProps.loading){ + return true; + } + return false; + } +*/ +}); diff --git a/src/index.js b/src/index.js index cd2f440..a92beed 100644 --- a/src/index.js +++ b/src/index.js @@ -23,8 +23,9 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ - + import SobjContainer from './SobjContainer'; +import ChatterUserContainer from './ChatterUserContainer'; import List from './List'; import RelevantItems from './RelevantItems'; import ScrollRefresh from './ScrollRefresh'; @@ -32,10 +33,11 @@ import {utils} from 'react.force.data'; module.exports = { SobjContainer: SobjContainer, + ChatterUserContainer: ChatterUserContainer, Sobj: SobjContainer, ListContainer: List, List: List, RelevantItems: RelevantItems, ScrollRefresh: ScrollRefresh, utils: utils -}; \ No newline at end of file +}; From 8d067b85022c610fbaf0da3ab4ee3a4f3b846ad4 Mon Sep 17 00:00:00 2001 From: Kapil Date: Tue, 14 Jun 2016 14:37:34 -0700 Subject: [PATCH 05/13] removed comments in ChatterUserContainer --- src/ChatterUserContainer/index.js | 50 ------------------------------- 1 file changed, 50 deletions(-) diff --git a/src/ChatterUserContainer/index.js b/src/ChatterUserContainer/index.js index 7418a2f..d47d492 100644 --- a/src/ChatterUserContainer/index.js +++ b/src/ChatterUserContainer/index.js @@ -36,17 +36,8 @@ const notify = (ids, records) => { const index = findIndex(ids, (id) => { return id.indexOf(searchId)>-1; }); -// const index = ids.indexOf(subscriber.props.id); if(index>-1){ const record = records[index]; - /* - subscriber.setState({ - sobj:sobj, - loading:false, - compactLayout:compactLayout, - defaultLayout:defaultLayout - }); - */ subscriber.updateChatterData(record); } } @@ -68,22 +59,16 @@ module.exports = React.createClass ({ }, childContextTypes: { chatterData: React.PropTypes.object, - // compactLayout: React.PropTypes.object, - // defaultLayout: React.PropTypes.object }, getInitialState(){ return { chatterData:this.props.chatterData?this.props.chatterData:{Name:' ',attributes:{}}, - // compactLayout:{}, - // defaultLayout:{}, loading:false }; }, getChildContext() { return { chatterData: this.state.chatterData, - // compactLayout:this.state.compactLayout, - // defaultLayout:this.state.defaultLayout }; }, componentDidMount(){ @@ -96,16 +81,12 @@ module.exports = React.createClass ({ updateChatterData(chatterData){ this.setState({ chatterData:chatterData, - // loading:false, - // compactLayout:compactLayout, - // defaultLayout:defaultLayout }); }, handleDataLoad(){ if(this.props.onData){ this.props.onData({ chatterData:this.state.chatterData - // compactLayout:this.state.compactLayout }); } }, @@ -122,17 +103,6 @@ module.exports = React.createClass ({ }); } }); - // getByTypeAndId(this.props.type,this.props.id) - // .then((opts)=>{ - // if(opts.cachedSobj){ - // this.setState({ - // sobj:opts.cachedSobj, - // compactTitle: opts.cachedSobj.attributes.compactTitle, - // compactLayout:opts.compactLayout, - // defaultLayout:opts.defaultLayout, - // }); - // } - // }); }, render() { @@ -146,25 +116,5 @@ module.exports = React.createClass ({ if(this.props.refreshDate !== newProps.refreshDate){ this.getInfo(); } - }, -/* - shouldComponentUpdate(nextProps, nextState){ - if(!this.props.update){ -// return false; - } - if(this.props.type !== nextProps.type){ - return true; - } - if(this.props.type !== nextProps.type){ - return true; - } - if(!shallowEqual(this.state.sobj, nextProps.sobj)){ - return true; - } - if(this.state.loading !== nextProps.loading){ - return true; - } - return false; } -*/ }); From 1ae269632d6789bf2aae7cda2c16fba2007bed06 Mon Sep 17 00:00:00 2001 From: Kapil Date: Wed, 15 Jun 2016 12:19:10 -0700 Subject: [PATCH 06/13] added componentUpdate and refresh methods to chatter user container --- src/ChatterUserContainer/index.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/ChatterUserContainer/index.js b/src/ChatterUserContainer/index.js index d47d492..866c8e6 100644 --- a/src/ChatterUserContainer/index.js +++ b/src/ChatterUserContainer/index.js @@ -54,11 +54,13 @@ module.exports = React.createClass ({ type:null, id:null, refreshDate:new Date(), - update:true + update:true, + style:{} }; }, childContextTypes: { chatterData: React.PropTypes.object, + doRefresh: React.PropTypes.func }, getInitialState(){ return { @@ -69,6 +71,7 @@ module.exports = React.createClass ({ getChildContext() { return { chatterData: this.state.chatterData, + doRefresh: this.handleRefresh }; }, componentDidMount(){ @@ -78,6 +81,10 @@ module.exports = React.createClass ({ componentWillUnmount(){ unsubscribe(this); }, + handleRefresh(){ + console.log('>>> REFRESH !!!'); + this.getInfo(); + }, updateChatterData(chatterData){ this.setState({ chatterData:chatterData, @@ -107,7 +114,7 @@ module.exports = React.createClass ({ render() { return ( - + {this.props.children} ) @@ -116,5 +123,17 @@ module.exports = React.createClass ({ if(this.props.refreshDate !== newProps.refreshDate){ this.getInfo(); } + }, + shouldComponentUpdate(nextProps, nextState){ + if(!this.props.update){ + return false; + } + if(this.props.id !== nextProps.id){ + return true; + } + if(!shallowEqual(this.state.chatterData, nextState.chatterData)){ + return true; + } + return false; } }); From 11f602bf624cade75a9e4ff5ca31be1d0337b065 Mon Sep 17 00:00:00 2001 From: Kapil Date: Fri, 24 Jun 2016 17:09:37 -0700 Subject: [PATCH 07/13] added report container --- src/ReportContainer/index.js | 139 +++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 src/ReportContainer/index.js diff --git a/src/ReportContainer/index.js b/src/ReportContainer/index.js new file mode 100644 index 0000000..ba8e8a4 --- /dev/null +++ b/src/ReportContainer/index.js @@ -0,0 +1,139 @@ +'use strict'; + +import React from 'react'; + +import ReactNative, { + Text, + View +} from 'react-native'; + +import shallowEqual from 'shallowequal'; +import findIndex from 'lodash.findindex'; + +import { + reportQuery, + getByReportUserId +} from 'react.force.data'; + +const subscribers = []; + +const subscribe = (comp)=>{ + subscribers.push(comp) +}; + +const unsubscribe = (comp) => { + const i = subscribers.indexOf(comp); + if(i != -1) { + subscribers.splice(i, 1); + } +}; + +const notify = (id, record) => { + if(subscribers && subscribers.length){ + subscribers.forEach((subscriber)=>{ + if(subscriber && subscriber.props && subscriber.props.id){ + const searchId = subscriber.props.id; + const index = id.indexOf(searchId)>-1; + + if(index>-1){ + // const record = records[index]; + subscriber.updateReportData(record); + } + } + }); + } +}; + +reportQuery.addListener(notify); + + +module.exports = React.createClass ({ + getDefaultProps(){ + return { + type:null, + id:null, + refreshDate:new Date(), + update:true, + style:{} + }; + }, + childContextTypes: { + reportData: React.PropTypes.object, + doRefresh: React.PropTypes.func + }, + getInitialState(){ + return { + reportData:this.props.reportData?this.props.reportData:{Name:' ',attributes:{}}, + loading:false + }; + }, + getChildContext() { + return { + reportData: this.state.reportData, + doRefresh: this.handleRefresh + }; + }, + componentDidMount(){ + this.getInfo(); + subscribe(this); + }, + componentWillUnmount(){ + unsubscribe(this); + }, + handleRefresh(){ + console.log('>>> REFRESH !!!'); + this.getInfo(); + }, + updateReportData(reportData){ + this.setState({ + reportData:reportData, + }); + }, + handleDataLoad(){ + if(this.props.onData){ + this.props.onData({ + reportData:this.state.reportData + }); + } + }, + getInfo() { + this.setState({loading:true}); + if(!this.props.id){ + return; + } + getByReportId(this.props.id) + .then((opts)=>{ + if(opts.cachedReportData){ + this.setState({ + reportData: opts.reportData + }); + } + }); + }, + + render() { + return ( + + {this.props.children} + + ) + }, + componentWillReceiveProps(newProps){ + //only refresh every 10 minutes + if(this.props.refreshDate.getTime() <= newProps.refreshDate.getTime()-600000){ + this.getInfo(); + } + }, + shouldComponentUpdate(nextProps, nextState){ + if(!this.props.update){ + return false; + } + if(this.props.id !== nextProps.id){ + return true; + } + if(!shallowEqual(this.state.reportData, nextState.reportData)){ + return true; + } + return false; + } +}); From b761bb916a44c77a87b0f61778cbc047b6f7a734 Mon Sep 17 00:00:00 2001 From: Kapil Date: Mon, 27 Jun 2016 16:56:11 -0700 Subject: [PATCH 08/13] added bluetail lgoo container --- .../index.js | 41 +++++++++---------- src/index.js | 4 +- 2 files changed, 23 insertions(+), 22 deletions(-) rename src/{ReportContainer => BtLogoContainer}/index.js (72%) diff --git a/src/ReportContainer/index.js b/src/BtLogoContainer/index.js similarity index 72% rename from src/ReportContainer/index.js rename to src/BtLogoContainer/index.js index ba8e8a4..b01d6ea 100644 --- a/src/ReportContainer/index.js +++ b/src/BtLogoContainer/index.js @@ -11,8 +11,8 @@ import shallowEqual from 'shallowequal'; import findIndex from 'lodash.findindex'; import { - reportQuery, - getByReportUserId + getBtLogoByCompanyName, + btLogoQuery } from 'react.force.data'; const subscribers = []; @@ -28,23 +28,24 @@ const unsubscribe = (comp) => { } }; -const notify = (id, record) => { +const notify = (ids, records) => { if(subscribers && subscribers.length){ subscribers.forEach((subscriber)=>{ if(subscriber && subscriber.props && subscriber.props.id){ const searchId = subscriber.props.id; - const index = id.indexOf(searchId)>-1; - + const index = findIndex(ids, (id) => { + return id.indexOf(searchId)>-1; + }); if(index>-1){ - // const record = records[index]; - subscriber.updateReportData(record); + const record = records[index]; + subscriber.updateBtData(record); } } }); } }; -reportQuery.addListener(notify); +btLogoQuery.addListener(notify); module.exports = React.createClass ({ @@ -58,18 +59,18 @@ module.exports = React.createClass ({ }; }, childContextTypes: { - reportData: React.PropTypes.object, + btLogoData: React.PropTypes.object, doRefresh: React.PropTypes.func }, getInitialState(){ return { - reportData:this.props.reportData?this.props.reportData:{Name:' ',attributes:{}}, + btLogoData:this.props.btLogoData?this.props.btLogoData:{Name:' ',attributes:{}}, loading:false }; }, getChildContext() { return { - reportData: this.state.reportData, + btLogoData: this.state.btLogoData, doRefresh: this.handleRefresh }; }, @@ -84,15 +85,15 @@ module.exports = React.createClass ({ console.log('>>> REFRESH !!!'); this.getInfo(); }, - updateReportData(reportData){ + updateBtData(btLogoData){ this.setState({ - reportData:reportData, + btLogoData:btLogoData, }); }, handleDataLoad(){ if(this.props.onData){ this.props.onData({ - reportData:this.state.reportData + btLogoData:this.state.btLogoData }); } }, @@ -101,16 +102,15 @@ module.exports = React.createClass ({ if(!this.props.id){ return; } - getByReportId(this.props.id) + getBtLogoByCompanyName(this.props.id) .then((opts)=>{ - if(opts.cachedReportData){ + if(opts.cachedBtLogoData){ this.setState({ - reportData: opts.reportData + btLogoData: opts.btLogoData }); } }); }, - render() { return ( @@ -119,8 +119,7 @@ module.exports = React.createClass ({ ) }, componentWillReceiveProps(newProps){ - //only refresh every 10 minutes - if(this.props.refreshDate.getTime() <= newProps.refreshDate.getTime()-600000){ + if(this.props.refreshDate !== newProps.refreshDate){ this.getInfo(); } }, @@ -131,7 +130,7 @@ module.exports = React.createClass ({ if(this.props.id !== nextProps.id){ return true; } - if(!shallowEqual(this.state.reportData, nextState.reportData)){ + if(!shallowEqual(this.state.btLogoData, nextState.btLogoData)){ return true; } return false; diff --git a/src/index.js b/src/index.js index a92beed..b2dc177 100644 --- a/src/index.js +++ b/src/index.js @@ -26,6 +26,7 @@ import SobjContainer from './SobjContainer'; import ChatterUserContainer from './ChatterUserContainer'; +import BtLogoContainer from './BtLogoContainer'; import List from './List'; import RelevantItems from './RelevantItems'; import ScrollRefresh from './ScrollRefresh'; @@ -39,5 +40,6 @@ module.exports = { List: List, RelevantItems: RelevantItems, ScrollRefresh: ScrollRefresh, - utils: utils + utils: utils, + BtLogoContainer: BtLogoContainer }; From 1046099ba297747d09a45342fdd704f175b677af Mon Sep 17 00:00:00 2001 From: Kapil Date: Tue, 28 Jun 2016 17:40:21 -0700 Subject: [PATCH 09/13] added report container and fixed cache bugs for btlogo and chatter user --- src/BtLogoContainer/index.js | 23 ++--- src/ChatterUserContainer/index.js | 2 +- src/ReportContainer/index.js | 147 ++++++++++++++++++++++++++++++ src/index.js | 4 +- 4 files changed, 163 insertions(+), 13 deletions(-) create mode 100755 src/ReportContainer/index.js diff --git a/src/BtLogoContainer/index.js b/src/BtLogoContainer/index.js index b01d6ea..f932764 100644 --- a/src/BtLogoContainer/index.js +++ b/src/BtLogoContainer/index.js @@ -106,7 +106,7 @@ module.exports = React.createClass ({ .then((opts)=>{ if(opts.cachedBtLogoData){ this.setState({ - btLogoData: opts.btLogoData + btLogoData: opts.cachedBtLogoData }); } }); @@ -124,15 +124,16 @@ module.exports = React.createClass ({ } }, shouldComponentUpdate(nextProps, nextState){ - if(!this.props.update){ - return false; - } - if(this.props.id !== nextProps.id){ - return true; - } - if(!shallowEqual(this.state.btLogoData, nextState.btLogoData)){ - return true; - } - return false; + // if(!this.props.update){ + // return false; + // } + // if(this.props.id !== nextProps.id){ + // return true; + // } + // if(!shallowEqual(this.state.btLogoData, nextState.btLogoData)){ + // return true; + // } + return true; + } }); diff --git a/src/ChatterUserContainer/index.js b/src/ChatterUserContainer/index.js index 866c8e6..30f9ca3 100644 --- a/src/ChatterUserContainer/index.js +++ b/src/ChatterUserContainer/index.js @@ -106,7 +106,7 @@ module.exports = React.createClass ({ .then((opts)=>{ if(opts.cachedChatterData){ this.setState({ - chatterData: opts.chatterData + chatterData: opts.cachedChatterData }); } }); diff --git a/src/ReportContainer/index.js b/src/ReportContainer/index.js new file mode 100755 index 0000000..3830045 --- /dev/null +++ b/src/ReportContainer/index.js @@ -0,0 +1,147 @@ + +'use strict'; + +import React from 'react'; + +import ReactNative, { + Text, + View, + ListView +} from 'react-native'; + +import shallowEqual from 'shallowequal'; +import findIndex from 'lodash.findindex'; +import {forceClient} from 'react.force'; + +import { + reportQuery, + getByReportId +} from 'react.force.data'; + +const subscribers = []; + +const subscribe = (comp)=>{ + subscribers.push(comp) +}; + +const unsubscribe = (comp) => { + const i = subscribers.indexOf(comp); + if(i != -1) { + subscribers.splice(i, 1); + } +}; + +const notify = (id, record) => { + if(subscribers && subscribers.length){ + subscribers.forEach((subscriber)=>{ + if(subscriber && subscriber.props && subscriber.props.id){ + const searchId = subscriber.props.id; + /*const index = findIndex(ids, (id) => { + return id.indexOf(searchId)>-1; + });*/ + const index = id.indexOf(searchId)>-1; + if(index>-1){ + //const record = records[index]; + subscriber.updateReportData(record); + } + } + }); + } +}; + +reportQuery.addListener(notify); + +module.exports = React.createClass ({ + getDefaultProps(){ + return { + type:null, + id:null, + refreshDate:new Date(), + update:true, + style:{} + }; + }, + childContextTypes: { + reportData: React.PropTypes.object, + doRefresh: React.PropTypes.func + }, + getInitialState(){ + return { + reportData:this.props.reportData?this.props.reportData:{Name:' ',attributes:{}}, + loading:false + }; + }, + getChildContext() { + return { + reportData: this.state.reportData, + doRefresh: this.handleRefresh + }; + }, + componentDidMount(){ + this.getInfo(); + subscribe(this); + }, + componentWillUnmount(){ + unsubscribe(this); + }, + handleRefresh(){ + console.log('>>> REFRESH !!!'); + this.getInfo(); + }, + updateReportData(reportData){ + this.setState({ + reportData:reportData, + }); + }, + handleDataLoad(){ + if(this.props.onData){ + this.props.onData({ + reportData:this.state.reportData + }); + } + }, + getInfo() { + this.setState({loading:true}); + if(!this.props.id){ + return; + } + getByReportId(this.props.id) + .then((opts)=>{ + if(opts.cachedReportData){ + this.setState({ + reportData: opts.cachedReportData + }); + } + }); + }, + render() { + return ( + + {this.props.children} + + ) + }, + componentWillReceiveProps(newProps){ + //only refresh reportData every 10 minutes + if(this.props.refreshDate.getTime() <= newProps.refreshDate.getTime()-600000){ + debugger; + this.getInfo(); + } + }, + shouldComponentUpdate(nextProps, nextState){ + //update if change in reportId, entityId, or reportData + if(!this.props.update){ + return false; + } + if(this.props.id !== nextProps.id){ + return true; + } + if(this.props.entityId !== nextProps.entityId) { + return true; + } + if(!shallowEqual(this.state.reportData, nextState.reportData)){ + return true; + } + return false; + } +}); diff --git a/src/index.js b/src/index.js index b2dc177..02b8357 100644 --- a/src/index.js +++ b/src/index.js @@ -27,6 +27,7 @@ import SobjContainer from './SobjContainer'; import ChatterUserContainer from './ChatterUserContainer'; import BtLogoContainer from './BtLogoContainer'; +import ReportContainer from './ReportContainer'; import List from './List'; import RelevantItems from './RelevantItems'; import ScrollRefresh from './ScrollRefresh'; @@ -41,5 +42,6 @@ module.exports = { RelevantItems: RelevantItems, ScrollRefresh: ScrollRefresh, utils: utils, - BtLogoContainer: BtLogoContainer + BtLogoContainer: BtLogoContainer, + ReportContainer: ReportContainer }; From ac01a0e278b42452cc5a20f74570a21268f7a018 Mon Sep 17 00:00:00 2001 From: Kapil Date: Tue, 28 Jun 2016 23:12:07 -0700 Subject: [PATCH 10/13] included the should component update changes --- src/BtLogoContainer/index.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/BtLogoContainer/index.js b/src/BtLogoContainer/index.js index f932764..0987a46 100644 --- a/src/BtLogoContainer/index.js +++ b/src/BtLogoContainer/index.js @@ -124,15 +124,15 @@ module.exports = React.createClass ({ } }, shouldComponentUpdate(nextProps, nextState){ - // if(!this.props.update){ - // return false; - // } - // if(this.props.id !== nextProps.id){ - // return true; - // } - // if(!shallowEqual(this.state.btLogoData, nextState.btLogoData)){ - // return true; - // } + if(!this.props.update){ + return false; + } + if(this.props.id !== nextProps.id){ + return true; + } + if(!shallowEqual(this.state.btLogoData, nextState.btLogoData)){ + return true; + } return true; } From 79d80bff4ca3653f73df4391ad5cff6c7a0ae372 Mon Sep 17 00:00:00 2001 From: Kapil Date: Thu, 30 Jun 2016 12:11:22 -0700 Subject: [PATCH 11/13] removed bt logo ocntainer --- src/BtLogoContainer/index.js | 139 ----------------------------------- src/index.js | 2 - 2 files changed, 141 deletions(-) delete mode 100644 src/BtLogoContainer/index.js diff --git a/src/BtLogoContainer/index.js b/src/BtLogoContainer/index.js deleted file mode 100644 index 0987a46..0000000 --- a/src/BtLogoContainer/index.js +++ /dev/null @@ -1,139 +0,0 @@ -'use strict'; - -import React from 'react'; - -import ReactNative, { - Text, - View -} from 'react-native'; - -import shallowEqual from 'shallowequal'; -import findIndex from 'lodash.findindex'; - -import { - getBtLogoByCompanyName, - btLogoQuery -} from 'react.force.data'; - -const subscribers = []; - -const subscribe = (comp)=>{ - subscribers.push(comp) -}; - -const unsubscribe = (comp) => { - const i = subscribers.indexOf(comp); - if(i != -1) { - subscribers.splice(i, 1); - } -}; - -const notify = (ids, records) => { - if(subscribers && subscribers.length){ - subscribers.forEach((subscriber)=>{ - if(subscriber && subscriber.props && subscriber.props.id){ - const searchId = subscriber.props.id; - const index = findIndex(ids, (id) => { - return id.indexOf(searchId)>-1; - }); - if(index>-1){ - const record = records[index]; - subscriber.updateBtData(record); - } - } - }); - } -}; - -btLogoQuery.addListener(notify); - - -module.exports = React.createClass ({ - getDefaultProps(){ - return { - type:null, - id:null, - refreshDate:new Date(), - update:true, - style:{} - }; - }, - childContextTypes: { - btLogoData: React.PropTypes.object, - doRefresh: React.PropTypes.func - }, - getInitialState(){ - return { - btLogoData:this.props.btLogoData?this.props.btLogoData:{Name:' ',attributes:{}}, - loading:false - }; - }, - getChildContext() { - return { - btLogoData: this.state.btLogoData, - doRefresh: this.handleRefresh - }; - }, - componentDidMount(){ - this.getInfo(); - subscribe(this); - }, - componentWillUnmount(){ - unsubscribe(this); - }, - handleRefresh(){ - console.log('>>> REFRESH !!!'); - this.getInfo(); - }, - updateBtData(btLogoData){ - this.setState({ - btLogoData:btLogoData, - }); - }, - handleDataLoad(){ - if(this.props.onData){ - this.props.onData({ - btLogoData:this.state.btLogoData - }); - } - }, - getInfo() { - this.setState({loading:true}); - if(!this.props.id){ - return; - } - getBtLogoByCompanyName(this.props.id) - .then((opts)=>{ - if(opts.cachedBtLogoData){ - this.setState({ - btLogoData: opts.cachedBtLogoData - }); - } - }); - }, - render() { - return ( - - {this.props.children} - - ) - }, - componentWillReceiveProps(newProps){ - if(this.props.refreshDate !== newProps.refreshDate){ - this.getInfo(); - } - }, - shouldComponentUpdate(nextProps, nextState){ - if(!this.props.update){ - return false; - } - if(this.props.id !== nextProps.id){ - return true; - } - if(!shallowEqual(this.state.btLogoData, nextState.btLogoData)){ - return true; - } - return true; - - } -}); diff --git a/src/index.js b/src/index.js index 02b8357..a8eb7d9 100644 --- a/src/index.js +++ b/src/index.js @@ -26,7 +26,6 @@ import SobjContainer from './SobjContainer'; import ChatterUserContainer from './ChatterUserContainer'; -import BtLogoContainer from './BtLogoContainer'; import ReportContainer from './ReportContainer'; import List from './List'; import RelevantItems from './RelevantItems'; @@ -42,6 +41,5 @@ module.exports = { RelevantItems: RelevantItems, ScrollRefresh: ScrollRefresh, utils: utils, - BtLogoContainer: BtLogoContainer, ReportContainer: ReportContainer }; From bc9d41f6ff1b99aa6903a57cbb66fb8776be17d7 Mon Sep 17 00:00:00 2001 From: Kapil Date: Thu, 30 Jun 2016 12:21:40 -0700 Subject: [PATCH 12/13] added refresh period prop --- src/ReportContainer/index.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/ReportContainer/index.js b/src/ReportContainer/index.js index 3830045..a54646e 100755 --- a/src/ReportContainer/index.js +++ b/src/ReportContainer/index.js @@ -58,7 +58,8 @@ module.exports = React.createClass ({ id:null, refreshDate:new Date(), update:true, - style:{} + style:{}, + refershPeriod: 600000 // default refresh period of 10 minutes }; }, childContextTypes: { @@ -122,9 +123,7 @@ module.exports = React.createClass ({ ) }, componentWillReceiveProps(newProps){ - //only refresh reportData every 10 minutes - if(this.props.refreshDate.getTime() <= newProps.refreshDate.getTime()-600000){ - debugger; + if(this.props.refreshDate.getTime() <= newProps.refreshDate.getTime()-(this.props.refreshPeriod*1000)){ this.getInfo(); } }, From df00ed4fd98f47b56ce7e509499cffc7fcbaf083 Mon Sep 17 00:00:00 2001 From: Kapil Date: Thu, 30 Jun 2016 12:23:11 -0700 Subject: [PATCH 13/13] fixed typo --- src/ReportContainer/index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/ReportContainer/index.js b/src/ReportContainer/index.js index a54646e..06591bc 100755 --- a/src/ReportContainer/index.js +++ b/src/ReportContainer/index.js @@ -1,4 +1,3 @@ - 'use strict'; import React from 'react'; @@ -59,7 +58,7 @@ module.exports = React.createClass ({ refreshDate:new Date(), update:true, style:{}, - refershPeriod: 600000 // default refresh period of 10 minutes + refreshPeriod: 600000 // default refresh period of 10 minutes, passed in as seconds }; }, childContextTypes: {