Convert WorkflowExecutionsActions to named exports
* avoid using 'this' in thunks Change-Id: I0c72f265e55644ab8054b5f01edc869e8d0c1ae8
This commit is contained in:
parent
a3dab0a523
commit
e3459a2c4b
|
@ -18,7 +18,7 @@ jest.useFakeTimers();
|
|||
|
||||
import { mockStore } from './utils';
|
||||
import MistralApiService from '../../js/services/MistralApiService';
|
||||
import WorkflowExecutionsActions from '../../js/actions/WorkflowExecutionsActions';
|
||||
import * as WorkflowExecutionsActions from '../../js/actions/WorkflowExecutionsActions';
|
||||
import * as WorkflowActions from '../../js/actions/WorkflowActions';
|
||||
import * as WorkflowExecutionsSelectors from '../../js/selectors/workflowExecutions';
|
||||
import * as WorkflowExecutionTimeoutsSelectors from '../../js/selectors/workflowExecutionTimeouts';
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
*/
|
||||
|
||||
import MistralApiService from '../../js/services/MistralApiService';
|
||||
import WorkflowExecutionsActions from '../../js/actions/WorkflowExecutionsActions';
|
||||
import * as WorkflowExecutionsActions from '../../js/actions/WorkflowExecutionsActions';
|
||||
import { mockStore } from './utils';
|
||||
|
||||
describe('fetchWorkflowExecutions action', () => {
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
import { handleErrors } from './ErrorActions';
|
||||
import MistralApiService from '../services/MistralApiService';
|
||||
import WorkflowExecutionsActions from './WorkflowExecutionsActions';
|
||||
import { addWorkflowExecution } from './WorkflowExecutionsActions';
|
||||
import WorkflowExecutionConstants from '../constants/WorkflowExecutionsConstants';
|
||||
import { getWorkflowExecution } from '../selectors/workflowExecutions';
|
||||
import { getWorkflowExecutionTimeout } from '../selectors/workflowExecutionTimeouts';
|
||||
|
@ -40,7 +40,7 @@ export const startWorkflow = (
|
|||
timeout = 30000
|
||||
) => dispatch =>
|
||||
dispatch(MistralApiService.runWorkflow(name, input)).then(execution => {
|
||||
dispatch(WorkflowExecutionsActions.addWorkflowExecution(execution));
|
||||
dispatch(addWorkflowExecution(execution));
|
||||
const t = setTimeout(
|
||||
() => dispatch(pollWorkflowExecution(execution.id, onFinished)),
|
||||
timeout
|
||||
|
@ -62,7 +62,7 @@ export const pollWorkflowExecution = (
|
|||
) => dispatch =>
|
||||
dispatch(MistralApiService.getWorkflowExecution(executionId))
|
||||
.then(execution => {
|
||||
dispatch(WorkflowExecutionsActions.addWorkflowExecution(execution));
|
||||
dispatch(addWorkflowExecution(execution));
|
||||
if (execution.state === 'RUNNING') {
|
||||
const t = setTimeout(
|
||||
() =>
|
||||
|
|
|
@ -21,74 +21,54 @@ import MistralApiService from '../services/MistralApiService';
|
|||
import WorkflowExecutionsConstants from '../constants/WorkflowExecutionsConstants';
|
||||
import { workflowExecutionSchema } from '../normalizrSchemas/workflowExecutions';
|
||||
|
||||
export default {
|
||||
fetchWorkflowExecutions() {
|
||||
return (dispatch, getState) => {
|
||||
dispatch(this.fetchWorkflowExecutionsPending());
|
||||
return dispatch(MistralApiService.getWorkflowExecutions())
|
||||
.then(response => {
|
||||
const executions =
|
||||
normalize(response, [workflowExecutionSchema]).entities
|
||||
.executions || {};
|
||||
dispatch(this.fetchWorkflowExecutionsSuccess(executions));
|
||||
})
|
||||
.catch(error => {
|
||||
dispatch(
|
||||
handleErrors(error, 'Workflow Executions could not be loaded')
|
||||
);
|
||||
dispatch(this.fetchWorkflowExecutionsFailed());
|
||||
});
|
||||
};
|
||||
},
|
||||
|
||||
fetchWorkflowExecutionsPending() {
|
||||
return {
|
||||
type: WorkflowExecutionsConstants.FETCH_WORKFLOW_EXECUTIONS_PENDING
|
||||
};
|
||||
},
|
||||
|
||||
fetchWorkflowExecutionsSuccess(executions) {
|
||||
return {
|
||||
type: WorkflowExecutionsConstants.FETCH_WORKFLOW_EXECUTIONS_SUCCESS,
|
||||
payload: executions
|
||||
};
|
||||
},
|
||||
|
||||
fetchWorkflowExecutionsFailed() {
|
||||
return {
|
||||
type: WorkflowExecutionsConstants.FETCH_WORKFLOW_EXECUTIONS_FAILED
|
||||
};
|
||||
},
|
||||
|
||||
addWorkflowExecution(execution) {
|
||||
return {
|
||||
type: WorkflowExecutionsConstants.ADD_WORKFLOW_EXECUTION,
|
||||
payload: execution
|
||||
};
|
||||
},
|
||||
|
||||
updateWorkflowExecution(id, patch) {
|
||||
return (dispatch, getState) => {
|
||||
dispatch(this.updateWorkflowExecutionPending(id, patch));
|
||||
return dispatch(MistralApiService.updateWorkflowExecution(id, patch))
|
||||
.then(response => {
|
||||
dispatch(this.addWorkflowExecution(response));
|
||||
})
|
||||
.catch(error => {
|
||||
dispatch(
|
||||
handleErrors(error, 'Workflow Execution could not be updated')
|
||||
);
|
||||
});
|
||||
};
|
||||
},
|
||||
|
||||
updateWorkflowExecutionPending(id, patch) {
|
||||
return {
|
||||
type: WorkflowExecutionsConstants.UPDATE_WORKFLOW_EXECUTION_PENDING,
|
||||
payload: {
|
||||
id,
|
||||
patch
|
||||
}
|
||||
};
|
||||
}
|
||||
export const fetchWorkflowExecutions = () => (dispatch, getState) => {
|
||||
dispatch(fetchWorkflowExecutionsPending());
|
||||
return dispatch(MistralApiService.getWorkflowExecutions())
|
||||
.then(response => {
|
||||
const executions =
|
||||
normalize(response, [workflowExecutionSchema]).entities.executions ||
|
||||
{};
|
||||
dispatch(fetchWorkflowExecutionsSuccess(executions));
|
||||
})
|
||||
.catch(error => {
|
||||
dispatch(handleErrors(error, 'Workflow Executions could not be loaded'));
|
||||
dispatch(fetchWorkflowExecutionsFailed());
|
||||
});
|
||||
};
|
||||
|
||||
export const fetchWorkflowExecutionsPending = () => ({
|
||||
type: WorkflowExecutionsConstants.FETCH_WORKFLOW_EXECUTIONS_PENDING
|
||||
});
|
||||
|
||||
export const fetchWorkflowExecutionsSuccess = executions => ({
|
||||
type: WorkflowExecutionsConstants.FETCH_WORKFLOW_EXECUTIONS_SUCCESS,
|
||||
payload: executions
|
||||
});
|
||||
|
||||
export const fetchWorkflowExecutionsFailed = () => ({
|
||||
type: WorkflowExecutionsConstants.FETCH_WORKFLOW_EXECUTIONS_FAILED
|
||||
});
|
||||
|
||||
export const addWorkflowExecution = execution => ({
|
||||
type: WorkflowExecutionsConstants.ADD_WORKFLOW_EXECUTION,
|
||||
payload: execution
|
||||
});
|
||||
|
||||
export const updateWorkflowExecution = (id, patch) => (dispatch, getState) => {
|
||||
dispatch(updateWorkflowExecutionPending(id, patch));
|
||||
return dispatch(MistralApiService.updateWorkflowExecution(id, patch))
|
||||
.then(response => {
|
||||
dispatch(addWorkflowExecution(response));
|
||||
})
|
||||
.catch(error => {
|
||||
dispatch(handleErrors(error, 'Workflow Execution could not be updated'));
|
||||
});
|
||||
};
|
||||
|
||||
export const updateWorkflowExecutionPending = (id, patch) => ({
|
||||
type: WorkflowExecutionsConstants.UPDATE_WORKFLOW_EXECUTION_PENDING,
|
||||
payload: {
|
||||
id,
|
||||
patch
|
||||
}
|
||||
});
|
||||
|
|
|
@ -30,7 +30,7 @@ import Nodes from './nodes/Nodes';
|
|||
import Plans from './plan/Plans.js';
|
||||
import StacksActions from '../actions/StacksActions';
|
||||
import { fetchPlans } from '../actions/PlansActions';
|
||||
import WorkflowExecutionsActions from '../actions/WorkflowExecutionsActions';
|
||||
import { fetchWorkflowExecutions } from '../actions/WorkflowExecutionsActions';
|
||||
import ZaqarWebSocketService from '../services/ZaqarWebSocketService';
|
||||
|
||||
const messages = defineMessages({
|
||||
|
@ -96,8 +96,7 @@ AuthenticatedContent.propTypes = {
|
|||
const mapDispatchToProps = (dispatch, ownProps) => ({
|
||||
fetchStacks: () => dispatch(StacksActions.fetchStacks()),
|
||||
fetchPlans: () => dispatch(fetchPlans()),
|
||||
fetchWorkflowExecutions: () =>
|
||||
dispatch(WorkflowExecutionsActions.fetchWorkflowExecutions()),
|
||||
fetchWorkflowExecutions: () => dispatch(fetchWorkflowExecutions()),
|
||||
initializeZaqarConnection: () => dispatch(ZaqarWebSocketService.init())
|
||||
});
|
||||
|
||||
|
|
|
@ -32,7 +32,10 @@ import {
|
|||
import ValidationsToolbar from './ValidationsToolbar';
|
||||
import Validation from './Validation';
|
||||
import ValidationDetail from './ValidationDetail';
|
||||
import WorkflowExecutionsActions from '../../actions/WorkflowExecutionsActions';
|
||||
import {
|
||||
fetchWorkflowExecutions,
|
||||
updateWorkflowExecution
|
||||
} from '../../actions/WorkflowExecutionsActions';
|
||||
import { getFilteredValidations } from '../../selectors/validations';
|
||||
|
||||
const messages = defineMessages({
|
||||
|
@ -233,14 +236,13 @@ const mapDispatchToProps = dispatch => ({
|
|||
addActiveFilter: data =>
|
||||
dispatch(addActiveFilter('validationsToolbar', data)),
|
||||
fetchValidations: () => dispatch(fetchValidations()),
|
||||
fetchWorkflowExecutions: () =>
|
||||
dispatch(WorkflowExecutionsActions.fetchWorkflowExecutions()),
|
||||
fetchWorkflowExecutions: () => dispatch(fetchWorkflowExecutions()),
|
||||
runValidation: (id, currentPlanName) => {
|
||||
dispatch(runValidation(id, currentPlanName));
|
||||
},
|
||||
stopValidation: executionId => {
|
||||
dispatch(
|
||||
WorkflowExecutionsActions.updateWorkflowExecution(executionId, {
|
||||
updateWorkflowExecution(executionId, {
|
||||
state: 'PAUSED'
|
||||
})
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue