[APM] Fix for default fields in correlations view (#91868)#92090
[APM] Fix for default fields in correlations view (#91868)#92090ogupte merged 4 commits intoelastic:masterfrom
Conversation
|
Pinging @elastic/apm-ui (Team:apm) |
|
@elasticmachine merge upstream |
| } | ||
| }, [key, defaultValue]); | ||
|
|
||
| const [item, setItem] = useState<T>(getFromStorage()); |
There was a problem hiding this comment.
Can we avoid useCallback and useEffect if the arguments are passed to getFromStorage?
| const [item, setItem] = useState<T>(getFromStorage()); | |
| const [item, setItem] = useState<T>(getFromStorage(key, defaultValue)); |
There was a problem hiding this comment.
i got rid of the useCallback, but it still needs the useEffect with dependencies on [key, defaultValue] since changes in any of these should trigger a state change resulting in a new value for the returned item. The lack of this update was the source of stale state in this issue. In correlations defaultValue gets updates from a useFetcher response (for dynamic index pattern). The new defaultValue should be the item value since this would be rendered as custom fields before any persistence happens.
| @@ -26,7 +24,9 @@ export function useLocalStorage<T>(key: string, defaultValue: T) { | |||
| } | |||
|
|
|||
| return toStore; | |||
There was a problem hiding this comment.
While you are at it: do we need toStore? Can't we just return immediately instead of mutating?
const storedItem = window.localStorage.getItem(key);
if (storedItem !== null) {
try {
return JSON.parse(storedItem) as T;
} catch (err) {
window.localStorage.removeItem(key);
// eslint-disable-next-line no-console
console.log(`Unable to decode: ${key}`);
}
}
return defaultValue;|
@elasticmachine merge upstream |
💛 Build succeeded, but was flaky
Test FailuresKibana Pipeline / general / Chrome UI Functional Tests.test/functional/apps/dashboard/dashboard_filtering·ts.dashboard app using current data dashboard filtering disabling a filter unfilters the data on saved searchesStandard OutStack TraceMetrics [docs]Async chunks
History
To update your PR or re-run it, just comment with: |
…astic#92090) * [APM] Fix for default fields in correlations view (elastic#91868) * removes useCallback hook Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
…astic#92090) * [APM] Fix for default fields in correlations view (elastic#91868) * removes useCallback hook Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
…bana into task-manager/docs-monitoring * 'task-manager/docs-monitoring' of github.com:gmmorris/kibana: (40 commits) [Security Solution][Case][Bug] Improve case logging (elastic#91924) [Alerts][Doc] Added README documentation for alerts plugin status and framework health checks configuration options. (elastic#92761) Add warning for EQL and Threshold rules if exception list contains value list items (elastic#92914) [Security Solution][Case] Fix subcases bugs on detections and case view (elastic#91836) [APM] Always allow access to Profiling via URL (elastic#92889) [Vega] Allow image loading without CORS policy by changing the default to crossOrigin=null (elastic#91991) skip flaky suite (elastic#92114) [APM] Fix for default fields in correlations view (elastic#91868) (elastic#92090) chore(NA): bump bazelisk to v1.7.5 (elastic#92905) [Maps] fix selecting EMS basemap does not populate input (elastic#92711) API docs (elastic#92827) [kbn/test] add import/export support to KbnClient (elastic#92526) Test fix management scripted field filter functional test and unskip it (elastic#92756) [App Search] Create Curation view/functionality (elastic#92560) [Reporting/Discover] include the document's entire set of fields (elastic#92730) [Fleet] Add new index to fleet for artifacts being served out of fleet-server (elastic#92860) [Alerts][Doc] Added README documentation for API key invalidation configuration options. (elastic#92757) [Discover][docs] Add search for relevance (elastic#90611) [Alerts][Docs] Extended README.md and the user docs with the licensing information. (elastic#92564) [7.12][Telemetry] Security telemetry allowlist fix. (elastic#92850) ...
Closes #91868.
Updates the internal state in in the
useLocalStoragehook whenever the default value changes.