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

[Infrastructure UI] Hosts View: Unified Search bar with auto-refresh enabled #157011

Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,16 @@ storiesOf('SearchBar', module)
showDatePicker: false,
} as SearchBarProps)
)
.add('with date picker off', () =>
.add('with the default date picker auto refresh interval on', () =>
wrapSearchBarInContext({
showDatePicker: false,
showDatePicker: true,
onRefreshChange: action('onRefreshChange'),
} as SearchBarProps)
)
.add('with the default date picker auto refresh interval off', () =>
wrapSearchBarInContext({
showDatePicker: true,
isAutoRefreshDisabled: true,
} as SearchBarProps)
)
.add('with only the date picker on', () =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ const defaultFiltersUpdated = (
};

// Respond to user changing the refresh settings
const defaultOnRefreshChange = (queryService: QueryStart) => {
const defaultOnRefreshChange = (queryService: QueryStart, isAutoRefreshDisabled?: boolean) => {
if (isAutoRefreshDisabled) {
return;
}
const { timefilter } = queryService.timefilter;
return (options: { isPaused: boolean; refreshInterval: number }) => {
timefilter.setRefreshInterval({
Expand Down Expand Up @@ -218,7 +221,7 @@ export function createSearchBar({
filters={filters}
query={query}
onFiltersUpdated={defaultFiltersUpdated(data.query, props.onFiltersUpdated)}
onRefreshChange={defaultOnRefreshChange(data.query)}
onRefreshChange={defaultOnRefreshChange(data.query, props.isAutoRefreshDisabled)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that there is no need to pass it to the function, just dont run the function if this prop is set to true

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it to set undefined there if we have isAutoRefreshDisabled set to true otherwise it will use the function.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking something like onRefreshChange={!props.isAutoRefreshDisabled ? defaultOnRefreshChange(data.query) : undefined}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see, this is what you need. This is a nit but can you add the undefined as the else clause? As I have it on my comment?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, thanks for checking that! 🙂 I changed the condition to return the function if we don't have isAutoRefreshDisabled and otherwise to be undefined. Is that what you mean?

savedQuery={savedQuery}
onQuerySubmit={defaultOnQuerySubmit(props, data.query, query)}
onClearSavedQuery={defaultOnClearSavedQuery(props, clearSavedQuery)}
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/unified_search/public/search_bar/search_bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ export interface SearchBarOwnProps<QT extends AggregateQuery | Query = Query> {

onRefresh?: (payload: { dateRange: TimeRange }) => void;
indicateNoData?: boolean;
// Disables the default auto-refresh option inside the date picker
isAutoRefreshDisabled?: boolean;

placeholder?: string;
isClearable?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export const UnifiedSearchBar = () => {
showQueryInput
showQueryMenu
useDefaultBehaviors
isAutoRefreshDisabled
/>
</EuiFlexItem>
<EuiFlexItem>
Expand Down