Skip to content

fix: populate condition field when editing extraction rules#6185

Open
DragonBot00 wants to merge 1 commit intokeephq:mainfrom
DragonBot00:fix/extraction-rule-edit-condition
Open

fix: populate condition field when editing extraction rules#6185
DragonBot00 wants to merge 1 commit intokeephq:mainfrom
DragonBot00:fix/extraction-rule-edit-condition

Conversation

@DragonBot00
Copy link
Copy Markdown
Contributor

Description

When creating an extraction rule with a condition (e.g. source.contains('grafana')), the condition is correctly saved and visible in the extraction rules overview. However, when clicking Edit on an existing rule, the condition field is empty — the previously saved condition is not pre-populated.

Root Cause

The AlertsRulesBuilder component initializes its internal CEL state from constructCELRules(selectedPreset), which returns an empty string when no preset is provided. Although the component accepts a defaultQuery prop, it was never wired into the state initialization, so the condition value passed from the edit form was silently ignored.

Additionally, the extraction edit form passes condition as defaultQuery, but condition is populated asynchronously via a useEffect. By the time condition is set, AlertsRulesBuilder has already mounted with an empty string.

Fix

Two changes were made:

  1. �lerts-rules-builder.tsx: Wire the defaultQuery prop into the useCelState initialization so it is used as the fallback default when no preset CEL is available.

  2. create-or-update-extraction-rule.tsx:

    • Derive initialCondition directly from extractionToEdit?.condition (synchronously available on render) instead of relying on the async state value.
    • Add a key prop to AlertsRulesBuilder based on extractionToEdit?.id so the component remounts with the correct initial condition whenever a different rule is opened for editing.

Testing

  1. Create an extraction rule with a condition (e.g. source.contains('grafana'))
  2. Click Edit on the rule
  3. Verify the condition field is pre-populated with the saved value

Fixes #5201

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 1, 2026

@DragonBot00 is attempting to deploy a commit to the KeepHQ Team on Vercel.

A member of the Team first needs to authorize it.

@DragonBot00
Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. Bug Something isn't working labels Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something isn't working size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[🐛 Bug]: Extraction rule: unable to edit condition after saving

1 participant