Extract common method to query when entropy is cleaned

We were always quering auto_close_at
https://37s.fizzy.37signals.com/collections/2/cards/743
This commit is contained in:
Jorge Manrubia
2025-06-02 18:03:14 +02:00
parent a3866348fd
commit 08c5abfbdb
4 changed files with 27 additions and 5 deletions
@@ -3,7 +3,7 @@ import { nextFrame } from "helpers/timing_helpers"
export default class extends Controller {
static targets = [ "item" ]
static values = { selectionAttribute: { type: String, default: "aria-selected" } }
static values = { selectionAttribute: { type: String, default: "aria-current" } }
connect() {
this.selectLast()
+15 -3
View File
@@ -26,11 +26,19 @@ module Card::Entropy
end
def subject_to_entropy?
doing? || (auto_closing? && considering?)
auto_reconsidering? || auto_closing?
end
def auto_reconsidering?
doing? && last_active_at
end
def auto_closing?
considering? && collection.auto_closing? && last_active_at
end
def auto_close_at
last_active_at + auto_close_period if auto_closing? && last_active_at
last_active_at + auto_close_period if auto_closing?
end
def days_until_close
@@ -38,10 +46,14 @@ module Card::Entropy
end
def auto_reconsider_at
last_active_at + AUTO_RECONSIDER_PERIOD if last_active_at
last_active_at + AUTO_RECONSIDER_PERIOD if auto_reconsidering?
end
def days_until_reconsider
(auto_reconsider_at.to_date - Date.current).to_i if auto_reconsider_at
end
def entropy_cleaned_at
auto_close_at || auto_reconsider_at
end
end
@@ -1,7 +1,7 @@
<div hidden class="bubble bubble--<%= card.engagement_status %>"
data-controller="bubble" data-action="turbo:morph-element->bubble#update"
data-bubble-reminder-before-value="<%= Card::ENTROPY_REMINDER_BEFORE.in_days.to_i %>"
data-bubble-closes-at-value="<%= card.auto_close_at.iso8601 %>"
data-bubble-closes-at-value="<%= card.entropy_cleaned_at.iso8601 %>"
data-bubble-entropy-action-value="<%= card_entropy_action(card) %>">
<svg viewBox="0 0 200 100">
<path id="top-half" fill="transparent" d="M 20,100 A 80,80 0 0,1 180,100" />
+10
View File
@@ -47,4 +47,14 @@ class Card::EntropyTest < ActiveSupport::TestCase
assert cards(:logo).reload.considering?
assert_equal Time.current, cards(:logo).last_active_at
end
test "entropy_cleaned_at returns when the entropy will be cleaned" do
cards(:logo).reconsider
assert_equal cards(:logo).auto_close_at, cards(:logo).entropy_cleaned_at
assert_not_nil cards(:logo).entropy_cleaned_at
cards(:logo).engage
assert_equal cards(:logo).auto_reconsider_at, cards(:logo).entropy_cleaned_at
assert_not_nil cards(:logo).entropy_cleaned_at
end
end