diff --git a/x-pack/legacy/plugins/upgrade_assistant/public/np_ready/application/components/tabs/checkup/__snapshots__/checkup_tab.test.tsx.snap b/x-pack/legacy/plugins/upgrade_assistant/public/np_ready/application/components/tabs/checkup/__snapshots__/checkup_tab.test.tsx.snap
index 4888aa39e93a1..d6878ffebb4e5 100644
--- a/x-pack/legacy/plugins/upgrade_assistant/public/np_ready/application/components/tabs/checkup/__snapshots__/checkup_tab.test.tsx.snap
+++ b/x-pack/legacy/plugins/upgrade_assistant/public/np_ready/application/components/tabs/checkup/__snapshots__/checkup_tab.test.tsx.snap
@@ -57,7 +57,7 @@ exports[`CheckupTab render with deprecations 1`] = `
-
@@ -143,7 +143,6 @@ export class CheckupTab extends UpgradeAssistantTabComponent void;
currentFilter: LevelFilterOption;
onFilterChange: (filter: LevelFilterOption) => void;
- search: string;
onSearchChange: (filter: string) => void;
availableGroupByOptions: GroupByOption[];
currentGroupBy: GroupByOption;
onGroupByChange: (groupBy: GroupByOption) => void;
}
-export const CheckupControlsUI: FunctionComponent = ({
+export const CheckupControls: FunctionComponent = ({
allDeprecations,
loadingState,
loadData,
currentFilter,
onFilterChange,
- search,
onSearchChange,
availableGroupByOptions,
currentGroupBy,
onGroupByChange,
- intl,
-}) => (
-
-
- onSearchChange(e.target.value)}
- />
-
-
- {/* These two components provide their own EuiFlexItem wrappers */}
-
-
+}) => {
+ const [searchTermError, setSearchTermError] = useState(null);
+ const filterInvalid = Boolean(searchTermError);
+ return (
+
+
+
+
+ {
+ const string = e.target.value;
+ const errorMessage = validateRegExpString(string);
+ if (errorMessage) {
+ // Emit an empty search term to listeners if search term is invalid.
+ onSearchChange('');
+ setSearchTermError(errorMessage);
+ } else {
+ onSearchChange(e.target.value);
+ if (searchTermError) {
+ setSearchTermError(null);
+ }
+ }
+ }}
+ />
+
-
-
-
-
-
-
-);
+ {/* These two components provide their own EuiFlexItem wrappers */}
+
+
-export const CheckupControls = injectI18n(CheckupControlsUI);
+
+
+
+
+
+
+
+ {filterInvalid && (
+
+
+
+ )}
+
+ );
+};
diff --git a/x-pack/legacy/plugins/upgrade_assistant/public/np_ready/application/utils.test.ts b/x-pack/legacy/plugins/upgrade_assistant/public/np_ready/application/utils.test.ts
new file mode 100644
index 0000000000000..067f11798e151
--- /dev/null
+++ b/x-pack/legacy/plugins/upgrade_assistant/public/np_ready/application/utils.test.ts
@@ -0,0 +1,20 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+import { validateRegExpString } from './utils';
+
+describe('validRegExpString', () => {
+ it('correctly returns false for invalid strings', () => {
+ expect(validateRegExpString('?asd')).toContain(`Invalid regular expression`);
+ expect(validateRegExpString('*asd')).toContain(`Invalid regular expression`);
+ expect(validateRegExpString('(')).toContain(`Invalid regular expression`);
+ });
+
+ it('correctly returns true for valid strings', () => {
+ expect(validateRegExpString('asd')).toBe('');
+ expect(validateRegExpString('.*asd')).toBe('');
+ expect(validateRegExpString('')).toBe('');
+ });
+});
diff --git a/x-pack/legacy/plugins/upgrade_assistant/public/np_ready/application/utils.ts b/x-pack/legacy/plugins/upgrade_assistant/public/np_ready/application/utils.ts
new file mode 100644
index 0000000000000..6a1f32fe8f20b
--- /dev/null
+++ b/x-pack/legacy/plugins/upgrade_assistant/public/np_ready/application/utils.ts
@@ -0,0 +1,19 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+import { pipe } from 'fp-ts/lib/pipeable';
+import { tryCatch, fold } from 'fp-ts/lib/Either';
+
+export const validateRegExpString = (s: string) =>
+ pipe(
+ tryCatch(
+ () => new RegExp(s),
+ e => (e as Error).message
+ ),
+ fold(
+ (errorMessage: string) => errorMessage,
+ () => ''
+ )
+ );