mirror of
https://github.com/hay-kot/mealie.git
synced 2025-08-22 22:43:34 -07:00
Revert "feat: add the selected recipe servings and yields in the content of the recipe post action"
This reverts commit 81c8cf3ac542d9d1be457d4a79552ff0bf001af8.
This commit is contained in:
parent
2377857607
commit
c83d3d9726
5 changed files with 16 additions and 27 deletions
|
@ -46,7 +46,10 @@ export const useGroupRecipeActions = function (
|
|||
return groupRecipeActions.value;
|
||||
});
|
||||
|
||||
function parseRecipeActionUrl(url: string, recipe: Recipe, recipeServings: number, recipeYieldQuantity: number): string {
|
||||
function parseRecipeActionUrl(url: string, recipe: Recipe, recipeScale: number): string {
|
||||
const recipeServings = (recipe.recipeServings || 1) * recipeScale;
|
||||
const recipeYieldQuantity = (recipe.recipeYieldQuantity || 1) * recipeScale;
|
||||
|
||||
/* eslint-disable no-template-curly-in-string */
|
||||
return url
|
||||
.replace("${url}", window.location.href)
|
||||
|
@ -59,29 +62,19 @@ export const useGroupRecipeActions = function (
|
|||
};
|
||||
|
||||
async function execute(action: GroupRecipeActionOut, recipe: Recipe, recipeScale: number): Promise<void | RequestResponse<unknown>> {
|
||||
const [recipeServings, recipeYieldQuantity] = calculateRecipeServingsAndYieldQuantity(recipe, recipeScale);
|
||||
const url = parseRecipeActionUrl(action.url, recipe, recipeServings, recipeYieldQuantity);
|
||||
const url = parseRecipeActionUrl(action.url, recipe, recipeScale);
|
||||
|
||||
switch (action.actionType) {
|
||||
case "link":
|
||||
window.open(url, "_blank")?.focus();
|
||||
return;
|
||||
case "post":
|
||||
return await api.groupRecipeActions.triggerAction(
|
||||
action.id,
|
||||
recipe.slug || "",
|
||||
recipeServings,
|
||||
recipeYieldQuantity
|
||||
);
|
||||
return await api.groupRecipeActions.triggerAction(action.id, recipe.slug || "");
|
||||
default:
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
function calculateRecipeServingsAndYieldQuantity(recipe: Recipe, recipeScale: number): [number, number] {
|
||||
return [(recipe.recipeServings || 1) * recipeScale, (recipe.recipeYieldQuantity || 1) * recipeScale];
|
||||
}
|
||||
|
||||
if (!groupRecipeActions.value && !loading.value) {
|
||||
refreshGroupRecipeActions();
|
||||
};
|
||||
|
|
|
@ -6,14 +6,14 @@ const prefix = "/api";
|
|||
const routes = {
|
||||
groupRecipeActions: `${prefix}/households/recipe-actions`,
|
||||
groupRecipeActionsId: (id: string | number) => `${prefix}/households/recipe-actions/${id}`,
|
||||
groupRecipeActionsIdTriggerRecipeSlug: (id: string | number, recipeSlug: string, servings: number, yield_quantity: number) => `${prefix}/households/recipe-actions/${id}/trigger/${recipeSlug}/${servings}/${yield_quantity}`,
|
||||
groupRecipeActionsIdTriggerRecipeSlug: (id: string | number, recipeSlug: string) => `${prefix}/households/recipe-actions/${id}/trigger/${recipeSlug}`,
|
||||
};
|
||||
|
||||
export class GroupRecipeActionsAPI extends BaseCRUDAPI<CreateGroupRecipeAction, GroupRecipeActionOut> {
|
||||
baseRoute = routes.groupRecipeActions;
|
||||
itemRoute = routes.groupRecipeActionsId;
|
||||
|
||||
async triggerAction(id: string | number, recipeSlug: string, servings: number, yield_quantity: number) {
|
||||
return await this.requests.post(routes.groupRecipeActionsIdTriggerRecipeSlug(id, recipeSlug, servings, yield_quantity), {});
|
||||
async triggerAction(id: string | number, recipeSlug: string) {
|
||||
return await this.requests.post(routes.groupRecipeActionsIdTriggerRecipeSlug(id, recipeSlug), {});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,10 +67,8 @@ class GroupRecipeActionController(BaseUserController):
|
|||
# ==================================================================================================================
|
||||
# Actions
|
||||
|
||||
@router.post("/{item_id}/trigger/{recipe_slug}/{servings}/{yield_quantity}", status_code=202)
|
||||
def trigger_action(
|
||||
self, item_id: UUID4, recipe_slug: str, servings: int, yield_quantity: int, bg_tasks: BackgroundTasks
|
||||
) -> None:
|
||||
@router.post("/{item_id}/trigger/{recipe_slug}", status_code=202)
|
||||
def trigger_action(self, item_id: UUID4, recipe_slug: str, bg_tasks: BackgroundTasks) -> None:
|
||||
recipe_action = self.repos.group_recipe_actions.get_one(item_id)
|
||||
if not recipe_action:
|
||||
raise HTTPException(
|
||||
|
@ -95,8 +93,6 @@ class GroupRecipeActionController(BaseUserController):
|
|||
detail=ErrorResponse.respond(message="Not found."),
|
||||
) from e
|
||||
|
||||
recipe.recipe_servings = servings
|
||||
recipe.recipe_yield_quantity = yield_quantity
|
||||
payload = GroupRecipeActionPayload(action=recipe_action, content=recipe)
|
||||
bg_tasks.add_task(
|
||||
task_action,
|
||||
|
|
|
@ -171,7 +171,7 @@ def test_group_recipe_actions_trigger_post(
|
|||
recipe_slug = recipe.slug
|
||||
|
||||
response = api_client.post(
|
||||
api_routes.households_recipe_actions_item_id_trigger_recipe_slug(action_id, recipe_slug, 1, 1),
|
||||
api_routes.households_recipe_actions_item_id_trigger_recipe_slug(action_id, recipe_slug),
|
||||
headers=unique_user.token,
|
||||
)
|
||||
|
||||
|
@ -187,7 +187,7 @@ def test_group_recipe_actions_trigger_invalid_type(api_client: TestClient, uniqu
|
|||
recipe = unique_user.repos.recipes.create(new_recipe(unique_user))
|
||||
|
||||
response = api_client.post(
|
||||
api_routes.households_recipe_actions_item_id_trigger_recipe_slug(recipe_action.id, recipe.id, 1, 1),
|
||||
api_routes.households_recipe_actions_item_id_trigger_recipe_slug(recipe_action.id, recipe.id),
|
||||
headers=unique_user.token,
|
||||
)
|
||||
|
||||
|
|
|
@ -365,9 +365,9 @@ def households_recipe_actions_item_id(item_id):
|
|||
return f"{prefix}/households/recipe-actions/{item_id}"
|
||||
|
||||
|
||||
def households_recipe_actions_item_id_trigger_recipe_slug(item_id, recipe_slug, servings, yield_quantity):
|
||||
"""`/api/households/recipe-actions/{item_id}/trigger/{recipe_slug}/{servings}/{yield_quantity}`"""
|
||||
return f"{prefix}/households/recipe-actions/{item_id}/trigger/{recipe_slug}/{servings}/{yield_quantity}"
|
||||
def households_recipe_actions_item_id_trigger_recipe_slug(item_id, recipe_slug):
|
||||
"""`/api/households/recipe-actions/{item_id}/trigger/{recipe_slug}`"""
|
||||
return f"{prefix}/households/recipe-actions/{item_id}/trigger/{recipe_slug}"
|
||||
|
||||
|
||||
def households_self_recipes_recipe_slug(recipe_slug):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue