diff --git a/embark-ui/src/actions/index.js b/embark-ui/src/actions/index.js index 720d943e7..acce3ca22 100644 --- a/embark-ui/src/actions/index.js +++ b/embark-ui/src/actions/index.js @@ -106,6 +106,15 @@ export const commands = { failure: (error) => action(COMMANDS[FAILURE], {error}) }; +export const COMMAND_SUGGESTIONS = createRequestTypes('COMMAND_SUGGESTIONS'); +export const command_suggestions = { + post: (command) => action(COMMAND_SUGGESTIONS[REQUEST], {command}), + success: (command, payload) => { + return action(COMMAND_SUGGESTIONS[SUCCESS], {command_suggestions: command.result }) + }, + failure: (error) => action(COMMAND_SUGGESTIONS[FAILURE], {error}) +}; + export const PROCESS_LOGS = createRequestTypes('PROCESS_LOGS'); export const processLogs = { request: (processName, limit) => { diff --git a/embark-ui/src/components/Console.js b/embark-ui/src/components/Console.js index a5b6ffc4b..ba1af26d9 100644 --- a/embark-ui/src/components/Console.js +++ b/embark-ui/src/components/Console.js @@ -112,7 +112,11 @@ class Console extends Component { } }} onSearch={(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("searching for " + 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']} maxHeight="200px" @@ -138,8 +142,10 @@ class Console extends Component { Console.propTypes = { postCommand: PropTypes.func, + postCommandSuggestions: PropTypes.func, isEmbark: PropTypes.func, processes: PropTypes.arrayOf(PropTypes.object).isRequired, + command_suggestions: PropTypes.arrayOf(PropTypes.object), processLogs: PropTypes.arrayOf(PropTypes.object).isRequired, updateTab: PropTypes.func }; diff --git a/embark-ui/src/containers/HomeContainer.js b/embark-ui/src/containers/HomeContainer.js index d5317901d..5faa5b3de 100644 --- a/embark-ui/src/containers/HomeContainer.js +++ b/embark-ui/src/containers/HomeContainer.js @@ -5,6 +5,7 @@ import {connect} from 'react-redux'; import { contracts as contractsAction, commands as commandsAction, + command_suggestions as commandSuggestionsAction, listenToProcessLogs, processLogs as processLogsAction, stopProcessLogs @@ -15,7 +16,7 @@ import Processes from '../components/Processes'; import Console from '../components/Console'; import {EMBARK_PROCESS_NAME, LOG_LIMIT} from '../constants'; import ContractsList from '../components/ContractsList'; -import {getContracts, getProcesses, getProcessLogs} from "../reducers/selectors"; +import {getContracts, getProcesses, getProcessLogs, getCommandSuggestions} from "../reducers/selectors"; class HomeContainer extends Component { constructor(props) { @@ -62,11 +63,13 @@ class HomeContainer extends Component { )} /> - 0 } {...this.props} render={({processes, postCommand, processLogs}) => ( + 0 } {...this.props} render={({processes, postCommand, postCommandSuggestions, processLogs, command_suggestions}) => ( this.isEmbark} updateTab={processName => this.updateTab(processName)} /> )} /> @@ -78,6 +81,7 @@ class HomeContainer extends Component { HomeContainer.propTypes = { processes: PropTypes.arrayOf(PropTypes.object), postCommand: PropTypes.func, + postCommandSuggestions: PropTypes.func, error: PropTypes.string, loading: PropTypes.bool }; @@ -88,6 +92,7 @@ function mapStateToProps(state) { contracts: getContracts(state), error: state.errorMessage, processLogs: getProcessLogs(state), + command_suggestions: getCommandSuggestions(state), loading: state.loading }; } @@ -96,6 +101,7 @@ export default connect( mapStateToProps, { postCommand: commandsAction.post, + postCommandSuggestions: commandSuggestionsAction.post, fetchProcessLogs: processLogsAction.request, fetchContracts: contractsAction.request, listenToProcessLogs, diff --git a/embark-ui/src/reducers/index.js b/embark-ui/src/reducers/index.js index 913491137..fdae3e833 100644 --- a/embark-ui/src/reducers/index.js +++ b/embark-ui/src/reducers/index.js @@ -14,6 +14,7 @@ const entitiesDefaultState = { transactions: [], processes: [], processLogs: [], + command_suggestions: [], contracts: [], contractProfiles: [], contractFunctions: [], @@ -81,6 +82,11 @@ const filtrer = { contracts: function(contract, index, self) { return index === self.findIndex((t) => t.className === contract.className); }, + command_suggestions: function(command, index, self) { + return index === self.findIndex((f) => ( + command.value === f.value + )); + }, accounts: function(account, index, self) { return index === self.findIndex((t) => t.address === account.address); }, diff --git a/embark-ui/src/reducers/selectors.js b/embark-ui/src/reducers/selectors.js index 29f0d5213..2cce34464 100644 --- a/embark-ui/src/reducers/selectors.js +++ b/embark-ui/src/reducers/selectors.js @@ -52,6 +52,10 @@ export function getProcessLogs(state) { return state.entities.processLogs; } +export function getCommandSuggestions(state) { + return state.entities.command_suggestions; +} + export function getContractLogsByContract(state, contractName) { return state.entities.contractLogs.filter((contractLog => contractLog.name === contractName)); } @@ -159,4 +163,4 @@ export function getCurrentFile(state) { export function getBaseEther(state) { return state.baseEther; -} \ No newline at end of file +} diff --git a/embark-ui/src/sagas/index.js b/embark-ui/src/sagas/index.js index fea051dfe..59a250122 100644 --- a/embark-ui/src/sagas/index.js +++ b/embark-ui/src/sagas/index.js @@ -2,7 +2,7 @@ import * as actions from '../actions'; import * as api from '../services/api'; import * as storage from '../services/storage'; import {eventChannel} from 'redux-saga'; -import {all, call, fork, put, takeEvery, take, select, race} from 'redux-saga/effects'; +import {all, call, fork, put, takeLatest, takeEvery, take, select, race} from 'redux-saga/effects'; import {getCredentials} from '../reducers/selectors'; function *doRequest(entity, serviceFn, payload) { @@ -25,6 +25,7 @@ export const fetchBlocks = doRequest.bind(null, actions.blocks, api.fetchBlocks) export const fetchTransactions = doRequest.bind(null, actions.transactions, api.fetchTransactions); export const fetchProcesses = doRequest.bind(null, actions.processes, api.fetchProcesses); export const postCommand = doRequest.bind(null, actions.commands, api.postCommand); +export const postCommandSuggestions = doRequest.bind(null, actions.command_suggestions, api.postCommandSuggestions); export const fetchProcessLogs = doRequest.bind(null, actions.processLogs, api.fetchProcessLogs); export const fetchContractLogs = doRequest.bind(null, actions.contractLogs, api.fetchContractLogs); export const fetchContracts = doRequest.bind(null, actions.contracts, api.fetchContracts); @@ -83,6 +84,10 @@ export function *watchPostCommand() { yield takeEvery(actions.COMMANDS[actions.REQUEST], postCommand); } +export function *watchPostCommandSuggestions() { + yield takeLatest(actions.COMMAND_SUGGESTIONS[actions.REQUEST], postCommandSuggestions); +} + export function *watchFetchProcessLogs() { yield takeEvery(actions.PROCESS_LOGS[actions.REQUEST], fetchProcessLogs); } @@ -308,6 +313,7 @@ export default function *root() { fork(watchFetchBlock), fork(watchFetchTransactions), fork(watchPostCommand), + fork(watchPostCommandSuggestions), fork(watchFetchVersions), fork(watchFetchPlugins), fork(watchFetchBlocks), diff --git a/embark-ui/src/services/api.js b/embark-ui/src/services/api.js index 1f99e8552..4c6e510e5 100644 --- a/embark-ui/src/services/api.js +++ b/embark-ui/src/services/api.js @@ -27,6 +27,10 @@ export function postCommand() { return post('/command', ...arguments); } +export function postCommandSuggestions() { + return post('/suggestions', ...arguments); +} + export function fetchAccounts() { return get('/blockchain/accounts', ...arguments); } diff --git a/lib/modules/console/index.js b/lib/modules/console/index.js index 9c97f22cd..961673332 100644 --- a/lib/modules/console/index.js +++ b/lib/modules/console/index.js @@ -4,10 +4,11 @@ const EmbarkJS = require('embarkjs'); const IpfsApi = require('ipfs-api'); const Web3 = require('web3'); const stringify = require('json-stringify-safe'); +const Suggestions = require('./suggestions') class Console { - constructor(_embark, options) { - this.embark = _embark; + constructor(embark, options) { + this.embark = embark; this.events = options.events; this.plugins = options.plugins; this.version = options.version; @@ -26,6 +27,8 @@ class Console { this.registerEmbarkJs(); this.registerConsoleCommands(); this.registerApi(); + + this.suggestions = new Suggestions(embark, options); } registerApi() { diff --git a/lib/modules/console/suggestions.js b/lib/modules/console/suggestions.js new file mode 100644 index 000000000..d7b734775 --- /dev/null +++ b/lib/modules/console/suggestions.js @@ -0,0 +1,23 @@ +let utils = require('../../utils/utils'); + +class Suggestions { + constructor(_embark, options) { + this.plugins = options.plugins; + this.registerApi(); + } + + registerApi() { + let plugin = this.plugins.createPlugin('consoleApi', {}); + plugin.registerAPICall('post', '/embark-api/suggestions', (req, res) => { + let suggestions = this.getSuggestions(req.body.command) + res.send({result: suggestions}) + }); + } + + getSuggestions(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"}] + } +} + +module.exports = Suggestions;