-
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
[Discover] Migrate angular context app controllers to react #100530
Conversation
…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
8ccd752
to
7f69c92
Compare
@elasticmachine merge upstream |
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.
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.
src/plugins/discover/public/application/components/context_app/utils/clamp.ts
Outdated
Show resolved
Hide resolved
src/plugins/discover/public/application/components/context_app/use_context_app_state.ts
Outdated
Show resolved
Hide resolved
|
||
useEffect(() => { | ||
const unsubscribeAppState = stateContainer.appState.subscribe((newState) => { | ||
stateContainer.flushToUrl(true); |
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.
isn't flushing to Url redundant? if there are changes in state they should be propagated to Url automatically?
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.
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
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.
@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 🥳
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.
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, |
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.
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).
src/plugins/discover/public/application/components/context_app/context_app.tsx
Outdated
Show resolved
Hide resolved
@timroes note that this PR fixes a memory leak when loading more documents 🥳 , since the route in no longer reloaded on every change! |
…/context_app.tsx Co-authored-by: Matthias Wilhelm <[email protected]>
@elasticmachine merge upstream |
@elasticmachine merge upstream |
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.
Had a quick look at the code, haven't tested it yet. Some (nitpicky) comments below.
src/plugins/discover/public/application/angular/context/components/action_bar/action_bar.tsx
Outdated
Show resolved
Hide resolved
src/plugins/discover/public/application/components/context_app/context_app.test.tsx
Outdated
Show resolved
Hide resolved
get: (key: string) => { | ||
if (key === CONTEXT_TIE_BREAKER_FIELDS_SETTING) { | ||
return ['_doc']; | ||
} else if (key === SEARCH_FIELDS_FROM_SOURCE) { |
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.
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?
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.
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]); |
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.
Are there really performance optimizations in using memo
here?
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 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>), |
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.
Since this is displayed to the user, let's log the error message and put something more user-friendly in the UI.
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.
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
src/plugins/discover/public/application/components/context_app/use_context_app_fetch.tsx
Outdated
Show resolved
Hide resolved
predecessorCount: 2, | ||
successorCount: 2, | ||
}, | ||
useNewFieldsApi: false, |
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.
can this be set to true?
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.
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
.
src/plugins/discover/public/application/components/context_app/context_app.tsx
Outdated
Show resolved
Hide resolved
@elasticmachine merge upstream |
💚 Build SucceededMetrics [docs]Module Count
Async chunks
History
To update your PR or re-run it, just comment with: cc @dmitriynj |
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.
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)
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.
Tested briefly in Chrome on Mac OSX, looks good to me. I trust @kertal has done a more thorough pass in testing.
…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
…#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
Part of #92573
Summary
ContextAppContent renders 7 times initially
DiscoverGrid/DocTable renders 4 times initially
each ActionBar component renders 3 times initially
Checklist