Skip to content

Commit

Permalink
Fix escalation condition and recipient removal
Browse files Browse the repository at this point in the history
  • Loading branch information
raviks789 committed Apr 23, 2024
1 parent d35dd96 commit 06362d1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 30 deletions.
35 changes: 9 additions & 26 deletions application/forms/EventRuleConfigElements/EscalationCondition.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ protected function assemble(): void
for ($i = 1; $i <= $conditionCount; $i++) {
$colName = 'column_' . $i;
$opName = 'operator_' . $i;
$typeName = 'type_' . $i;
$valName = 'val_' . $i;

$col = $this->createElement(
Expand Down Expand Up @@ -133,18 +132,6 @@ protected function assemble(): void
]
);

if (
$this->getPopulatedValue($typeName) !== 'incident_severity'
&& $this->getPopulatedValue($valName) !== null
) {
$this->clearPopulatedValue($typeName);
$this->clearPopulatedValue($valName);
}

$this->addElement('hidden', $typeName, [
'value' => 'incident_severity'
]);

break;
case 'incident_age':
$val = $this->createElement(
Expand Down Expand Up @@ -173,18 +160,6 @@ protected function assemble(): void
]
);

if (
$this->getPopulatedValue($typeName) !== 'incident_age'
&& $this->getPopulatedValue($valName) !== null
) {
$this->clearPopulatedValue($typeName);
$this->clearPopulatedValue($valName);
}

$this->addElement('hidden', $typeName, [
'value' => 'incident_age'
]);

break;
default:
$val = $this->createElement('text', $valName, [
Expand Down Expand Up @@ -221,7 +196,7 @@ protected function assemble(): void
$this->conditions[$nextCount]->conditionType->setName('column_' . $n);
$this->conditions[$nextCount]->operator->setName('operator_' . $n);
$this->conditions[$nextCount]->conditionVal->setName('val_' . $n);
if ($conditionCount === 1) {
if ($conditionCount === 1 && ! $this->allowZeroConditions) {
$this->conditions[$nextCount]->removeButton = null;
} elseif ($this->conditions[$nextCount]->removeButton) {
$this->conditions[$nextCount]->removeButton->setValue((string) $n);
Expand Down Expand Up @@ -290,9 +265,17 @@ public function getCondition(): string
$filter = Filter::any();
/** @var int $count */
$count = $this->getValue('condition-count');
$removePosition = $this->getValue('remove');
if ($removePosition) {
$count += 1;
}

if ($count > 0) { // if count is 0, loop runs in reverse direction
foreach (range(1, $count) as $count) {
if ($count === (int) $removePosition) {
continue;
}

$chosenType = $this->getValue('column_' . $count, 'placeholder');

$filterStr = $chosenType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,17 @@ public function getRecipients(): array
{
/** @var int $count */
$count = $this->getValue('recipient-count');
$removePosition = $this->getValue('remove');
if ($removePosition) {
$count += 1;
}

$values = [];
for ($i = 1; $i <= $count; $i++) {
if ($i === (int) $removePosition) {
continue;
}

$value = [];
$value['channel_id'] = $this->getValue('val_' . $i);
$value['id'] = $this->getValue('id_' . $i);
Expand Down
4 changes: 2 additions & 2 deletions application/forms/EventRuleConfigForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,15 +250,15 @@ protected function assemble(): void

if ($noZeroEscalationConditions === true) {
foreach ($escalations as $escalation) {
$escalation->getCondition()
$escalation->condition
->setAllowZeroConditions(true);
}

$this->getElement('zero-condition-escalation')
->setValue(null);
} elseif ($zeroConditionEscalation) {
$escalations[$zeroConditionEscalation]
->getCondition()
->condition
->setAllowZeroConditions(true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ class EscalationRecipientListItem extends BaseHtmlElement
public $channel;

public function __construct(
BaseFormElement $reipient,
BaseFormElement $recipient,
BaseFormElement $channel,
?SubmitButtonElement $removeButton
) {
$this->recipient = $reipient;
$this->recipient = $recipient;
$this->channel = $channel;
$this->removeButton = $removeButton;
}
Expand Down

0 comments on commit 06362d1

Please sign in to comment.