Skip to content
This repository was archived by the owner on Jan 19, 2024. It is now read-only.
5 changes: 0 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
139 changes: 139 additions & 0 deletions src/ChatterUserContainer/index.js
Original file line number Diff line number Diff line change
@@ -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 {
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;
});
if(index>-1){
const record = records[index];
subscriber.updateChatterData(record);
}
}
});
}
};

chatterQuery.addListener(notify);


module.exports = React.createClass ({
getDefaultProps(){
return {
type:null,
id:null,
refreshDate:new Date(),
update:true,
style:{}
};
},
childContextTypes: {
chatterData: React.PropTypes.object,
doRefresh: React.PropTypes.func
},
getInitialState(){
return {
chatterData:this.props.chatterData?this.props.chatterData:{Name:' ',attributes:{}},
loading:false
};
},
getChildContext() {
return {
chatterData: this.state.chatterData,
doRefresh: this.handleRefresh
};
},
componentDidMount(){
this.getInfo();
subscribe(this);
},
componentWillUnmount(){
unsubscribe(this);
},
handleRefresh(){
console.log('>>> REFRESH !!!');
this.getInfo();
},
updateChatterData(chatterData){
this.setState({
chatterData:chatterData,
});
},
handleDataLoad(){
if(this.props.onData){
this.props.onData({
chatterData:this.state.chatterData
});
}
},
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.cachedChatterData
});
}
});
},

render() {
return (
<View style={this.props.style}>
{this.props.children}
</View>
)
},
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.chatterData, nextState.chatterData)){
return true;
}
return false;
}
});
4 changes: 3 additions & 1 deletion src/List/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@

'use strict';

import React, {
import React from 'react';

import ReactNative, {
Text,
View,
ListView
Expand Down
4 changes: 3 additions & 1 deletion src/RelevantItems/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@

'use strict';

import React, {
import React from 'react';

import ReactNative, {
View,
ListView
} from 'react-native';
Expand Down
145 changes: 145 additions & 0 deletions src/ReportContainer/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
'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:{},
refreshPeriod: 600000 // default refresh period of 10 minutes, passed in as seconds
};
},
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 (
<View style={this.props.style}>
{this.props.children}
</View>
)
},
componentWillReceiveProps(newProps){
if(this.props.refreshDate.getTime() <= newProps.refreshDate.getTime()-(this.props.refreshPeriod*1000)){
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;
}
});
6 changes: 5 additions & 1 deletion src/ScrollRefresh/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@

'use strict';

import React, {
import React from 'react';

import ReactNative, {
View,
ScrollView,
RefreshControl
Expand Down Expand Up @@ -68,7 +70,9 @@ module.exports = React.createClass ({
/>
}
>
<View>
{this.props.children}
</View>
</ScrollView>
)
},
Expand Down
4 changes: 3 additions & 1 deletion src/SobjContainer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@

'use strict';

import React, {
import React from 'react';

import ReactNative, {
Text,
View
} from 'react-native';
Expand Down
10 changes: 7 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,23 @@
* 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 ReportContainer from './ReportContainer';
import List from './List';
import RelevantItems from './RelevantItems';
import ScrollRefresh from './ScrollRefresh';
import {utils} from 'react.force.data';

module.exports = {
SobjContainer: SobjContainer,
ChatterUserContainer: ChatterUserContainer,
Sobj: SobjContainer,
ListContainer: List,
List: List,
RelevantItems: RelevantItems,
ScrollRefresh: ScrollRefresh,
utils: utils
};
utils: utils,
ReportContainer: ReportContainer
};