The changes are persisted to localstorage, so they cannot be restored on a new computer, but for right now it's a nice organizational feature.feature/default_network_editable
parent
24fc5f9ea3
commit
95a3cfe3fc
@ -0,0 +1,36 @@ |
||||
var jsdom = require('mocha-jsdom') |
||||
var assert = require('assert') |
||||
var freeze = require('deep-freeze-strict') |
||||
var path = require('path') |
||||
|
||||
var actions = require(path.join(__dirname, '..', '..', '..', 'ui', 'app', 'actions.js')) |
||||
var reducers = require(path.join(__dirname, '..', '..', '..', 'ui', 'app', 'reducers.js')) |
||||
|
||||
describe('SAVE_ACCOUNT_LABEL', function() { |
||||
|
||||
it('updates the state.metamask.identities[:i].name property of the state to the action.value.label', function() { |
||||
var initialState = { |
||||
metamask: { |
||||
identities: { |
||||
foo: { |
||||
name: 'bar' |
||||
} |
||||
}, |
||||
} |
||||
} |
||||
freeze(initialState) |
||||
|
||||
const action = { |
||||
type: actions.SAVE_ACCOUNT_LABEL, |
||||
value: { |
||||
account: 'foo', |
||||
label: 'baz' |
||||
}, |
||||
} |
||||
freeze(action) |
||||
|
||||
var resultingState = reducers(initialState, action) |
||||
assert.equal(resultingState.metamask.identities.foo.name, action.value.label) |
||||
}); |
||||
}); |
||||
|
@ -0,0 +1,52 @@ |
||||
const Component = require('react').Component |
||||
const h = require('react-hyperscript') |
||||
const inherits = require('util').inherits |
||||
const findDOMNode = require('react-dom').findDOMNode |
||||
|
||||
module.exports = EditableLabel |
||||
|
||||
|
||||
inherits(EditableLabel, Component) |
||||
function EditableLabel() { |
||||
Component.call(this) |
||||
} |
||||
|
||||
EditableLabel.prototype.render = function() { |
||||
const props = this.props |
||||
let state = this.state |
||||
|
||||
if (state && state.isEditingLabel) { |
||||
|
||||
return h('div.editable-label', [ |
||||
h('input', { |
||||
defaultValue: props.textValue, |
||||
onKeyPress:(event) => { |
||||
this.saveIfEnter(event) |
||||
}, |
||||
}), |
||||
h('button', { |
||||
onClick:() => this.saveText(), |
||||
}, 'Save') |
||||
]) |
||||
|
||||
} else { |
||||
return h('div', { |
||||
onClick:(event) => { |
||||
this.setState({ isEditingLabel: true }) |
||||
}, |
||||
}, this.props.children) |
||||
} |
||||
} |
||||
|
||||
EditableLabel.prototype.saveIfEnter = function(event) { |
||||
if (event.key === 'Enter') { |
||||
this.saveText() |
||||
} |
||||
} |
||||
|
||||
EditableLabel.prototype.saveText = function() { |
||||
var container = findDOMNode(this) |
||||
var text = container.querySelector('.editable-label input').value |
||||
this.props.saveText(text) |
||||
this.setState({ isEditingLabel: false, textLabel: text }) |
||||
} |
Loading…
Reference in new issue