-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow for injection of new tabs on edit page
This commit adds a new code seam allowing for the modification of tab ordering and the addition (or removal) of tabs on a form by form basis. The default tab order is moved out of the guts4form view partial and into a helper. To modify the default list of tabs in an application override the `form_tabs_for` helper method and make sure it gets loaded after Hyrax::HyraxHelperBehavoir (by default included in app/helpers/hyrax_helper.rb). For example: ``` module WorksHelper def form_tabs_for(form:) super + ["my_new_tab"] end end ``` A deprecation warning was added for cases where the view calling guts4form doesn't pass the tabs local param. The share tab has not been included in the default tab order because it wasn't in the view partial. Future work is to simplify the guts4form partial so share can be treated the same as the other tabs and included in the default list. Backport of #4440.
- Loading branch information
Showing
9 changed files
with
105 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,3 +78,4 @@ _yardoc | |
lib/bundler/man | ||
spec/reports | ||
/spec/examples.txt | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# frozen_string_literal: true | ||
module Hyrax | ||
module WorkFormHelper | ||
def form_tabs_for(form:) | ||
if form.instance_of? Hyrax::Forms::BatchUploadForm | ||
%w[files metadata relationships] | ||
else | ||
%w[metadata files relationships] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe Hyrax::WorkFormHelper do | ||
describe 'form_tabs_for' do | ||
context 'with a work form' do | ||
let(:work) { stub_model(GenericWork, id: '456') } | ||
let(:ability) { double } | ||
let(:form) { Hyrax::GenericWorkForm.new(work, ability, controller) } | ||
|
||
it 'returns a default tab list' do | ||
expect(form_tabs_for(form: form)).to eq ["metadata", "files", "relationships"] | ||
end | ||
end | ||
|
||
context 'with a batch upload form' do | ||
let(:work) { stub_model(GenericWork, id: '456') } | ||
let(:ability) { double } | ||
let(:form) { Hyrax::Forms::BatchUploadForm.new(work, ability, controller) } | ||
|
||
it 'returns an alternate tab ordering' do | ||
expect(form_tabs_for(form: form)).to eq ["files", "metadata", "relationships"] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters