Skip to content

Commit 06362d1

Browse files
committed
Fix escalation condition and recipient removal
1 parent d35dd96 commit 06362d1

File tree

4 files changed

+21
-30
lines changed

4 files changed

+21
-30
lines changed

application/forms/EventRuleConfigElements/EscalationCondition.php

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ protected function assemble(): void
8383
for ($i = 1; $i <= $conditionCount; $i++) {
8484
$colName = 'column_' . $i;
8585
$opName = 'operator_' . $i;
86-
$typeName = 'type_' . $i;
8786
$valName = 'val_' . $i;
8887

8988
$col = $this->createElement(
@@ -133,18 +132,6 @@ protected function assemble(): void
133132
]
134133
);
135134

136-
if (
137-
$this->getPopulatedValue($typeName) !== 'incident_severity'
138-
&& $this->getPopulatedValue($valName) !== null
139-
) {
140-
$this->clearPopulatedValue($typeName);
141-
$this->clearPopulatedValue($valName);
142-
}
143-
144-
$this->addElement('hidden', $typeName, [
145-
'value' => 'incident_severity'
146-
]);
147-
148135
break;
149136
case 'incident_age':
150137
$val = $this->createElement(
@@ -173,18 +160,6 @@ protected function assemble(): void
173160
]
174161
);
175162

176-
if (
177-
$this->getPopulatedValue($typeName) !== 'incident_age'
178-
&& $this->getPopulatedValue($valName) !== null
179-
) {
180-
$this->clearPopulatedValue($typeName);
181-
$this->clearPopulatedValue($valName);
182-
}
183-
184-
$this->addElement('hidden', $typeName, [
185-
'value' => 'incident_age'
186-
]);
187-
188163
break;
189164
default:
190165
$val = $this->createElement('text', $valName, [
@@ -221,7 +196,7 @@ protected function assemble(): void
221196
$this->conditions[$nextCount]->conditionType->setName('column_' . $n);
222197
$this->conditions[$nextCount]->operator->setName('operator_' . $n);
223198
$this->conditions[$nextCount]->conditionVal->setName('val_' . $n);
224-
if ($conditionCount === 1) {
199+
if ($conditionCount === 1 && ! $this->allowZeroConditions) {
225200
$this->conditions[$nextCount]->removeButton = null;
226201
} elseif ($this->conditions[$nextCount]->removeButton) {
227202
$this->conditions[$nextCount]->removeButton->setValue((string) $n);
@@ -290,9 +265,17 @@ public function getCondition(): string
290265
$filter = Filter::any();
291266
/** @var int $count */
292267
$count = $this->getValue('condition-count');
268+
$removePosition = $this->getValue('remove');
269+
if ($removePosition) {
270+
$count += 1;
271+
}
293272

294273
if ($count > 0) { // if count is 0, loop runs in reverse direction
295274
foreach (range(1, $count) as $count) {
275+
if ($count === (int) $removePosition) {
276+
continue;
277+
}
278+
296279
$chosenType = $this->getValue('column_' . $count, 'placeholder');
297280

298281
$filterStr = $chosenType

application/forms/EventRuleConfigElements/EscalationRecipient.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,17 @@ public function getRecipients(): array
219219
{
220220
/** @var int $count */
221221
$count = $this->getValue('recipient-count');
222+
$removePosition = $this->getValue('remove');
223+
if ($removePosition) {
224+
$count += 1;
225+
}
222226

223227
$values = [];
224228
for ($i = 1; $i <= $count; $i++) {
229+
if ($i === (int) $removePosition) {
230+
continue;
231+
}
232+
225233
$value = [];
226234
$value['channel_id'] = $this->getValue('val_' . $i);
227235
$value['id'] = $this->getValue('id_' . $i);

application/forms/EventRuleConfigForm.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,15 +250,15 @@ protected function assemble(): void
250250

251251
if ($noZeroEscalationConditions === true) {
252252
foreach ($escalations as $escalation) {
253-
$escalation->getCondition()
253+
$escalation->condition
254254
->setAllowZeroConditions(true);
255255
}
256256

257257
$this->getElement('zero-condition-escalation')
258258
->setValue(null);
259259
} elseif ($zeroConditionEscalation) {
260260
$escalations[$zeroConditionEscalation]
261-
->getCondition()
261+
->condition
262262
->setAllowZeroConditions(true);
263263
}
264264

library/Notifications/Widget/ItemList/EscalationRecipientListItem.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ class EscalationRecipientListItem extends BaseHtmlElement
2424
public $channel;
2525

2626
public function __construct(
27-
BaseFormElement $reipient,
27+
BaseFormElement $recipient,
2828
BaseFormElement $channel,
2929
?SubmitButtonElement $removeButton
3030
) {
31-
$this->recipient = $reipient;
31+
$this->recipient = $recipient;
3232
$this->channel = $channel;
3333
$this->removeButton = $removeButton;
3434
}

0 commit comments

Comments
 (0)