Skip to content

Commit 95a323e

Browse files
committed
fixed display of arguments for better UI
1 parent c726dbc commit 95a323e

2 files changed

Lines changed: 76 additions & 16 deletions

File tree

app/presenters/solid_queue_monitor/base_presenter.rb

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,24 @@ def format_datetime(datetime)
8181
def format_arguments(arguments)
8282
return '-' if arguments.blank?
8383

84-
# For ActiveJob format
85-
if arguments.is_a?(Hash) && arguments['arguments'].present?
86-
return "<code>#{arguments['arguments'].inspect}</code>"
87-
elsif arguments.is_a?(Array) && arguments.length == 1 && arguments[0].is_a?(Hash) && arguments[0]['arguments'].present?
88-
return "<code>#{arguments[0]['arguments'].inspect}</code>"
84+
# Extract and format the arguments more cleanly
85+
formatted_args = if arguments.is_a?(Hash) && arguments['arguments'].present?
86+
format_job_arguments(arguments)
87+
elsif arguments.is_a?(Array) && arguments.length == 1 && arguments[0].is_a?(Hash) && arguments[0]['arguments'].present?
88+
format_job_arguments(arguments[0])
89+
else
90+
arguments.inspect
91+
end
92+
93+
if formatted_args.length <= 50
94+
"<code class='args-single-line'>#{formatted_args}</code>"
95+
else
96+
<<-HTML
97+
<div class="args-container">
98+
<code class="args-content">#{formatted_args}</code>
99+
</div>
100+
HTML
89101
end
90-
91-
# For regular arguments format
92-
"<code>#{arguments.inspect}</code>"
93102
end
94103

95104
def format_hash(hash)
@@ -102,18 +111,14 @@ def format_hash(hash)
102111
"<code>#{formatted}</code>"
103112
end
104113

105-
# Helper method to get the current request path
106114
def request_path
107-
# Try to get the current path from the controller's request
108115
if defined?(controller) && controller.respond_to?(:request)
109116
controller.request.path
110117
else
111-
# Fallback to a default path if we can't get the current path
112118
'/solid_queue'
113119
end
114120
end
115121

116-
# Helper method to get the mount point of the engine
117122
def engine_mount_point
118123
path_parts = request_path.split('/')
119124
if path_parts.length >= 3
@@ -134,13 +139,24 @@ def query_params
134139
params.empty? ? '' : "&#{params.join('&')}"
135140
end
136141

137-
# Helper method to get the full path for a route
138142
def full_path(route_name, *args)
139-
# Try to use the engine routes first
140143
SolidQueueMonitor::Engine.routes.url_helpers.send(route_name, *args)
141144
rescue NoMethodError
142-
# Fall back to main app routes
143145
Rails.application.routes.url_helpers.send("solid_queue_#{route_name}", *args)
144146
end
147+
148+
def format_job_arguments(job_data)
149+
args = if job_data['arguments'].is_a?(Array)
150+
if job_data['arguments'].first.is_a?(Hash) && job_data['arguments'].first['_aj_ruby2_keywords'].present?
151+
job_data['arguments'].first.except('_aj_ruby2_keywords')
152+
else
153+
job_data['arguments']
154+
end
155+
else
156+
job_data['arguments']
157+
end
158+
159+
args.inspect
160+
end
145161
end
146162
end

app/services/solid_queue_monitor/stylesheet_generator.rb

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,51 @@ def generate
282282
font-weight: 500;
283283
}
284284
285+
/* Arguments styling */
286+
.solid_queue_monitor .args-container {
287+
position: relative;
288+
max-height: 100px;
289+
overflow: hidden;
290+
}
291+
292+
.solid_queue_monitor .args-content {
293+
display: block;
294+
white-space: pre-wrap;
295+
word-break: break-word;
296+
max-height: 100px;
297+
overflow-y: auto;
298+
padding: 8px;
299+
background: #f5f5f5;
300+
border-radius: 4px;
301+
font-size: 0.9em;
302+
}
303+
304+
.solid_queue_monitor .args-single-line {
305+
display: inline-block;
306+
padding: 4px 8px;
307+
background: #f5f5f5;
308+
border-radius: 4px;
309+
font-size: 0.9em;
310+
}
311+
312+
.solid_queue_monitor .args-content::-webkit-scrollbar {
313+
width: 8px;
314+
}
315+
316+
.solid_queue_monitor .args-content::-webkit-scrollbar-track {
317+
background: #f1f1f1;
318+
border-radius: 4px;
319+
}
320+
321+
.solid_queue_monitor .args-content::-webkit-scrollbar-thumb {
322+
background: #888;
323+
border-radius: 4px;
324+
}
325+
326+
.solid_queue_monitor .args-content::-webkit-scrollbar-thumb:hover {
327+
background: #666;
328+
}
329+
285330
@media (max-width: 768px) {
286331
.solid_queue_monitor .container {
287332
padding: 0.5rem;
@@ -432,7 +477,6 @@ def generate
432477
background: #e5e7eb;
433478
}
434479
435-
/* Action buttons for retry/discard */
436480
.solid_queue_monitor .action-button {
437481
padding: 0.5rem 1rem;
438482
border-radius: 0.375rem;

0 commit comments

Comments
 (0)