Skip to content

Commit db6538b

Browse files
kibanamachinegeorgianaonoleata1904adcoelho
authored
[9.2] [ResponseOps][Rules] Save button in settings flyout should remain disabled until settings are modified (#241238) (#241321)
# Backport This will backport the following commits from `main` to `9.2`: - [[ResponseOps][Rules] Save button in settings flyout should remain disabled until settings are modified (#241238)](#241238) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Georgiana-Andreea Onoleață","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-10-30T15:31:03Z","message":"[ResponseOps][Rules] Save button in settings flyout should remain disabled until settings are modified (#241238)\n\nCloses https://github.com/elastic/kibana/issues/238586\n\n## Summary\n\n- Fixed the save button enabled/disabled state in `Rules Settings\nFlyout`\n\n**Problem**: the save button was enabled on flyout open, even when no\nchanges were made\n\n**Solution**:\n- updated the enable/disable logic to include `hasFlappingChanged` and\n`hasQueryDelayChanged` ensuring the save button is disabled until the\nuser changes at least one setting.\n- updated the `useResettableState` hook so that loading initial values\nresets the `hasChanged` flag to `false`\n\n---------\n\nCo-authored-by: Antonio <[email protected]>","sha":"5f1c7f3249446eaaf46ca8e818fab8513a9f1878","branchLabelMapping":{"^v9.3.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:ResponseOps","backport:version","v9.3.0","v8.19.7","v9.1.7","v9.2.1"],"title":"[ResponseOps][Rules] Save button in settings flyout should remain disabled until settings are modified","number":241238,"url":"https://github.com/elastic/kibana/pull/241238","mergeCommit":{"message":"[ResponseOps][Rules] Save button in settings flyout should remain disabled until settings are modified (#241238)\n\nCloses https://github.com/elastic/kibana/issues/238586\n\n## Summary\n\n- Fixed the save button enabled/disabled state in `Rules Settings\nFlyout`\n\n**Problem**: the save button was enabled on flyout open, even when no\nchanges were made\n\n**Solution**:\n- updated the enable/disable logic to include `hasFlappingChanged` and\n`hasQueryDelayChanged` ensuring the save button is disabled until the\nuser changes at least one setting.\n- updated the `useResettableState` hook so that loading initial values\nresets the `hasChanged` flag to `false`\n\n---------\n\nCo-authored-by: Antonio <[email protected]>","sha":"5f1c7f3249446eaaf46ca8e818fab8513a9f1878"}},"sourceBranch":"main","suggestedTargetBranches":["8.19","9.1","9.2"],"targetPullRequestStates":[{"branch":"main","label":"v9.3.0","branchLabelMappingKey":"^v9.3.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/241238","number":241238,"mergeCommit":{"message":"[ResponseOps][Rules] Save button in settings flyout should remain disabled until settings are modified (#241238)\n\nCloses https://github.com/elastic/kibana/issues/238586\n\n## Summary\n\n- Fixed the save button enabled/disabled state in `Rules Settings\nFlyout`\n\n**Problem**: the save button was enabled on flyout open, even when no\nchanges were made\n\n**Solution**:\n- updated the enable/disable logic to include `hasFlappingChanged` and\n`hasQueryDelayChanged` ensuring the save button is disabled until the\nuser changes at least one setting.\n- updated the `useResettableState` hook so that loading initial values\nresets the `hasChanged` flag to `false`\n\n---------\n\nCo-authored-by: Antonio <[email protected]>","sha":"5f1c7f3249446eaaf46ca8e818fab8513a9f1878"}},{"branch":"8.19","label":"v8.19.7","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"9.1","label":"v9.1.7","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"9.2","label":"v9.2.1","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Georgiana-Andreea Onoleață <[email protected]> Co-authored-by: Antonio <[email protected]>
1 parent cba1aed commit db6538b

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

x-pack/platform/plugins/shared/triggers_actions_ui/public/application/components/rules_setting/rules_settings_flyout.test.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,4 +509,17 @@ describe('rules_settings_flyout', () => {
509509

510510
expect(result.queryByTestId('alert-delete-open-modal-button')).toBe(null);
511511
});
512+
513+
test('save button is disabled on initial load and enabled when user changes a setting', async () => {
514+
render(<RulesSettingsFlyoutWithProviders {...flyoutProps} />);
515+
await waitForFlyoutLoad();
516+
517+
const saveButton = screen.getByTestId('rulesSettingsFlyoutSaveButton');
518+
expect(saveButton).toBeDisabled();
519+
520+
const lookBackWindowInput = screen.getByTestId('lookBackWindowRangeInput');
521+
fireEvent.change(lookBackWindowInput, { target: { value: 20 } });
522+
523+
expect(saveButton).not.toBeDisabled();
524+
});
512525
});

x-pack/platform/plugins/shared/triggers_actions_ui/public/application/components/rules_setting/rules_settings_flyout.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,12 @@ const useResettableState: <T>(
8080
};
8181
const updateValue = (next: typeof value, shouldUpdateInitialValue = false) => {
8282
setValue(next);
83-
setHasChanged(true);
84-
if (shouldUpdateInitialValue) initialValueRef.current = next;
83+
if (shouldUpdateInitialValue) {
84+
initialValueRef.current = next;
85+
setHasChanged(false);
86+
} else {
87+
setHasChanged(true);
88+
}
8589
};
8690
return [value, hasChanged, updateValue, reset];
8791
};
@@ -172,6 +176,10 @@ export const RulesSettingsFlyout = memo((props: RulesSettingsFlyoutProps) => {
172176
const canShowQueryDelaySettings = readQueryDelaySettingsUI;
173177
const canShowAlertDeleteSettings = readAlertDeleteSettingsUI;
174178

179+
const isChanged = hasFlappingChanged || hasQueryDelayChanged;
180+
const hasMinimumWritePermissions = canWriteFlappingSettings || canWriteQueryDelaySettings;
181+
const shouldDisableSaveButton = !isChanged || !hasMinimumWritePermissions;
182+
175183
const handleSettingsChange = (
176184
setting: keyof RulesSettingsProperties,
177185
key: keyof RulesSettingsFlappingProperties | keyof RulesSettingsQueryDelayProperties,
@@ -324,7 +332,7 @@ export const RulesSettingsFlyout = memo((props: RulesSettingsFlyoutProps) => {
324332
fill
325333
data-test-subj="rulesSettingsFlyoutSaveButton"
326334
onClick={handleSave}
327-
disabled={!canWriteFlappingSettings && !canWriteQueryDelaySettings}
335+
disabled={shouldDisableSaveButton}
328336
>
329337
<FormattedMessage
330338
id="xpack.triggersActionsUI.rulesSettings.flyout.saveButton"

0 commit comments

Comments
 (0)