Skip to content

Commit 015bfb8

Browse files
WIP rewok getJsonPaths
1 parent 2e49f45 commit 015bfb8

4 files changed

Lines changed: 35 additions & 14 deletions

File tree

application/controllers/EventRuleController.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,14 +231,14 @@ function (Condition $condition) use ($hook) {
231231
if (! $hook->isValidCondition($condition)) {
232232
throw new SearchException($this->translate('Is not a valid column'));
233233
}
234-
235-
$condition->metaData()->set('jsonPaths', $hook->getJsonPaths($condition));
236234
}
237235
)
238236
->on(Form::ON_SUBMIT, function (SearchEditor $form) use ($ruleId, $hook) {
237+
$filter = $form->getFilter();
238+
239239
$this->session->set(
240240
'object_filter',
241-
(new RuleSerializer($form->getFilter()))->getJson()
241+
(new RuleSerializer($filter, $hook->getJsonPaths($this->collectColumns($filter))))->getJson()
242242
);
243243
$this->redirectNow(Links::eventRule($ruleId)->setParam('_filterOnly'));
244244
});
@@ -358,4 +358,19 @@ private function fetchRule(int $ruleId): Rule
358358

359359
return $rule;
360360
}
361+
362+
private function collectColumns(Filter\Rule $rule): array
363+
{
364+
if ($rule instanceof Filter\Chain) {
365+
$result = [];
366+
foreach ($rule as $element) {
367+
$result = array_merge($result, $this->collectColumns($element));
368+
}
369+
370+
return array_unique($result);
371+
} else {
372+
/** @var $rule Condition */
373+
return [$rule->getColumn()];
374+
}
375+
}
361376
}

library/Notifications/Hook/V2/SourceHook.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ public function isValidCondition(Condition $condition): bool;
5252
public function enrichCondition(Condition $condition): void;
5353

5454
/**
55-
* Get all jsonPaths for the condition's column
55+
* All JsonPaths for all given columns
5656
*
57-
* @param Condition $condition
57+
* @param array<string> $columns
5858
*
59-
* @return array<string>
59+
* @return array<array<string>>
6060
*/
61-
public function getJsonPaths(Condition $condition): array;
61+
public function getJsonPaths(array $columns): array;
6262

6363
/**
6464
* Get suggestions for a value field

library/Notifications/Util/RuleSerializer.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,18 @@ class RuleSerializer
1616
/** @var Filter\Condition|Filter\Chain */
1717
protected Filter\Rule $filter;
1818

19+
protected array $jsonPaths;
20+
1921
/**
2022
* Create an object that can be used to serialize a rule to JSON
2123
*
2224
* @param Filter\Rule $filter
25+
* @param array $jsonPaths
2326
*/
24-
public function __construct(Filter\Rule $filter)
27+
public function __construct(Filter\Rule $filter, array $jsonPaths)
2528
{
2629
$this->filter = $filter;
30+
$this->jsonPaths = $jsonPaths;
2731
}
2832

2933
/**
@@ -100,7 +104,7 @@ protected function serializeCondition(Filter\Condition $condition): array
100104

101105
return [
102106
'op' => $op,
103-
'attributes' => $condition->metaData()->get('jsonPaths'),
107+
'attributes' => $this->jsonPaths[$condition->getColumn()],
104108
...$value,
105109
];
106110
}

library/Notifications/Web/Control/SearchEditor/RuleFilterSuggestions.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,13 @@ public function __construct(SourceHook $hook)
3636
$provider = $this->hook->getColumnSuggestions($this->getSearchTerm() ?? '');
3737
$this->setGroupingCallback(fn($x) => $x['group']);
3838
} else {
39-
$provider = $this->hook->getValueSuggestions(
40-
$this->column,
41-
$this->getSearchTerm() ?? '',
42-
$this->searchFilter
43-
);
39+
$provider = $this->column
40+
? $this->hook->getValueSuggestions(
41+
$this->column,
42+
$this->getSearchTerm() ?? '',
43+
$this->searchFilter
44+
)
45+
: [];
4446
}
4547

4648
yield from $provider;

0 commit comments

Comments
 (0)