PromucFlow_constructor/app/client/src/actions/actionActions.ts

201 lines
4.1 KiB
TypeScript
Raw Normal View History

2020-06-04 13:49:22 +00:00
import { PaginationField, ActionResponse } from "api/ActionAPI";
2020-01-24 09:54:40 +00:00
import {
ReduxActionTypes,
ReduxAction,
ReduxActionErrorTypes,
} from "constants/ReduxActionConstants";
2020-06-04 13:49:22 +00:00
import { Action, RestAction } from "entities/Action";
import { batchAction } from "actions/batchActions";
2019-10-21 15:12:45 +00:00
2020-06-04 13:49:22 +00:00
export const createActionRequest = (payload: Partial<Action>) => {
2019-10-21 15:12:45 +00:00
return {
type: ReduxActionTypes.CREATE_ACTION_INIT,
2019-10-21 15:12:45 +00:00
payload,
};
};
2020-06-04 13:49:22 +00:00
export const createActionSuccess = (payload: Action) => {
2019-10-21 15:12:45 +00:00
return {
type: ReduxActionTypes.CREATE_ACTION_SUCCESS,
payload,
2019-10-21 15:12:45 +00:00
};
};
export type FetchActionsPayload = {
2020-01-24 09:54:40 +00:00
applicationId: string;
};
export const fetchActions = (
2020-01-24 09:54:40 +00:00
applicationId: string,
): ReduxAction<FetchActionsPayload> => {
2019-10-21 15:12:45 +00:00
return {
type: ReduxActionTypes.FETCH_ACTIONS_INIT,
2020-01-24 09:54:40 +00:00
payload: { applicationId },
2019-10-21 15:12:45 +00:00
};
};
2020-02-21 12:16:49 +00:00
export const fetchActionsForPage = (pageId: string) => {
return {
type: ReduxActionTypes.FETCH_ACTIONS_FOR_PAGE_INIT,
payload: { pageId },
};
};
export const fetchActionsForPageSuccess = (actions: RestAction[]) => {
return {
type: ReduxActionTypes.FETCH_ACTIONS_FOR_PAGE_SUCCESS,
payload: actions,
};
};
export const runAction = (id: string, paginationField?: PaginationField) => {
2019-10-21 15:12:45 +00:00
return {
type: ReduxActionTypes.RUN_ACTION_REQUEST,
2020-02-07 02:32:52 +00:00
payload: {
id,
paginationField,
2020-02-07 02:32:52 +00:00
},
};
};
export const updateAction = (payload: { data: RestAction }) => {
return {
type: ReduxActionTypes.UPDATE_ACTION_INIT,
payload,
};
};
export const updateActionSuccess = (payload: { data: RestAction }) => {
return {
type: ReduxActionTypes.UPDATE_ACTION_SUCCESS,
2019-10-21 15:12:45 +00:00
payload,
};
};
2020-03-06 04:59:24 +00:00
export const deleteAction = (payload: { id: string; name: string }) => {
2019-10-21 15:12:45 +00:00
return {
type: ReduxActionTypes.DELETE_ACTION_INIT,
2019-10-21 15:12:45 +00:00
payload,
};
};
export const deleteActionSuccess = (payload: { id: string }) => {
2019-10-21 15:12:45 +00:00
return {
type: ReduxActionTypes.DELETE_ACTION_SUCCESS,
2019-10-21 15:12:45 +00:00
payload,
};
};
2020-01-24 09:54:40 +00:00
export const moveActionRequest = (payload: {
id: string;
destinationPageId: string;
originalPageId: string;
name: string;
}) => {
return {
type: ReduxActionTypes.MOVE_ACTION_INIT,
payload,
};
};
2020-01-27 13:53:33 +00:00
export const moveActionSuccess = (payload: RestAction) => {
2020-01-24 09:54:40 +00:00
return {
type: ReduxActionTypes.MOVE_ACTION_SUCCESS,
payload,
};
};
export const moveActionError = (payload: {
id: string;
originalPageId: string;
}) => {
return {
type: ReduxActionErrorTypes.MOVE_ACTION_ERROR,
payload,
};
};
export const copyActionRequest = (payload: {
id: string;
destinationPageId: string;
name: string;
}) => {
return {
type: ReduxActionTypes.COPY_ACTION_INIT,
payload,
};
};
export const copyActionSuccess = (payload: {
id: string;
destinationPageId: string;
}) => {
return {
type: ReduxActionTypes.COPY_ACTION_SUCCESS,
payload,
};
};
export const copyActionError = (payload: {
id: string;
destinationPageId: string;
}) => {
return {
type: ReduxActionErrorTypes.COPY_ACTION_ERROR,
payload,
};
};
2020-02-18 10:41:52 +00:00
export const executeApiActionRequest = (payload: { id: string }) => ({
type: ReduxActionTypes.EXECUTE_API_ACTION_REQUEST,
payload: payload,
});
export const executeApiActionSuccess = (payload: {
id: string;
response: ActionResponse;
}) => ({
type: ReduxActionTypes.EXECUTE_API_ACTION_SUCCESS,
payload: payload,
});
2020-06-18 07:46:53 +00:00
export const saveApiName = (payload: { id: string; name: string }) => ({
2020-06-16 10:23:19 +00:00
type: ReduxActionTypes.SAVE_API_NAME,
payload: payload,
});
export type SetActionPropertyPayload = {
actionId: string;
propertyName: string;
value: string;
};
export const setActionProperty = (payload: SetActionPropertyPayload) => ({
type: ReduxActionTypes.SET_ACTION_PROPERTY,
payload,
2020-06-16 10:23:19 +00:00
});
export type UpdateActionPropertyActionPayload = {
id: string;
field: string;
value: any;
};
export const updateActionProperty = (
payload: UpdateActionPropertyActionPayload,
) =>
batchAction({
type: ReduxActionTypes.UPDATE_ACTION_PROPERTY,
payload,
});
2019-10-21 15:12:45 +00:00
export default {
createAction: createActionRequest,
2019-10-21 15:12:45 +00:00
fetchActions,
runAction: runAction,
2019-10-21 15:12:45 +00:00
deleteAction,
deleteActionSuccess,
updateAction,
updateActionSuccess,
2019-10-21 15:12:45 +00:00
};