intiial code to get suggestions from embark

This commit is contained in:
Iuri Matias 2018-10-13 19:12:35 -04:00 committed by Pascal Precht
parent b2ef42df32
commit ce19fd96c4
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
9 changed files with 74 additions and 7 deletions

View File

@ -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) => {

View File

@ -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
};

View File

@ -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 {
</div>
)} />
<DataWrapper shouldRender={this.props.processes.length > 0 } {...this.props} render={({processes, postCommand, processLogs}) => (
<DataWrapper shouldRender={this.props.processes.length > 0 } {...this.props} render={({processes, postCommand, postCommandSuggestions, processLogs, command_suggestions}) => (
<Console activeProcess={this.state.activeProcess}
postCommand={postCommand}
postCommandSuggestions={postCommandSuggestions}
processes={processes}
processLogs={processLogs}
command_suggestions={command_suggestions}
isEmbark={() => 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,

View File

@ -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);
},

View File

@ -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;
}
}

View File

@ -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),

View File

@ -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);
}

View File

@ -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() {

View File

@ -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;