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 7 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
2 changes: 2 additions & 0 deletions bullet_train-super_scaffolding/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ gem "sprockets-rails"
gem "bullet_train"
gem "bullet_train-api"

gem "refine-rails", github: "clickfunnels2/refine-rails"
kaspth marked this conversation as resolved.
Show resolved Hide resolved

# Start debugger with binding.b [https://github.com/ruby/debug]
# gem "debug", ">= 1.0.0"
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
51 changes: 51 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,51 @@
class ApplicationFilter < Refine::Filter
include Refine::Conditions

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

def empty_option
[{id: "null", display: "Empty"}]
end

# Helper method used in certain applications of invalid filter checks. This will
def empty_query
model.where("1 = 0")
end

private

def condition(field, type)
CONDITIONS.fetch(type).new(field.to_s).with_display(heading(field)).then do
type == :option ? _1.with_options(options_for(field)) : _1
end
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, **options)
I18n.t("#{i18n_scope}.fields.#{key}", **options)
end

def i18n_scope
@i18n_scope ||= self.class.name.chomp("::Filter").pluralize.underscore.gsub("/", ".")
end
end
kaspth marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Scaffolding::CompletelyConcrete::TangibleThings::Assignment < ApplicationRecord
# 🚅 add concerns above.

# 🚅 add attribute accessors above.

belongs_to :tangible_thing, class_name: "Scaffolding::CompletelyConcrete::TangibleThing"
belongs_to :membership, class_name: "Membership"
# 🚅 add belongs_to associations above.

# 🚅 add has_many associations above.

has_one :team, through: :tangible_thing
# 🚅 add has_one associations above.

# 🚅 add scopes above.

# 🚅 add validations above.

# 🚅 add callbacks above.

# 🚅 add delegations above.

# 🚅 add methods above.
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
class Scaffolding::CompletelyConcrete::TangibleThing::Filter < ApplicationFilter
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

def i18n_scope
@i18n_scope ||= "account.#{super}"
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 @@ -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 @@ -5,6 +5,7 @@

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