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

Refine Integration #710

Draft
wants to merge 19 commits into
base: main
Choose a base branch
from
Draft
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
3 changes: 3 additions & 0 deletions bullet_train-api/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ PATH
indefinite_article
masamune-ast (~> 2.0.2)
rails (>= 6.0.0)
refine-rails

PATH
remote: ../bullet_train
Expand Down Expand Up @@ -354,6 +355,8 @@ GEM
rake (13.0.6)
redis-client (0.17.0)
connection_pool
refine-rails (2.9.0)
rails (>= 6.0)
regexp_parser (2.8.1)
responders (3.1.0)
actionpack (>= 5.2)
Expand Down
3 changes: 3 additions & 0 deletions bullet_train-fields/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ PATH
indefinite_article
masamune-ast (~> 2.0.2)
rails (>= 6.0.0)
refine-rails

PATH
remote: ../bullet_train
Expand Down Expand Up @@ -347,6 +348,8 @@ GEM
rake (13.1.0)
redis-client (0.18.0)
connection_pool
refine-rails (2.9.0)
rails (>= 6.0)
regexp_parser (2.5.0)
responders (3.1.1)
actionpack (>= 5.2)
Expand Down
3 changes: 3 additions & 0 deletions bullet_train-incoming_webhooks/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ PATH
indefinite_article
masamune-ast (~> 2.0.2)
rails (>= 6.0.0)
refine-rails

PATH
remote: ../bullet_train
Expand Down Expand Up @@ -386,6 +387,8 @@ GEM
psych (>= 4.0.0)
redis-client (0.18.0)
connection_pool
refine-rails (2.9.0)
rails (>= 6.0)
reline (0.4.0)
io-console (~> 0.5)
responders (3.1.1)
Expand Down
3 changes: 3 additions & 0 deletions bullet_train-integrations-stripe/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ PATH
indefinite_article
masamune-ast (~> 2.0.2)
rails (>= 6.0.0)
refine-rails

PATH
remote: ../bullet_train
Expand Down Expand Up @@ -403,6 +404,8 @@ GEM
psych (>= 4.0.0)
redis-client (0.18.0)
connection_pool
refine-rails (2.9.0)
rails (>= 6.0)
reline (0.4.0)
io-console (~> 0.5)
responders (3.1.1)
Expand Down
3 changes: 3 additions & 0 deletions bullet_train-outgoing_webhooks/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ PATH
indefinite_article
masamune-ast (~> 2.0.2)
rails (>= 6.0.0)
refine-rails

PATH
remote: ../bullet_train
Expand Down Expand Up @@ -359,6 +360,8 @@ GEM
rake (13.0.6)
redis-client (0.18.0)
connection_pool
refine-rails (2.9.0)
rails (>= 6.0)
regexp_parser (2.8.1)
responders (3.1.1)
actionpack (>= 5.2)
Expand Down
3 changes: 3 additions & 0 deletions bullet_train-sortable/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ PATH
indefinite_article
masamune-ast (~> 2.0.2)
rails (>= 6.0.0)
refine-rails

PATH
remote: ../bullet_train
Expand Down Expand Up @@ -384,6 +385,8 @@ GEM
psych (>= 4.0.0)
redis-client (0.18.0)
connection_pool
refine-rails (2.9.0)
rails (>= 6.0)
regexp_parser (2.8.2)
reline (0.4.0)
io-console (~> 0.5)
Expand Down
3 changes: 3 additions & 0 deletions bullet_train-super_scaffolding/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ PATH
indefinite_article
masamune-ast (~> 2.0.2)
rails (>= 6.0.0)
refine-rails

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -351,6 +352,8 @@ GEM
rake (13.0.6)
redis-client (0.18.0)
connection_pool
refine-rails (2.9.0)
rails (>= 6.0)
regexp_parser (2.8.1)
responders (3.1.1)
actionpack (>= 5.2)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
class Account::Scaffolding::CompletelyConcrete::TangibleThingsController < Account::ApplicationController
include Refine::FilterApplicationController
account_load_and_authorize_resource :tangible_thing, through: :absolutely_abstract_creative_concept, through_association: :completely_concrete_tangible_things

# GET /account/scaffolding/absolutely_abstract/creative_concepts/:absolutely_abstract_creative_concept_id/completely_concrete/tangible_things
# GET /account/scaffolding/absolutely_abstract/creative_concepts/:absolutely_abstract_creative_concept_id/completely_concrete/tangible_things.json
def index
apply_inline_filter Scaffolding::CompletelyConcrete::TangibleThing::Filter, initial_query: @tangible_things
@tangible_things = @refine_filter.get_query
delegate_json_to_api
end

Expand Down
55 changes: 55 additions & 0 deletions bullet_train-super_scaffolding/app/models/application_filter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
class ApplicationFilter < Refine::Filter
include Refine::Conditions

class_attribute :i18n_scope, instance_writer: false

def self.inherited(klass)
klass.i18n_scope = klass.name.sub(/(::)?Filter$/, "").pluralize.underscore.tr("/", ".")
super
end

CONDITIONS = {
option: OptionCondition,
numeric: NumericCondition,
text: TextCondition,
boolean: BooleanCondition,
date: DateCondition,
datetime: DateWithTimeCondition,
}

# list conditions in alphabetical order
def conditions_to_array
super&.sort_by { _1[:display].to_s.downcase }
end

private

def condition(field, type)
condition = CONDITIONS.fetch(type).new(field.to_s).with_display(heading(field))

# Reject set/not_set clause options in case the field can't be null in the database.
if (column = column_for(field))
condition = condition.without_clauses([Clauses::SET, Clauses::NOT_SET]) if column.null == false
end

# Derive options via I18n scope.
condition = condition.with_options(options_for(field)) if type == :option
condition
end

def column_for(field)
model.connection.columns(model.table_name).index_by(&:name)[field.to_s]
end

def heading(field)
t("#{field}.heading")
end

def options_for(field)
t("#{field}.options").map { {id: _1.to_s, display: _2} }
end

def t(key, **)
I18n.t("#{i18n_scope}.fields.#{key}", **)
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
class Scaffolding::CompletelyConcrete::TangibleThing::Filter < ApplicationFilter
self.i18n_scope = "account.#{i18n_scope}"

def conditions
[
condition(:text_field_value, :text),
condition(:email_field_value, :text),
condition(:phone_field_value, :text),
condition(:address_value, :text),
condition(:text_area_value, :text),
condition(:action_text_value, :text),

condition(:sort_order, :numeric),

condition(:color_picker_value, :option),
condition(:button_value, :option),
condition(:boolean_button_value, :option),
condition(:multiple_button_values, :option),
condition(:option_value, :option),
condition(:multiple_option_values, :option),
condition(:super_select_value, :option),
condition(:multiple_super_select_values, :option),

condition(:date_field_value, :date),
condition(:date_and_time_field_value, :datetime),
condition(:created_at, :datetime),
Copy link

Choose a reason for hiding this comment

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

One thing I would recommend is we add in the clause manipulations for created_at and updated_at generators. The IS_SET and IS_NOT_SET clauses serve no purpose for these fields since they are always present so the scaffolding should probably automatically apply
.without_clauses([DateWithTimeCondition::CLAUSE_SET, DateWithTimeCondition::CLAUSE_NOT_SET]) for simplicity

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ssteffen good point! I just pushed 382ef94 which will use a column's null: false information to automatically reject the presence concerned clauses aka SET/NOT_SET.

I think I found a bug in Refine though, so I'll submit a PR shortly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope, looks like that was fixed in clickfunnels2/refine-rails#157, but I happened to be running an older version of Refine (thought I'd updated ugh).

condition(:updated_at, :datetime),
]
end

def model
self.class.module_parent
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,39 @@
<% end %>

<% box.table do %>
<% if tangible_things.any? %>
<table class="table">
<thead>
<tr>
<%= render "shared/tables/select_all" %>
<%# 🚅 skip this section when scaffolding. %>
<th><%= t('.fields.text_field_value.heading') %></th>
<th><%= t('.fields.boolean_button_value.heading') %></th>
<th><%= t('.fields.button_value.heading') %></th>
<th><%= t('.fields.multiple_button_values.heading') %></th>
<%# 🚅 stop any skipping we're doing now. %>
<%# 🚅 super scaffolding will insert new field headers above this line. %>
<th><%= t('.fields.created_at.heading') %></th>
<th class="text-right"></th>
</tr>
</thead>
<tbody>
<%= render partial: 'account/scaffolding/completely_concrete/tangible_things/tangible_thing', collection: tangible_things %>
</tbody>
</table>
<% if @refine_filter %>
<div class="px-8 py-2">
<%= form_with method: :get, data: { controller: "refine-support--form", action: "filter-submit-success->refine-support--form#requestSubmit", turbo_frame: "tangible_things_table" } do |form| %>
<%= form.hidden_field :stable_id, value: @refine_stable_id %>
<%= render "refine/inline/filters/show" %>
<% end %>
</div>
<% end %>

<%= turbo_frame_tag :tangible_things_table, target: "_top" do %>
<% if tangible_things.any? %>
<table class="table">
<thead>
<tr>
<%= render "shared/tables/select_all" %>
<%# 🚅 skip this section when scaffolding. %>
<th><%= t('.fields.text_field_value.heading') %></th>
<th><%= t('.fields.boolean_button_value.heading') %></th>
<th><%= t('.fields.button_value.heading') %></th>
<th><%= t('.fields.multiple_button_values.heading') %></th>
<%# 🚅 stop any skipping we're doing now. %>
<%# 🚅 super scaffolding will insert new field headers above this line. %>
<th><%= t('.fields.created_at.heading') %></th>
<th class="text-right"></th>
</tr>
</thead>
<tbody>
<%= render partial: 'account/scaffolding/completely_concrete/tangible_things/tangible_thing', collection: tangible_things %>
</tbody>
</table>
<% elsif @refine_filter %>
<div class="px-8 py-4">No tangible things found.</div>
<% end %>
<% end %>
<% end %>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Gem::Specification.new do |spec|
spec.add_dependency "rails", ">= 6.0.0"
spec.add_dependency "masamune-ast", "~> 2.0.2"
spec.add_dependency "colorizer"
spec.add_dependency "refine-rails"

# For Super Scaffolding: "select *a* team member" vs. "select *an* option".
spec.add_dependency "indefinite_article"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ en:
_: &address_value Address Value
label: *address_value
heading: *address_value
sort_order:
_: &sort_order Sort Order
label: *sort_order
heading: *sort_order
option_value:
_: &option_value Option Value
label: *option_value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

require "indefinite_article"
require "colorizer"
require "refine/rails"

module BulletTrain
module SuperScaffolding
Expand Down
3 changes: 3 additions & 0 deletions bullet_train-themes-light/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ PATH
indefinite_article
masamune-ast (~> 2.0.2)
rails (>= 6.0.0)
refine-rails

PATH
remote: ../bullet_train
Expand Down Expand Up @@ -390,6 +391,8 @@ GEM
psych (>= 4.0.0)
redis-client (0.18.0)
connection_pool
refine-rails (2.9.0)
rails (>= 6.0)
regexp_parser (2.8.2)
reline (0.4.0)
io-console (~> 0.5)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

@import './bulk_actions';
@import "./electron";
@import "./refine";
@import './devise';
@import './fields';
@import './turn';
Expand Down
Loading
Loading