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 24, 2024
1 parent bc513eb commit b72e697
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 28 deletions.
38 changes: 12 additions & 26 deletions application/forms/EventRuleConfigElements/EscalationCondition.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ protected function assemble(): void
['value' => (string) $defaultCount]
);

$this->addElement('hidden', 'remove-position');

$addCondition = $this->createElement(
'submitButton',
'add-condition',
Expand All @@ -76,7 +78,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 @@ -126,18 +127,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 @@ -166,18 +155,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 All @@ -197,6 +174,7 @@ protected function assemble(): void

$removePosition = (int) $this->getValue('remove');
if ($removePosition) {
$this->getElement('remove-position')->setValue($removePosition);
unset($this->conditions[$removePosition]);
$conditionCount -= 1;
if ($conditionCount === 1 && ! $this->allowZeroConditions && $removePosition === 2) {
Expand All @@ -207,7 +185,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 @@ -275,9 +253,17 @@ public function getCondition(): string
$filter = Filter::any();
/** @var int $count */
$count = $this->getValue('condition-count');
$removePosition = $this->getValue('remove-position');
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
11 changes: 11 additions & 0 deletions application/forms/EventRuleConfigElements/EscalationRecipient.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ protected function assemble(): void
{
$this->addElement('hidden', 'recipient-count', ['value' => '1']);

$this->addElement('hidden', 'remove-position');

$addRecipientButton = $this->createElement(
'submitButton',
'add-recipient',
Expand Down Expand Up @@ -105,6 +107,7 @@ protected function assemble(): void

$removePosition = (int) $this->getValue('remove');
if ($removePosition) {
$this->getElement('remove-position')->setValue($removePosition);
unset($this->recipients[$removePosition]);
$recipientCount -= 1;
if ($recipientCount === 1 && $removePosition === 2) {
Expand Down Expand Up @@ -201,9 +204,17 @@ public function getRecipients(): array
{
/** @var int $count */
$count = $this->getValue('recipient-count');
$removePosition = $this->getValue('remove-position');
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 @@ -247,15 +247,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

0 comments on commit b72e697

Please sign in to comment.