Skip to content
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 from slice to reducers/actions and simplify loading #113324

Merged

Conversation

mbondyra
Copy link
Contributor

@mbondyra mbondyra commented Sep 28, 2021

Summary

Fixes #113218 - it was caused by not creating the new searchSession on start.

  • Instead of using redux-toolkit slice, I converted it to actions + reducers. The reason for this change was to be able to create reducer maker that would get the access to passed datasourceMap & visualizationMap.
  • Initialization invokes only one single action that is an effect of combining few
  • I've merged into one reducer switchVisualization and selectSuggestion, as they are almost the same.
  • I updated some tests and mocks. I tried to make them a bit better by:
    • Not testing just middleware but the whole path from mounting the store to checking the state. It’s still not ideal, but better
    • Unifying the mocked components we use in all places

@mbondyra mbondyra added auto-backport Deprecated - use backport:version if exact versions are needed Feature:Lens release_note:skip Skip the PR/issue when compiling release notes Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.16.0 v8.0.0 labels Sep 28, 2021
@mbondyra mbondyra force-pushed the lens/change_structure_simplify_loading branch 2 times, most recently from 1df0b6d to 2750888 Compare September 30, 2021 16:10
initEmpty({
newState: {
...emptyState,
searchSessionId: currentSessionId || data.search.session.start(),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is what fixes the mentioned bug - somehow it was lost in the previous PRs and undefined searchSessionId caused infinite loop of requesting for data.

expect(deps.lensServices.attributeService.unwrapAttributes).not.toHaveBeenCalled();
});

it('starts new searchSessionId', async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the new test that tests the bug this PR fixes. The rest is refactored to test the whole path from invoking loadInitial (we do it in mounter) to run through middleware and reducer (before it was only checking middleware in separation)

import moment from 'moment';
import { initialState } from './lens_slice';
import { LensAppState } from './types';
import { PayloadAction } from '@reduxjs/toolkit';

const sessionIdSubject = new Subject<string>();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all these lines are now being shared from mocks file.

@elastic elastic deleted a comment from kibanamachine Sep 30, 2021
@mbondyra mbondyra marked this pull request as ready for review September 30, 2021 16:16
@mbondyra mbondyra requested a review from a team as a code owner September 30, 2021 16:16
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-vis-editors (Team:VisEditors)

@mbondyra mbondyra force-pushed the lens/change_structure_simplify_loading branch from 2750888 to 448cc01 Compare September 30, 2021 19:57
@mbondyra mbondyra force-pushed the lens/change_structure_simplify_loading branch from 448cc01 to 9cb6f34 Compare October 1, 2021 08:08
Copy link
Contributor

@dej611 dej611 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review, left a couple fo comments.

const suggestions = getSuggestions({
datasourceMap,
datasourceStates,
visualizationMap,
activeVisualization,
visualizationState,
activeVisualization: visualizationMap?.[Object.keys(visualizationMap)[0]] || null,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate?

@@ -94,7 +100,7 @@ describe('Lens App', () => {

async function mountWith({
props = makeDefaultProps(),
services = makeDefaultServices(sessionIdSubject),
services = makeDefaultServices(sessionIdSubject, 'sessionId-1'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be a constant on top?

@mbondyra
Copy link
Contributor Author

mbondyra commented Oct 4, 2021

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
lens 1.0MB 1.0MB +1.1KB
Unknown metric groups

References to deprecated APIs

id before after diff
lens 248 246 -2

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

Copy link
Contributor

@dej611 dej611 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally in Chrome 👍

@mbondyra mbondyra merged commit 6bfa2a4 into elastic:master Oct 4, 2021
@mbondyra mbondyra deleted the lens/change_structure_simplify_loading branch October 4, 2021 11:32
kibanamachine added a commit to kibanamachine/kibana that referenced this pull request Oct 4, 2021
…tic#113324)

* structure changes

* tests & fix for sessionId

* share mocks in time_range_middleware

* make switchVisualization and selectSuggestion one reducer as it's very similar

* CR

Co-authored-by: Kibana Machine <[email protected]>
@kibanamachine
Copy link
Contributor

💚 Backport successful

Status Branch Result
7.x

This backport PR will be merged automatically after passing CI.

kibanamachine added a commit that referenced this pull request Oct 4, 2021
) (#113740)

* structure changes

* tests & fix for sessionId

* share mocks in time_range_middleware

* make switchVisualization and selectSuggestion one reducer as it's very similar

* CR

Co-authored-by: Kibana Machine <[email protected]>

Co-authored-by: Marta Bondyra <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Deprecated - use backport:version if exact versions are needed Feature:Lens release_note:skip Skip the PR/issue when compiling release notes Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.16.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Lens] Infinite requests on visualizations with indices with many documents
4 participants