Rework system events

- Restyle system events so they don't look like comments and aren't attributed to the system user
- Ensure the event creator is included in the description so it's clear who did it.
- Walk back system comment replacement. Yes, it potentially avoids embarassing people when they change their mind, it's also losing data. If two intentional assigments happen in proximity, we've been only showing the latest one,.
This commit is contained in:
Jason Zimdars
2025-05-28 15:26:41 -05:00
parent f17742fdc2
commit c6c9e0d5fc
3 changed files with 35 additions and 31 deletions
+29 -1
View File
@@ -37,6 +37,10 @@
}
.comment__author {
.comment--system & strong {
display: none;
}
.btn {
font-weight: inherit;
}
@@ -49,9 +53,17 @@
.comment--mine_ & {
margin-inline: calc(var(--comment-padding-inline) * -0.75);
}
.comment--system & {
display: none;
}
}
.comment__body {
.comment--system & {
text-align: center;
}
p {
&:first-child {
margin-block-start: 0;
@@ -95,8 +107,13 @@
}
}
.comment__event {
.comment--system {
--comment-padding-block: calc(var(--block-space) * 0.66);
line-height: 1.2;
max-inline-size: var(--comment-max);
text-align: center;
&::before {
/* Make up space for lack of avatar */
@@ -104,6 +121,17 @@
display: flex;
inline-size: calc(var(--comment-padding-inline) * 0.75);
}
.comment__author {
a {
margin: 0 auto;
}
}
.comment__body {
margin-block-start: calc(var(--block-space-half) * -0.33);
text-align: center !important;
}
}
.comment__input {
+5 -29
View File
@@ -8,46 +8,22 @@ class Card::Eventable::SystemCommenter
def comment
return unless comment_body.present?
if comment = find_replaceable_system_comment
comment.update! body: comment_body
else
card.comments.create! creator: User.system, body: comment_body, created_at: event.created_at
end
card.comments.create! creator: User.system, body: comment_body, created_at: event.created_at
end
private
RELATED_EVENTS = [
%w[ card_assigned card_unassigned ]
]
def comment_body
case event.action
when "card_assigned"
"Assigned to #{event.assignees.pluck(:name).to_sentence}."
"#{event.creator.name} assigned this to #{event.assignees.pluck(:name).to_sentence}."
when "card_unassigned"
"Unassigned from #{event.assignees.pluck(:name).to_sentence}."
"#{event.creator.name} unassigned from #{event.assignees.pluck(:name).to_sentence}."
when "card_staged"
"#{event.creator.name} moved this to '#{event.stage_name}'."
when "card_closed"
"Closed by #{ event.creator.name }"
"Closed as “#{ card.closure.reason } by #{ event.creator.name }"
when "card_title_changed"
"#{event.creator.name} changed title from '#{event.particulars.dig('particulars', 'old_title')}' to '#{event.particulars.dig('particulars', 'new_title')}'."
"#{event.creator.name} changed the title from '#{event.particulars.dig('particulars', 'old_title')}' to '#{event.particulars.dig('particulars', 'new_title')}'."
end
end
def find_replaceable_system_comment
previous_comment, previous_event = card.comments.last, card.events[-2]
if previous_comment&.creator&.system? && replaceable_event?(previous_event, event)
previous_comment
end
end
def replaceable_event?(candidate_event, replacement_event)
candidate_event && replacement_event &&
(candidate_event.action == replacement_event.action || related_events?(candidate_event, replacement_event))
end
def related_events?(candidate_event, replacement_event)
RELATED_EVENTS.find { |related_actions| related_actions.include?(candidate_event.action) && related_actions.include?(replacement_event.action) }
end
end
+1 -1
View File
@@ -1,6 +1,6 @@
<% cache comment do %>
<%= turbo_frame_tag comment do %>
<div class="comment flex align-start full-width" data-creator-id="<%= comment.creator_id %>" data-created-by-current-user-target="creation">
<div class="comment flex align-start full-width <%= "comment--system" if comment.creator.system? %>" data-creator-id="<%= comment.creator_id %>" data-created-by-current-user-target="creation">
<figure class="comment__avatar flex-item-no-shrink" aria-hidden="true">
<%= avatar_tag comment.creator, hidden_for_screen_reader: true %>
</figure>