Skip to content

Commit

Permalink
Fix time filter on dashboard
Browse files Browse the repository at this point in the history
Time range and time interval needs to be able to update child embeddable, and also persisted globally.

Signed-off-by: abbyhu2000 <abigailhu2000@gmail.com>
  • Loading branch information
abbyhu2000 committed Jun 22, 2023
1 parent 23c5dae commit f7969cf
Showing 1 changed file with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import EventEmitter from 'events';
import { useEffect, useState } from 'react';
import { merge } from 'rxjs';
import { DashboardAppState, DashboardAppStateContainer, DashboardServices } from '../../../types';
import { DashboardContainer } from '../../embeddable';

Expand All @@ -21,18 +22,14 @@ export const useEditorUpdates = (

const {
timefilter: { timefilter },
filterManager,
queryString,
state$,
} = services.data.query;

useEffect(() => {
if (appState && dashboardInstance && dashboardContainer) {
const initialState = appState.getState();
setCurrentAppState(initialState);

const unsubscribeStateUpdates = appState.subscribe((state) => {
setCurrentAppState(state);
const refreshDashboardContainer = () => {
if (dashboardContainer.getChangesFromAppStateForContainerState) {
const changes = dashboardContainer.getChangesFromAppStateForContainerState(
dashboardContainer
Expand All @@ -41,6 +38,23 @@ export const useEditorUpdates = (
dashboardContainer.updateInput(changes);
}
}
};

const unsubscribeStateUpdates = appState.subscribe((state) => {
setCurrentAppState(state);
refreshDashboardContainer();
});

// Need to add subscription for time filter specifically because app state is not tracking time filters
// since they are part of the global state, not app state
// However, we still need to update the dashboard container with the correct time filters because dashboard
// container embeddable needs them to correctly pass them down and update its child visualization embeddables
const timeFilterChange$ = merge(
timefilter.getRefreshIntervalUpdate$(),
timefilter.getTimeUpdate$()
);
timeFilterChange$.subscribe(() => {
refreshDashboardContainer();
});

return () => {
Expand All @@ -54,6 +68,7 @@ export const useEditorUpdates = (
services,
dashboardContainer,
isEmbeddableRendered,
timefilter,
]);

useEffect(() => {
Expand Down

0 comments on commit f7969cf

Please sign in to comment.