-
Notifications
You must be signed in to change notification settings - Fork 8.1k
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
[ML] Adds redux toolkit example for response_stream
to developer examples.
#182690
[ML] Adds redux toolkit example for response_stream
to developer examples.
#182690
Conversation
10f9f2f
to
ed30783
Compare
8105d5d
to
9946011
Compare
138324e
to
7dfe90b
Compare
Pinging @elastic/ml-ui (:ml) |
7992dbc
to
c03a427
Compare
const randomEntity = entities[Math.floor(Math.random() * entities.length)]; | ||
const randomAction = actions[Math.floor(Math.random() * actions.length)]; | ||
|
||
if (randomAction === 'add') { |
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.
super duper nit: I think a switch statement would be more readable 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.
updated in 737bdfd.
examples/response_stream/public/containers/app/pages/page_redux_stream/index.tsx
Outdated
Show resolved
Hide resolved
@@ -58,7 +49,7 @@ export const PageReducerStream: FC = () => { | |||
RESPONSE_STREAM_API_ENDPOINT.REDUCER_STREAM, | |||
'1', | |||
{ compressResponse, flushFix, simulateErrors }, | |||
{ reducer: reducerStreamReducer, initialState } | |||
{ reducer: reducerStreamReducer, initialState: getInitialState() } |
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.
getInitialState() will be called every render here even though it's already been used to create the reducer initially. Is that what we want?
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.
updated in 73d148a.
examples/response_stream/public/containers/app/components/bar_chart_race.tsx
Show resolved
Hide resolved
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 🎉
deleteEntity: (state, action: PayloadAction<string>) => { | ||
delete state.entities[action.payload]; | ||
}, | ||
error: (state, action: PayloadAction<string>) => { |
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.
Should there be a way to clear out errors other than the reset?
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.
The example UI doesn't have an option for that, so it's not necessary.
…kibana into ml-response-stream-createslice
@alvarezmelissa87 great question and finding about an error not triggering a toast. Had to read/understand again myself since it's been a while since I wrote that pattern. On the server side we have these two parts:
So the first case throws an error server side, but it will not be propagated to the client side, because a HTTP stream can only return an error on the initial return (that would be something instead of |
💚 Build Succeeded
Metrics [docs]Module Count
History
To update your PR or re-run it, just comment with: cc @walterra |
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.
LGTM ⚡
Summary
Follow up to #132590.
Part of #181111.
This updates the developer examples for
@kbn/ml-response-stream
to include a variant with a full Redux Toolkit setup. For this case, the@kbn/ml-response-stream
now includes a generic slicestreamSlice
that can be used. This allows the actions created to be streamed via NDJSON to be shared across server and client.Functional tests for the examples were added too. To run these tests you can use the following commands:
Checklist