Skip to content

Commit 043c05b

Browse files
Keep plan navigation state current
Amp-Thread-ID: https://ampcode.com/threads/T-01a01147-8d44-7468-ac98-bf40b04e3cee Co-authored-by: Amp <amp@ampcode.com>
1 parent 0f53de9 commit 043c05b

4 files changed

Lines changed: 14 additions & 7 deletions

File tree

engine/app/controllers/coplan/plans_controller.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,7 @@ def set_plan
687687

688688
def broadcast_plan_update(plan)
689689
Broadcaster.replace_to(plan, target: "plan-header", partial: "coplan/plans/header", locals: { plan: plan })
690+
Broadcaster.replace_to(plan, target: "plan-nav-context", partial: "coplan/plans/nav_context", locals: { plan: plan })
690691
end
691692

692693
# Turbo Streams for a visibility change: re-render the header (the
@@ -708,6 +709,7 @@ def visibility_streams(message)
708709
def archive_streams(message)
709710
[
710711
turbo_stream.replace("plan-header", partial: "coplan/plans/header", locals: { plan: @plan }),
712+
turbo_stream.replace("plan-nav-context", partial: "coplan/plans/nav_context", locals: { plan: @plan }),
711713
turbo_stream.replace("plan-banner-slot", partial: "coplan/plans/banner", locals: { plan: @plan }),
712714
turbo_stream.replace("plan-toolbar", partial: "coplan/plans/toolbar", locals: { plan: @plan }),
713715
toast_stream(message, "notice")
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<% author_placement = local_assigns.fetch(:author_placement) { plan.author_placement } %>
2+
<span id="plan-nav-context" class="site-nav__plan-context" data-controller="coplan--nav-title" aria-hidden="true">
3+
<%= render "coplan/plans/location_link", plan: plan, placement: author_placement, location: :nav %>
4+
<a href="#plan-header" class="site-nav__doc-title" data-action="click->coplan--nav-title#scrollToTop" tabindex="-1">
5+
<%= plan_type_icon(plan, size: :sm) %>
6+
<span class="site-nav__doc-title-text"><%= plan.title %></span>
7+
</a>
8+
</span>

engine/app/views/coplan/plans/show.html.erb

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,7 @@
1616
containing-folder control, icon, and title mirror the masthead;
1717
coplan--nav-title fades them in once #plan-header scrolls behind the bar. %>
1818
<% content_for :nav_title do %>
19-
<span class="site-nav__plan-context" data-controller="coplan--nav-title" aria-hidden="true">
20-
<%= render "coplan/plans/location_link", plan: @plan, placement: @author_placement, location: :nav %>
21-
<a href="#plan-header" class="site-nav__doc-title" data-action="click->coplan--nav-title#scrollToTop" tabindex="-1">
22-
<%= plan_type_icon(@plan, size: :sm) %>
23-
<span class="site-nav__doc-title-text"><%= @plan.title %></span>
24-
</a>
25-
</span>
19+
<%= render "coplan/plans/nav_context", plan: @plan, author_placement: @author_placement %>
2620
<% end %>
2721

2822
<%= turbo_stream_from @plan %>

spec/system/human_editing_spec.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ def open_plan_menu
109109

110110
it "archives and restores the plan in place" do
111111
visit plan_path(plan)
112+
expect(page).to have_css(".plan-location-link--nav", visible: :all)
112113

113114
open_plan_menu
114115
within("#plan-menu") { click_button "Archive plan" }
@@ -117,6 +118,7 @@ def open_plan_menu
117118
# undo, no navigation away from the document.
118119
expect(page).to have_css(".plan-banner--archived", text: "hidden from lists")
119120
expect(page).to have_content("Editable Plan")
121+
expect(page).not_to have_css(".plan-location-link", visible: :all)
120122
expect(plan.reload.archived?).to be(true)
121123

122124
# Archive leaves the menu while archived.
@@ -126,6 +128,7 @@ def open_plan_menu
126128

127129
within(".plan-banner--archived") { click_button "Restore" }
128130
expect(page).not_to have_css(".plan-banner--archived")
131+
expect(page).to have_css(".plan-location-link--nav", visible: :all)
129132
expect(plan.reload.archived?).to be(false)
130133
end
131134

0 commit comments

Comments
 (0)