Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 0 additions & 7 deletions src/ui/public/vis/__tests__/_vis.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,6 @@ describe('Vis Class', function () {
});
});

describe('clone()', function () {
it('should make clone of itself', function () {
const clone = vis.clone();
verifyVis(clone);
});
});

describe('setState()', function () {
it('should set the state to defualts', function () {
const vis = new Vis(indexPattern);
Expand Down
24 changes: 8 additions & 16 deletions src/ui/public/vis/vis.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function VisProvider(Private, Promise, indexPatterns, timefilter, getAppS
const filterManager = Private(FilterManagerProvider);

class Vis extends EventEmitter {
constructor(indexPattern, visState, uiState) {
constructor(indexPattern, visState) {
super();
visState = visState || {};

Expand All @@ -44,14 +44,9 @@ export function VisProvider(Private, Promise, indexPatterns, timefilter, getAppS
};
}
this.indexPattern = indexPattern;

if (!uiState) {
uiState = new PersistedState();
}

this._setUiState(new PersistedState());
this.setCurrentState(visState);
this.setState(this.getCurrentState(), false);
this.setUiState(uiState);

// Session state is for storing information that is transitory, and will not be saved with the visualization.
// For instance, map bounds, which depends on the view port, browser window size, etc.
Expand Down Expand Up @@ -156,14 +151,6 @@ export function VisProvider(Private, Promise, indexPatterns, timefilter, getAppS
return this.getStateInternal(true);
}

clone() {
const uiJson = this.hasUiState() ? this.getUiState().toJSON() : {};
const uiState = new PersistedState(uiJson);
const clonedVis = new Vis(this.indexPattern, this.getState(), uiState);
clonedVis.editorMode = this.editorMode;
return clonedVis;
}

/**
* Hook for pre-flight logic, see AggType#onSearchRequestStart()
* @param {Courier.SearchSource} searchSource
Expand Down Expand Up @@ -197,7 +184,12 @@ export function VisProvider(Private, Promise, indexPatterns, timefilter, getAppS
return !!this.__uiState;
}

setUiState(uiState) {
/***
* this should not be used outside of visualize
* @param uiState
* @private
*/
_setUiState(uiState) {
if (uiState instanceof PersistedState) {
this.__uiState = uiState;
}
Expand Down
14 changes: 4 additions & 10 deletions src/ui/public/visualize/visualization.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { uiModules } from 'ui/modules';
import { ResizeCheckerProvider } from 'ui/resize_checker';
import visualizationTemplate from 'ui/visualize/visualization.html';
import { getUpdateStatus } from 'ui/vis/update_status';
import { PersistedState } from 'ui/persisted_state';
import 'angular-sanitize';

uiModules
Expand Down Expand Up @@ -34,15 +33,10 @@ uiModules

$scope.addLegend = false;

// Set the passed in uiState to the vis object, so we don't require any
// users of the <visualization/> directive to manually set the uiState.
if (!$scope.uiState) $scope.uiState = new PersistedState({});
$scope.vis.setUiState($scope.uiState);
// Whenever the uiState changed, that the visualization should use,
// attach it to the actual Vis class.
$scope.$watch('uiState', (uiState) => {
$scope.vis.setUiState(uiState);
});
// Set the passed in uiState to the vis object. uiState reference should never be changed
if (!$scope.uiState) $scope.uiState = $scope.vis.getUiState();
else $scope.vis._setUiState($scope.uiState);


// Show no results message when isZeroHits is true and it requires search
$scope.showNoResultsMessage = function () {
Expand Down
7 changes: 5 additions & 2 deletions src/ui/public/visualize/visualize.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import 'angular-sanitize';
import './visualization';
import './visualization_editor';
import { FilterBarQueryFilterProvider } from 'ui/filter_bar/query_filter';
import { PersistedState } from 'ui/persisted_state';


import {
Expand Down Expand Up @@ -48,9 +47,13 @@ uiModules

if (!$scope.savedObj) throw(`saved object was not provided to <visualize> directive`);
if (!$scope.appState) $scope.appState = getAppState();
if (!$scope.uiState) $scope.uiState = new PersistedState({});

$scope.vis = $scope.savedObj.vis;

// Set the passed in uiState to the vis object. uiState reference should never be changed
if (!$scope.uiState) $scope.uiState = $scope.vis.getUiState();
else $scope.vis._setUiState($scope.uiState);

$scope.vis.visualizeScope = true;
$scope.vis.description = $scope.savedObj.description;

Expand Down