Skip to content

A platform for community discussion. Free, open, simple.

FIX: destroy automation not working (#31945)

Samad992d7b2d3d
diff --git a/plugins/automation/admin/assets/javascripts/admin/components/automation-list.gjs b/plugins/automation/admin/assets/javascripts/admin/components/automation-list.gjs
index b42ec03ab02..6ae4e76aef1 100644
--- a/plugins/automation/admin/assets/javascripts/admin/components/automation-list.gjs
+++ b/plugins/automation/admin/assets/javascripts/admin/components/automation-list.gjs
@@ -22,18 +22,26 @@ export default class AutomationList extends Component {
@service router;
@action
- destroyAutomation(automation) {
- this.dialog.deleteConfirm({
- message: i18n("discourse_automation.destroy_automation.confirm", {
- name: escapeExpression(automation.name),
- }),
- didConfirm: () => {
- return automation
- .destroyRecord()
- .then(() => this.send("triggerRefresh"))
- .catch(popupAjaxError);
- },
- });
+ async destroyAutomation(automation) {
+ automation.set("isDeleting", true);
+ try {
+ await this.dialog.deleteConfirm({
+ message: i18n("discourse_automation.destroy_automation.confirm", {
+ name: escapeExpression(automation.name),
+ }),
+ didConfirm: () => {
+ try {
+ automation.destroyRecord();
+ this.args.model.removeObject(automation);
+ automation = null;
+ } catch (e) {
+ popupAjaxError(e);
+ }
+ },
+ });
+ } finally {
+ automation?.set("isDeleting", false);
+ }
}
@action
@@ -212,8 +220,9 @@ export default class AutomationList extends Component {
<DButton
@icon="trash-can"
- @action={{this.destroyAutomation automation}}
- class="btn-small btn-danger"
+ @disabled={{automation.isDeleting}}
+ {{on "click" (fn this.destroyAutomation automation)}}
+ class="btn-small btn-danger automations__delete"
/>
</td>
</tr>
diff --git a/plugins/automation/spec/system/smoke_test_spec.rb b/plugins/automation/spec/system/smoke_test_spec.rb
index c9751334d12..93b426e44a1 100644
--- a/plugins/automation/spec/system/smoke_test_spec.rb
+++ b/plugins/automation/spec/system/smoke_test_spec.rb
@@ -20,7 +20,7 @@ describe "DiscourseAutomation | smoke test", type: :system do
after { DiscourseAutomation::Scriptable.remove("test") }
- it "populate correctly" do
+ it "populates correctly and can be deleted" do
visit("/admin/plugins/automation")
find(".admin-config-area-empty-list__cta-button").click
@@ -33,6 +33,23 @@ describe "DiscourseAutomation | smoke test", type: :system do
select_kit.select_row_by_value("post_created_edited")
expect(find(".field input[name=test]").value).to eq("test-default-value")
+
+ automation = Fabricate(:automation, name: "automation-test")
+
+ visit("/admin/plugins/automation")
+ # find the row of "automation test" then click on trash icon
+ find(".automations__name", text: "automation-test")
+ .find(:xpath, "..")
+ .find(".automations__delete")
+ .click
+
+ find(".dialog-footer .btn-danger").click
+
+ expect(page).not_to have_css(".automations__name", text: "automation-test")
+
+ try_until_success do
+ expect(DiscourseAutomation::Automation.exists?(id: automation.id)).to be(false)
+ end
end
end