From 8b9f7993e44226c2ce35d6ddb9fb986b3679ef6b Mon Sep 17 00:00:00 2001 From: Walter Rafelsberger Date: Tue, 11 Apr 2023 12:41:41 +0200 Subject: [PATCH] Disable Apply button when form hadn't been touched. Disable select/deselect button if search returns no ofields --- .../explain_log_rate_spikes/field_filter_popover.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/aiops/public/components/explain_log_rate_spikes/field_filter_popover.tsx b/x-pack/plugins/aiops/public/components/explain_log_rate_spikes/field_filter_popover.tsx index 707f75bf5f069..38d34983db1a3 100644 --- a/x-pack/plugins/aiops/public/components/explain_log_rate_spikes/field_filter_popover.tsx +++ b/x-pack/plugins/aiops/public/components/explain_log_rate_spikes/field_filter_popover.tsx @@ -54,6 +54,7 @@ export const FieldFilterPopover: FC = ({ [euiThemeContext] ); + const [isTouched, setIsTouched] = useState(false); const [fieldSearchText, setFieldSearchText] = useState(''); const [skippedFields, setSkippedFields] = useState([]); const setFieldsFilter = (fieldNames: string[], checked: boolean) => { @@ -64,6 +65,7 @@ export const FieldFilterPopover: FC = ({ updatedSkippedFields = skippedFields.filter((d) => !fieldNames.includes(d)); } setSkippedFields(updatedSkippedFields); + setIsTouched(true); }; const [isFieldSelectionPopoverOpen, setIsFieldSelectionPopoverOpen] = useState(false); @@ -160,6 +162,7 @@ export const FieldFilterPopover: FC = ({ size="xs" flush="left" onClick={() => setFieldsFilter(filteredUniqueFieldNames, true)} + disabled={fieldSearchText.length > 0 && filteredUniqueFieldNames.length === 0} data-test-subj="aiopsFieldSelectorSelectAllFieldsButton" > {fieldSearchText.length > 0 ? ( @@ -180,6 +183,7 @@ export const FieldFilterPopover: FC = ({ size="xs" flush="right" onClick={() => setFieldsFilter(filteredUniqueFieldNames, false)} + disabled={fieldSearchText.length > 0 && filteredUniqueFieldNames.length === 0} data-test-subj="aiopsFieldSelectorDeselectAllFieldsButton" > {fieldSearchText.length > 0 ? ( @@ -204,7 +208,7 @@ export const FieldFilterPopover: FC = ({ setIsFieldSelectionPopoverOpen(false); closePopover(); }} - disabled={disabledApplyButton || selectedFieldCount < 2} + disabled={disabledApplyButton || selectedFieldCount < 2 || !isTouched} tooltipContent={ selectedFieldCount < 2 ? i18n.translate('xpack.aiops.analysis.fieldSelectorNotEnoughFieldsSelected', {