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

Commit

Permalink
lookup dropdowns - work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
Dunkat committed May 9, 2017
1 parent 7dfe8b4 commit 1ddc620
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 44 deletions.
5 changes: 2 additions & 3 deletions src/components/widget/List/List.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ class List extends Component {
}

handleSelect = (option) => {
const {onChange, lookupList, properties} = this.props;
const {onChange, lookupList, properties, setNextProperty, mainProperty} = this.props;

if(lookupList){
onChange(properties[0].field, option);
this.setState({
selectedItem: option
});
setNextProperty(mainProperty[0].field);
} else {
onChange(option);
}
Expand All @@ -61,8 +62,6 @@ class List extends Component {
} = this.props;
const {list, loading, selectedItem} = this.state;



return (
<RawList
list={list}
Expand Down
9 changes: 5 additions & 4 deletions src/components/widget/List/RawList.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ class RawList extends Component {
componentDidMount = () => {
const {autofocus} = this.props;

// console.log(autofocus);


(this.dropdown && autofocus) && this.dropdown.focus();
}

componentDidUpdate = prevProps => {
const { list, mandatory, defaultValue } = this.props;
const { list, mandatory, defaultValue, autofocus } = this.props;

// console.log(defaultValue);
(this.dropdown && autofocus) && this.dropdown.focus();

if(prevProps.defaultValue != defaultValue){
this.dropdown && this.dropdown.focus();
Expand Down Expand Up @@ -110,9 +110,10 @@ class RawList extends Component {
}

handleBlur = () => {
console.log('handleBlur');
const { selected, doNotOpenOnFocus } = this.props;

!doNotOpenOnFocus && this.dropdown.blur();
!doNotOpenOnFocus && this.dropdown && this.dropdown.blur();
this.setState({
isOpen: false,
selected: selected || 0
Expand Down
93 changes: 60 additions & 33 deletions src/components/widget/Lookup/Lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Lookup extends Component {
isInputEmpty: true,
propertiesCopy: getItemsByProperty(properties, 'source', 'list'),
showNextDropdown: false,
property: properties[0].field
property: ''
}

// console.log(this.state.propertiesCopy);
Expand All @@ -40,6 +40,7 @@ class Lookup extends Component {
const {defaultValue, properties} = this.props;
console.log('defaultValue component did mount');
console.log(defaultValue);
console.log(properties);

// this.setState({
// property: properties[0].field
Expand All @@ -52,20 +53,22 @@ class Lookup extends Component {
const {defaultValue, properties} = this.props;
const {property} = this.state;


if(JSON.stringify(prevProps.defaultValue)!==JSON.stringify(defaultValue)){

defaultValue.map((item, index)=>{
const prevIndex = index-1;
if(prevIndex>-1 && defaultValue[prevIndex].field === property){
console.log(properties[index].field);
this.setState({
property: properties[index].field
})
}
// console.log('property');
// console.log(property);

// if(JSON.stringify(prevProps.defaultValue)!==JSON.stringify(defaultValue)){

// defaultValue.map((item, index)=>{
// const prevIndex = index-1;
// if(prevIndex>-1 && defaultValue[prevIndex].field === property){
// console.log(properties[index].field);
// this.setState({
// property: properties[index].field
// })
// }

})
}
// })
// }
// console.log('defaultValue');
// console.log(defaultValue);

Expand All @@ -79,19 +82,39 @@ class Lookup extends Component {
})
}

getNextDropdown=(state)=> {
this.setState({
showNextDropdown: state
});
}
// getNextDropdown=(state)=> {
// this.setState({
// showNextDropdown: state
// });
// }

setProperty = (property)=> {
const {defaultValue} = this.props;
console.log('setProperty');
setNextProperty = (property)=> {
const {defaultValue, properties} = this.props;
console.log('setNextProperty');
console.log(property);
this.setState({
property: property
});
// property && this.setState({
// property: property
// });


defaultValue.map((item, index)=>{
const nextIndex = index+1;
if(nextIndex<defaultValue.length && defaultValue[index].field === property){
console.log(properties[nextIndex].field);
this.setState({
property: properties[nextIndex].field
})
return;
} else if(defaultValue[defaultValue.length-1].field === property){
console.log('else-----------------------------');
this.setState({
property: ''
})
}

})


}

checkIfDefaultValue = () => {
Expand Down Expand Up @@ -134,8 +157,9 @@ class Lookup extends Component {
onChange(properties, null, false);
this.setState({
isInputEmpty: true,
property: properties[0].field
});
property: properties[0].field,
property: ''
});
}

render() {
Expand All @@ -146,7 +170,7 @@ class Lookup extends Component {
subentity, subentityId, viewId
} = this.props;

const {isInputEmpty, showNextDropdown} = this.state;
const {isInputEmpty, property} = this.state;

return (
<div
Expand Down Expand Up @@ -198,8 +222,7 @@ class Lookup extends Component {
onChange={onChange}
item={item}
handleInputEmptyStatus={this.handleInputEmptyStatus}
getNextDropdown={this.getNextDropdown}
setProperty={this.setProperty}
setNextProperty={this.setNextProperty}
/>

} else if (item.source === 'list') {
Expand All @@ -208,8 +231,10 @@ class Lookup extends Component {
defaultValue, 'field', item.field
)[0].value;

{/*console.log(objectValue);*/}
{/*console.log(showNextDropdown);*/}
{/*console.log('----');
console.log(item.field);
console.log(property);*/}


return <div className="raw-lookup-wrapper raw-lookup-wrapper-bcg" key={index}>
<List
Expand All @@ -225,9 +250,11 @@ class Lookup extends Component {
viewId={viewId}
onChange={onChange}
lookupList={true}
autofocus={!objectValue && showNextDropdown ? true : false}
autofocus={item.field == property ? true : false}
defaultValue={objectValue[Object.keys(objectValue)[0]]}
isInputEmpty={isInputEmpty}
setNextProperty={this.setNextProperty}
mainProperty={[item]}
/>
</div>
}
Expand Down
7 changes: 3 additions & 4 deletions src/components/widget/Lookup/RawLookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class RawLookup extends Component {
handleSelect = (select) => {
const {
onChange, filterWidget, parameterName, subentity, handleInputEmptyStatus, mainProperty,
getNextDropdown, setProperty
getNextDropdown, setNextProperty
} = this.props;

this.setState({
Expand All @@ -74,7 +74,6 @@ class RawLookup extends Component {

this.inputSearch.value = select[Object.keys(select)[0]];
handleInputEmptyStatus(false);
getNextDropdown(true);

this.handleBlur();
} else {
Expand All @@ -87,8 +86,8 @@ class RawLookup extends Component {

this.inputSearch.value = select[Object.keys(select)[0]];
handleInputEmptyStatus(false);
getNextDropdown(true);
setProperty(mainProperty[0].field);
// getNextDropdown(true);
setNextProperty(mainProperty[0].field);

this.handleBlur();

Expand Down

0 comments on commit 1ddc620

Please sign in to comment.