Commit a08d2d2
[Alerting v2] Fix YAML blur handler + splitQuery round-trip tests (#269779)
## Summary
Scoped down from the original PR after #269584 merged. The split-mode
sync and YAML toggle-off dispatch fixes are now redundant — this PR
retains only the changes that #269584 did not address.
### Changes
1. **`YamlRuleForm` blur handler fix:** In the compose-discover flyout
the RHF form uses `ComposeFormValues` (with `query: RuleQuery`), but
`YamlRuleForm`'s blur handler called `reset(FormValues)` directly —
overwriting the form with the wrong shape (`evaluation.query.base`
instead of `RuleQuery`). After #269584 this no longer clears the sandbox
visually (the sandbox now reads from the draft, not RHF), but it
silently corrupts the form state, which could cause malformed API
payloads at submit time. Adds an `onBlurSync` prop so the flyout can
route through `formValuesFromYamlToCompose`, cancelling the pending
debounce and syncing the draft in one shot.
2. **`YamlParseResult` discriminated union:** Changes the type from two
independently-nullable fields to a proper discriminated union (`{
values: FormValues; error: null } | { values: null; error: string }`) so
TypeScript narrows automatically after error checks, eliminating
non-null assertions. (Addresses Jason's [review
feedback](#269779 (review)).)
3. **`splitQuery` round-trip idempotency tests:** Asserts that
`splitQuery(join(split(q))) === split(q)`, which is the invariant the
split-mode sync relies on.
Closes [#269777](#270168)
## How to test
1. Navigate to **Alerting v2 → Rules list** → Create a rule via the
flyout
2. Open the Sandbox, write a query, click **Apply changes**
3. Toggle to **YAML view**
4. Edit the query in YAML (e.g. change a threshold value)
5. Click outside the YAML editor (blur)
6. Toggle back to **Form view** and click **Create rule**
7. **Verify:** The API request payload (`evaluation.query.base`)
contains the edited query value — the YAML edit persisted correctly
through the blur → RHF → submit pipeline
---------
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Jason Rhodes <jason.rhodes@elastic.co>1 parent 120c2cf commit a08d2d2
4 files changed
Lines changed: 58 additions & 22 deletions
File tree
Lines changed: 11 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
419 | 419 | | |
420 | 420 | | |
421 | 421 | | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
422 | 431 | | |
423 | 432 | | |
424 | 433 | | |
| |||
480 | 489 | | |
481 | 490 | | |
482 | 491 | | |
483 | | - | |
| 492 | + | |
484 | 493 | | |
485 | 494 | | |
486 | 495 | | |
| |||
576 | 585 | | |
577 | 586 | | |
578 | 587 | | |
| 588 | + | |
579 | 589 | | |
580 | 590 | | |
581 | 591 | | |
| |||
Lines changed: 28 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
148 | 148 | | |
149 | 149 | | |
150 | 150 | | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
151 | 179 | | |
152 | 180 | | |
153 | 181 | | |
| |||
Lines changed: 1 addition & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
| 16 | + | |
20 | 17 | | |
21 | 18 | | |
22 | 19 | | |
| |||
Lines changed: 18 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
39 | 46 | | |
40 | 47 | | |
41 | 48 | | |
| |||
60 | 67 | | |
61 | 68 | | |
62 | 69 | | |
| 70 | + | |
63 | 71 | | |
64 | 72 | | |
65 | 73 | | |
| |||
70 | 78 | | |
71 | 79 | | |
72 | 80 | | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | 81 | | |
81 | 82 | | |
82 | 83 | | |
83 | 84 | | |
84 | | - | |
| 85 | + | |
85 | 86 | | |
86 | 87 | | |
87 | 88 | | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
| 89 | + | |
| 90 | + | |
92 | 91 | | |
93 | 92 | | |
94 | 93 | | |
95 | 94 | | |
96 | 95 | | |
97 | 96 | | |
98 | | - | |
| 97 | + | |
99 | 98 | | |
100 | 99 | | |
101 | 100 | | |
102 | | - | |
103 | | - | |
104 | | - | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
105 | 106 | | |
106 | | - | |
| 107 | + | |
107 | 108 | | |
108 | 109 | | |
109 | 110 | | |
| |||
0 commit comments