mirror of https://github.com/embarklabs/embark.git
intiial code to get suggestions from embark
This commit is contained in:
parent
b2ef42df32
commit
ce19fd96c4
|
@ -106,6 +106,15 @@ export const commands = {
|
||||||
failure: (error) => action(COMMANDS[FAILURE], {error})
|
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 PROCESS_LOGS = createRequestTypes('PROCESS_LOGS');
|
||||||
export const processLogs = {
|
export const processLogs = {
|
||||||
request: (processName, limit) => {
|
request: (processName, limit) => {
|
||||||
|
|
|
@ -112,7 +112,11 @@ class Console extends Component {
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
onSearch={(value) => {
|
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']}
|
filterBy={['value', 'description']}
|
||||||
maxHeight="200px"
|
maxHeight="200px"
|
||||||
|
@ -138,8 +142,10 @@ class Console extends Component {
|
||||||
|
|
||||||
Console.propTypes = {
|
Console.propTypes = {
|
||||||
postCommand: PropTypes.func,
|
postCommand: PropTypes.func,
|
||||||
|
postCommandSuggestions: PropTypes.func,
|
||||||
isEmbark: PropTypes.func,
|
isEmbark: PropTypes.func,
|
||||||
processes: PropTypes.arrayOf(PropTypes.object).isRequired,
|
processes: PropTypes.arrayOf(PropTypes.object).isRequired,
|
||||||
|
command_suggestions: PropTypes.arrayOf(PropTypes.object),
|
||||||
processLogs: PropTypes.arrayOf(PropTypes.object).isRequired,
|
processLogs: PropTypes.arrayOf(PropTypes.object).isRequired,
|
||||||
updateTab: PropTypes.func
|
updateTab: PropTypes.func
|
||||||
};
|
};
|
||||||
|
|
|
@ -5,6 +5,7 @@ import {connect} from 'react-redux';
|
||||||
import {
|
import {
|
||||||
contracts as contractsAction,
|
contracts as contractsAction,
|
||||||
commands as commandsAction,
|
commands as commandsAction,
|
||||||
|
command_suggestions as commandSuggestionsAction,
|
||||||
listenToProcessLogs,
|
listenToProcessLogs,
|
||||||
processLogs as processLogsAction,
|
processLogs as processLogsAction,
|
||||||
stopProcessLogs
|
stopProcessLogs
|
||||||
|
@ -15,7 +16,7 @@ import Processes from '../components/Processes';
|
||||||
import Console from '../components/Console';
|
import Console from '../components/Console';
|
||||||
import {EMBARK_PROCESS_NAME, LOG_LIMIT} from '../constants';
|
import {EMBARK_PROCESS_NAME, LOG_LIMIT} from '../constants';
|
||||||
import ContractsList from '../components/ContractsList';
|
import ContractsList from '../components/ContractsList';
|
||||||
import {getContracts, getProcesses, getProcessLogs} from "../reducers/selectors";
|
import {getContracts, getProcesses, getProcessLogs, getCommandSuggestions} from "../reducers/selectors";
|
||||||
|
|
||||||
class HomeContainer extends Component {
|
class HomeContainer extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
|
@ -62,11 +63,13 @@ class HomeContainer extends Component {
|
||||||
</div>
|
</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}
|
<Console activeProcess={this.state.activeProcess}
|
||||||
postCommand={postCommand}
|
postCommand={postCommand}
|
||||||
|
postCommandSuggestions={postCommandSuggestions}
|
||||||
processes={processes}
|
processes={processes}
|
||||||
processLogs={processLogs}
|
processLogs={processLogs}
|
||||||
|
command_suggestions={command_suggestions}
|
||||||
isEmbark={() => this.isEmbark}
|
isEmbark={() => this.isEmbark}
|
||||||
updateTab={processName => this.updateTab(processName)} />
|
updateTab={processName => this.updateTab(processName)} />
|
||||||
)} />
|
)} />
|
||||||
|
@ -78,6 +81,7 @@ class HomeContainer extends Component {
|
||||||
HomeContainer.propTypes = {
|
HomeContainer.propTypes = {
|
||||||
processes: PropTypes.arrayOf(PropTypes.object),
|
processes: PropTypes.arrayOf(PropTypes.object),
|
||||||
postCommand: PropTypes.func,
|
postCommand: PropTypes.func,
|
||||||
|
postCommandSuggestions: PropTypes.func,
|
||||||
error: PropTypes.string,
|
error: PropTypes.string,
|
||||||
loading: PropTypes.bool
|
loading: PropTypes.bool
|
||||||
};
|
};
|
||||||
|
@ -88,6 +92,7 @@ function mapStateToProps(state) {
|
||||||
contracts: getContracts(state),
|
contracts: getContracts(state),
|
||||||
error: state.errorMessage,
|
error: state.errorMessage,
|
||||||
processLogs: getProcessLogs(state),
|
processLogs: getProcessLogs(state),
|
||||||
|
command_suggestions: getCommandSuggestions(state),
|
||||||
loading: state.loading
|
loading: state.loading
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -96,6 +101,7 @@ export default connect(
|
||||||
mapStateToProps,
|
mapStateToProps,
|
||||||
{
|
{
|
||||||
postCommand: commandsAction.post,
|
postCommand: commandsAction.post,
|
||||||
|
postCommandSuggestions: commandSuggestionsAction.post,
|
||||||
fetchProcessLogs: processLogsAction.request,
|
fetchProcessLogs: processLogsAction.request,
|
||||||
fetchContracts: contractsAction.request,
|
fetchContracts: contractsAction.request,
|
||||||
listenToProcessLogs,
|
listenToProcessLogs,
|
||||||
|
|
|
@ -14,6 +14,7 @@ const entitiesDefaultState = {
|
||||||
transactions: [],
|
transactions: [],
|
||||||
processes: [],
|
processes: [],
|
||||||
processLogs: [],
|
processLogs: [],
|
||||||
|
command_suggestions: [],
|
||||||
contracts: [],
|
contracts: [],
|
||||||
contractProfiles: [],
|
contractProfiles: [],
|
||||||
contractFunctions: [],
|
contractFunctions: [],
|
||||||
|
@ -81,6 +82,11 @@ const filtrer = {
|
||||||
contracts: function(contract, index, self) {
|
contracts: function(contract, index, self) {
|
||||||
return index === self.findIndex((t) => t.className === contract.className);
|
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) {
|
accounts: function(account, index, self) {
|
||||||
return index === self.findIndex((t) => t.address === account.address);
|
return index === self.findIndex((t) => t.address === account.address);
|
||||||
},
|
},
|
||||||
|
|
|
@ -52,6 +52,10 @@ export function getProcessLogs(state) {
|
||||||
return state.entities.processLogs;
|
return state.entities.processLogs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getCommandSuggestions(state) {
|
||||||
|
return state.entities.command_suggestions;
|
||||||
|
}
|
||||||
|
|
||||||
export function getContractLogsByContract(state, contractName) {
|
export function getContractLogsByContract(state, contractName) {
|
||||||
return state.entities.contractLogs.filter((contractLog => contractLog.name === contractName));
|
return state.entities.contractLogs.filter((contractLog => contractLog.name === contractName));
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ import * as actions from '../actions';
|
||||||
import * as api from '../services/api';
|
import * as api from '../services/api';
|
||||||
import * as storage from '../services/storage';
|
import * as storage from '../services/storage';
|
||||||
import {eventChannel} from 'redux-saga';
|
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';
|
import {getCredentials} from '../reducers/selectors';
|
||||||
|
|
||||||
function *doRequest(entity, serviceFn, payload) {
|
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 fetchTransactions = doRequest.bind(null, actions.transactions, api.fetchTransactions);
|
||||||
export const fetchProcesses = doRequest.bind(null, actions.processes, api.fetchProcesses);
|
export const fetchProcesses = doRequest.bind(null, actions.processes, api.fetchProcesses);
|
||||||
export const postCommand = doRequest.bind(null, actions.commands, api.postCommand);
|
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 fetchProcessLogs = doRequest.bind(null, actions.processLogs, api.fetchProcessLogs);
|
||||||
export const fetchContractLogs = doRequest.bind(null, actions.contractLogs, api.fetchContractLogs);
|
export const fetchContractLogs = doRequest.bind(null, actions.contractLogs, api.fetchContractLogs);
|
||||||
export const fetchContracts = doRequest.bind(null, actions.contracts, api.fetchContracts);
|
export const fetchContracts = doRequest.bind(null, actions.contracts, api.fetchContracts);
|
||||||
|
@ -83,6 +84,10 @@ export function *watchPostCommand() {
|
||||||
yield takeEvery(actions.COMMANDS[actions.REQUEST], postCommand);
|
yield takeEvery(actions.COMMANDS[actions.REQUEST], postCommand);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function *watchPostCommandSuggestions() {
|
||||||
|
yield takeLatest(actions.COMMAND_SUGGESTIONS[actions.REQUEST], postCommandSuggestions);
|
||||||
|
}
|
||||||
|
|
||||||
export function *watchFetchProcessLogs() {
|
export function *watchFetchProcessLogs() {
|
||||||
yield takeEvery(actions.PROCESS_LOGS[actions.REQUEST], fetchProcessLogs);
|
yield takeEvery(actions.PROCESS_LOGS[actions.REQUEST], fetchProcessLogs);
|
||||||
}
|
}
|
||||||
|
@ -308,6 +313,7 @@ export default function *root() {
|
||||||
fork(watchFetchBlock),
|
fork(watchFetchBlock),
|
||||||
fork(watchFetchTransactions),
|
fork(watchFetchTransactions),
|
||||||
fork(watchPostCommand),
|
fork(watchPostCommand),
|
||||||
|
fork(watchPostCommandSuggestions),
|
||||||
fork(watchFetchVersions),
|
fork(watchFetchVersions),
|
||||||
fork(watchFetchPlugins),
|
fork(watchFetchPlugins),
|
||||||
fork(watchFetchBlocks),
|
fork(watchFetchBlocks),
|
||||||
|
|
|
@ -27,6 +27,10 @@ export function postCommand() {
|
||||||
return post('/command', ...arguments);
|
return post('/command', ...arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function postCommandSuggestions() {
|
||||||
|
return post('/suggestions', ...arguments);
|
||||||
|
}
|
||||||
|
|
||||||
export function fetchAccounts() {
|
export function fetchAccounts() {
|
||||||
return get('/blockchain/accounts', ...arguments);
|
return get('/blockchain/accounts', ...arguments);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,10 +4,11 @@ const EmbarkJS = require('embarkjs');
|
||||||
const IpfsApi = require('ipfs-api');
|
const IpfsApi = require('ipfs-api');
|
||||||
const Web3 = require('web3');
|
const Web3 = require('web3');
|
||||||
const stringify = require('json-stringify-safe');
|
const stringify = require('json-stringify-safe');
|
||||||
|
const Suggestions = require('./suggestions')
|
||||||
|
|
||||||
class Console {
|
class Console {
|
||||||
constructor(_embark, options) {
|
constructor(embark, options) {
|
||||||
this.embark = _embark;
|
this.embark = embark;
|
||||||
this.events = options.events;
|
this.events = options.events;
|
||||||
this.plugins = options.plugins;
|
this.plugins = options.plugins;
|
||||||
this.version = options.version;
|
this.version = options.version;
|
||||||
|
@ -26,6 +27,8 @@ class Console {
|
||||||
this.registerEmbarkJs();
|
this.registerEmbarkJs();
|
||||||
this.registerConsoleCommands();
|
this.registerConsoleCommands();
|
||||||
this.registerApi();
|
this.registerApi();
|
||||||
|
|
||||||
|
this.suggestions = new Suggestions(embark, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
registerApi() {
|
registerApi() {
|
||||||
|
|
|
@ -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;
|
Loading…
Reference in New Issue