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

[Discover] Migrate angular context app controllers to react #100530

Merged
merged 53 commits into from
Jun 17, 2021

Conversation

dimaanj
Copy link
Contributor

@dimaanj dimaanj commented May 25, 2021

Part of #92573

Summary

  • Data fetching of context app migrated from angular to react
  • UI action handlers moved to react
  • Removed redundant angular controller logic, keept only router resolver
  • Now users can toggle columns using the doc viewer table
  • Changing filters, successor and predecessor count no longer reloads the URL (And with that there's no more memory leak caused by the query bar)

ContextAppContent renders 7 times initially

C5323534-F787-403C-9473-B9B1DF8D680A_1_105_c

DiscoverGrid/DocTable renders 4 times initially

1588213B-D489-436E-8DAE-5254131BF7AB_1_105_c

each ActionBar component renders 3 times initially

0D1C271A-FF3F-4158-AAB6-CAD4D4685C4B_1_105_c

Checklist

dimaanj and others added 22 commits May 3, 2021 10:55
…ts-migration

# Conflicts:
#	src/plugins/discover/public/application/angular/context/query_parameters/actions.test.ts
#	src/plugins/discover/public/application/components/context_error_message/context_error_message.test.tsx
#	src/plugins/discover/public/application/components/context_error_message/context_error_message.tsx
…ange sorting, highlight anchor doc, rename legacy variables
@dimaanj dimaanj added the Feature:Discover Discover Application label May 25, 2021
@dimaanj dimaanj requested a review from kertal May 25, 2021 07:52
@dimaanj dimaanj self-assigned this May 25, 2021
@dimaanj dimaanj force-pushed the migrate-angular-ctrls branch from 8ccd752 to 7f69c92 Compare May 28, 2021 11:47
@dimaanj
Copy link
Contributor Author

dimaanj commented May 28, 2021

@elasticmachine merge upstream

@dimaanj dimaanj added Feature:Discover Discover Application release_note:skip Skip the PR/issue when compiling release notes v7.14.0 v8.0.0 labels Jun 9, 2021
Copy link
Member

@kertal kertal left a comment

Choose a reason for hiding this comment

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

WIP review, currently trying to compare master vs this branch Kibana in terms of performance, now my computer is stuck, guess I need a new one ... so here are my first comments. So far congrats, it's a big improvement + step forward! One thing that I noticed is ContextApp and ContextAppContent are rendered 9 time initially, it's clear hat they have to bei re-rendered serveral time due to multiple serial data fetching operation, but there might be a potential to reduce renderings a bit e.g. ContextAppContent re-renders because the property row changes, but comparing new and old rows, content is the same.


useEffect(() => {
const unsubscribeAppState = stateContainer.appState.subscribe((newState) => {
stateContainer.flushToUrl(true);
Copy link
Member

Choose a reason for hiding this comment

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

isn't flushing to Url redundant? if there are changes in state they should be propagated to Url automatically?

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 functional test needs flushing url. The line await browser.goBack(); there will not gonna do redirect to discover page if we do not flushing the url

Copy link
Member

@kertal kertal Jun 15, 2021

Choose a reason for hiding this comment

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

@dmitriynj Had a closer look at it, works, but with a few changes calling this function could be omitted (it was implemented for testing). So in context we do not want to push to history like in Discover Main, we want to replace in history. If we would change the number of successor, predecessors 3 times, we would need 4 back button clicks to come back to Discover Main.

This can be solved in context_state.ts by 2 changes like

Line 192

stateStorage.set(APP_STATE_URL_KEY, mergedState, { replace: true });

Line 207

stateStorage.set(GLOBAL_STATE_URL_KEY, { filters: globalFilters }, { replace: true });

Line 216

const nextState = { ...appStateContainer.getState(), ...{ filters: appFilters } };
stateStorage.set(APP_STATE_URL_KEY, nextState, { replace: true });

Then

stateContainer.flushToUrl(true);

will no longer be necessary 🥳

Copy link
Member

Choose a reason for hiding this comment

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

Checked again in the old version, and there filters are pushed to history, not replaced. So the only change necessary should be in Line 192

if (!tieBreakerField) {
setState(createError(statusKey, FailureReason.INVALID_TIEBREAKER));
toastNotifications.addDanger({
title: errorTitle,
Copy link
Member

Choose a reason for hiding this comment

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

we can remove the check for the tieBreakerField, without having an anchor, it makes no sense to fetch the surrounding documents (info of the anchor record is needed).

@kertal
Copy link
Member

kertal commented Jun 10, 2021

@timroes note that this PR fixes a memory leak when loading more documents 🥳 , since the route in no longer reloaded on every change!
dom count context

@dimaanj
Copy link
Contributor Author

dimaanj commented Jun 10, 2021

@elasticmachine merge upstream

@dimaanj
Copy link
Contributor Author

dimaanj commented Jun 14, 2021

@elasticmachine merge upstream

Copy link
Contributor

@majagrubic majagrubic left a comment

Choose a reason for hiding this comment

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

Had a quick look at the code, haven't tested it yet. Some (nitpicky) comments below.

get: (key: string) => {
if (key === CONTEXT_TIE_BREAKER_FIELDS_SETTING) {
return ['_doc'];
} else if (key === SEARCH_FIELDS_FROM_SOURCE) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this being set to true here? Would this test not work with SEARCH_FIELDS_FROM_SOURCE set to the default value, ie. false?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tests will work when SEARCH_FIELDS_FROM_SOURCE will set to false, since testing method doesn't depend on this setting

const { uiSettings: config, capabilities, indexPatterns, navigation, filterManager } = services;

const isLegacy = useMemo(() => config.get(DOC_TABLE_LEGACY), [config]);
const useNewFieldsApi = useMemo(() => !config.get(SEARCH_FIELDS_FROM_SOURCE), [config]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Are there really performance optimizations in using memo here?

Copy link
Contributor Author

@dimaanj dimaanj Jun 14, 2021

Choose a reason for hiding this comment

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

In case of omitting memo here, on each render useNewFieldsApi and isLegacy settings will be retrived from uiSettings

setState(createError('anchorStatus', FailureReason.UNKNOWN, error));
toastNotifications.addDanger({
title: errorTitle,
text: toMountPoint(<MarkdownSimple>{error.message}</MarkdownSimple>),
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is displayed to the user, let's log the error message and put something more user-friendly in the UI.

Copy link
Contributor Author

@dimaanj dimaanj Jun 14, 2021

Choose a reason for hiding this comment

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

Assume we can't really provide more user friendly message to the UI, since it's unknown error which might be caused bad network, bad es response... one meaningful message we already providing is localised errortitle

predecessorCount: 2,
successorCount: 2,
},
useNewFieldsApi: false,
Copy link
Contributor

Choose a reason for hiding this comment

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

can this be set to true?

Copy link
Contributor Author

@dimaanj dimaanj Jun 16, 2021

Choose a reason for hiding this comment

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

It can be set to true but it not really affect the resault of the tests since the entire '../../angular/context/api/context' and '../../angular/context/api/anchor' modules were mocked in the top of the file and they will return hits not depending on the useNewFieldsApi.

@dimaanj
Copy link
Contributor Author

dimaanj commented Jun 16, 2021

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
discover 368 360 -8

Async chunks

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

id before after diff
discover 416.9KB 411.9KB -5.1KB

History

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

cc @dmitriynj

Copy link
Member

@kertal kertal left a comment

Choose a reason for hiding this comment

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

Code LGTM, tested locally with Chrome, Firefox, Safari, works as expected. Great work 👍 , this is a big step in our effort to remove Angular! Thanks for the fine tuning in terms of re-rendering
Note that you should add 2 more improvements to the description of this PR:

  • Now users can toggle columns using the doc viewer table (didn't work before)
  • Changing filters, successor and predecessor count no longer reloads the URL (And with that there's no more memory leak caused by the query bar)

Copy link
Contributor

@majagrubic majagrubic left a comment

Choose a reason for hiding this comment

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

Tested briefly in Chrome on Mac OSX, looks good to me. I trust @kertal has done a more thorough pass in testing.

@dimaanj dimaanj merged commit 0cfd04c into elastic:master Jun 17, 2021
dimaanj added a commit to dimaanj/kibana that referenced this pull request Jun 17, 2021
…100530)

* [Discover] migrate remaining context files from js to ts

* [Discover] get rid of any types

* [Discover] replace constants with enums, update imports

* [Discover] use unknown instead of any, correct types

* [Discover] skip any type for tests

* [Discover] add euiDataGrid view

* [Discover] add support dataGrid columns, provide ability to do not change sorting, highlight anchor doc, rename legacy variables

* [Discover] update context_legacy test and types

* [Discover] update unit tests, add context header

* [Discover] update unit and functional tests

* [Discover] remove docTable from context test which uses new data grid

* [Discover] update EsHitRecord type, use it for context app. add no pagination support

* [Discover] resolve type error in test

* [Discover] move fetching methods

* [Discover] complete fetching part

* [Discover] remove redundant controller

* [Discover] split up context state and components

* [Discover] revert redundant css class

* [Discover] rename component

* [Discover] revert to upstream changes

* [Discover] return upstream changes

* [Discover] refactoring, context test update

* [Discover] add tests for fetching methods, remove redundant files

* [Discover] remove redundant angular utils, add filter test

* [Discover] refactor error feedback

* [Discover] fix functional test

* [Discover] provide defaultSize

* [Discover] clean up code

* [Discover] fix eslint error

* [Discover] fiix context settings

* [Discover] return tieBreaker field check

* [Discover] optimize things

* [Discover] optimize rerenders

* Update src/plugins/discover/public/application/components/context_app/context_app.tsx

Co-authored-by: Matthias Wilhelm <[email protected]>

* [Discover] resolve comments

* [Discover] replace url instead of pushing to history. refactoring

Co-authored-by: Kibana Machine <[email protected]>
Co-authored-by: Matthias Wilhelm <[email protected]>
# Conflicts:
#	src/plugins/discover/public/application/angular/context/query_parameters/state.ts
dimaanj added a commit that referenced this pull request Jun 17, 2021
…#102503)

* [Discover] migrate remaining context files from js to ts

* [Discover] get rid of any types

* [Discover] replace constants with enums, update imports

* [Discover] use unknown instead of any, correct types

* [Discover] skip any type for tests

* [Discover] add euiDataGrid view

* [Discover] add support dataGrid columns, provide ability to do not change sorting, highlight anchor doc, rename legacy variables

* [Discover] update context_legacy test and types

* [Discover] update unit tests, add context header

* [Discover] update unit and functional tests

* [Discover] remove docTable from context test which uses new data grid

* [Discover] update EsHitRecord type, use it for context app. add no pagination support

* [Discover] resolve type error in test

* [Discover] move fetching methods

* [Discover] complete fetching part

* [Discover] remove redundant controller

* [Discover] split up context state and components

* [Discover] revert redundant css class

* [Discover] rename component

* [Discover] revert to upstream changes

* [Discover] return upstream changes

* [Discover] refactoring, context test update

* [Discover] add tests for fetching methods, remove redundant files

* [Discover] remove redundant angular utils, add filter test

* [Discover] refactor error feedback

* [Discover] fix functional test

* [Discover] provide defaultSize

* [Discover] clean up code

* [Discover] fix eslint error

* [Discover] fiix context settings

* [Discover] return tieBreaker field check

* [Discover] optimize things

* [Discover] optimize rerenders

* Update src/plugins/discover/public/application/components/context_app/context_app.tsx

Co-authored-by: Matthias Wilhelm <[email protected]>

* [Discover] resolve comments

* [Discover] replace url instead of pushing to history. refactoring

Co-authored-by: Kibana Machine <[email protected]>
Co-authored-by: Matthias Wilhelm <[email protected]>
# Conflicts:
#	src/plugins/discover/public/application/angular/context/query_parameters/state.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Discover Discover Application release_note:skip Skip the PR/issue when compiling release notes Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.14.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants