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 { mockStore } from './utils';
|
||||||
import MistralApiService from '../../js/services/MistralApiService';
|
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 WorkflowActions from '../../js/actions/WorkflowActions';
|
||||||
import * as WorkflowExecutionsSelectors from '../../js/selectors/workflowExecutions';
|
import * as WorkflowExecutionsSelectors from '../../js/selectors/workflowExecutions';
|
||||||
import * as WorkflowExecutionTimeoutsSelectors from '../../js/selectors/workflowExecutionTimeouts';
|
import * as WorkflowExecutionTimeoutsSelectors from '../../js/selectors/workflowExecutionTimeouts';
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import MistralApiService from '../../js/services/MistralApiService';
|
import MistralApiService from '../../js/services/MistralApiService';
|
||||||
import WorkflowExecutionsActions from '../../js/actions/WorkflowExecutionsActions';
|
import * as WorkflowExecutionsActions from '../../js/actions/WorkflowExecutionsActions';
|
||||||
import { mockStore } from './utils';
|
import { mockStore } from './utils';
|
||||||
|
|
||||||
describe('fetchWorkflowExecutions action', () => {
|
describe('fetchWorkflowExecutions action', () => {
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
import { handleErrors } from './ErrorActions';
|
import { handleErrors } from './ErrorActions';
|
||||||
import MistralApiService from '../services/MistralApiService';
|
import MistralApiService from '../services/MistralApiService';
|
||||||
import WorkflowExecutionsActions from './WorkflowExecutionsActions';
|
import { addWorkflowExecution } from './WorkflowExecutionsActions';
|
||||||
import WorkflowExecutionConstants from '../constants/WorkflowExecutionsConstants';
|
import WorkflowExecutionConstants from '../constants/WorkflowExecutionsConstants';
|
||||||
import { getWorkflowExecution } from '../selectors/workflowExecutions';
|
import { getWorkflowExecution } from '../selectors/workflowExecutions';
|
||||||
import { getWorkflowExecutionTimeout } from '../selectors/workflowExecutionTimeouts';
|
import { getWorkflowExecutionTimeout } from '../selectors/workflowExecutionTimeouts';
|
||||||
@ -40,7 +40,7 @@ export const startWorkflow = (
|
|||||||
timeout = 30000
|
timeout = 30000
|
||||||
) => dispatch =>
|
) => dispatch =>
|
||||||
dispatch(MistralApiService.runWorkflow(name, input)).then(execution => {
|
dispatch(MistralApiService.runWorkflow(name, input)).then(execution => {
|
||||||
dispatch(WorkflowExecutionsActions.addWorkflowExecution(execution));
|
dispatch(addWorkflowExecution(execution));
|
||||||
const t = setTimeout(
|
const t = setTimeout(
|
||||||
() => dispatch(pollWorkflowExecution(execution.id, onFinished)),
|
() => dispatch(pollWorkflowExecution(execution.id, onFinished)),
|
||||||
timeout
|
timeout
|
||||||
@ -62,7 +62,7 @@ export const pollWorkflowExecution = (
|
|||||||
) => dispatch =>
|
) => dispatch =>
|
||||||
dispatch(MistralApiService.getWorkflowExecution(executionId))
|
dispatch(MistralApiService.getWorkflowExecution(executionId))
|
||||||
.then(execution => {
|
.then(execution => {
|
||||||
dispatch(WorkflowExecutionsActions.addWorkflowExecution(execution));
|
dispatch(addWorkflowExecution(execution));
|
||||||
if (execution.state === 'RUNNING') {
|
if (execution.state === 'RUNNING') {
|
||||||
const t = setTimeout(
|
const t = setTimeout(
|
||||||
() =>
|
() =>
|
||||||
|
@ -21,74 +21,54 @@ import MistralApiService from '../services/MistralApiService';
|
|||||||
import WorkflowExecutionsConstants from '../constants/WorkflowExecutionsConstants';
|
import WorkflowExecutionsConstants from '../constants/WorkflowExecutionsConstants';
|
||||||
import { workflowExecutionSchema } from '../normalizrSchemas/workflowExecutions';
|
import { workflowExecutionSchema } from '../normalizrSchemas/workflowExecutions';
|
||||||
|
|
||||||
export default {
|
export const fetchWorkflowExecutions = () => (dispatch, getState) => {
|
||||||
fetchWorkflowExecutions() {
|
dispatch(fetchWorkflowExecutionsPending());
|
||||||
return (dispatch, getState) => {
|
return dispatch(MistralApiService.getWorkflowExecutions())
|
||||||
dispatch(this.fetchWorkflowExecutionsPending());
|
.then(response => {
|
||||||
return dispatch(MistralApiService.getWorkflowExecutions())
|
const executions =
|
||||||
.then(response => {
|
normalize(response, [workflowExecutionSchema]).entities.executions ||
|
||||||
const executions =
|
{};
|
||||||
normalize(response, [workflowExecutionSchema]).entities
|
dispatch(fetchWorkflowExecutionsSuccess(executions));
|
||||||
.executions || {};
|
})
|
||||||
dispatch(this.fetchWorkflowExecutionsSuccess(executions));
|
.catch(error => {
|
||||||
})
|
dispatch(handleErrors(error, 'Workflow Executions could not be loaded'));
|
||||||
.catch(error => {
|
dispatch(fetchWorkflowExecutionsFailed());
|
||||||
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 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 Plans from './plan/Plans.js';
|
||||||
import StacksActions from '../actions/StacksActions';
|
import StacksActions from '../actions/StacksActions';
|
||||||
import { fetchPlans } from '../actions/PlansActions';
|
import { fetchPlans } from '../actions/PlansActions';
|
||||||
import WorkflowExecutionsActions from '../actions/WorkflowExecutionsActions';
|
import { fetchWorkflowExecutions } from '../actions/WorkflowExecutionsActions';
|
||||||
import ZaqarWebSocketService from '../services/ZaqarWebSocketService';
|
import ZaqarWebSocketService from '../services/ZaqarWebSocketService';
|
||||||
|
|
||||||
const messages = defineMessages({
|
const messages = defineMessages({
|
||||||
@ -96,8 +96,7 @@ AuthenticatedContent.propTypes = {
|
|||||||
const mapDispatchToProps = (dispatch, ownProps) => ({
|
const mapDispatchToProps = (dispatch, ownProps) => ({
|
||||||
fetchStacks: () => dispatch(StacksActions.fetchStacks()),
|
fetchStacks: () => dispatch(StacksActions.fetchStacks()),
|
||||||
fetchPlans: () => dispatch(fetchPlans()),
|
fetchPlans: () => dispatch(fetchPlans()),
|
||||||
fetchWorkflowExecutions: () =>
|
fetchWorkflowExecutions: () => dispatch(fetchWorkflowExecutions()),
|
||||||
dispatch(WorkflowExecutionsActions.fetchWorkflowExecutions()),
|
|
||||||
initializeZaqarConnection: () => dispatch(ZaqarWebSocketService.init())
|
initializeZaqarConnection: () => dispatch(ZaqarWebSocketService.init())
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -32,7 +32,10 @@ import {
|
|||||||
import ValidationsToolbar from './ValidationsToolbar';
|
import ValidationsToolbar from './ValidationsToolbar';
|
||||||
import Validation from './Validation';
|
import Validation from './Validation';
|
||||||
import ValidationDetail from './ValidationDetail';
|
import ValidationDetail from './ValidationDetail';
|
||||||
import WorkflowExecutionsActions from '../../actions/WorkflowExecutionsActions';
|
import {
|
||||||
|
fetchWorkflowExecutions,
|
||||||
|
updateWorkflowExecution
|
||||||
|
} from '../../actions/WorkflowExecutionsActions';
|
||||||
import { getFilteredValidations } from '../../selectors/validations';
|
import { getFilteredValidations } from '../../selectors/validations';
|
||||||
|
|
||||||
const messages = defineMessages({
|
const messages = defineMessages({
|
||||||
@ -233,14 +236,13 @@ const mapDispatchToProps = dispatch => ({
|
|||||||
addActiveFilter: data =>
|
addActiveFilter: data =>
|
||||||
dispatch(addActiveFilter('validationsToolbar', data)),
|
dispatch(addActiveFilter('validationsToolbar', data)),
|
||||||
fetchValidations: () => dispatch(fetchValidations()),
|
fetchValidations: () => dispatch(fetchValidations()),
|
||||||
fetchWorkflowExecutions: () =>
|
fetchWorkflowExecutions: () => dispatch(fetchWorkflowExecutions()),
|
||||||
dispatch(WorkflowExecutionsActions.fetchWorkflowExecutions()),
|
|
||||||
runValidation: (id, currentPlanName) => {
|
runValidation: (id, currentPlanName) => {
|
||||||
dispatch(runValidation(id, currentPlanName));
|
dispatch(runValidation(id, currentPlanName));
|
||||||
},
|
},
|
||||||
stopValidation: executionId => {
|
stopValidation: executionId => {
|
||||||
dispatch(
|
dispatch(
|
||||||
WorkflowExecutionsActions.updateWorkflowExecution(executionId, {
|
updateWorkflowExecution(executionId, {
|
||||||
state: 'PAUSED'
|
state: 'PAUSED'
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user