fix options update; add sorting

This commit is contained in:
Iuri Matias 2018-10-13 23:27:20 -04:00 committed by Pascal Precht
parent ce19fd96c4
commit 1906b17c5d
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
3 changed files with 21 additions and 7 deletions

View File

@ -112,16 +112,12 @@ class Console extends Component {
} }
}} }}
onSearch={(value) => { onSearch={(value) => {
console.dir("searching for " + value);
this.props.postCommandSuggestions(value) this.props.postCommandSuggestions(value)
// this.setState({ isLoading: false, options: [{value: 'hello', command_type: "embark", description: "says hello back!"}, {value: 'SimpleStorage', command_type: "web3 object", description: ""}, {value: 'web3.eth.getAccounts', command_type: "web3", description: "get list of accounts"}] })
console.dir(this.props.command_suggestions)
this.setState({ isLoading: false, options: this.props.command_suggestions })
}} }}
filterBy={['value', 'description']} filterBy={['value', 'description']}
maxHeight="200px" maxHeight="200px"
placeholder="Type a command (e.g help)" placeholder="Type a command (e.g help)"
options={this.state.options} options={this.props.command_suggestions}
placeholder="Choose a state..." placeholder="Choose a state..."
renderMenuItemChildren={(option) => ( renderMenuItemChildren={(option) => (
<div> <div>

View File

@ -43,6 +43,17 @@ const sorter = {
if (b.name === EMBARK_PROCESS_NAME) return 1; if (b.name === EMBARK_PROCESS_NAME) return 1;
return 0; return 0;
}, },
command_suggestions: function(a, b) {
if (a.value.indexOf('.').length > 0) {
let a_levels = a.value.split('.').length
let b_levels = b.value.split('.').length
let diff = b_levels - a_levels
if (diff !== 0) return lengthDiff * -1
}
let lengthDiff = b.value.length - a.value.length;
if (lengthDiff !== 0) return lengthDiff * -1
return 0;
},
processLogs: function(a, b) { processLogs: function(a, b) {
if (a.name !== b.name) { if (a.name !== b.name) {
if(a.name < b.name) return -1; if(a.name < b.name) return -1;
@ -83,8 +94,8 @@ const filtrer = {
return index === self.findIndex((t) => t.className === contract.className); return index === self.findIndex((t) => t.className === contract.className);
}, },
command_suggestions: function(command, index, self) { command_suggestions: function(command, index, self) {
return index === self.findIndex((f) => ( return index === self.findIndex((c) => (
command.value === f.value command.value === c.value
)); ));
}, },
accounts: function(account, index, self) { accounts: function(account, index, self) {

View File

@ -15,6 +15,13 @@ class Suggestions {
} }
getSuggestions(cmd) { getSuggestions(cmd) {
if (cmd === 'web3') {
return [
{value: 'web3.eth', command_type: "web3 object", description: "ethereum"},
{value: 'web3.net', command_type: "web3 object", description: "network"},
{value: 'web3.shh', command_type: "web3 object", description: "whisper"}
]
}
console.dir("printing suggestions for " + cmd); console.dir("printing suggestions for " + cmd);
return [{value: 'hello', command_type: "embark", description: "says hello back!"}, {value: 'SimpleStorage', command_type: "web3 object", description: ""}, {value: 'web3.eth.getAccounts', command_type: "web3", description: "get list of accounts"}] return [{value: 'hello', command_type: "embark", description: "says hello back!"}, {value: 'SimpleStorage', command_type: "web3 object", description: ""}, {value: 'web3.eth.getAccounts', command_type: "web3", description: "get list of accounts"}]
} }