-
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] Move dataViews cache into main Lens state #137309
Conversation
indexPatternId: dataView.id, | ||
setDatasourceState, | ||
}); | ||
dispatchChangeIndexPattern(dataView.id); |
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.
When a new data view is created from within Lens, the data panel crashes (seems like the new data view isn't added to the cache correctly?)
reportUnhandledError.js:10 Uncaught TypeError: Cannot read properties of undefined (reading 'fields')
at InnerIndexPatternDataPanel (datapanel.tsx:211:1)
at nh (react-dom.profiling.min.js:153:1)
at ii (react-dom.profiling.min.js:175:1)
at hi (react-dom.profiling.min.js:175:1)
at fi (react-dom.profiling.min.js:174:1)
at ek (react-dom.profiling.min.js:272:1)
at dk (react-dom.profiling.min.js:248:1)
at Xj (react-dom.profiling.min.js:247:1)
at Ij (react-dom.profiling.min.js:240:1)
at react-dom.profiling.min.js:122:1
InnerIndexPatternDataPanel @ datapanel
} | ||
) => { | ||
const { visualizationIds, datasourceIds, layerId, indexPatternId, dataViews } = payload; | ||
const newState: Partial<LensAppState> = { dataViews: { ...state.dataViews, ...dataViews } }; |
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 I realized this problem - on changing the index pattern, we don't update the list of index pattern refs, but if it has been created on the spot this is necessary. At this point we could make sure that the new index pattern is listed in the refs and add it if that's not the case.
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.
Right. I've added a loading check in the top nav change index pattern function to reload all refs in case the target id is missing in the refs cache.
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.
there's a small bug when switching data view for a layer, doesn't happen for all dimensions.
Aug-11-2022.13-26-53.mp4
@mbondyra the layer dataViews switch bug should have been addressed in the latest version |
Pinging @elastic/kibana-vis-editors @elastic/kibana-vis-editors-external (Team:VisEditors) |
@@ -126,6 +131,7 @@ export const getXyVisualization = ({ | |||
seriesType: firstUsedSeriesType || state.preferredSeriesType, | |||
layerId, | |||
layerType, | |||
indexPatternId: indexPatternId ?? core.uiSettings.get('defaultIndex'), |
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.
Seems like these bits are related to query based annotations. Does it make sense to keep them here? We definitely need to extract/inject these references and as it's not happening on this PRs it's probably better to split it out of this PR.
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.
In terms of the refactoring, this looks great, however it seems like there is a little leftover from the query based annotations that should probably be removed
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.
LGTM, tested and didn't find any problems.
Conflicts are due to the improved error handling, shouldn't be too difficult to resolve |
Conflicts should be solved now. |
💚 Build Succeeded
Metrics [docs]Module Count
Public APIs missing comments
Async chunks
Page load bundle
History
To update your PR or re-run it, just comment with: |
Retested and couldn't find anything not working! Amazing work! |
* Move lens dataViews state into main state * 🔥 Remove some old cruft from the code * 🐛 Fix dataViews layer change * 🐛 Fix datasourceLayers refs * 🔥 Remove more old cruft * 🐛 Fix bug when loading SO * 🐛 Fix initial existence flag * 🏷️ Fix type issues * 🏷️ Fix types and tests * 🏷️ Fix types issues * ✅ Fix more tests * ✅ Fix with new dataViews structure * ✅ Fix more test mocks * ✅ More tests fixed * 🔥 Removed unused prop * ✅ Down to single broken test suite * 🏷️ Fix type issue * 👌 Integrate selector feedback * ✅ Fix remaining unit tests * 🏷️ fix type issues * 🐛 Fix bug when creating dataview in place * 🐛 Fix edit + remove field flow * Update x-pack/plugins/lens/public/visualizations/xy/types.ts * 📸 Fix snapshot * 🐛 Fix the dataViews switch bug * 🔥 remove old cruft Co-authored-by: Joe Reuter <johannes.reuter@elastic.co>
Summary
This PR is a required step for #129299 and more future features in Lens.
The dataViews state was historically stored into the specific
indexPatterns
datasource, which was one of many potential datasources of the editor, but since Visualization starts to know more about it, it had to be lifted up to the editor main state to be reachable.A new
dataViews
lens inner group has been created in the main Lens state, which holds refs, dataViews cache, fields existence and potential errors states.Also the loading phase has been refactored to inspect directly the SO references to load only required dataViews (this sounds like a possible assumption as there is no hidden dataViews concept in Lens yet).
All the dataViews management method, which used to be stored into
datasource
are now stored within theindexPatternService
, which is a tiny API around few functions that can be shared across the Lens app hierarchy.The current state has not been stored into the
indexPatternService
as this is used also outside of theframe
and it was easier to manage two variables rather than duplicate all the code for the TopNav + EditorFrame + Embeddable .IndexPatternServiceAPI
Checklist
Delete any items that are not applicable to this PR.
Risk Matrix
Delete this section if it is not applicable to this PR.
Before closing this PR, invite QA, stakeholders, and other developers to identify risks that should be tested prior to the change/feature release.
When forming the risk matrix, consider some of the following examples and how they may potentially impact the change:
For maintainers