From d14246c8a5cef0d70ff5f0eb33e65c72f6d701c3 Mon Sep 17 00:00:00 2001 From: Darren Siegel Date: Thu, 9 Nov 2023 09:42:32 -0500 Subject: [PATCH] [BUG FIX] handle unordered move (#4416) --- lib/oli_web/live/resources/pages_view.ex | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/oli_web/live/resources/pages_view.ex b/lib/oli_web/live/resources/pages_view.ex index a7152755a3a..958d3060106 100644 --- a/lib/oli_web/live/resources/pages_view.ex +++ b/lib/oli_web/live/resources/pages_view.ex @@ -78,6 +78,7 @@ defmodule OliWeb.Resources.PagesView do assign(socket, ctx: ctx, + last_selected_slug: nil, breadcrumbs: breadcrumb(project), project_hierarchy: project_hierarchy, project: project, @@ -522,6 +523,8 @@ defmodule OliWeb.Resources.PagesView do """ end + socket = socket |> assign(last_selected_slug: slug) + {:noreply, show_modal( socket, @@ -550,6 +553,27 @@ defmodule OliWeb.Resources.PagesView do {:noreply, hide_modal(socket, modal_assigns: nil)} end + def handle_event( + "MoveModal.move_item", + %{"to_uuid" => to_uuid}, + socket + ) do + %{ + author: author, + project: project, + modal_assigns: %{hierarchy: hierarchy} + } = socket.assigns + + # This handles the case where the page that was selected to be moved + # does not exist within the hierarchy. + revision = AuthoringResolver.from_revision_slug(project.slug, socket.assigns.last_selected_slug) + %{revision: to_container} = Hierarchy.find_in_hierarchy(hierarchy, to_uuid) + + {:ok, _} = ContainerEditor.move_to(revision, nil, to_container, author, project) + + {:noreply, hide_modal(socket, modal_assigns: nil)} + end + def handle_event("MoveModal.remove", %{"from_uuid" => from_uuid}, socket) do %{ author: author,