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

implement filters in nested select #300 #301

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ var initializer = function() {
var url = element.data('url');
var fields = element.data('fields');
var predicate = element.data('predicate');
var filters = element.data('filters');
var displayName = element.data('display-name');
var parent = element.data('parent');
var width = element.data('width');
Expand Down Expand Up @@ -117,6 +118,8 @@ var initializer = function() {
query.q[parent + '_eq'] = parentId;
}

Object.assign(query.q, filters);

return query;
},
processResults: function(data) {
Expand Down
1 change: 1 addition & 0 deletions app/inputs/nested_level_input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def load_control_attributes
load_class(@options[:class])
load_data_attr(:fields, default: ["name"], formatter: :to_json)
load_data_attr(:predicate, default: "contains")
load_data_attr(:filters)
load_data_attr(:model, value: model_name)
load_data_attr(:display_name, default: "name")
load_data_attr(:minimum_input_length, default: 1)
Expand Down
77 changes: 77 additions & 0 deletions spec/features/inputs/nested_select_input_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,83 @@
end
end
end
context "with filters", focus: true do
before do
register_page(Country, false) {}
register_page(Region, false) {}
register_page(City, false) {}

register_form(Invoice, false) do |f|
f.input :city_id, as: :nested_select,
level_1: { attribute: :country_id },
level_2: {
attribute: :region_id,
filters: { name_contains: 'Met' }
},
Copy link

Choose a reason for hiding this comment

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

Indent the right brace the same as the start of the line where the left brace is.

level_3: { attribute: :city_id }
end

create_cities
create_invoice(city: @colina)

Choose a reason for hiding this comment

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

Replace instance variable with local variable or let.

visit edit_admin_invoice_path(@invoice)

Choose a reason for hiding this comment

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

Replace instance variable with local variable or let.

end

it "shows filled select controls based on defined city_id", js: true do
on_input_ctx("invoice_country_id") { expect_select2_selection("Chile") }
on_input_ctx("invoice_region_id") { expect_select2_selection("Metropolitana") }
on_input_ctx("invoice_city_id") { expect_select2_selection("Colina") }
end

context "updating medium level" do

Choose a reason for hiding this comment

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

Start context description with 'when', 'with', or 'without'.

before do
on_input_ctx("invoice_region_id") { open_select2_options }
select2_input.set("a")
end

it "shows no results based on entered text", js: true do
expect_select2_results_count_to_eq(1)
end
end
end

context "without filters", focus: true do

Choose a reason for hiding this comment

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

Focused spec found.

before do
register_page(Country, false) {}
register_page(Region, false) {}
register_page(City, false) {}

register_form(Invoice, false) do |f|
f.input :city_id, as: :nested_select,
level_1: { attribute: :country_id },
level_2: {
attribute: :region_id,

Choose a reason for hiding this comment

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

Avoid comma after the last item of a hash.

# filters: { name_contains: 'Met' }

Choose a reason for hiding this comment

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

Incorrect indentation detected (column 28 instead of 30).

},

Choose a reason for hiding this comment

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

Indent the right brace the same as the start of the line where the left brace is.

level_3: { attribute: :city_id }
end

create_cities
create_invoice(city: @colina)

Choose a reason for hiding this comment

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

Replace instance variable with local variable or let.

visit edit_admin_invoice_path(@invoice)

Choose a reason for hiding this comment

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

Replace instance variable with local variable or let.

end

it "shows filled select controls based on defined city_id", js: true do
on_input_ctx("invoice_country_id") { expect_select2_selection("Chile") }
on_input_ctx("invoice_region_id") { expect_select2_selection("Metropolitana") }
on_input_ctx("invoice_city_id") { expect_select2_selection("Colina") }
end

context "updating medium level" do

Choose a reason for hiding this comment

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

Start context description with 'when', 'with', or 'without'.

before do
on_input_ctx("invoice_region_id") { open_select2_options }
select2_input.set("a")
end

it "shows no results based on entered text", js: true do
expect_select2_results_count_to_eq(2)
end
end
end

context "with nested resources" do
before do
Expand Down