mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-09 07:25:19 +02:00
Add ability to name a rule
This commit is contained in:
parent
d8e34cf791
commit
cf1b4d3056
8 changed files with 37 additions and 4 deletions
|
@ -64,7 +64,7 @@ class RulesController < ApplicationController
|
|||
|
||||
def rule_params
|
||||
params.require(:rule).permit(
|
||||
:resource_type, :effective_date, :active,
|
||||
:resource_type, :effective_date, :active, :name,
|
||||
conditions_attributes: [
|
||||
:id, :condition_type, :operator, :value, :_destroy,
|
||||
sub_conditions_attributes: [ :id, :condition_type, :operator, :value, :_destroy ]
|
||||
|
|
|
@ -8,7 +8,10 @@ class Rule < ApplicationRecord
|
|||
accepts_nested_attributes_for :conditions, allow_destroy: true
|
||||
accepts_nested_attributes_for :actions, allow_destroy: true
|
||||
|
||||
before_validation :normalize_name
|
||||
|
||||
validates :resource_type, presence: true
|
||||
validates :name, length: { minimum: 1 }, allow_nil: true
|
||||
validate :no_nested_compound_conditions
|
||||
|
||||
# Every rule must have at least 1 action
|
||||
|
@ -87,4 +90,8 @@ class Rule < ApplicationRecord
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
def normalize_name
|
||||
self.name = nil if name.is_a?(String) && name.strip.empty?
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,6 +9,16 @@
|
|||
<%= render "shared/form_errors", model: @rule %>
|
||||
<% end %>
|
||||
|
||||
<section class="space-y-4">
|
||||
<h3 class="text-sm font-medium text-primary flex items-center gap-1">
|
||||
<%= lucide_icon("tag", class: "w-4 h-4") %>
|
||||
Rule name (optional)
|
||||
</h3>
|
||||
<div class="flex items-center gap-2">
|
||||
<%= f.text_field :name, placeholder: "Enter a name for this rule", class: "form-field__input" %>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="space-y-4">
|
||||
<h3 class="text-sm font-medium text-primary">If <%= rule.resource_type %></h3>
|
||||
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
|
||||
<div class="flex justify-between items-center gap-4 bg-white shadow-border-xs rounded-md p-4">
|
||||
<div class="text-sm space-y-1.5">
|
||||
<% if rule.name.present? %>
|
||||
<h3 class="font-medium text-lg text-primary"><%= rule.name %></h3>
|
||||
<% end %>
|
||||
<% if rule.conditions.any? %>
|
||||
<p class="flex items-center flex-wrap gap-1.5">
|
||||
<span class="px-2 py-1 border border-alpha-black-200 rounded-full">
|
||||
|
|
|
@ -2,7 +2,13 @@
|
|||
<div class="space-y-4 p-4 max-w-[400px]">
|
||||
<div>
|
||||
<div class="flex justify-between mb-2 gap-4">
|
||||
<h3 class="font-medium text-md">Confirm changes</h3>
|
||||
<h3 class="font-medium text-md">
|
||||
<% if @rule.name.present? %>
|
||||
Confirm changes to "<%= @rule.name %>"
|
||||
<% else %>
|
||||
Confirm changes
|
||||
<% end %>
|
||||
</h3>
|
||||
<button data-action="mousedown->modal#close">
|
||||
<%= lucide_icon("x", class: "w-5 h-5 shrink-0 text-secondary") %>
|
||||
</button>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<%= link_to "Back to rules", rules_path %>
|
||||
|
||||
<%= modal_form_wrapper title: "Edit #{@rule.resource_type} rule" do %>
|
||||
<%= modal_form_wrapper title: @rule.name.present? ? "Edit #{@rule.resource_type} rule \"#{@rule.name}\"" : "Edit #{@rule.resource_type} rule" do %>
|
||||
<%= render "rules/form", rule: @rule %>
|
||||
<% end %>
|
||||
|
|
5
db/migrate/20250429021255_add_name_to_rules.rb
Normal file
5
db/migrate/20250429021255_add_name_to_rules.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
class AddNameToRules < ActiveRecord::Migration[7.2]
|
||||
def change
|
||||
add_column :rules, :name, :string
|
||||
end
|
||||
end
|
4
db/schema.rb
generated
4
db/schema.rb
generated
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[7.2].define(version: 2025_04_16_235758) do
|
||||
ActiveRecord::Schema[7.2].define(version: 2025_04_29_021255) do
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "pgcrypto"
|
||||
enable_extension "plpgsql"
|
||||
|
@ -18,6 +18,7 @@ ActiveRecord::Schema[7.2].define(version: 2025_04_16_235758) do
|
|||
# Custom types defined in this database.
|
||||
# Note that some types may not work with other database engines. Be careful if changing database.
|
||||
create_enum "account_status", ["ok", "syncing", "error"]
|
||||
create_enum "user_role", ["admin", "member"]
|
||||
|
||||
create_table "accounts", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
||||
t.string "subtype"
|
||||
|
@ -502,6 +503,7 @@ ActiveRecord::Schema[7.2].define(version: 2025_04_16_235758) do
|
|||
t.boolean "active", default: false, null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "name"
|
||||
t.index ["family_id"], name: "index_rules_on_family_id"
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue