Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DialogFieldTagControl - don't add <None> for multiselects #19696

Merged
merged 2 commits into from
Jan 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/models/dialog_field_tag_control.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ def force_multi_value
!single_value?
end

def multiselect?
force_multi_value
end
Comment on lines +40 to +42
Copy link
Member

@eclarizio eclarizio Jan 8, 2020

Choose a reason for hiding this comment

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

Should we add this method or just use force_multi_value on line 71? Or, if we do want multiselect?, should we just change it to an alias?

Just seems like we're making a method for the name, since it does nothing other than call the other method that already exists.

We could alternatively just call single_value? on line 71 and reverse the ternary. I think I like this idea the best.

Copy link
Contributor Author

@himdel himdel Jan 9, 2020

Choose a reason for hiding this comment

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

I'm adding it for consistency with dropdowns, which are already using the method.

But, I can change both :).

But, then it can't be single_value? which doesn't exist for dropdowns, and to me force_multi sounds misleading, we don't care about "forced" but about what we're actually using, that's why I introduced multiselect? in the first place.

(And in fact, with tagging, force_multi_value now gives the wrong value when the category doesn't allow multiselect, but the editor didn't know that, but I'm not sure what that change should affect yet.)

WDYT, anything we can use in both?

Copy link
Member

@eclarizio eclarizio Jan 9, 2020

Choose a reason for hiding this comment

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

Ah ok that makes sense, maybe we just do alias_method :multiselect?, :force_multi_value then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah, next PR then :)


def self.allowed_tag_categories
tag_cats = Classification.is_category.where(:show => true, :read_only => false).includes(:tag).to_a

Expand Down Expand Up @@ -64,7 +68,7 @@ def values
end

empty = required? ? "<Choose>" : "<None>"
blank_value = [{:id => nil, :name => empty, :description => empty}]
blank_value = multiselect? ? [] : [{:id => nil, :name => empty, :description => empty}]

return blank_value + available_tags if sort_field == :none

Expand Down
19 changes: 16 additions & 3 deletions spec/models/dialog_field_tag_control_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,13 @@ def add_entry(cat, options)

describe "#values" do
let(:dialog_field) { described_class.new(:options => options, :data_type => data_type, :required => required) }
let(:options) { {:category_id => category_id, :sort_by => sort_by, :sort_order => sort_order} }
let(:options) { {:category_id => category_id, :sort_by => sort_by, :sort_order => sort_order, :force_single_value => single?} }
let(:category_id) { 123 }
let(:required) { false }
let(:sort_by) { :none }
let(:sort_order) { :ascending }
let(:data_type) { "string" }
let(:single?) { true }

before do
allow(Classification).to receive(:find_by).with(:id => category_id).and_return(classification)
Expand All @@ -165,8 +166,20 @@ def add_entry(cat, options)
shared_examples_for "DialogFieldTagControl#values when required is true" do
let(:required) { true }

it "the blank value uses 'Choose' for its name and description" do
expect(dialog_field.values[0]).to eq(:id => nil, :name => "<Choose>", :description => "<Choose>")
context "singlevalue" do
let(:single?) { true }

it "the blank value uses 'Choose' for its name and description" do
expect(dialog_field.values[0]).to eq(:id => nil, :name => "<Choose>", :description => "<Choose>")
end
end

context "multi value" do
let(:single?) { false }

it "has no blank value" do
expect(%w[<Choose> <None>]).to_not include(dialog_field.values[0][:name])
end
end
end

Expand Down