Skip to content

Commit

Permalink
change how default timerange is passed to dashboard
Browse files Browse the repository at this point in the history
improve

revert
  • Loading branch information
Dosant committed Mar 24, 2020
1 parent 0deb6b4 commit 7b3ec89
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
IndexPattern,
IndexPatternsContract,
Query,
QueryState,
SavedQuery,
syncQueryStateWithUrl,
} from '../../../../../../plugins/data/public';
Expand Down Expand Up @@ -132,13 +133,6 @@ export class DashboardAppController {
const queryFilter = filterManager;
const timefilter = queryService.timefilter.timefilter;

// starts syncing `_g` portion of url with query services
// note: dashboard_state_manager.ts syncs `_a` portion of url
const {
stop: stopSyncingQueryServiceStateWithUrl,
hasInheritedQueryFromUrl: hasInheritedGlobalStateFromUrl,
} = syncQueryStateWithUrl(queryService, kbnUrlStateStorage);

let lastReloadRequestTime = 0;
const dash = ($scope.dash = $route.current.locals.dash);
if (dash.id) {
Expand Down Expand Up @@ -170,9 +164,20 @@ export class DashboardAppController {

// The hash check is so we only update the time filter on dashboard open, not during
// normal cross app navigation.
if (dashboardStateManager.getIsTimeSavedWithDashboard() && !hasInheritedGlobalStateFromUrl) {
const initialGlobalStateInUrl = kbnUrlStateStorage.get<QueryState>('_g');
const hasInheritedTimeRange = Boolean(initialGlobalStateInUrl?.time);
if (dashboardStateManager.getIsTimeSavedWithDashboard() && !hasInheritedTimeRange) {
dashboardStateManager.syncTimefilterWithDashboard(timefilter);
}
// starts syncing `_g` portion of url with query services
// note: dashboard_state_manager.ts syncs `_a` portion of url
// it is important to start this syncing after `dashboardStateManager.syncTimefilterWithDashboard(timefilter);` above is run,
// otherwise it will case redundant browser history record
const { stop: stopSyncingQueryServiceStateWithUrl } = syncQueryStateWithUrl(
queryService,
kbnUrlStateStorage
);

$scope.showSaveQuery = dashboardCapabilities.saveQuery as boolean;

const getShouldShowEditHelp = () =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ describe('.execute()', () => {
const navigateToApp = jest.fn();
const dataPluginActions = dataPluginMock.createStartContract().actions;
const savedObjectsClient = savedObjectsServiceMock.createStartContract().client;
savedObjectsClient.get = jest
.fn()
.mockReturnValue({ attributes: { from: 'now-15m', to: 'now' } });

const drilldown = new DashboardToDashboardDrilldown({
getNavigateToApp: () => Promise.resolve(navigateToApp),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ export class DashboardToDashboardDrilldown
) => {
const getUrlGenerator = await this.params.getGetUrlGenerator();
const navigateToApp = await this.params.getNavigateToApp();
const savedObjectsClient = await this.params.getSavedObjectsClient();

const {
selectRangeActionGetFilters,
Expand All @@ -72,16 +71,6 @@ export class DashboardToDashboardDrilldown
filters: currentFilters,
} = context.embeddable.getInput();

const savedDashboard = await savedObjectsClient.get<{ timeTo: string; timeFrom: string }>(
'dashboard',
config.dashboardId as string
);

const defaultTimeRange = {
to: savedDashboard.attributes.timeTo,
from: savedDashboard.attributes.timeFrom,
};

// if useCurrentDashboardFilters enabled, then preserve all the filters (pinned and unpinned)
// otherwise preserve only pinned
const filters =
Expand All @@ -92,7 +81,7 @@ export class DashboardToDashboardDrilldown
// if useCurrentDashboardDataRange is enabled, then preserve current time range
// if undefined is passed, then destination dashboard will figure out time range itself
// for brush event this time range would be overwritten
let timeRange = config.useCurrentDateRange ? currentTimeRange : defaultTimeRange;
let timeRange = config.useCurrentDateRange ? currentTimeRange : undefined;

if (context.data.range) {
// look up by range
Expand Down

0 comments on commit 7b3ec89

Please sign in to comment.