Skip to content

Show actions dropdown on edit order page only when there are actions available#13760

Draft
drummer83 wants to merge 2 commits intoopenfoodfoundation:masterfrom
drummer83:order_links
Draft

Show actions dropdown on edit order page only when there are actions available#13760
drummer83 wants to merge 2 commits intoopenfoodfoundation:masterfrom
drummer83:order_links

Conversation

@drummer83
Copy link
Copy Markdown
Contributor

What? Why?

On cancelled orders there are no actions that can be taken, like ship order, cancel order, send invoice, print invoice etc. So the actions dropdown is empty. Instead of showing the empty dropdown we should simply hide it.

This PR makes sure that the actions dropdown is only rendered when there are actions available.

Before

Dropdown open and no actions available:
image

After

No dropdown:
image

Before and after (unchanged)

Dropdown is shown when actions are available:
image

What should we test?

  • Visit the edit order page for orders in all different order states.
  • Check that the actions dropdown is only shown when there are actions available.
  • Check that the actions are working properly.

Release notes

Changelog Category (reviewers may add a label for the release notes):

  • User facing changes
  • API changes (V0, V1, DFC or Webhook)
  • Technical changes only
  • Feature toggled

The title of the pull request will be included in the release notes.

Dependencies

Documentation updates

@github-project-automation github-project-automation Bot moved this to All the things 💤 in OFN Delivery board Nov 25, 2025
@sigmundpetersen sigmundpetersen moved this from All the things 💤 to In Progress ⚙ in OFN Delivery board Nov 25, 2025
@drummer83
Copy link
Copy Markdown
Contributor Author

drummer83 commented Nov 25, 2025

Hi @filipefurtad0,
Could you please help me adding a spec here?
I tried it in my second commit, but it seems like the test is not checking the buttons at the top. I have no clue how to proceed.
Thanks in advance! 🙏

@filipefurtad0
Copy link
Copy Markdown
Contributor

Hey @drummer83 ,
Sure, I'll have a look at the PR and the test, and will get back to you.

render

expect(rendered).to have_content("Actions")
end
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @drummer83,
I believe this assertion will pass, if you run it within the file ./spec/views/spree/admin/orders/index.html.haml_spec.rb, instead of this one here (.spec/views/spree/admin/orders/edit.html.haml_spec.rb - this deals with the edit variants section of the edit orders page).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...Hum, not quite. It passes, because it deals with the bulk orders page. You're looking at the right file @drummer83 👍 But the view is not generating that menu. Will investigate further.

Copy link
Copy Markdown
Contributor

@filipefurtad0 filipefurtad0 Nov 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so I think I was close 😅
So, we need to run that test on the right component, which is spree/admin/shared/_order_links.html.haml which is the one you change in this PR. However, view specs test one component at a time, system specs test them all. So, to test the component in a granular way 💪 I'd say you need to create a specific test for this component, as I've found none.

So, I'd suggest creating this view test, on a separate file and commit (code suggestion below), and then create a context in which the actions menu is hidden (e.g., cancelled):

Suggested change
end
# frozen_string_literal: true
require "spec_helper"
RSpec.describe "spree/admin/shared/_order_links.html.haml" do
helper Spree::Admin::OrdersHelper
around do |example|
original_config = Spree::Config[:enable_invoices?]
example.run
Spree::Config[:enable_invoices?] = original_config
end
let(:current_test_user) { create(:admin_user) }
before do
controller.singleton_class.class_eval do
attr_accessor :current_test_user
def current_ability
Spree::Ability.new(current_test_user)
end
end
controller.current_test_user = current_test_user
allow(view).to receive_messages spree_current_user: current_test_user
end
context "when order is complete" do
let(:order) { create(:completed_order_with_fees) }
before do
order.distributor = create(:distributor_enterprise)
assign(:order, order)
assign(:shops, [order.distributor])
assign(:order_cycles, [])
end
it "displays the order_links dropdown" do
render
expect(rendered).to have_content("Actions")
end
end
end

What do you think @drummer83 ?

(PS: this comment looks weird as it suggests to replace the end line; the idea I'm proposing is rather replacing this commit with another one, in which you create a new spec file, with the code in green above. Please let me know if this clarifies.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress ⚙

Development

Successfully merging this pull request may close these issues.

3 participants