зеркало из https://github.com/mozilla/normandy.git
CRUD actions for recipes
This commit is contained in:
Родитель
7a61a73e4a
Коммит
418ea89f48
|
@ -2,6 +2,7 @@
|
|||
|
||||
export const ACTION_RECEIVE = 'ACTION_RECEIVE';
|
||||
export const APPROVAL_REQUEST_RECEIVE = 'APPROVAL_REQUEST_RECEIVE';
|
||||
export const RECIPE_DELETE = 'RECIPE_DELETE';
|
||||
export const RECIPE_RECEIVE = 'RECIPE_RECEIVE';
|
||||
export const RECIPE_FILTERS_RECEIVE = 'RECIPE_FILTERS_RECEIVE';
|
||||
export const RECIPE_HISTORY_RECEIVE = 'RECIPE_HISTORY_RECEIVE';
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import {
|
||||
ACTION_RECEIVE,
|
||||
RECIPE_DELETE,
|
||||
RECIPE_RECEIVE,
|
||||
RECIPE_FILTERS_RECEIVE,
|
||||
RECIPE_HISTORY_RECEIVE,
|
||||
|
@ -59,6 +60,46 @@ export function fetchAllRecipes() {
|
|||
}
|
||||
|
||||
|
||||
export function createRecipe(recipeData) {
|
||||
return async dispatch => {
|
||||
const requestId = 'create-recipe';
|
||||
const recipe = await dispatch(makeApiRequest(requestId, 'v2/recipe/', {
|
||||
method: 'POST',
|
||||
data: recipeData,
|
||||
}));
|
||||
dispatch(recipeReceived(recipe));
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
export function updateRecipe(pk, recipeData) {
|
||||
return async dispatch => {
|
||||
const requestId = `update-recipe-${pk}`;
|
||||
const recipe = await dispatch(makeApiRequest(requestId, `v2/recipe/${pk}`, {
|
||||
method: 'PATCH',
|
||||
data: recipeData,
|
||||
}));
|
||||
dispatch(recipeReceived(recipe));
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
export function deleteRecipe(pk) {
|
||||
return async dispatch => {
|
||||
const requestId = `delete-recipe-${pk}`;
|
||||
|
||||
await dispatch(makeApiRequest(requestId, `v2/recipe/${pk}`, {
|
||||
method: 'DELETE',
|
||||
}));
|
||||
|
||||
dispatch({
|
||||
type: RECIPE_DELETE,
|
||||
recipeId: pk,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
export function fetchRecipeHistory(pk) {
|
||||
return async dispatch => {
|
||||
const requestId = `fetch-recipe-history-${pk}`;
|
||||
|
|
|
@ -2,6 +2,7 @@ import { fromJS, Map } from 'immutable';
|
|||
import { combineReducers } from 'redux';
|
||||
|
||||
import {
|
||||
RECIPE_DELETE,
|
||||
RECIPE_RECEIVE,
|
||||
RECIPE_FILTERS_RECEIVE,
|
||||
RECIPE_HISTORY_RECEIVE,
|
||||
|
@ -24,6 +25,9 @@ function history(state = new Map(), action) {
|
|||
case RECIPE_HISTORY_RECEIVE:
|
||||
return state.set(action.recipeId, fromJS(action.revisions.map(revision => revision.id)));
|
||||
|
||||
case RECIPE_DELETE:
|
||||
return state.remove(action.recipeId);
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
@ -54,6 +58,9 @@ function items(state = new Map(), action) {
|
|||
|
||||
return state.set(action.recipe.id, recipe);
|
||||
|
||||
case RECIPE_DELETE:
|
||||
return state.remove(action.recipeId);
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ import { fromJS, Map } from 'immutable';
|
|||
import { combineReducers } from 'redux';
|
||||
|
||||
import {
|
||||
RECIPE_DELETE,
|
||||
REVISION_RECEIVE,
|
||||
} from '../action-types';
|
||||
|
||||
|
@ -17,6 +18,9 @@ function items(state = new Map(), action) {
|
|||
|
||||
return state.set(action.revision.id, revision);
|
||||
|
||||
case RECIPE_DELETE:
|
||||
return state.filterNot(item => item.getIn(['recipe', 'id']) === action.recipeId);
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче