-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Lens] Integrate searchSessionId into Lens app #86297
Changes from 2 commits
596ebe4
0d389aa
928687b
daa92c3
bcb83c9
a1a4296
1e4f18a
42e15d1
19a3bac
1614dc1
c35e4c0
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 |
---|---|---|
|
@@ -89,6 +89,7 @@ export function App({ | |
isSaveModalVisible: false, | ||
indicateNoData: false, | ||
isSaveable: false, | ||
searchSessionId: data.search.session.start(), | ||
}; | ||
}); | ||
|
||
|
@@ -160,7 +161,11 @@ export function App({ | |
|
||
const filterSubscription = data.query.filterManager.getUpdates$().subscribe({ | ||
next: () => { | ||
setState((s) => ({ ...s, filters: data.query.filterManager.getFilters() })); | ||
setState((s) => ({ | ||
...s, | ||
filters: data.query.filterManager.getFilters(), | ||
searchSessionId: data.search.session.start(), | ||
})); | ||
trackUiEvent('app_filters_updated'); | ||
}, | ||
}); | ||
|
@@ -174,6 +179,7 @@ export function App({ | |
fromDate: currentRange.from, | ||
toDate: currentRange.to, | ||
}, | ||
searchSessionId: data.search.session.start(), | ||
})); | ||
}, | ||
}); | ||
|
@@ -196,6 +202,7 @@ export function App({ | |
}, [ | ||
data.query.filterManager, | ||
data.query.timefilter.timefilter, | ||
data.search.session, | ||
notifications.toasts, | ||
uiSettings, | ||
data.query, | ||
|
@@ -205,6 +212,8 @@ export function App({ | |
|
||
useEffect(() => { | ||
onAppLeave((actions) => { | ||
// Clear the session when leaving Lens | ||
data.search.session.clear(); | ||
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. We definitely should not be adding side effects to the What this means is that I don't think we have a reliable way to make a side effect happen as the user is leaving, and I don't think we should be adding any side effects to the 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. Good point, I guess we can put it in an unmount handler (e.g. useUnmount() ) 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. Did some investigation on this area:
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. Discussed with @flash1293 and found a simpler solution to that |
||
// Confirm when the user has made any changes to an existing doc | ||
// or when the user has configured something without saving | ||
if ( | ||
|
@@ -231,6 +240,7 @@ export function App({ | |
state.persistedDoc, | ||
getLastKnownDocWithoutPinnedFilters, | ||
application.capabilities.visualize.save, | ||
data.search.session, | ||
]); | ||
|
||
// Sync Kibana breadcrumbs any time the saved document's title changes | ||
|
@@ -428,13 +438,15 @@ export function App({ | |
if (saveProps.returnToOrigin && redirectToOrigin) { | ||
// disabling the validation on app leave because the document has been saved. | ||
onAppLeave((actions) => { | ||
data.search.session.clear(); | ||
return actions.default(); | ||
}); | ||
redirectToOrigin({ input: newInput, isCopied: saveProps.newCopyOnSave }); | ||
return; | ||
} else if (saveProps.dashboardId && redirectToDashboard) { | ||
// disabling the validation on app leave because the document has been saved. | ||
onAppLeave((actions) => { | ||
data.search.session.clear(); | ||
return actions.default(); | ||
}); | ||
redirectToDashboard(newInput, saveProps.dashboardId); | ||
|
@@ -541,6 +553,7 @@ export function App({ | |
if (savingPermitted && lastKnownDoc) { | ||
// disabling the validation on app leave because the document has been saved. | ||
onAppLeave((actions) => { | ||
data.search.session.clear(); | ||
return actions.default(); | ||
}); | ||
runSave( | ||
|
@@ -601,14 +614,16 @@ export function App({ | |
data.query.timefilter.timefilter.setTime(dateRange); | ||
trackUiEvent('app_date_change'); | ||
} else { | ||
// Query has changed, renew the session id. | ||
// Time change will be picked up by the time subscription | ||
setState((s) => ({ | ||
...s, | ||
searchSessionId: data.search.session.start(), | ||
})); | ||
trackUiEvent('app_query_change'); | ||
} | ||
setState((s) => ({ | ||
...s, | ||
dateRange: { | ||
fromDate: dateRange.from, | ||
toDate: dateRange.to, | ||
}, | ||
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. So we're using the 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. The code was already using the We still need the |
||
query: query || s.query, | ||
})); | ||
}} | ||
|
@@ -650,6 +665,7 @@ export function App({ | |
className="lnsApp__frame" | ||
render={editorFrame.mount} | ||
nativeProps={{ | ||
searchSessionId: state.searchSessionId, | ||
dateRange: state.dateRange, | ||
query: state.query, | ||
filters: state.filters, | ||
|
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.
Can you remove
dateRange
from theLensAppState
now?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.
Moved the
dateRange
out of state in the last commit. An object reference needs to be still hold for theframe
component, but there's a single source of truth now for it.