-
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 all 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 |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
import './app.scss'; | ||
|
||
import _ from 'lodash'; | ||
import React, { useState, useEffect, useCallback } from 'react'; | ||
import React, { useState, useEffect, useCallback, useMemo } from 'react'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { NotificationsStart } from 'kibana/public'; | ||
import { EuiBreadcrumb } from '@elastic/eui'; | ||
|
@@ -71,7 +71,6 @@ export function App({ | |
} = useKibana<LensAppServices>().services; | ||
|
||
const [state, setState] = useState<LensAppState>(() => { | ||
const currentRange = data.query.timefilter.timefilter.getTime(); | ||
return { | ||
query: data.query.queryString.getQuery(), | ||
// Do not use app-specific filters from previous app, | ||
|
@@ -81,14 +80,11 @@ export function App({ | |
: data.query.filterManager.getFilters(), | ||
isLoading: Boolean(initialInput), | ||
indexPatternsForTopNav: [], | ||
dateRange: { | ||
fromDate: currentRange.from, | ||
toDate: currentRange.to, | ||
}, | ||
isLinkedToOriginatingApp: Boolean(incomingState?.originatingApp), | ||
isSaveModalVisible: false, | ||
indicateNoData: false, | ||
isSaveable: false, | ||
searchSessionId: data.search.session.start(), | ||
}; | ||
}); | ||
|
||
|
@@ -107,10 +103,14 @@ export function App({ | |
state.indicateNoData, | ||
state.query, | ||
state.filters, | ||
state.dateRange, | ||
state.indexPatternsForTopNav, | ||
state.searchSessionId, | ||
]); | ||
|
||
// Need a stable reference for the frame component of the dateRange | ||
const { from: fromDate, to: toDate } = data.query.timefilter.timefilter.getTime(); | ||
const currentDateRange = useMemo(() => ({ fromDate, toDate }), [fromDate, toDate]); | ||
|
||
const onError = useCallback( | ||
(e: { message: string }) => | ||
notifications.toasts.addDanger({ | ||
|
@@ -160,24 +160,35 @@ 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'); | ||
}, | ||
}); | ||
|
||
const timeSubscription = data.query.timefilter.timefilter.getTimeUpdate$().subscribe({ | ||
next: () => { | ||
const currentRange = data.query.timefilter.timefilter.getTime(); | ||
setState((s) => ({ | ||
...s, | ||
dateRange: { | ||
fromDate: currentRange.from, | ||
toDate: currentRange.to, | ||
}, | ||
searchSessionId: data.search.session.start(), | ||
})); | ||
}, | ||
}); | ||
|
||
const autoRefreshSubscription = data.query.timefilter.timefilter | ||
.getAutoRefreshFetch$() | ||
.subscribe({ | ||
next: () => { | ||
setState((s) => ({ | ||
...s, | ||
searchSessionId: data.search.session.start(), | ||
})); | ||
}, | ||
}); | ||
|
||
const kbnUrlStateStorage = createKbnUrlStateStorage({ | ||
history, | ||
useHash: uiSettings.get('state:storeInSessionStorage'), | ||
|
@@ -192,10 +203,12 @@ export function App({ | |
stopSyncingQueryServiceStateWithUrl(); | ||
filterSubscription.unsubscribe(); | ||
timeSubscription.unsubscribe(); | ||
autoRefreshSubscription.unsubscribe(); | ||
}; | ||
}, [ | ||
data.query.filterManager, | ||
data.query.timefilter.timefilter, | ||
data.search.session, | ||
notifications.toasts, | ||
uiSettings, | ||
data.query, | ||
|
@@ -594,21 +607,21 @@ export function App({ | |
appName={'lens'} | ||
onQuerySubmit={(payload) => { | ||
const { dateRange, query } = payload; | ||
if ( | ||
dateRange.from !== state.dateRange.fromDate || | ||
dateRange.to !== state.dateRange.toDate | ||
) { | ||
const currentRange = data.query.timefilter.timefilter.getTime(); | ||
if (dateRange.from !== currentRange.from || dateRange.to !== currentRange.to) { | ||
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, | ||
})); | ||
}} | ||
|
@@ -622,12 +635,6 @@ export function App({ | |
setState((s) => ({ | ||
...s, | ||
savedQuery: { ...savedQuery }, // Shallow query for reference issues | ||
dateRange: savedQuery.attributes.timefilter | ||
? { | ||
fromDate: savedQuery.attributes.timefilter.from, | ||
toDate: savedQuery.attributes.timefilter.to, | ||
} | ||
: s.dateRange, | ||
})); | ||
}} | ||
onClearSavedQuery={() => { | ||
|
@@ -640,8 +647,8 @@ export function App({ | |
})); | ||
}} | ||
query={state.query} | ||
dateRangeFrom={state.dateRange.fromDate} | ||
dateRangeTo={state.dateRange.toDate} | ||
dateRangeFrom={fromDate} | ||
dateRangeTo={toDate} | ||
indicateNoData={state.indicateNoData} | ||
/> | ||
</div> | ||
|
@@ -650,7 +657,8 @@ export function App({ | |
className="lnsApp__frame" | ||
render={editorFrame.mount} | ||
nativeProps={{ | ||
dateRange: state.dateRange, | ||
searchSessionId: state.searchSessionId, | ||
dateRange: currentDateRange, | ||
query: state.query, | ||
filters: state.filters, | ||
savedQuery: state.savedQuery, | ||
|
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.