Skip to content
This repository has been archived by the owner on Dec 13, 2020. It is now read-only.

Commit

Permalink
Lookup debugging (wip) #2
Browse files Browse the repository at this point in the history
  • Loading branch information
damianprzygodzki committed Nov 7, 2016
1 parent ebe40ea commit fbdbeac
Showing 1 changed file with 22 additions and 24 deletions.
46 changes: 22 additions & 24 deletions src/components/widget/Lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Lookup extends Component {
selected: null,
model: null,
property: "",
properties: {},
properts: {},
loading: false,
propertiesCopy: getItemsByProperty(this.props.properties, "source", "list"),
mainProperty: getItemsByProperty(this.props.properties, "source", "lookup"),
Expand Down Expand Up @@ -61,7 +61,7 @@ class Lookup extends Component {
} = this.props;

const {
mainProperty, propertiesCopy
mainProperty, propertiesCopy, property
} = this.state;

// removing selection
Expand All @@ -79,12 +79,11 @@ class Lookup extends Component {
} else {
// handling selection when main is not set or set.

if(this.state.property === "") {
if(property === "") {

const promise = onChange(mainProperty[0].field, select);

promise && promise.then(() => {
console.log(select)
this.inputSearch.value = select[Object.keys(select)[0]];
// call for more properties
if(propertiesCopy.length > 0){
Expand All @@ -94,15 +93,14 @@ class Lookup extends Component {
);

Promise.all(batchArray).then(props => {
const newProps = [];
const newProps = {};
props.map((prop, index) => {
newProps[propertiesCopy[index].field] = prop.data.values;
});

console.log(newProps)

this.setState(Object.assign({}, this.state, {
properties: newProps,
properts: newProps,
model: select
}), () => {
this.generatingPropsSelection();
Expand All @@ -113,18 +111,16 @@ class Lookup extends Component {
}
})
} else {
onChange(this.state.property, select);
this.setState(
update(this.state, {
properties: {$apply: item => {
delete item[this.state.property];
return item;
}}
}),
() => {
this.generatingPropsSelection();
}
);
onChange(property, select);

this.setState(update(this.state, {
properts: {$apply: item => {
delete item[this.state.property];
return item;
}}
}), () => {
this.generatingPropsSelection();
});
}

}
Expand All @@ -134,8 +130,9 @@ class Lookup extends Component {

generatingPropsSelection = () => {
const {dispatch, onChange} = this.props;
const {properties} = this.state;
const propertiesKeys = Object.keys(properties);
const {properts} = this.state;
const propertiesKeys = Object.keys(properts);


// Chcecking properties model if there is some
// unselected properties and handling further
Expand All @@ -150,10 +147,11 @@ class Lookup extends Component {
}

for(let i=0; i < propertiesKeys.length; i++){
if(properties[propertiesKeys[i]].length > 1){

if(properts[propertiesKeys[i]].length > 1){
// Generating list of props choice
this.setState(Object.assign({}, this.state, {
list: properties[propertiesKeys[i]],
list: properts[propertiesKeys[i]],
property: propertiesKeys[i]
}));
break;
Expand Down Expand Up @@ -222,7 +220,7 @@ class Lookup extends Component {
this.inputSearch.value = "";

properties.map(item => {
onChange(item.field, "");
onChange(item.field, null);
})

this.setState(Object.assign({}, this.state, {
Expand Down

0 comments on commit fbdbeac

Please sign in to comment.