[Lens] Move dataViews cache into main Lens state#137309
[Lens] Move dataViews cache into main Lens state#137309stratoula merged 32 commits intoelastic:mainfrom
Conversation
| indexPatternId: dataView.id, | ||
| setDatasourceState, | ||
| }); | ||
| dispatchChangeIndexPattern(dataView.id); |
There was a problem hiding this comment.
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.
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.
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.
mbondyra
left a comment
There was a problem hiding this comment.
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) |
| seriesType: firstUsedSeriesType || state.preferredSeriesType, | ||
| layerId, | ||
| layerType, | ||
| indexPatternId: indexPatternId ?? core.uiSettings.get('defaultIndex'), |
There was a problem hiding this comment.
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.
flash1293
left a comment
There was a problem hiding this comment.
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
flash1293
left a comment
There was a problem hiding this comment.
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
indexPatternsdatasource, 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
dataViewslens 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
datasourceare 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
indexPatternServiceas this is used also outside of theframeand it was easier to manage two variables rather than duplicate all the code for the TopNav + EditorFrame + Embeddable .IndexPatternServiceAPIChecklist
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