Skip to content

Commit

Permalink
[Metrics UI] use global kibana time for metrics explorer in Default V…
Browse files Browse the repository at this point in the history
…iew (#92520)

* use global kibana time for explorer, stop using local storage for time

* fix inventory time
  • Loading branch information
neptunian authored Feb 25, 2021
1 parent 272bf97 commit fa4dda0
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ export const useWaffleViewState = () => {
region: newState.region,
legend: newState.legend,
});
if (newState.time) {
// if this is the "Default View" view, don't update the time range to the view's time range,
// this way it will use the global Kibana time or the default time already set
if (newState.time && newState.id !== '0') {
setWaffleTimeState({
currentTime: newState.time,
isAutoReloading: newState.autoReload,
Expand All @@ -100,4 +102,5 @@ export type WaffleViewState = WaffleOptionsState & {
time: number;
autoReload: boolean;
filterQuery: WaffleFiltersState;
id?: string;
};
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface MetricExplorerViewState {
chartOptions: MetricsExplorerChartOptions;
currentTimerange: MetricsExplorerTimeOptions;
options: MetricsExplorerOptions;
id?: string;
}

export const useMetricsExplorerState = (
Expand All @@ -42,6 +43,7 @@ export const useMetricsExplorerState = (
setTimeRange,
setOptions,
} = useContext(MetricsExplorerOptionsContainer.Context);

const { loading, error, data, loadData } = useMetricsExplorerData(
options,
source,
Expand Down Expand Up @@ -121,7 +123,11 @@ export const useMetricsExplorerState = (
setChartOptions(vs.chartOptions);
}
if (vs.currentTimerange) {
setTimeRange(vs.currentTimerange);
// if this is the "Default View" view, don't update the time range to the view's time range,
// this way it will use the global Kibana time or the default time already set
if (vs.id !== '0') {
setTimeRange(vs.currentTimerange);
}
}
if (vs.options) {
setOptions(vs.options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ describe('useMetricExplorerOptions', () => {
expect(result.current.currentTimerange).toEqual(DEFAULT_TIMERANGE);
expect(result.current.isAutoReloading).toEqual(false);
expect(STORE.MetricsExplorerOptions).toEqual(JSON.stringify(DEFAULT_OPTIONS));
expect(STORE.MetricsExplorerTimeRange).toEqual(JSON.stringify(DEFAULT_TIMERANGE));
});

it('should change the store when options update', () => {
Expand Down Expand Up @@ -96,7 +95,6 @@ describe('useMetricExplorerOptions', () => {
});
rerender();
expect(result.current.currentTimerange).toEqual(newTimeRange);
expect(STORE.MetricsExplorerTimeRange).toEqual(JSON.stringify(newTimeRange));
});

it('should load from store when available', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,7 @@ export const useMetricsExplorerOptions = () => {
'MetricsExplorerOptions',
DEFAULT_OPTIONS
);
const [currentTimerange, setTimeRange] = useStateWithLocalStorage<MetricsExplorerTimeOptions>(
'MetricsExplorerTimeRange',
defaultTimeRange
);
const [currentTimerange, setTimeRange] = useState<MetricsExplorerTimeOptions>(defaultTimeRange);

useSyncKibanaTimeFilterTime(TIME_DEFAULTS, {
from: currentTimerange.from,
Expand Down

0 comments on commit fa4dda0

Please sign in to comment.