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

Feature - inline ui can now merge OR groupings #193

Merged
merged 5 commits into from
Sep 19, 2024
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 2.11.5
* New Feature - Adds the ability to delete OR groupings which merge them as AND conjunctions
* Inline UI - adds support for stimulus tooltip plugins
* Inline UI - tweaks to responsive behavior of the toolbar
### 2.11.4
* Inline UI - Fixing bug with popup edit modals so clicking outside properly closes them
### 2.11.3
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
refine-rails (2.11.4)
refine-rails (2.11.5)
rails (>= 6.0)

GEM
Expand Down
39 changes: 29 additions & 10 deletions app/assets/stylesheets/index.tailwind.css
Original file line number Diff line number Diff line change
Expand Up @@ -418,12 +418,23 @@
flex-wrap: wrap;
display: flex;
align-items: center;
justify-content: end;
}

@media (max-width: 960px) {

@media (max-width: 1525px) {
.refine--filter-control-group {
width: 24%;
}
}
@media (max-width: 1200px) {
.refine--filter-control-group {
width: 30%;
}
}
@media (max-width: 1100px) {
.refine--filter-control-group {
justify-content: end;
width: 25%;
width: 40%;
}
}

Expand All @@ -444,6 +455,14 @@
text-align: left;
}

.refine--group-join {
&:hover {
.refine--remove-group {
display: block;
}
}
}

.refine--group {
display: flex;
gap: 10px;
Expand Down Expand Up @@ -563,7 +582,7 @@
padding: 4px;
}

.refine--remove-condition {
.refine--remove-condition, .refine--remove-group {
display: none;
color: #fff;
padding: 0px 2px 0px 2px;
Expand All @@ -580,15 +599,15 @@
.icon.refine--icon-sm {
padding: 2px 0 ;
}

}
&:hover {
border-color: #999;
.remove-applied-condition {
display: block;
&:hover {
border-color: #999;
.remove-applied-condition {
display: block;
}
}
}


.refine--condition-value-wrapper {
position: absolute;
top: 100%;
Expand Down
11 changes: 8 additions & 3 deletions app/controllers/refine/inline/criteria_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,17 @@ def clear
handle_filter_update()
end

private
def merge_groups
@criterion = Refine::Inline::Criterion.new(criterion_params.merge(refine_filter: @refine_filter))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Technically we don't need a criterion object to perform the operation required here, but the controller expects a criterion so the action just passes in the first element of the group being acted on. Its not ideal and arguably we should have a conjunction controller or a rethink of how criteria are managed. Today criterion are also acting on their surrounding conjunctions and it can be confusing but I didn't want to mess with this paradigm in this work

Refine::Filters::BlueprintEditor
.new(@refine_filter.blueprint)
.change_conjunction(criterion_params[:position].to_i - 1, "and")

def set_blank_filter
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This wasn't being used anywhere and was leftover from my work on the clear button. So removed

@refine_filter = Refine::Rails.configuration.stabilizer_classes[:url].new
handle_filter_update(@refine_filter.to_stable_id)
end

private

def set_refine_filter
@refine_filter ||= Refine::Rails.configuration.stabilizer_classes[:url]
.new
Expand Down
8 changes: 8 additions & 0 deletions app/models/refine/filters/blueprint_editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ def update(index, criterion:)
blueprint[index][:input] = input
end

def change_conjunction(index, conjunction_word)
if conjunction_word == "and"
blueprint[index][:word] = "and"
elsif conjunction_word == "or"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No real use case for this behavior but I went ahead and added it since it was easy

blueprint[index][:word] = "or"
end
end

def delete(index)
# To support 'groups' there is some complicated logic for deleting criterion.
#
Expand Down
2 changes: 1 addition & 1 deletion app/views/refine/inline/filters/_criterion.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<%= link_to edit_refine_inline_criterion_path(criterion.position, criterion.to_params), class:"refine--condition-pill-button", data: {controller: "refine--turbo-stream-link", action: "refine--turbo-stream-link#visit refine--popup#show"} do %>
<div class="refine--condition-pill-name"><%= criterion.condition_display %></div>
<div class="refine--condition-value-clause"><%= criterion.clause_display %></div>
<div class="refine--condition-value-self" title="<%= criterion.human_readable_value %>">
<div class="refine--condition-value-self" title="<%= criterion.human_readable_value %>" data-controller="tooltip" data-tooltip-content-value="<%= criterion.human_readable_value %>">
<%= criterion.human_readable_value %>
</div>
<% end %>
Expand Down
16 changes: 16 additions & 0 deletions app/views/refine/inline/filters/_or_separator.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<% group_position ||= 0 %>

<% unless group_position == 0 %>
<% if render_stack %>
<div class="refine--group-join-stack">
<% end %>
<div class="refine--group-join">
<%= t("refine.inline.filters.or") %>
<%= link_to merge_groups_refine_inline_criteria_path(group.first.to_params), class: "refine--remove-group", data: {turbo_method: :post, controller: "refine--turbo-stream-link", action: "refine--turbo-stream-link#visit"} do %>
<span class="material-icons-outlined refine--icon-sm">clear</span>
<% end %>
</div>
<% if render_stack %>
</div>
<% end %>
<% end %>
10 changes: 1 addition & 9 deletions app/views/refine/inline/filters/_show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,7 @@
<% else %>
<div class="refine--groups-wrapper">
<% groups.each.with_index do |group, i| %>
<% unless i == 0 %>
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

most of this got moved into the or_separator partial

<% if render_stack %>
<div class="refine--group-join-stack">
<% end %>
<div class="refine--group-join"><%= t("refine.inline.filters.or") %></div>
<% if render_stack %>
</div>
<% end %>
<% end %>
<%= render "refine/inline/filters/or_separator", group: group, group_position: i, render_stack: render_stack %>
<%= render "refine/inline/filters/group", group: group, group_count: groups.count, condition_count: group.count, render_stack: render_stack %>
<% if i == groups.length - 1 %>
<%= render "refine/inline/filters/or_button", position: @refine_filter.blueprint.length %>
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
end
namespace :inline do
resources :criteria, except: [:show] do
post "merge_groups", on: :collection
post "clear", on: :collection
end
resources :stored_filters, only: [:index, :new, :create] do
Expand Down
2 changes: 1 addition & 1 deletion lib/refine/rails/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Refine
module Rails
VERSION = "2.11.4"
VERSION = "2.11.5"
end
end
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@clickfunnels/refine-stimulus",
"version": "2.11.4",
"version": "2.11.5",
"description": "Refine is a flexible query builder for your apps. It lets your users filter down to exactly what they're looking for. Completely configured on the backend.",
"browserslist": [
"defaults",
Expand Down
Loading