Add Reset AI cache button to rules index

Add menu button with confirmation dialog to reset AI cache. Fix menu_item to safely handle non-standard confirm values.
This commit is contained in:
eureka928
2026-01-26 09:46:31 +01:00
parent b511b3add9
commit 329fe9832a
2 changed files with 13 additions and 1 deletions

View File

@@ -50,7 +50,8 @@ class DS::MenuItem < DesignSystemComponent
data = merged_opts.delete(:data) || {}
if confirm.present?
data = data.merge(turbo_confirm: confirm.to_data_attribute)
confirm_value = confirm.respond_to?(:to_data_attribute) ? confirm.to_data_attribute : confirm
data = data.merge(turbo_confirm: confirm_value)
end
if frame.present?

View File

@@ -3,6 +3,17 @@
<div class="flex items-center gap-2">
<% if @rules.any? %>
<%= render DS::Menu.new do |menu| %>
<% menu.with_item(
variant: "button",
text: "Reset AI cache",
href: clear_ai_cache_rules_path,
icon: "refresh-cw",
method: :post,
confirm: CustomConfirm.new(
title: "Reset AI cache?",
body: "Are you sure you want to reset the AI cache? This will allow AI rules to re-process all transactions. This may incur additional API costs.",
btn_text: "Reset Cache"
)) %>
<% menu.with_item(
variant: "button",
text: "Delete all rules",