[8.8] [Enterprise Search] Fix bug saving edited field rules (#156259) (#156282)

# Backport

This will backport the following commits from `main` to `8.8`:
- [[Enterprise Search] Fix bug saving edited field rules
(#156259)](https://github.com/elastic/kibana/pull/156259)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Sander
Philipse","email":"94373878+sphilipse@users.noreply.github.com"},"sourceCommit":{"committedDate":"2023-05-01T16:54:09Z","message":"[Enterprise
Search] Fix bug saving edited field rules (#156259)\n\n##
Summary\r\n\r\nThis fixes a bug causing edited field rules to always
overwrite the\r\nfirst rule in the list when
saved.","sha":"83ca5a78234eabc86578e70c286c0c5631267e9d","branchLabelMapping":{"^v8.9.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:EnterpriseSearch","v8.8.0","v8.7.1","v8.7.2","v8.9.0"],"number":156259,"url":"https://github.com/elastic/kibana/pull/156259","mergeCommit":{"message":"[Enterprise
Search] Fix bug saving edited field rules (#156259)\n\n##
Summary\r\n\r\nThis fixes a bug causing edited field rules to always
overwrite the\r\nfirst rule in the list when
saved.","sha":"83ca5a78234eabc86578e70c286c0c5631267e9d"}},"sourceBranch":"main","suggestedTargetBranches":["8.8","8.7"],"targetPullRequestStates":[{"branch":"8.8","label":"v8.8.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.7","label":"v8.7.1","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.9.0","labelRegex":"^v8.9.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/156259","number":156259,"mergeCommit":{"message":"[Enterprise
Search] Fix bug saving edited field rules (#156259)\n\n##
Summary\r\n\r\nThis fixes a bug causing edited field rules to always
overwrite the\r\nfirst rule in the list when
saved.","sha":"83ca5a78234eabc86578e70c286c0c5631267e9d"}}]}]
BACKPORT-->

Co-authored-by: Sander Philipse <94373878+sphilipse@users.noreply.github.com>
This commit is contained in:
Kibana Machine 2023-06-29 12:07:10 -04:00 committed by GitHub
parent 73dea41ed2
commit 7620b02ad9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 2 additions and 13 deletions

View file

@ -103,7 +103,7 @@ export const EditExtractionRule: React.FC<EditExtractionRuleProps> = ({
saveRule,
}) => {
const { closeEditRuleFlyout, openEditRuleFlyout } = useActions(ExtractionRulesLogic);
const { fieldRuleFlyoutVisible, fieldRuleToEdit, fieldRuleToEditIndex, fieldRuleToEditIsNew } =
const { fieldRuleFlyoutVisible, fieldRuleToEdit, fieldRuleToEditIsNew } =
useValues(ExtractionRulesLogic);
const [urlToggle, setUrlToggle] = useState<UrlState>(UrlState.ALL);
const { control, formState, getValues, handleSubmit, reset, setValue } =
@ -437,6 +437,7 @@ export const EditExtractionRule: React.FC<EditExtractionRuleProps> = ({
if (fieldRuleToEditIsNew) {
appendRule(fieldRule);
} else {
const fieldRuleToEditIndex = rulesFields.findIndex(({ id: ruleId }) => ruleId === id);
updateRule(fieldRuleToEditIndex ?? 0, fieldRule);
}
closeEditRuleFlyout();

View file

@ -57,15 +57,12 @@ interface ExtractionRulesActions {
hideDeleteModal: () => void;
openEditRuleFlyout({
fieldRule,
fieldRuleIndex,
isNewRule,
}: {
fieldRule?: ExtractionRuleFieldRule;
fieldRuleIndex?: number;
isNewRule: boolean;
}): {
fieldRule: ExtractionRuleFieldRule;
fieldRuleIndex?: number;
isNewRule: boolean;
};
fetchDomainData: CrawlerDomainDetailActions['fetchDomainData'];
@ -101,7 +98,6 @@ interface ExtractionRulesValues {
fieldRuleFlyoutVisible: boolean;
fieldRuleToDelete: { extractionRuleId?: string; fieldRuleIndex?: number };
fieldRuleToEdit: ExtractionRuleFieldRule | null;
fieldRuleToEditIndex: number | null;
fieldRuleToEditIsNew: boolean;
indexName: string;
isLoading: boolean;
@ -289,13 +285,6 @@ export const ExtractionRulesLogic = kea<
openEditRuleFlyout: (_, { fieldRule }) => fieldRule ?? null,
},
],
fieldRuleToEditIndex: [
null,
{
closeEditRuleFlyout: () => null,
openEditRuleFlyout: (_, { fieldRuleIndex }) => fieldRuleIndex ?? null,
},
],
fieldRuleToEditIsNew: [
true,
{

View file

@ -66,7 +66,6 @@ export const ExtractionRulesTable: React.FC = () => {
if (rule) {
openEditRuleFlyout({
fieldRule: rule,
fieldRuleIndex: rule.index,
isNewRule: false,
});
}