Skip to content

Commit

Permalink
Revert most of changes to dashboard app because of changes in elastic…
Browse files Browse the repository at this point in the history
  • Loading branch information
Liza K committed Jan 29, 2020
1 parent 62e54da commit 469f41c
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,22 @@
show-save-query="showSaveQuery"

query="model.query"
saved-query="savedQuery"
screen-title="screenTitle"
on-query-submit="updateQueryAndFetch"
index-patterns="indexPatterns"
use-default-behaviors="true"
index-patterns="indexPatterns"
filters="model.filters"
on-filters-updated="onFiltersUpdated"
date-range-from="model.timeRange.from"
date-range-to="model.timeRange.to"
is-refresh-paused="model.refreshInterval.pause"
refresh-interval="model.refreshInterval.value"
on-saved="onQuerySaved"
on-saved-query-updated="onSavedQueryUpdated"
on-clear-saved-query="onClearSavedQuery"
on-refresh-change="onRefreshChange"
>

</kbn-top-nav>

<!--
Expand All @@ -32,10 +43,10 @@
show-filter-bar="true"
show-save-query="false"
show-date-picker="false"
show-query-bar="false"

filters="model.filters"
index-patterns="indexPatterns"

use-default-behaviors="true"
on-filters-updated="onFiltersUpdated"
>
</kbn-top-nav>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ import { IInjector } from '../legacy_imports';
import { ViewMode } from '../../../../embeddable_api/public/np_ready/public';
import { SavedObjectDashboard } from '../saved_dashboard/saved_dashboard';
import { DashboardAppState, SavedDashboardPanel, ConfirmModalFn } from './types';
import { IIndexPattern, TimeRange, Query, esFilters } from '../../../../../../plugins/data/public';
import {
IIndexPattern,
TimeRange,
Query,
esFilters,
SavedQuery,
} from '../../../../../../plugins/data/public';

import { DashboardAppController } from './dashboard_app_controller';
import { RenderDeps } from './application';
Expand All @@ -45,6 +51,7 @@ export interface DashboardAppScope extends ng.IScope {
| { to: string | moment.Moment | undefined; from: string | moment.Moment | undefined };
refreshInterval: any;
};
savedQuery?: SavedQuery;
refreshInterval: any;
panels: SavedDashboardPanel[];
indexPatterns: IIndexPattern[];
Expand All @@ -53,8 +60,19 @@ export interface DashboardAppScope extends ng.IScope {
getShouldShowEditHelp: () => boolean;
getShouldShowViewHelp: () => boolean;
updateQueryAndFetch: ({ query, dateRange }: { query: Query; dateRange?: TimeRange }) => void;
onRefreshChange: ({
isPaused,
refreshInterval,
}: {
isPaused: boolean;
refreshInterval: any;
}) => void;
onFiltersUpdated: (filters: esFilters.Filter[]) => void;
onCancelApplyFilters: () => void;
onApplyFilters: (filters: esFilters.Filter[]) => void;
onQuerySaved: (savedQuery: SavedQuery) => void;
onSavedQueryUpdated: (savedQuery: SavedQuery) => void;
onClearSavedQuery: () => void;
topNavMenu: any;
showFilterBar: () => boolean;
showAddPanel: any;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
IndexPattern,
IndexPatternsContract,
Query,
SavedQuery,
syncAppFilters,
syncQuery,
} from '../../../../../../plugins/data/public';
Expand Down Expand Up @@ -440,6 +441,10 @@ export class DashboardAppController {
};

$scope.updateQueryAndFetch = function({ query, dateRange }) {
if (dateRange) {
timefilter.setTime(dateRange);
}

const oldQuery = $scope.model.query;
if (_.isEqual(oldQuery, query)) {
// The user can still request a reload in the query bar, even if the
Expand All @@ -453,6 +458,93 @@ export class DashboardAppController {
}
};

$scope.onRefreshChange = function({ isPaused, refreshInterval }) {
timefilter.setRefreshInterval({
pause: isPaused,
value: refreshInterval ? refreshInterval : $scope.model.refreshInterval.value,
});
};

$scope.onFiltersUpdated = filters => {
// The filters will automatically be set when the filterManager emits an update event (see below)
filterManager.setFilters(filters);
};

$scope.onQuerySaved = savedQuery => {
$scope.savedQuery = savedQuery;
};

$scope.onSavedQueryUpdated = savedQuery => {
$scope.savedQuery = { ...savedQuery };
};

$scope.onClearSavedQuery = () => {
delete $scope.savedQuery;
dashboardStateManager.setSavedQueryId(undefined);
dashboardStateManager.applyFilters(
{
query: '',
language:
localStorage.get('kibana.userQueryLanguage') || config.get('search:queryLanguage'),
},
filterManager.getGlobalFilters()
);
// Making this method sync broke the updates.
// Temporary fix, until we fix the complex state in this file.
setTimeout(() => {
filterManager.setFilters(filterManager.getGlobalFilters());
}, 0);
};

const updateStateFromSavedQuery = (savedQuery: SavedQuery) => {
const savedQueryFilters = savedQuery.attributes.filters || [];
const globalFilters = filterManager.getGlobalFilters();
const allFilters = [...globalFilters, ...savedQueryFilters];

dashboardStateManager.applyFilters(savedQuery.attributes.query, allFilters);
if (savedQuery.attributes.timefilter) {
timefilter.setTime({
from: savedQuery.attributes.timefilter.from,
to: savedQuery.attributes.timefilter.to,
});
if (savedQuery.attributes.timefilter.refreshInterval) {
timefilter.setRefreshInterval(savedQuery.attributes.timefilter.refreshInterval);
}
}
// Making this method sync broke the updates.
// Temporary fix, until we fix the complex state in this file.
setTimeout(() => {
filterManager.setFilters(allFilters);
}, 0);
};

$scope.$watch('savedQuery', (newSavedQuery: SavedQuery) => {
if (!newSavedQuery) return;
dashboardStateManager.setSavedQueryId(newSavedQuery.id);

updateStateFromSavedQuery(newSavedQuery);
});

$scope.$watch(
() => {
return dashboardStateManager.getSavedQueryId();
},
newSavedQueryId => {
if (!newSavedQueryId) {
$scope.savedQuery = undefined;
return;
}
if (!$scope.savedQuery || newSavedQueryId !== $scope.savedQuery.id) {
savedQueryService.getSavedQuery(newSavedQueryId).then((savedQuery: SavedQuery) => {
$scope.$evalAsync(() => {
$scope.savedQuery = savedQuery;
updateStateFromSavedQuery(savedQuery);
});
});
}
}
);

$scope.indexPatterns = [];

$scope.$watch('model.query', (newQuery: Query) => {
Expand Down

0 comments on commit 469f41c

Please sign in to comment.