Skip to content

Commit

Permalink
feat: support to duplicate favorites
Browse files Browse the repository at this point in the history
Close #30
  • Loading branch information
luin committed Dec 3, 2016
1 parent bd9d1c9 commit c2bc438
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
17 changes: 17 additions & 0 deletions client/components/main/Main/ConnectionSelector/Config.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ class Config extends React.Component {
this.setProp(property, value);
}

duplicate() {
if (this.props.favorite) {
const data = Object.assign(this.props.favorite.toJS(), this.state.data.toJS());
delete data.key;
this.props.onDuplicate(data);
} else {
const data = this.state.data.toJS();
data.name = 'Quick Connect'
this.props.onDuplicate(data);
}
}

save() {
if (this.props.favorite && this.state.changed) {
this.props.onSave(this.state.data.toJS());
Expand Down Expand Up @@ -141,6 +153,11 @@ class Config extends React.Component {
</div>
</div>
<div className="nt-button-group nt-button-group--pull-right" style={ { width: 500, margin: '10px auto 0' } }>
<button className="nt-button" style={
{ float: 'left' }
} onClick={() => {
this.duplicate();
}}>{ this.props.favorite ? 'Duplicate' : 'Add to Favorite' }</button>
<button className="nt-button" style={ { display: this.state.changed ? 'inline-block' : 'none' } } onClick={() => {
this.save();
}}>Save Changes</button>
Expand Down
3 changes: 3 additions & 0 deletions client/components/main/Main/ConnectionSelector/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class ConnectionSelector extends React.Component {
onSave={(data) => {
store.dispatch(actions('updateFavorite', { key: selectedFavorite.get('key'), data }));
}}
onDuplicate={(data) => {
store.dispatch(actions('addFavorite', data, () => {}));
}}
/>
</div>
</div>;
Expand Down

0 comments on commit c2bc438

Please sign in to comment.