Skip to content

Commit

Permalink
Disable Apply button when form hadn't been touched. Disable select/de…
Browse files Browse the repository at this point in the history
…select button if search returns no ofields
  • Loading branch information
walterra committed Apr 11, 2023
1 parent ae9ba6b commit 8b9f799
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export const FieldFilterPopover: FC<FieldFilterPopoverProps> = ({
[euiThemeContext]
);

const [isTouched, setIsTouched] = useState(false);
const [fieldSearchText, setFieldSearchText] = useState('');
const [skippedFields, setSkippedFields] = useState<string[]>([]);
const setFieldsFilter = (fieldNames: string[], checked: boolean) => {
Expand All @@ -64,6 +65,7 @@ export const FieldFilterPopover: FC<FieldFilterPopoverProps> = ({
updatedSkippedFields = skippedFields.filter((d) => !fieldNames.includes(d));
}
setSkippedFields(updatedSkippedFields);
setIsTouched(true);
};

const [isFieldSelectionPopoverOpen, setIsFieldSelectionPopoverOpen] = useState(false);
Expand Down Expand Up @@ -160,6 +162,7 @@ export const FieldFilterPopover: FC<FieldFilterPopoverProps> = ({
size="xs"
flush="left"
onClick={() => setFieldsFilter(filteredUniqueFieldNames, true)}
disabled={fieldSearchText.length > 0 && filteredUniqueFieldNames.length === 0}
data-test-subj="aiopsFieldSelectorSelectAllFieldsButton"
>
{fieldSearchText.length > 0 ? (
Expand All @@ -180,6 +183,7 @@ export const FieldFilterPopover: FC<FieldFilterPopoverProps> = ({
size="xs"
flush="right"
onClick={() => setFieldsFilter(filteredUniqueFieldNames, false)}
disabled={fieldSearchText.length > 0 && filteredUniqueFieldNames.length === 0}
data-test-subj="aiopsFieldSelectorDeselectAllFieldsButton"
>
{fieldSearchText.length > 0 ? (
Expand All @@ -204,7 +208,7 @@ export const FieldFilterPopover: FC<FieldFilterPopoverProps> = ({
setIsFieldSelectionPopoverOpen(false);
closePopover();
}}
disabled={disabledApplyButton || selectedFieldCount < 2}
disabled={disabledApplyButton || selectedFieldCount < 2 || !isTouched}
tooltipContent={
selectedFieldCount < 2
? i18n.translate('xpack.aiops.analysis.fieldSelectorNotEnoughFieldsSelected', {
Expand Down

0 comments on commit 8b9f799

Please sign in to comment.