Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
6bbdd7f
Add 5s min refresh interval to timefilter with validation
nickofthyme Jul 22, 2024
85eb553
Merge branch 'main' into min-refresh-interval
nickofthyme Jul 29, 2024
f37e7f4
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Jul 29, 2024
2be42e1
remove `setMinRefreshInterval` method
nickofthyme Aug 7, 2024
44e5bbd
remove data dep from navigation plugin
nickofthyme Aug 7, 2024
ea3519e
Merge branch 'main' into min-refresh-interval
nickofthyme Aug 7, 2024
b858a86
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Aug 7, 2024
ca79323
add config option for minRefreshInterval default
nickofthyme Aug 8, 2024
2187cc3
change `QueryService` service to allow usage in `security_solution` p…
nickofthyme Aug 8, 2024
00451eb
fix: jest tests and type errors
nickofthyme Aug 8, 2024
986728e
Merge branch 'main' into min-refresh-interval
nickofthyme Aug 8, 2024
64ed4dc
test: update and add timefilter tests
nickofthyme Aug 8, 2024
b3f7e55
chore: fix type errors in tests
nickofthyme Aug 8, 2024
1edd8d0
fix expected config check
nickofthyme Aug 8, 2024
e1c065a
Merge branch 'main' into min-refresh-interval
nickofthyme Aug 8, 2024
99760dd
fix more tests
nickofthyme Aug 8, 2024
ec3bc54
fix config test
nickofthyme Aug 9, 2024
b4622ce
Merge branch 'main' into min-refresh-interval
nickofthyme Aug 9, 2024
d3aebad
pause when interval is 0, cleanup default intervals in test code
nickofthyme Aug 9, 2024
ce76a1f
Merge branch 'main' into min-refresh-interval
nickofthyme Aug 12, 2024
59b39bc
revert SO changes, add and fix tests
nickofthyme Aug 12, 2024
e852cf0
fix: failing to start refresh loop on browser refresh
nickofthyme Aug 14, 2024
6612e77
chore: update discover data loop check
nickofthyme Aug 14, 2024
ffb3dc5
Merge branch 'main' into min-refresh-interval
nickofthyme Aug 14, 2024
5892855
update config optional type
nickofthyme Aug 14, 2024
3cc60d8
Merge branch 'main' into min-refresh-interval
mbondyra Aug 19, 2024
ce93360
Merge branch 'main' into min-refresh-interval
mbondyra Aug 20, 2024
155744c
Merge branch 'main' into min-refresh-interval
nickofthyme Aug 22, 2024
40509ff
Merge branch 'main' into min-refresh-interval
nickofthyme Aug 23, 2024
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
13 changes: 13 additions & 0 deletions src/plugins/data/public/query/timefilter/timefilter.ts
Comment thread
nickofthyme marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export class Timefilter {
// Denotes whether setTime has been called, can be used to determine if the constructor defaults are being used.
private _isTimeTouched: boolean = false;
private _refreshInterval!: RefreshInterval;
private _minRefreshInterval: number;
// Denotes whether the refresh interval defaults were overriden.
private _isRefreshIntervalTouched: boolean = false;
private _history: TimeHistoryContract;
Expand All @@ -62,6 +63,7 @@ export class Timefilter {
this._history = timeHistory;
this.timeDefaults = config.timeDefaults;
this.refreshIntervalDefaults = config.refreshIntervalDefaults;
this._minRefreshInterval = config.minRefreshIntervalDefault;
this._time = config.timeDefaults;
this.setRefreshInterval(config.refreshIntervalDefaults);
}
Expand Down Expand Up @@ -148,6 +150,14 @@ export class Timefilter {
return _.clone(this._refreshInterval);
};

public getMinRefreshInterval = () => {
return this._minRefreshInterval;
};

public setMinRefreshInterval = (t: number) => {
this._minRefreshInterval = Math.max(t, 0);
};
Comment thread
nickofthyme marked this conversation as resolved.
Outdated

/**
* Set timefilter refresh interval.
* @param {Object} refreshInterval
Expand All @@ -157,6 +167,9 @@ export class Timefilter {
public setRefreshInterval = (refreshInterval: Partial<RefreshInterval>) => {
const prevRefreshInterval = this.getRefreshInterval();
const newRefreshInterval = { ...prevRefreshInterval, ...refreshInterval };

if (newRefreshInterval.value < this._minRefreshInterval) return;

let shouldUnpauseRefreshLoop =
newRefreshInterval.pause === false && prevRefreshInterval != null;
if (prevRefreshInterval?.value > 0 && newRefreshInterval.value <= 0) {
Expand Down
11 changes: 9 additions & 2 deletions src/plugins/data/public/query/timefilter/timefilter_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@

import { IUiSettingsClient } from '@kbn/core/public';
import { IStorageWrapper } from '@kbn/kibana-utils-plugin/public';
import { TimeHistory, Timefilter, TimeHistoryContract, TimefilterContract } from '.';
import {
TimeHistory,
Timefilter,
TimeHistoryContract,
TimefilterContract,
TimefilterConfig,
} from '.';
import { UI_SETTINGS } from '../../../common';
import { NowProviderInternalContract } from '../../now_provider';

Expand All @@ -26,9 +32,10 @@ export class TimefilterService {
constructor(private readonly nowProvider: NowProviderInternalContract) {}

public setup({ uiSettings, storage }: TimeFilterServiceDependencies): TimefilterSetup {
const timefilterConfig = {
const timefilterConfig: TimefilterConfig = {
timeDefaults: uiSettings.get(UI_SETTINGS.TIMEPICKER_TIME_DEFAULTS),
refreshIntervalDefaults: uiSettings.get(UI_SETTINGS.TIMEPICKER_REFRESH_INTERVAL_DEFAULTS),
minRefreshIntervalDefault: 5000,
Comment thread
nickofthyme marked this conversation as resolved.
Outdated
};
const history = new TimeHistory(storage);
const timefilter = new Timefilter(timefilterConfig, history, this.nowProvider);
Expand Down
1 change: 1 addition & 0 deletions src/plugins/data/public/query/timefilter/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { RefreshInterval } from '../../../common';
export interface TimefilterConfig {
timeDefaults: TimeRange;
refreshIntervalDefaults: RefreshInterval;
minRefreshIntervalDefault: number;
}

// Timefilter accepts moment input but always returns string output
Expand Down
12 changes: 8 additions & 4 deletions src/plugins/navigation/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class NavigationPublicPlugin
this.coreStart = core;
this.depsStart = depsStart;

const { unifiedSearch, cloud, cloudExperiments, spaces } = depsStart;
const { unifiedSearch, data, cloud, cloudExperiments, spaces } = depsStart;
const extensions = this.topNavMenuExtensionsRegistry.getAll();
const chrome = core.chrome as InternalChromeStart;
const activeSpace$ = spaces?.getActiveSpace$() ?? of(undefined);
Expand All @@ -89,7 +89,11 @@ export class NavigationPublicPlugin
customUnifiedSearch?: UnifiedSearchPublicPluginStart,
customExtensions?: RegisteredTopNavMenuData[]
) => {
return createTopNav(customUnifiedSearch ?? unifiedSearch, customExtensions ?? extensions);
return createTopNav(
data,
customUnifiedSearch ?? unifiedSearch,
customExtensions ?? extensions
);
};

const onCloud = cloud !== undefined; // The new side nav will initially only be available to cloud users
Expand Down Expand Up @@ -118,8 +122,8 @@ export class NavigationPublicPlugin

return {
ui: {
TopNavMenu: createTopNav(unifiedSearch, extensions),
AggregateQueryTopNavMenu: createTopNav(unifiedSearch, extensions),
TopNavMenu: createTopNav(data, unifiedSearch, extensions),
AggregateQueryTopNavMenu: createTopNav(data, unifiedSearch, extensions),
createTopNavWithCustomContext: createCustomTopNav,
},
addSolutionNavigation: (solutionNavigation) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ import React from 'react';
import { I18nProvider } from '@kbn/i18n-react';
import { AggregateQuery, Query } from '@kbn/es-query';
import { UnifiedSearchPublicPluginStart } from '@kbn/unified-search-plugin/public';
import { DataPublicPluginStart } from '@kbn/data-plugin/public';
import { TopNavMenuProps, TopNavMenu } from './top_nav_menu';
import { RegisteredTopNavMenuData } from './top_nav_menu_data';

export function createTopNav(
data: DataPublicPluginStart,
unifiedSearch: UnifiedSearchPublicPluginStart,
extraConfig: RegisteredTopNavMenuData[]
) {
const minRefreshInterval = data.query.timefilter.timefilter.getMinRefreshInterval();
return <QT extends AggregateQuery | Query = Query>(props: TopNavMenuProps<QT>) => {
const relevantConfig = extraConfig.filter(
(dataItem) => dataItem.appName === undefined || dataItem.appName === props.appName
Expand All @@ -25,7 +28,12 @@ export function createTopNav(

return (
<I18nProvider>
<TopNavMenu {...props} unifiedSearch={unifiedSearch} config={config} />
<TopNavMenu
{...props}
unifiedSearch={unifiedSearch}
config={config}
minRefreshInterval={minRefreshInterval}
Comment thread
nickofthyme marked this conversation as resolved.
Outdated
/>
</I18nProvider>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export function TopNavMenu<QT extends AggregateQuery | Query = Query>(
}

function renderSearchBar(): ReactElement | null {
// Validate presense of all required fields
// Validate presence of all required fields
if (!showSearchBar || !props.unifiedSearch) return null;
const { AggregateQuerySearchBar } = props.unifiedSearch.ui;
return <AggregateQuerySearchBar<QT> {...searchBarProps} />;
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/navigation/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type { SpacesPluginSetup, SpacesPluginStart } from '@kbn/spaces-plugin/pu
import type { CloudExperimentsPluginStart } from '@kbn/cloud-experiments-plugin/common';

import { PanelContentProvider } from '@kbn/shared-ux-chrome-navigation';
import { DataPublicPluginStart } from '@kbn/data-plugin/public';
import { TopNavMenuProps, TopNavMenuExtensionsRegistrySetup, createTopNav } from './top_nav_menu';
import type { RegisteredTopNavMenuData } from './top_nav_menu/top_nav_menu_data';

Expand Down Expand Up @@ -52,6 +53,7 @@ export interface NavigationPublicSetupDependencies {

export interface NavigationPublicStartDependencies {
unifiedSearch: UnifiedSearchPublicPluginStart;
data: DataPublicPluginStart;
cloud?: CloudStart;
cloudExperiments?: CloudExperimentsPluginStart;
spaces?: SpacesPluginStart;
Expand Down
1 change: 1 addition & 0 deletions src/plugins/navigation/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@kbn/config-schema",
"@kbn/i18n",
"@kbn/std",
"@kbn/data-plugin",
],
"exclude": [
"target/**/*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ export interface QueryBarTopRowProps<QT extends Query | AggregateQuery = Query>
prepend?: React.ComponentProps<typeof EuiFieldText>['prepend'];
query?: Query | QT;
refreshInterval?: number;
minRefreshInterval?: number;
screenTitle?: string;
showQueryInput?: boolean;
showAddFilter?: boolean;
Expand Down Expand Up @@ -502,6 +503,7 @@ export const QueryBarTopRow = React.memo(
end={props.dateRangeTo}
isPaused={props.isRefreshPaused}
refreshInterval={props.refreshInterval}
refreshMinInterval={props.minRefreshInterval}
onTimeChange={onTimeChange}
onRefresh={onRefresh}
onRefreshChange={props.onRefreshChange}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export function createSearchBar({
query: props.query,
queryStringManager: data.query.queryString,
}) as { query: QT };
const { timeRange, refreshInterval } = useTimefilter({
const { timeRange, refreshInterval, minRefreshInterval } = useTimefilter({
dateRangeFrom: props.dateRangeFrom,
dateRangeTo: props.dateRangeTo,
refreshInterval: props.refreshInterval,
Expand Down Expand Up @@ -232,6 +232,7 @@ export function createSearchBar({
timeHistory={data.query.timefilter.history}
dateRangeFrom={timeRange.from}
dateRangeTo={timeRange.to}
minRefreshInterval={minRefreshInterval}
refreshInterval={refreshInterval.value}
isRefreshPaused={refreshInterval.pause}
isLoading={props.isLoading}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,6 @@ export const useTimefilter = (props: UseTimefilterProps) => {
return {
refreshInterval,
timeRange,
minRefreshInterval: props.timefilter.getMinRefreshInterval(),
};
};
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 @@ -72,6 +72,7 @@ export interface SearchBarOwnProps<QT extends AggregateQuery | Query = Query> {
// Date picker
isRefreshPaused?: boolean;
refreshInterval?: number;
minRefreshInterval?: number;
dateRangeFrom?: string;
dateRangeTo?: string;
// Query bar - should be in SearchBarInjectedDeps
Expand Down Expand Up @@ -612,6 +613,7 @@ class SearchBarUI<QT extends (Query | AggregateQuery) | Query = Query> extends C
dateRangeTo={this.state.dateRangeTo}
isRefreshPaused={this.props.isRefreshPaused}
refreshInterval={this.props.refreshInterval}
minRefreshInterval={this.props.minRefreshInterval}
showAutoRefreshOnly={this.props.showAutoRefreshOnly}
showQueryInput={this.props.showQueryInput}
showAddFilter={this.props.showFilterBar}
Expand Down