mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
Fixes persist/restore of time/refreshInterval in data visualizer.
This commit is contained in:
parent
01a77f4ce2
commit
c057f266f9
1 changed files with 37 additions and 3 deletions
|
@ -41,6 +41,7 @@ import { useKibanaContext, SavedSearchQuery } from '../../contexts/kibana';
|
|||
import { kbnTypeToMLJobType } from '../../util/field_types_utils';
|
||||
import { timeBasedIndexCheck, getQueryFromSavedSearch } from '../../util/index_utils';
|
||||
import { TimeBuckets } from '../../util/time_buckets';
|
||||
import { useUrlState } from '../../util/url_state';
|
||||
import { FieldRequestConfig, FieldVisConfig } from './common';
|
||||
import { ActionsPanel } from './components/actions_panel';
|
||||
import { FieldsPanel } from './components/fields_panel';
|
||||
|
@ -102,6 +103,26 @@ export const Page: FC = () => {
|
|||
|
||||
const dataLoader = new DataLoader(currentIndexPattern, kibanaConfig);
|
||||
|
||||
const [globalState, setGlobalState] = useUrlState('_g');
|
||||
useEffect(() => {
|
||||
if (globalState?.time !== undefined) {
|
||||
timefilter.setTime({
|
||||
from: globalState.time.from,
|
||||
to: globalState.time.to,
|
||||
});
|
||||
}
|
||||
}, [globalState?.time?.from, globalState?.time?.to]);
|
||||
useEffect(() => {
|
||||
if (globalState?.refreshInterval !== undefined) {
|
||||
timefilter.setRefreshInterval(globalState.refreshInterval);
|
||||
}
|
||||
}, [globalState?.refreshInterval?.pause, globalState?.refreshInterval?.value]);
|
||||
|
||||
const [lastRefresh, setLastRefresh] = useState(0);
|
||||
useEffect(() => {
|
||||
loadOverallStats();
|
||||
}, [lastRefresh]);
|
||||
|
||||
useEffect(() => {
|
||||
if (currentIndexPattern.timeFieldName !== undefined) {
|
||||
timefilter.enableTimeRangeSelector();
|
||||
|
@ -175,7 +196,13 @@ export const Page: FC = () => {
|
|||
const timeUpdateSubscription = merge(
|
||||
timefilter.getTimeUpdate$(),
|
||||
mlTimefilterRefresh$
|
||||
).subscribe(loadOverallStats);
|
||||
).subscribe(() => {
|
||||
setGlobalState({
|
||||
time: timefilter.getTime(),
|
||||
refreshInterval: timefilter.getRefreshInterval(),
|
||||
});
|
||||
setLastRefresh(Date.now());
|
||||
});
|
||||
return () => {
|
||||
timeUpdateSubscription.unsubscribe();
|
||||
};
|
||||
|
@ -231,9 +258,16 @@ export const Page: FC = () => {
|
|||
const tf = timefilter as any;
|
||||
let earliest;
|
||||
let latest;
|
||||
|
||||
const activeBounds = tf.getActiveBounds();
|
||||
|
||||
if (currentIndexPattern.timeFieldName !== undefined && activeBounds === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentIndexPattern.timeFieldName !== undefined) {
|
||||
earliest = tf.getActiveBounds().min.valueOf();
|
||||
latest = tf.getActiveBounds().max.valueOf();
|
||||
earliest = activeBounds.min.valueOf();
|
||||
latest = activeBounds.max.valueOf();
|
||||
}
|
||||
|
||||
try {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue