Skip to content

Commit

Permalink
Allow to delete event rule
Browse files Browse the repository at this point in the history
  • Loading branch information
sukhwinder33445 committed Jul 10, 2024
1 parent bd53dde commit 22f4f67
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 42 deletions.
12 changes: 0 additions & 12 deletions application/controllers/EventRuleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,9 @@ public function indexAction(): void
);
}

$disableRemoveButton = false;
if (ctype_digit($ruleId)) {
$incidents = Incident::on(Database::get())
->with('rule')
->filter(Filter::equal('rule.id', $ruleId));

if ($incidents->count() > 0) {
$disableRemoveButton = true;
}
}

$saveForm = (new SaveEventRuleForm())
->setShowRemoveButton()
->setShowDismissChangesButton($cache !== null)
->setRemoveButtonDisabled($disableRemoveButton)
->setSubmitButtonDisabled($cache === null)
->setSubmitLabel($this->translate('Save Changes'))
->on(SaveEventRuleForm::ON_SUCCESS, function ($form) use ($ruleId, $eventRuleConfig) {
Expand Down
30 changes: 0 additions & 30 deletions application/forms/SaveEventRuleForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ class SaveEventRuleForm extends Form
/** @var bool Whether to show a button to dismiss cached changes */
protected $showDismissChangesButton = false;

/** @var bool Whether to disable the remove button */
protected $disableRemoveButton = false;

/** @var int The rule id */
protected $ruleId;

Expand Down Expand Up @@ -83,20 +80,6 @@ public function setSubmitButtonDisabled(bool $state = true): self
return $this;
}

/**
* Set whether to enable or disable the remove button
*
* @param bool $state
*
* @return $this
*/
public function setRemoveButtonDisabled(bool $state = true): self
{
$this->disableRemoveButton = $state;

return $this;
}

/**
* Set the submit label
*
Expand Down Expand Up @@ -196,19 +179,6 @@ protected function assemble()
]);
$this->registerElement($removeBtn);

$this->getElement('remove')
->getAttributes()
->registerAttributeCallback('disabled', function () {
return $this->disableRemoveButton;
})
->registerAttributeCallback('title', function () {
if ($this->disableRemoveButton) {
return $this->translate(
'There exist active incidents for this event rule and hence cannot be deleted'
);
}
});

$additionalButtons[] = $removeBtn;
}

Expand Down

0 comments on commit 22f4f67

Please sign in to comment.