Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

explicitly passing filters and query to visualize #19172

Merged
merged 25 commits into from
Jun 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
4725254
explicitly passing filters and query to visualize
ppisljar May 17, 2018
be448dd
updating dashboard to explicitly pass filters and query to visualize
ppisljar May 21, 2018
683d4bc
updating discovery to accept explicitly passed in query and filters
ppisljar May 21, 2018
697a03e
cleaning up and removing rootSearchSource and appSearchSource concepts
ppisljar May 21, 2018
bcc4c5b
extracting timefilter calculateBounds
ppisljar May 21, 2018
85b25fa
fixing saved searches to work with timerange
ppisljar May 21, 2018
a154ed0
fixing bugs
ppisljar May 22, 2018
a461d8e
using watch instead of rootscope event
ppisljar May 22, 2018
eed53ca
fixing visualizations with saved filters and queries
ppisljar May 22, 2018
7644411
fixes console.log messages
ppisljar May 22, 2018
731e1e8
updating based on Tim's review
ppisljar May 24, 2018
0f33739
create a new searchsource for time filter so dashboard filters do not…
ppisljar May 24, 2018
618836b
fixing shouldQuery to correctly work with new approach
ppisljar May 25, 2018
9ca930e
cleaning up
ppisljar Jun 4, 2018
611a43c
updating based on Spencer's feedback
ppisljar Jun 5, 2018
bd9e70a
removing editorMode from requestHandler
ppisljar Jun 5, 2018
18f6d36
ups, broke time fillter for search embeddable
ppisljar Jun 5, 2018
e79409b
fixing history
ppisljar Jun 5, 2018
ed38367
applying feedback from timroes
ppisljar Jun 7, 2018
b6800e7
merging with master
ppisljar Jun 8, 2018
3a7fe8c
fixing issues tim found
ppisljar Jun 8, 2018
c8822cd
does this fix all the weird issues ?
ppisljar Jun 8, 2018
c6db1fe
last suggestion by tim
ppisljar Jun 8, 2018
0388f37
removing unnecesarry async
ppisljar Jun 13, 2018
1e9ebfe
adding documentation
ppisljar Jun 13, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/core_plugins/kibana/public/dashboard/actions/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ export const updateIsFullScreenMode = createAction('UPDATE_IS_FULL_SCREEN_MODE')
export const updateUseMargins = createAction('UPDATE_USE_MARGINS');
export const updateHidePanelTitles = createAction('HIDE_PANEL_TITLES');
export const updateTimeRange = createAction('UPDATE_TIME_RANGE');
export const updateFilters = createAction('UPDATE_FILTERS');
export const updateQuery = createAction('UPDATE_QUERY');
3 changes: 0 additions & 3 deletions src/core_plugins/kibana/public/dashboard/dashboard_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,6 @@ app.directive('dashboardApp', function ($injector) {

timefilter.enableAutoRefreshSelector();
timefilter.enableTimeRangeSelector();
dash.searchSource.highlightAll(true);
dash.searchSource.version(true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm concerned with these deletions

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its not needed for visualize and discovery sets this on its own searchsource, so we don't need it here in dashboard.

courier.setRootSearchSource(dash.searchSource);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With removing this, does the searchSource attached to dash still have any functionality at all? I think it's saved with the saved object, could we actually remove saving a searchSource altogether with a dashboard?

/cc @stacey-gammon

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think so... would be great to see it go. Can do in another PR though, imo. Or I can handle it too.


updateState();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import {
updateHidePanelTitles,
updateTimeRange,
clearStagedFilters,
updateFilters,
updateQuery,
} from './actions';
import { stateMonitorFactory } from 'ui/state_management/state_monitor_factory';
import { createPanelState } from './panel';
Expand All @@ -50,7 +52,9 @@ import {
getHidePanelTitles,
getStagedFilters,
getEmbeddables,
getEmbeddableMetadata
getEmbeddableMetadata,
getQuery,
getFilters,
} from '../selectors';

/**
Expand Down Expand Up @@ -196,6 +200,17 @@ export class DashboardStateManager {
if (getDescription(state) !== this.getDescription()) {
store.dispatch(updateDescription(this.getDescription()));
}

if (!_.isEqual(
FilterUtils.cleanFiltersForComparison(this.appState.filters),
FilterUtils.cleanFiltersForComparison(getFilters(state))
)) {
store.dispatch(updateFilters(this.appState.filters));
}

if (getQuery(state) !== this.getQuery()) {
store.dispatch(updateQuery(this.getQuery()));
}
}

_handleStoreChanges() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ DashboardPanel.propTypes = {
]),
destroy: PropTypes.func.isRequired,
containerState: PropTypes.shape({
timeRange: PropTypes.object.isRequired,
timeRange: PropTypes.object,
filters: PropTypes.array,
query: PropTypes.object,
embeddableCustomization: PropTypes.object,
hidePanelTitles: PropTypes.bool.isRequired,
}),
Expand Down
12 changes: 12 additions & 0 deletions src/core_plugins/kibana/public/dashboard/reducers/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import {
updateHidePanelTitles,
updateIsFullScreenMode,
updateTimeRange,
updateFilters,
updateQuery,
setVisibleContextMenuPanelId,
} from '../actions';

Expand All @@ -47,6 +49,16 @@ export const view = handleActions({
timeRange: payload
}),

[updateFilters]: (state, { payload }) => ({
...state,
filters: payload
}),

[updateQuery]: (state, { payload }) => ({
...state,
query: payload
}),

[updateUseMargins]: (state, { payload }) => ({
...state,
useMargins: payload
Expand Down
6 changes: 6 additions & 0 deletions src/core_plugins/kibana/public/dashboard/selectors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ export const getMaximizedPanelId = dashboard => dashboard.view.maximizedPanelId;
*/
export const getTimeRange = dashboard => dashboard.view.timeRange;

export const getFilters = dashboard => dashboard.view.filters;

export const getQuery = dashboard => dashboard.view.query;

/**
* @typedef {Object} DashboardMetadata
* @property {string} title
Expand Down Expand Up @@ -205,6 +209,8 @@ export const getContainerState = (dashboard, panelId) => {
to: time.to,
from: time.from,
},
filters: getFilters(dashboard),
query: getQuery(dashboard),
embeddableCustomization: _.cloneDeep(getEmbeddableCustomization(dashboard, panelId) || {}),
hidePanelTitles: getHidePanelTitles(dashboard),
customTitle: getPanel(dashboard, panelId).title,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,15 @@ function discoverController(
.highlightAll(true)
.version(true);

// searchSource which applies time range
const timeRangeSearchSource = savedSearch.searchSource.new();
timeRangeSearchSource.set('filter', () => {
return timefilter.get($scope.indexPattern);
});

$scope.searchSource.inherits(timeRangeSearchSource);


const pageTitleSuffix = savedSearch.id && savedSearch.title ? `: ${savedSearch.title}` : '';
docTitle.change(`Discover${pageTitleSuffix}`);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import angular from 'angular';
import { Embeddable } from 'ui/embeddable';
import searchTemplate from './search_template.html';
import * as columnActions from 'ui/doc_table/actions/columns';
import { getTime } from 'ui/timefilter/get_time';

export class SearchEmbeddable extends Embeddable {
constructor({ onEmbeddableStateChanged, savedSearch, editUrl, loader, $rootScope, $compile }) {
Expand Down Expand Up @@ -52,13 +53,20 @@ export class SearchEmbeddable extends Embeddable {
pushContainerStateParamsToScope() {
// If there is column or sort data on the panel, that means the original columns or sort settings have
// been overridden in a dashboard.

this.searchScope.columns = this.customization.columns || this.savedSearch.columns;
this.searchScope.sort = this.customization.sort || this.savedSearch.sort;
this.searchScope.sharedItemTitle = this.panelTitle;

this.filtersSearchSource.set('filter', this.filters);
this.filtersSearchSource.set('query', this.query);
}

onContainerStateChanged(containerState) {
this.customization = containerState.embeddableCustomization || {};
this.filters = containerState.filters;
this.query = containerState.query;
this.timeRange = containerState.timeRange;
this.panelTitle = '';
if (!containerState.hidePanelTitles) {
this.panelTitle = containerState.customTitle !== undefined ?
Expand All @@ -74,11 +82,21 @@ export class SearchEmbeddable extends Embeddable {
initializeSearchScope() {
this.searchScope = this.$rootScope.$new();

this.pushContainerStateParamsToScope();

this.searchScope.description = this.savedSearch.description;
this.searchScope.searchSource = this.savedSearch.searchSource;

const timeRangeSearchSource = this.searchScope.searchSource.new();
timeRangeSearchSource.filter(() => {
return getTime(this.searchScope.searchSource.get('index'), this.timeRange);
});

this.filtersSearchSource = this.searchScope.searchSource.new();
this.filtersSearchSource.inherits(timeRangeSearchSource);

this.searchScope.searchSource.inherits(this.filtersSearchSource);

this.pushContainerStateParamsToScope();

this.searchScope.setSortOrder = (columnName, direction) => {
this.searchScope.sort = this.customization.sort = [columnName, direction];
this.emitEmbeddableStateChange(this.getEmbeddableState());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module.factory('SavedSearch', function (courier) {
hits: 0,
sort: [],
version: 1
}
},
});

this.showInRecenltyAccessed = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ export const getMaximizedPanelId = state => DashboardSelectors.getMaximizedPanel
export const getUseMargins = state => DashboardSelectors.getUseMargins(getDashboard(state));
export const getHidePanelTitles = state => DashboardSelectors.getHidePanelTitles(getDashboard(state));
export const getTimeRange = state => DashboardSelectors.getTimeRange(getDashboard(state));
export const getFilters = state => DashboardSelectors.getFilters(getDashboard(state));
export const getQuery = state => DashboardSelectors.getQuery(getDashboard(state));

export const getTitle = state => DashboardSelectors.getTitle(getDashboard(state));
export const getDescription = state => DashboardSelectors.getDescription(getDashboard(state));
3 changes: 1 addition & 2 deletions src/core_plugins/kibana/public/visualize/editor/editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,9 @@
<visualize
saved-obj="savedVis"
ui-state="uiState"
app-state="state"
time-range="timeRange"
editor-mode="chrome.getVisible()"
show-spy-panel="chrome.getVisible()"
time-range="timeRange"
>

</visualize>
Expand Down
4 changes: 3 additions & 1 deletion src/core_plugins/kibana/public/visualize/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,14 @@ function VisEditor($scope, $route, timefilter, AppState, $window, kbnUrl, courie

// update the searchSource when filters update
$scope.$listen(queryFilter, 'update', function () {
$state.save();
$scope.fetch();
});

// update the searchSource when query updates
$scope.fetch = function () {
$state.save();
savedVis.searchSource.set('query', $state.query);
savedVis.searchSource.set('filter', $state.filters);
$scope.vis.forceReload();
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,18 @@ export class VisualizeEmbeddable extends Embeddable {
this.timeRange = containerState.timeRange;
}

// Check if filters has changed
if (containerState.filters !== this.filters) {
updatedParams.filters = containerState.filters;
this.filters = containerState.filters;
}

// Check if query has changed
if (containerState.query !== this.query) {
updatedParams.query = containerState.query;
this.query = containerState.query;
}

const derivedPanelTitle = this.getPanelTitle(containerState);
if (this.panelTitle !== derivedPanelTitle) {
updatedParams.dataAttrs = {
Expand All @@ -119,6 +131,8 @@ export class VisualizeEmbeddable extends Embeddable {
render(domNode, containerState) {
this.panelTitle = this.getPanelTitle(containerState);
this.timeRange = containerState.timeRange;
this.query = containerState.query;
this.filters = containerState.filters;

this.transferCustomizationsToUiState(containerState);

Expand All @@ -127,6 +141,8 @@ export class VisualizeEmbeddable extends Embeddable {
// Append visualization to container instead of replacing its content
append: true,
timeRange: containerState.timeRange,
query: containerState.query,
filters: containerState.filters,
cssClass: `panel-content panel-content--fullWidth`,
// The chrome is permanently hidden in "embed mode" in which case we don't want to show the spy pane, since
// we deem that situation to be more public facing and want to hide more detailed information.
Expand Down
4 changes: 0 additions & 4 deletions src/ui/public/courier/courier.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import { SearchSourceProvider } from './data_source/search_source';
import { requestQueue } from './_request_queue';
import { FetchSoonProvider } from './fetch';
import { SearchLooperProvider } from './looper/search';
import { RootSearchSourceProvider } from './data_source/_root_search_source';
import { SavedObjectProvider } from './saved_object';
import { RedirectWhenMissingProvider } from './_redirect_when_missing';

Expand All @@ -42,9 +41,6 @@ uiModules.get('kibana/courier')
const fetchSoon = Private(FetchSoonProvider);
const searchLooper = self.searchLooper = Private(SearchLooperProvider);

// expose some internal modules
self.setRootSearchSource = Private(RootSearchSourceProvider).set;

self.SavedObject = Private(SavedObjectProvider);
self.indexPatterns = indexPatterns;
self.redirectWhenMissing = Private(RedirectWhenMissingProvider);
Expand Down
89 changes: 0 additions & 89 deletions src/ui/public/courier/data_source/_root_search_source.js

This file was deleted.

Loading