Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

feat[Op#50737]: Expand FrameComponent to allow explicit id with context

Kabiru Mwenjadad0c2420f31
diff --git a/app/components/op_turbo/frame_component.rb b/app/components/op_turbo/frame_component.rb
index 6f3876a84ad..4db96dd27a0 100644
--- a/app/components/op_turbo/frame_component.rb
+++ b/app/components/op_turbo/frame_component.rb
@@ -29,7 +29,19 @@
module OpTurbo
class FrameComponent < ApplicationComponent
def turbo_frame_id
+ optional_custom_id || turbo_frame_id_from_model
+ end
+
+ private
+
+ def turbo_frame_id_from_model
ActionView::RecordIdentifier.dom_id(model, options[:context])
end
+
+ def optional_custom_id
+ return if options[:id].blank?
+
+ options.values_at(:context, :id).compact.join("_")
+ end
end
end
diff --git a/spec/components/op_turbo/frame_component_spec.rb b/spec/components/op_turbo/frame_component_spec.rb
index 9a056f96810..6cbd030a1df 100644
--- a/spec/components/op_turbo/frame_component_spec.rb
+++ b/spec/components/op_turbo/frame_component_spec.rb
@@ -47,5 +47,21 @@ RSpec.describe OpTurbo::FrameComponent, type: :component do
expect(component.turbo_frame_id).to eq('storages_nextcloud_storage_1')
end
end
+
+ context 'with `id:` option' do
+ it 'returns the turbo frame id' do
+ component = described_class.new(id: 'test_id')
+
+ expect(component.turbo_frame_id).to eq('test_id')
+ end
+ end
+
+ context 'with `id:` and `context:` option' do
+ it 'returns the turbo frame id' do
+ component = described_class.new(id: 'test_id', context: :general_info)
+
+ expect(component.turbo_frame_id).to eq('general_info_test_id')
+ end
+ end
end
end