Extract useRequest and sendRequest from SR into elasticsearch-ui-shared plugin#40777
Extract useRequest and sendRequest from SR into elasticsearch-ui-shared plugin#40777cjcenizal merged 25 commits intoelastic:masterfrom
Conversation
|
Pinging @elastic/es-ui |
3b50a35 to
0c1e55f
Compare
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
💔 Build Failed |
0566dc6 to
76b5f1d
Compare
💔 Build Failed |
💔 Build Failed |
aa50d19 to
4921550
Compare
💚 Build Succeeded |
💚 Build Succeeded |
…ed plugin. - Refactor SR's consumption to send UI metric telemetry in the promise chain, to uncouple the request functions from telemetry.
- Rename loading flag to isLoading. - Rename changeInterval callback to setRequestInterval. - Remove initialData from return value. - Preserve complete response shape instead of removing everything except the data property. - Send a request when path, body, or method changes. - Don't send a request when the interval changes.
2f661fd to
38c0be4
Compare
💔 Build Failed |
|
@cjcenizal did another quick test of watcher with your latest changes and did not find any issues. |
- Remove unnecessary kibana.json and no-op plugin definition. - Remove root-level index file because it's a scalability bottleneck. - Move request module into its own directory.
💔 Build Failed |
|
@sebelga Here's the new folder structure, updated with the same pattern as used by the |
jen-huang
left a comment
There was a problem hiding this comment.
Did another local test of SR and didn't find any regressions. LGTM!
💔 Build Failed |
💔 Build Failed |
|
Retest |
💚 Build Succeeded |
|
Thanks for making the changes @cjcenizal ! I added my comment about the implicit scheduler so you see where I'm coming from. I am not sure about the folder structure, I keep thinking that what we are doing is a hack around the "we don't know where to put static code" problem. To me, As an example: the "mappings editor" is a reusable component that belongs to the Index management plugin. But it will be consumed by other plugins (ML). As a reusable static code, I made it available from the Everything will eventually work, this is just to make things more explicit. 😊 |
💔 Build Failed |
💔 Build Failed |
|
Retest |
1 similar comment
|
Retest |
💚 Build Succeeded |
|
I spoke with @sebelga on Slack and he agreed that we could merge this PR and discuss the other points he brought up later. I'll leave my thoughts here for now.
Critiquing
This sounds like a good question for the Platform team.
Makes sense. I'm open to working through this more! |
…lastic#40777) - Refactor SR's consumption to send UI metric telemetry in the promise chain, to uncouple the request functions from telemetry. - Refactor useRequest to return isInitialRequest instead of tracking polling state. - Rename request callback to sendRequest. - Rename loading flag to isLoading. - Rename changeInterval callback to setRequestInterval. - Rename interval parameter to pollIntervalMs. - Remove initialData from return value. - Preserve complete response shape instead of removing everything except the data property. - Send a request when path, body, or method changes. - Don't send a request when the interval changes. - Remove setRequestInterval from return value. - Expect the consumer to change the interval config in order to set it to a new value. - Refactor internals so that calling sendRequest resets the interval. - Migrate Watcher to use shared request library. - Rename onSuccess to deserializer and use it to process data. - Rename updateInterval function to scheduleRequest. - Don’t watch method parameter.
…40777) (#42200) - Refactor SR's consumption to send UI metric telemetry in the promise chain, to uncouple the request functions from telemetry. - Refactor useRequest to return isInitialRequest instead of tracking polling state. - Rename request callback to sendRequest. - Rename loading flag to isLoading. - Rename changeInterval callback to setRequestInterval. - Rename interval parameter to pollIntervalMs. - Remove initialData from return value. - Preserve complete response shape instead of removing everything except the data property. - Send a request when path, body, or method changes. - Don't send a request when the interval changes. - Remove setRequestInterval from return value. - Expect the consumer to change the interval config in order to set it to a new value. - Refactor internals so that calling sendRequest resets the interval. - Migrate Watcher to use shared request library. - Rename onSuccess to deserializer and use it to process data. - Rename updateInterval function to scheduleRequest. - Don’t watch method parameter.
|
Note for myself and future discussion: Another reason why "static" is better than "public" and "server" is that it does not make a difference where the code will be consumed (server or client). When we will put the AuthorizationProvider code in the "es_ui_shared" we will be forced to put it in the "public". Even though the server code also consumes the typings. Instead of "static", we can think of "packages" or "node_modules".
I thought we were going to solve this at our team level and inspire others 😊 |

Note to reviewers: I tried to structure my commit history in a way that makes my changes easy to follower. If the changes in this PR seem too disparate to digest I recommend reviewing each commit individually.
Changes to
useRequest:sendRequestfunction anduseRequesthook used by SR into anelasticsearch-ui-sharedplugin (based off Lib "Hook form" #39347).sendRequestanduseRequest.useRequestcontract a bit, most notably removing thepollingflag from the return value and adding anisInitialRequestflag in its place. I also removed thechangeIntervalfunction from the return value so that consumers are expected to change theintervalconfig parameter instead.sendRequestanduseRequestfrom the concept of telemetry, by requiring consumers ofsendRequestto do their own telemetry logic inside of the returned promise's success callback. I think this is more flexible because this is the logical place for consumers to perform any actions once the request has succeeded. I added aprocessDataparameter to theuseRequesthook which is intended for processing the data resolved by a request, but it can also support similar telemetry functionality or other side effects that need to occur after a request has successfully resolved.I also simplified the
httpanduiMetricservices in SR by exporting methods directly from these modules, instead of exporting a namespace object. This reduced some boilerplate on the consumer's side. @jen-huang How do these changes look to you as the original author?