Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Watcher] Retain query in watcher list #163297

Merged
merged 6 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export type TestSubjects =
| 'appTitle'
| 'documentationLink'
| 'watchesTable'
| 'watcherListSearchError'
| 'cell'
| 'row'
| 'deleteWatchButton'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ describe('<WatchListPage />', () => {
testBed.component.update();
});

test('should show error callout if search is invalid', async () => {
const { exists, actions } = testBed;

actions.searchWatches('or');

expect(exists('watcherListSearchError')).toBe(true);
});

test('should retain the search query', async () => {
const { table, actions } = testBed;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
EuiIcon,
EuiLink,
EuiPageContent_Deprecated as EuiPageContent,
EuiCallOut,
EuiSpacer,
EuiText,
EuiToolTip,
Expand All @@ -24,6 +25,7 @@ import {
EuiContextMenuPanel,
EuiContextMenuItem,
EuiPageHeader,
EuiSearchBarOnChangeArgs,
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
Expand Down Expand Up @@ -53,6 +55,9 @@ export const WatchListPage = () => {
history,
links: { watcherGettingStartedUrl },
} = useAppContext();
const [query, setQuery] = useState('');
const [queryError, setQueryError] = useState<string | null>(null);

const [selection, setSelection] = useState([]);
const [watchesToDelete, setWatchesToDelete] = useState<string[]>([]);
// Filter out deleted watches on the client, because the API will return 200 even though some watches
Expand Down Expand Up @@ -446,7 +451,18 @@ export const WatchListPage = () => {
: '',
};

const handleOnChange = ({ queryText, error: searchError }: EuiSearchBarOnChangeArgs) => {
if (!searchError) {
setQuery(queryText);
setQueryError(null);
} else {
setQueryError(searchError.message);
}
};

const searchConfig = {
onChange: handleOnChange,
query,
box: {
incremental: true,
},
Expand Down Expand Up @@ -498,6 +514,25 @@ export const WatchListPage = () => {
}}
selection={selectionConfig}
isSelectable={true}
childrenBetween={
queryError && (
<>
<EuiCallOut
data-test-subj="watcherListSearchError"
iconType="warning"
color="danger"
title={
<FormattedMessage
id="xpack.watcher.sections.watchList.watchTable.errorOnSearch"
defaultMessage="Invalid search: {queryError}"
values={{ queryError }}
/>
}
/>
<EuiSpacer />
</>
)
}
message={
<FormattedMessage
id="xpack.watcher.sections.watchList.watchTable.noWatchesMessage"
Expand Down