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

feat(api, app): add state change information to rpc #5512

Merged
merged 7 commits into from
May 5, 2020
Merged

Conversation

sfoster1
Copy link
Member

This adds an extra structure of StateInfo to the RPC session that
transmits information like the reason behind a state change to the app.

As a first pass at using it, it also displays the message from a
protocol pause in the pause alert box.

Testing

  • On a robot with this commit, make sure that if you put a protocol_context.pause() (or robot.pause() in your protocol the message shows up in the alert box
  • On a robot without this commit, make sure pausing still works and shows the old reason-less result box

This is a precursor and set of new functionality for adding the rest of the window switch pausing; displaying the user pause message is just a good example of what it can do.

This adds an extra structure of StateInfo to the RPC session that
transmits information like the reason behind a state change to the app.

As a first pass at using it, it also displays the message from a
protocol pause in the pause alert box.
@sfoster1 sfoster1 added app Affects the `app` project api Affects the `api` project labels Apr 29, 2020
@sfoster1 sfoster1 requested review from a team April 29, 2020 20:55
@sfoster1 sfoster1 requested a review from a team as a code owner April 29, 2020 20:55
@sfoster1 sfoster1 requested review from shlokamin and removed request for a team April 29, 2020 20:55
@codecov
Copy link

codecov bot commented Apr 29, 2020

Codecov Report

Merging #5512 into edge will increase coverage by 0.11%.
The diff coverage is 10.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             edge    #5512      +/-   ##
==========================================
+ Coverage   65.83%   65.95%   +0.11%     
==========================================
  Files        1094     1114      +20     
  Lines       31126    31358     +232     
==========================================
+ Hits        20493    20681     +188     
- Misses      10633    10677      +44     
Impacted Files Coverage Δ
app/src/components/RunLog/CommandList.js 0.00% <0.00%> (ø)
app/src/components/RunLog/SessionAlert.js 0.00% <0.00%> (ø)
app/src/components/RunLog/index.js 0.00% <ø> (ø)
app/src/robot/reducer/session.js 96.66% <ø> (ø)
app/src/robot/selectors.js 80.36% <0.00%> (-0.50%) ⬇️
app/src/robot/api-client/client.js 90.87% <100.00%> (+0.03%) ⬆️
app/src/pages/More/index.js 0.00% <0.00%> (ø)
opentrons/commands/commands.py 91.35% <0.00%> (ø)
app/src/components/MenuPanel/index.js 0.00% <0.00%> (ø)
...src/components/AppSettings/AdvancedSettingsCard.js 0.00% <0.00%> (ø)
... and 32 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 60f6b16...6a4ca82. Read the comment docs.

Copy link
Contributor

@mcous mcous left a comment

Choose a reason for hiding this comment

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

Got some naming and type definition nits, but mostly I'd like to make sure there are unit tests in place for:

  • RPC full session comes into api-client with stateInfo undefined (old robot)
  • RPC full session comes into api-client with stateInfo === {} (initial state)
  • RPC full session comes into api-client with stateInfo set with properties
  • Same tests for RPC state update notification

The RPC API client is not typechecked because it's old and janky, so these unit tests are (even more) important to have in place when we make changes

app/src/robot/api-client/client.js Outdated Show resolved Hide resolved
app/src/robot/reducer/session.js Outdated Show resolved Hide resolved
app/src/robot/types.js Outdated Show resolved Hide resolved
self.state = None
self.state: 'State' = None
#: The current state
self.stateInfo: 'StateInfo' = {}
Copy link
Contributor

Choose a reason for hiding this comment

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

See comment about statusInfo vs stateInfo. Also, is this only ever going to be used for pause? Should it be pauseInfo?

Copy link
Member Author

Choose a reason for hiding this comment

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

It can be used for any state; many of the functions will only be used in pause for now, but e.g. changedAt and estimatedDuration could be used for more.

app/src/components/RunLog/styles.css Outdated Show resolved Hide resolved
api/src/opentrons/api/dev_types.py Show resolved Hide resolved
api/src/opentrons/api/session.py Outdated Show resolved Hide resolved
@sfoster1 sfoster1 requested a review from a team as a code owner April 30, 2020 14:16
if state not in VALID_STATES:
raise ValueError(
'Invalid state: {0}. Valid states are: {1}'
.format(state, VALID_STATES))
self.state = state
if user_message:
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't it be easier to just create a new self.stateInfo object here? No need to clear previous values, just overwrite instance with a new one.

Copy link
Member Author

Choose a reason for hiding this comment

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

It would definitely be cleaner if I wanted to have all the keys there all the time but I kind of like the idea of removing keys and making sure they always have values if present

Copy link
Contributor

Choose a reason for hiding this comment

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

Have it your way, but I'll make one last statement. Up to you. It's not that big a deal.

So... I am not a fan of having several if / else clauses that do almost exactly the same thing. You can filter out the None values when creating payload below.

@sfoster1 sfoster1 requested a review from mcous April 30, 2020 18:38
if state not in VALID_STATES:
raise ValueError(
'Invalid state: {0}. Valid states are: {1}'
.format(state, VALID_STATES))
self.state = state
if user_message:
Copy link
Contributor

Choose a reason for hiding this comment

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

Have it your way, but I'll make one last statement. Up to you. It's not that big a deal.

So... I am not a fan of having several if / else clauses that do almost exactly the same thing. You can filter out the None values when creating payload below.

Copy link
Contributor

@mcous mcous left a comment

Choose a reason for hiding this comment

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

JS tests look good 👍

`Run paused${buildPauseMessage(message)}`

const buildPauseUserMessage = (message: ?string) =>
message && <div className={styles.pause_user_message}>{message}</div>
Copy link
Contributor

Choose a reason for hiding this comment

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

<p> is more appropriate for copy than a <div>

@sfoster1 sfoster1 merged commit ca3ef95 into edge May 5, 2020
@sfoster1 sfoster1 deleted the add-pause-comms branch May 5, 2020 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Affects the `api` project app Affects the `app` project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants