-
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
[7.6.1] [Lens] Fix bugs in Lens filters (#56441) #56648
Changes from 6 commits
b8c7cc4
7af76da
1659294
c2f0725
2d7eef3
7011360
4fff8e8
4880d6b
71144c6
b6f5d4e
3772ea1
19bd60a
7870e5b
424a8b6
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 |
---|---|---|
|
@@ -39,7 +39,6 @@ interface State { | |
toDate: string; | ||
}; | ||
query: Query; | ||
filters: esFilters.Filter[]; | ||
savedQuery?: SavedQuery; | ||
} | ||
|
||
|
@@ -76,16 +75,22 @@ export function App({ | |
fromDate: currentRange.from, | ||
toDate: currentRange.to, | ||
}, | ||
filters: [], | ||
}; | ||
}); | ||
|
||
const { lastKnownDoc } = state; | ||
|
||
useEffect(() => { | ||
// Clear app-specific filters when navigating to Lens. Necessary because Lens | ||
// can be loaded without a full page refresh, using the same singleton | ||
if (data.query.filterManager.getAppFilters().length) { | ||
data.query.filterManager.setFilters(data.query.filterManager.getGlobalFilters()); | ||
} | ||
|
||
const filterSubscription = data.query.filterManager.getUpdates$().subscribe({ | ||
next: () => { | ||
setState(s => ({ ...s, filters: data.query.filterManager.getFilters() })); | ||
// Trigger a re-render, since filters are no longer tracked on state | ||
setState(s => ({ ...s })); | ||
trackUiEvent('app_filters_updated'); | ||
}, | ||
}); | ||
|
@@ -123,13 +128,23 @@ export function App({ | |
core.notifications | ||
) | ||
.then(indexPatterns => { | ||
// Keep any pinned filters and set app filters from doc | ||
data.query.filterManager.setFilters( | ||
data.query.filterManager | ||
.getGlobalFilters() | ||
.concat( | ||
(doc.state.filters || []).filter( | ||
filter => filter.$state?.store === esFilters.FilterStateStore.APP_STATE | ||
) | ||
) | ||
); | ||
|
||
setState(s => ({ | ||
...s, | ||
isLoading: false, | ||
persistedDoc: doc, | ||
lastKnownDoc: doc, | ||
query: doc.state.query, | ||
filters: doc.state.filters, | ||
indexPatternsForTopNav: indexPatterns, | ||
})); | ||
}) | ||
|
@@ -239,7 +254,7 @@ export function App({ | |
setState(s => ({ ...s, savedQuery })); | ||
}} | ||
onSavedQueryUpdated={savedQuery => { | ||
data.query.filterManager.setFilters(savedQuery.attributes.filters || state.filters); | ||
data.query.filterManager.setFilters(savedQuery.attributes.filters || []); | ||
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. Great as a fix for 7.6.1, but consider using #56160 for 7.7 to avoid similar issues 🙏 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 fix using that code is already in 7.7, but I couldn't backport it to 7.6 |
||
setState(s => ({ | ||
...s, | ||
savedQuery: { ...savedQuery }, // Shallow query for reference issues | ||
|
@@ -256,7 +271,6 @@ export function App({ | |
setState(s => ({ | ||
...s, | ||
savedQuery: undefined, | ||
filters: [], | ||
query: { | ||
query: '', | ||
language: | ||
|
@@ -278,7 +292,7 @@ export function App({ | |
nativeProps={{ | ||
dateRange: state.dateRange, | ||
query: state.query, | ||
filters: state.filters, | ||
filters: data.query.filterManager.getFilters(), | ||
savedQuery: state.savedQuery, | ||
doc: state.persistedDoc, | ||
onError, | ||
|
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.
Nitpick: Not sure if it's valuable (treat this comment as learning opportunity for me :D ) but in the query tests below we construct filters using setting Filter Store:
while here you construct the filter object. Maybe it's worth to unify it?
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 looked into this a bit more and specifically the
exists
filter has a different type definition than the other types. This is definitely worth highlighting to so I'm building the filters manually!