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

Commit

Permalink
Add cache value for List widget #600
Browse files Browse the repository at this point in the history
  • Loading branch information
Dunkat committed May 24, 2017
1 parent 60b8437 commit 5d697c3
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 70 deletions.
13 changes: 1 addition & 12 deletions src/actions/GenericActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,7 @@ export function patchRequest(

if (docId === 'NEW') {
payload = [];
}
// else if (Array.isArray(property) && Array.isArray(value)) {
// property.map((item, index) => {
// payload.push({
// 'op': 'replace',
// 'path': item.field,
// 'value': value[index]
// });
// });
// } //needed to send more than one value

else if (Array.isArray(property) && value !== undefined) {
} else if (Array.isArray(property) && value !== undefined) {
property.map(item => {
payload.push({
'op': 'replace',
Expand Down
2 changes: 1 addition & 1 deletion src/components/widget/Checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Checkbox extends Component {
/>
<div className="input-checkbox-tick" />
</label>
{(filterWidget && !disabled && !widgetData[0].readonly &&
{(filterWidget && !disabled && !widgetData[0].readonly &&
widgetData[0].value !== '') ?
<span className="input-icon-checkbox input-icon-lg">
<i
Expand Down
49 changes: 23 additions & 26 deletions src/components/widget/List/List.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,18 @@ class List extends Component {
this.state = {
list: [],
loading: false,
selectedItem: ''
selectedItem: '',
prevValue: ''
}
}

componentDidMount(){
const {defaultValue} = this.props;

if(defaultValue) {
this.setState({
prevValue: defaultValue
});
}
}

Expand Down Expand Up @@ -42,34 +53,20 @@ class List extends Component {

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

if(lookupList){
// if(children.length > 0) {
// let dataToChange = [];
// const valuesToSet = [];

// dataToChange.push(mainProperty[0]);
// valuesToSet.push(option);

// children.map(item=>{
// dataToChange.push(item);
// valuesToSet.push(null);
// });

// onChange(dataToChange, valuesToSet);
// } else {
// onChange(properties[0].field, option);
// }

onChange(properties[0].field, option);

this.setState({
selectedItem: option
});
setNextProperty(mainProperty[0].field);
if( prevValue !== option[Object.keys(option)[0]] ) {
onChange(properties[0].field, option);

this.setState({
selectedItem: option,
prevValue: option[Object.keys(option)[0]]
});
setNextProperty(mainProperty[0].field);
}
} else {
onChange(option);
}
Expand Down
6 changes: 0 additions & 6 deletions src/components/widget/List/RawList.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ class RawList extends Component {
*/
handleClick = (e) => {
const {lookupList} = this.props;

if(!lookupList){
e.preventDefault();
const {onFocus, doNotOpenOnFocus} = this.props;
Expand All @@ -147,10 +146,6 @@ class RawList extends Component {
isOpen: true
})
}




}

handleFocus = (e) => {
Expand All @@ -165,7 +160,6 @@ class RawList extends Component {
isOpen: true
})
}

}

handleChange = (e) => {
Expand Down
8 changes: 1 addition & 7 deletions src/components/widget/Lookup/Lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,6 @@ class Lookup extends Component {
properties && properties.map((item, index) => {
const disabled = isInputEmpty && index != 0;

//children to remove
const children = properties.slice(
index+1, properties.length
);

if(item.source === 'lookup'){
return <RawLookup
key={index}
Expand All @@ -153,7 +148,7 @@ class Lookup extends Component {
windowType, parameterName, entity, dataId,
isModal, recent, rank, updated, filterWidget,
mandatory, validStatus, align, onChange, item,
disabled, children, fireClickOutside}}
disabled, fireClickOutside}}
/>

} else if (item.source === 'list') {
Expand Down Expand Up @@ -196,7 +191,6 @@ class Lookup extends Component {
mainProperty={[item]}
blur={!property?true:false}
readonly={disabled}
children={children}
/>
</div>
}
Expand Down
19 changes: 1 addition & 18 deletions src/components/widget/Lookup/RawLookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,29 +72,12 @@ class RawLookup extends Component {

handleSelect = (select) => {
const {
onChange, handleInputEmptyStatus, mainProperty, setNextProperty,
children, properties
onChange, handleInputEmptyStatus, mainProperty, setNextProperty
} = this.props;

this.setState({
selected: null
}, () => {
// if(children.length > 0) {
// let dataToChange = [];
// const valuesToSet = [];

// dataToChange.push(mainProperty[0]);
// valuesToSet.push(select);

// children.map(item=>{
// dataToChange.push(item);
// valuesToSet.push(null);
// });

// onChange(dataToChange, valuesToSet);
// } else {
// onChange(properties[0].field, select);
// }

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

Expand Down

0 comments on commit 5d697c3

Please sign in to comment.