Convert processes
This commit is contained in:
parent
5731f7e1df
commit
89b64adc4a
|
@ -56,10 +56,13 @@ export const transaction = {
|
|||
failure: (error) => action(TRANSACTION[FAILURE], {error})
|
||||
};
|
||||
|
||||
// Processes
|
||||
export const FETCH_PROCESSES = 'FETCH_PROCESSES';
|
||||
export const RECEIVE_PROCESSES = 'RECEIVE_PROCESSES';
|
||||
export const RECEIVE_PROCESSES_ERROR = 'RECEIVE_PROCESSES_ERROR';
|
||||
export const PROCESSES = createRequestTypes('PROCESSES');
|
||||
export const processes = {
|
||||
request: () => action(PROCESSES[REQUEST]),
|
||||
success: (processes) => action(PROCESSES[SUCCESS], {processes}),
|
||||
failure: (error) => action(PROCESSES[FAILURE], {error})
|
||||
};
|
||||
|
||||
// Process logs
|
||||
export const FETCH_PROCESS_LOGS = 'FETCH_PROCESS_LOGS';
|
||||
export const RECEIVE_PROCESS_LOGS = 'RECEIVE_PROCESS_LOGS';
|
||||
|
@ -69,26 +72,6 @@ export const RECEIVE_PROCESS_LOGS_ERROR = 'RECEIVE_PROCESS_LOGS_ERROR';
|
|||
// BlockHeader
|
||||
export const INIT_BLOCK_HEADER = 'INIT_BLOCK_HEADER';
|
||||
|
||||
export function fetchProcesses() {
|
||||
return {
|
||||
type: FETCH_PROCESSES
|
||||
};
|
||||
}
|
||||
|
||||
export function receiveProcesses(processes) {
|
||||
return {
|
||||
type: RECEIVE_PROCESSES,
|
||||
processes
|
||||
};
|
||||
}
|
||||
|
||||
export function receiveProcessesError(error) {
|
||||
return {
|
||||
type: RECEIVE_PROCESSES_ERROR,
|
||||
error
|
||||
};
|
||||
}
|
||||
|
||||
export function fetchProcessLogs(processName) {
|
||||
return {
|
||||
type: FETCH_PROCESS_LOGS,
|
||||
|
|
|
@ -36,7 +36,7 @@ export function fetchTransaction(payload) {
|
|||
}
|
||||
|
||||
export function fetchProcesses() {
|
||||
return axios.get(`${constants.httpEndpoint}/processes`);
|
||||
return get('/processes');
|
||||
}
|
||||
|
||||
export function fetchProcessLogs(processName) {
|
||||
|
|
|
@ -6,7 +6,7 @@ import React, {Component} from 'react';
|
|||
import history from '../history';
|
||||
import Layout from '../components/Layout';
|
||||
import routes from '../routes';
|
||||
import {initBlockHeader, fetchProcesses} from '../actions';
|
||||
import {initBlockHeader, processes as processesAction} from '../actions';
|
||||
|
||||
class AppContainer extends Component {
|
||||
componentDidMount() {
|
||||
|
@ -34,6 +34,6 @@ export default connect(
|
|||
null,
|
||||
{
|
||||
initBlockHeader,
|
||||
fetchProcesses
|
||||
fetchProcesses: processesAction.request
|
||||
},
|
||||
)(AppContainer);
|
||||
|
|
|
@ -1,19 +1,12 @@
|
|||
import {
|
||||
RECEIVE_PROCESSES,
|
||||
RECEIVE_PROCESSES_ERROR,
|
||||
RECEIVE_PROCESS_LOGS,
|
||||
RECEIVE_PROCESS_LOGS_ERROR,
|
||||
RECEIVE_NEW_PROCESS_LOG,
|
||||
WATCH_NEW_PROCESS_LOGS
|
||||
} from "../actions";
|
||||
import * as actions from "../actions";
|
||||
|
||||
export default function processes(state = {}, action) {
|
||||
switch (action.type) {
|
||||
case RECEIVE_PROCESSES:
|
||||
case actions.PROCESSES[actions.SUCCESS]:
|
||||
return Object.assign({}, state, {data: action.processes.data});
|
||||
case RECEIVE_PROCESSES_ERROR:
|
||||
case actions.PROCESSES[actions.FAILURE]:
|
||||
return Object.assign({}, state, {error: action.error});
|
||||
case RECEIVE_PROCESS_LOGS:
|
||||
case actions.RECEIVE_PROCESS_LOGS:
|
||||
return {
|
||||
...state,
|
||||
data: {
|
||||
|
@ -24,7 +17,7 @@ export default function processes(state = {}, action) {
|
|||
}
|
||||
}
|
||||
};
|
||||
case RECEIVE_NEW_PROCESS_LOG: {
|
||||
case actions.RECEIVE_NEW_PROCESS_LOG: {
|
||||
const logs = state.data[action.processName].logs || [];
|
||||
logs.push(action.log);
|
||||
return {
|
||||
|
@ -38,7 +31,7 @@ export default function processes(state = {}, action) {
|
|||
}
|
||||
};
|
||||
}
|
||||
case WATCH_NEW_PROCESS_LOGS: {
|
||||
case actions.WATCH_NEW_PROCESS_LOGS: {
|
||||
return {
|
||||
...state,
|
||||
data: {
|
||||
|
@ -50,7 +43,7 @@ export default function processes(state = {}, action) {
|
|||
}
|
||||
};
|
||||
}
|
||||
case RECEIVE_PROCESS_LOGS_ERROR:
|
||||
case actions.RECEIVE_PROCESS_LOGS_ERROR:
|
||||
return Object.assign({}, state, {error: action.error});
|
||||
default:
|
||||
return state;
|
||||
|
|
|
@ -3,7 +3,7 @@ import * as api from '../api';
|
|||
import {eventChannel} from 'redux-saga';
|
||||
import {all, call, fork, put, takeEvery, take} from 'redux-saga/effects';
|
||||
|
||||
const {account, accounts, block, blocks, transaction, transactions} = actions;
|
||||
const {account, accounts, block, blocks, transaction, transactions, processes} = actions;
|
||||
|
||||
function *fetchEntity(entity, apiFn, id) {
|
||||
const {response, error} = yield call(apiFn, id);
|
||||
|
@ -20,6 +20,7 @@ export const fetchTransaction = fetchEntity.bind(null, transaction, api.fetchTra
|
|||
export const fetchAccounts = fetchEntity.bind(null, accounts, api.fetchAccounts);
|
||||
export const fetchBlocks = fetchEntity.bind(null, blocks, api.fetchBlocks);
|
||||
export const fetchTransactions = fetchEntity.bind(null, transactions, api.fetchTransactions);
|
||||
export const fetchProcesses = fetchEntity.bind(null, processes, api.fetchProcesses);
|
||||
|
||||
export function *watchFetchTransaction() {
|
||||
yield takeEvery(actions.TRANSACTION[actions.REQUEST], fetchTransaction);
|
||||
|
@ -45,17 +46,8 @@ export function *watchFetchAccounts() {
|
|||
yield takeEvery(actions.ACCOUNTS[actions.REQUEST], fetchAccounts);
|
||||
}
|
||||
|
||||
export function *fetchProcesses() {
|
||||
try {
|
||||
const processes = yield call(api.fetchProcesses);
|
||||
yield put(actions.receiveProcesses(processes));
|
||||
} catch (e) {
|
||||
yield put(actions.receiveProcessesError(e));
|
||||
}
|
||||
}
|
||||
|
||||
export function *watchFetchProcesses() {
|
||||
yield takeEvery(actions.FETCH_PROCESSES, fetchProcesses);
|
||||
yield takeEvery(actions.PROCESSES[actions.REQUEST], fetchProcesses);
|
||||
}
|
||||
|
||||
export function *fetchProcessLogs(action) {
|
||||
|
|
Loading…
Reference in New Issue