Skip to content

Commit

Permalink
Fix search issue with Alert search bar (elastic#155796)
Browse files Browse the repository at this point in the history
Fixes elastic#155655

Added `onQuerySubmit` ~as optional~ parameter to `AlertsSearchBar` and
made `onQueryChange` as optional parameter as this is not needed for
Observability Alerts.

### [Observability] Alerts page:

https://user-images.githubusercontent.com/69037875/234622864-c18e338c-2ea3-4c79-9340-30c5e8fa470e.mov

### [Security] Alerts filter in action:

https://user-images.githubusercontent.com/69037875/234623243-c882a866-83fa-4d09-a1fb-d36588922f30.mov
(cherry picked from commit 44c40a3)
  • Loading branch information
benakansara committed May 2, 2023
1 parent 2f7357c commit f426ce4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export function ObservabilityAlertSearchBar({
rangeFrom={rangeFrom}
rangeTo={rangeTo}
query={kuery}
onQueryChange={onSearchBarParamsChange}
onQuerySubmit={onSearchBarParamsChange}
/>
</EuiFlexItem>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export const ActionAlertsFilterQuery: React.FC<ActionAlertsFilterQueryProps> = (
query={query.kql}
filters={query.filters ?? []}
onQueryChange={onQueryChange}
onQuerySubmit={onQueryChange}
onFiltersUpdated={onFiltersUpdated}
showFilterBar
submitOnBlur
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export function AlertsSearchBar({
query,
filters,
onQueryChange,
onQuerySubmit,
onFiltersUpdated,
rangeFrom,
rangeTo,
Expand All @@ -39,9 +40,20 @@ export function AlertsSearchBar({
const [queryLanguage, setQueryLanguage] = useState<QueryLanguageType>('kuery');
const { value: dataView, loading, error } = useAlertDataView(featureIds);

const onQuerySubmit = useCallback(
const onSearchQuerySubmit = useCallback(
({ dateRange, query: nextQuery }: { dateRange: TimeRange; query?: Query }) => {
onQueryChange({
onQuerySubmit({
dateRange,
query: typeof nextQuery?.query === 'string' ? nextQuery.query : undefined,
});
setQueryLanguage((nextQuery?.language ?? 'kuery') as QueryLanguageType);
},
[onQuerySubmit, setQueryLanguage]
);

const onSearchQueryChange = useCallback(
({ dateRange, query: nextQuery }: { dateRange: TimeRange; query?: Query }) => {
onQueryChange?.({
dateRange,
query: typeof nextQuery?.query === 'string' ? nextQuery.query : undefined,
});
Expand All @@ -50,7 +62,7 @@ export function AlertsSearchBar({
[onQueryChange, setQueryLanguage]
);
const onRefresh = ({ dateRange }: { dateRange: TimeRange }) => {
onQueryChange({
onQuerySubmit({
dateRange,
});
};
Expand All @@ -66,13 +78,13 @@ export function AlertsSearchBar({
dateRangeTo={rangeTo}
displayStyle="inPage"
showFilterBar={showFilterBar}
onQuerySubmit={onQuerySubmit}
onQuerySubmit={onSearchQuerySubmit}
onFiltersUpdated={onFiltersUpdated}
onRefresh={onRefresh}
showDatePicker={showDatePicker}
showSubmitButton={showSubmitButton}
submitOnBlur={submitOnBlur}
onQueryChange={onQuerySubmit}
onQueryChange={onSearchQueryChange}
/>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ export interface AlertsSearchBarProps {
showSubmitButton?: boolean;
placeholder?: string;
submitOnBlur?: boolean;
onQueryChange: (query: {
onQueryChange?: (query: {
dateRange: { from: string; to: string; mode?: 'absolute' | 'relative' };
query?: string;
}) => void;
onQuerySubmit: (query: {
dateRange: { from: string; to: string; mode?: 'absolute' | 'relative' };
query?: string;
}) => void;
Expand Down

0 comments on commit f426ce4

Please sign in to comment.