-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[Visualize] Make linked saved search work when user navigates back using browser back button #59690
Changes from 2 commits
c8f3527
bdc2e4a
05a4eee
85e40c0
b45bd07
75e3d32
d1ebdad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,7 +115,8 @@ function VisualizeAppController( | |
savedVis.vis.on('apply', _applyVis); | ||
// vis is instance of src/legacy/ui/public/vis/vis.js. | ||
// SearchSource is a promise-based stream of search results that can inherit from other search sources. | ||
const { vis, searchSource } = savedVis; | ||
const { vis, searchSource, savedSearchId } = savedVis; | ||
const searchSourceParent = searchSource.getParent(); | ||
|
||
$scope.vis = vis; | ||
|
||
|
@@ -379,6 +380,18 @@ function VisualizeAppController( | |
}, | ||
}; | ||
|
||
const handleLinkedSearch = linked => { | ||
if (linked && !savedVis.savedSearchId) { | ||
savedVis.savedSearchId = savedSearchId; | ||
vis.savedSearchId = savedSearchId; | ||
|
||
searchSource.setParent(searchSourceParent); | ||
} else if (!linked && savedVis.savedSearchId) { | ||
delete savedVis.savedSearchId; | ||
delete vis.savedSearchId; | ||
} | ||
}; | ||
|
||
// Create a PersistedState instance for uiState. | ||
const { persistedState, unsubscribePersisted, persistOnChange } = makeStateful( | ||
'uiState', | ||
|
@@ -387,9 +400,9 @@ function VisualizeAppController( | |
$scope.uiState = persistedState; | ||
$scope.savedVis = savedVis; | ||
$scope.query = initialState.query; | ||
$scope.linked = initialState.linked; | ||
$scope.searchSource = searchSource; | ||
$scope.refreshInterval = timefilter.getRefreshInterval(); | ||
handleLinkedSearch(initialState.linked); | ||
|
||
const addToDashMode = | ||
$route.current.params[DashboardConstants.ADD_VISUALIZATION_TO_DASHBOARD_MODE_PARAM]; | ||
|
@@ -468,7 +481,7 @@ function VisualizeAppController( | |
$scope.fetch = function() { | ||
const { query, linked, filters } = stateContainer.getState(); | ||
$scope.query = query; | ||
$scope.linked = linked; | ||
handleLinkedSearch(linked); | ||
savedVis.searchSource.setField('query', query); | ||
savedVis.searchSource.setField('filter', filters); | ||
$scope.$broadcast('render'); | ||
|
@@ -558,20 +571,6 @@ function VisualizeAppController( | |
updateStateFromSavedQuery(savedQuery); | ||
}; | ||
|
||
$scope.$watch('linked', linked => { | ||
if (linked && !savedVis.savedSearchId) { | ||
savedVis.savedSearchId = savedVis.searchSource.id; | ||
vis.savedSearchId = savedVis.searchSource.id; | ||
|
||
$scope.$broadcast('render'); | ||
} else if (!linked && savedVis.savedSearchId) { | ||
delete savedVis.savedSearchId; | ||
delete vis.savedSearchId; | ||
|
||
$scope.$broadcast('render'); | ||
} | ||
}); | ||
|
||
/** | ||
* Called when the user clicks "Save" button. | ||
*/ | ||
|
@@ -663,23 +662,21 @@ function VisualizeAppController( | |
} | ||
|
||
const unlinkFromSavedSearch = () => { | ||
const searchSourceParent = searchSource.getParent(); | ||
const searchSourceGrandparent = searchSourceParent.getParent(); | ||
if (!searchSourceParent) { | ||
return; | ||
} | ||
|
||
delete savedVis.savedSearchId; | ||
delete vis.savedSearchId; | ||
searchSourceParent.setField( | ||
'filter', | ||
_.union(searchSource.getOwnField('filter'), searchSourceParent.getOwnField('filter')) | ||
); | ||
const searchSourceGrandparent = searchSourceParent.getParent(); | ||
const currentIndex = searchSourceParent.getField('index'); | ||
|
||
stateContainer.transitions.unlinkSavedSearch( | ||
searchSourceParent.getField('query'), | ||
searchSourceParent.getField('filter') | ||
); | ||
searchSource.setField('index', searchSourceParent.getField('index')); | ||
searchSource.setField('index', currentIndex); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm still not sure, whether we should inherit the index of the parent source while unlinking, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if you create visualization based on saved search, then searchsource won't have index field, but the parent will. |
||
searchSource.setParent(searchSourceGrandparent); | ||
|
||
stateContainer.transitions.unlinkSavedSearch({ | ||
query: searchSourceParent.getField('query'), | ||
parentFilters: searchSourceParent.getOwnField('filter'), | ||
}); | ||
|
||
toastNotifications.addSuccess( | ||
i18n.translate('kbn.visualize.linkedToSearch.unlinkSuccessNotificationText', { | ||
defaultMessage: `Unlinked from saved search '{searchTitle}'`, | ||
|
@@ -688,8 +685,6 @@ function VisualizeAppController( | |
}, | ||
}) | ||
); | ||
|
||
$scope.fetch(); | ||
}; | ||
|
||
$scope.getAdditionalMessage = () => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this confuses me ... you desctructure
savedSearchId
fromsavedVis
... so this logic is actually:also i am not sure why we need to duplicate information on
vis.savedSearchId
, which is also violating the types (vis has no savedSearchId property)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think once you unlink, all we need is to delete savedVis.savedSearchId (for the sake of saved object) and remove the parent search source (for the sake of current view)
and when linking back, you will need to select the saved search, so you get the new savedSearchId and you can set it on savedVis
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ps: i am working on a small refactor to vis saved object and vis state, which will allow to further clean this up: you will no longer need to care about savedVis here, all you will need to do is remove parent search source and we will provide utilities to serialize searchSource + vis into the saved vis object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @ppisljar , thanks for taking a look and reasonable comments here!
PR updated!
About storing the
vis.savedSearchId
, I'm not sure why, but it's presented in thevis
object on creation of a visualization based on saved search:so would be great if you could get rid of it in your refactoring pr.