Skip to content

Commit

Permalink
Fix 2: Review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
raviks789 committed May 15, 2024
1 parent 836d43b commit 8b5bffe
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
7 changes: 4 additions & 3 deletions application/controllers/EventRuleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,12 @@ public function indexAction(): void
$buttonsWrapper->add([$eventRuleConfigSubmitButton, $discardChangesButton, $deleteButton]);

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

if ($incidents->count() > 0) {
if ($incidentCount) {
$deleteButton->addAttributes([
'disabled' => true,
'title' => t('There exist active incidents for this escalation and hence cannot be removed')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ protected function assemble(): void
$this->getElement('recipient-count')->setValue(++$recipientCount);
}

$options = ['' => sprintf(' - %s - ', $this->translate('Please choose'))];
$removePosition = null;

foreach (range(1, $recipientCount) as $i) {
$this->addElement('hidden', 'id_' . $i);

Expand All @@ -55,9 +57,7 @@ protected function assemble(): void
'column_' . $i,
[
'class' => ['autosubmit', 'left-operand'],
'options' => [
'' => sprintf(' - %s - ', $this->translate('Please choose'))
] + $this->fetchOptions(),
'options' => $options + $this->fetchOptions(),
'disabledOptions' => [''],
'required' => true,
'value' => $this->getPopulatedValue('column_' . $i)
Expand All @@ -66,7 +66,6 @@ protected function assemble(): void

$this->registerElement($col);

$options = ['' => sprintf(' - %s - ', $this->translate('Please choose'))];
$options += Channel::fetchChannelNames(Database::get());

$val = $this->createElement(
Expand Down
16 changes: 8 additions & 8 deletions application/forms/EventRuleConfigForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,7 @@ public function populate($values): self
foreach ($values['rule_escalation'] as $position => $escalation) {
$conditions = explode('|', $escalation['condition'] ?? '');
$conditionFormValues = [];
$conditionCount = count($conditions);
$conditionFormValues['condition-count'] = $conditionCount;
$conditionFormValues['condition-count'] = count($conditions);
$conditionFormValues['id'] = $escalation['id'] ?? bin2hex(random_bytes(4));

foreach ($conditions as $key => $condition) {
Expand Down Expand Up @@ -381,11 +380,12 @@ protected function createRemoveButton(string $prefix): SubmitButtonElement
$escalationId = $escalations[$pos]['id'] ?? null;

if ($escalationId && ctype_digit($escalationId)) {
$incident = Incident::on(Database::get())->with('rule_escalation');
$incident->filter(Filter::equal('rule_escalation.id', $escalationId));
if ($incident->count() > 0) {
$disableRemoveButton = true;
}
$incidentCount = Incident::on(Database::get())
->with('rule_escalation')
->filter(Filter::equal('rule_escalation.id', $escalationId))
->count();

$disableRemoveButton = $incidentCount > 0;
}

$button = new SubmitButtonElement(
Expand Down Expand Up @@ -639,7 +639,7 @@ protected function getPrefixesMap(int $escalationCount): string
{
$prefixesMap = [];
for ($i = 1; $i <= $escalationCount; $i++) {
$prefixesMap[(string) $i] = bin2hex((string) $i);
$prefixesMap[] = bin2hex((string) $i);
}

return implode(',', $prefixesMap);
Expand Down

0 comments on commit 8b5bffe

Please sign in to comment.