Navigation Menu

Skip to content

Commit

Permalink
Implemented the logic to allow the user to edit individual item capti…
Browse files Browse the repository at this point in the history
…ons by clicking the 'Edit item...' button.
  • Loading branch information
maratbn committed Aug 5, 2018
1 parent 894c565 commit 5871aa5
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion webpack_in/entry.jsx
Expand Up @@ -107,6 +107,17 @@ class ListWidget extends React.Component {
total_added: state.total_added + 1
});

this._mutateStateToUpdateItemCaption = (state, id, strCaptionNew) => ({
...state,
items: state.items.map(objItem => (
objItem.id === id ? {
...objItem,
caption: strCaptionNew
}
: objItem
))
});

this._mutateStateToUpdateItemChecked = (state, id, isChecked) => ({
...state,
items: state.items.map(objItem => (
Expand Down Expand Up @@ -168,7 +179,20 @@ class ListWidget extends React.Component {
strItemNew));
}}/>
<ButtonWidget caption="Edit item..."
isDisabled={ arrItemsSelected.length !== 1 }/>
isDisabled={ arrItemsSelected.length !== 1 }
onClick={() => {
const objItemEdit = arrItemsSelected[0];
const strItemEdited = prompt("Please edit item:",
objItemEdit.caption);
if (strItemEdited === null) {
return;
}

this.setState(this._mutateStateToUpdateItemCaption(
this.state,
objItemEdit.id,
strItemEdited));
}}/>
<ButtonWidget caption={ arrItemsSelected.length > 1 ? "Remove items..."
: "Remove item..." }
isDisabled={ arrItemsSelected.length === 0 }/>
Expand Down

0 comments on commit 5871aa5

Please sign in to comment.