8000 UI: mark visually motor positions outside of limits by elmjag · Pull Request #1640 · mxcube/mxcubeweb · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

UI: mark visually motor positions outside of limits #1640

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

Merged
merged 2 commits into from
May 13, 2025

Conversation

elmjag
Copy link
Contributor
@elmjag elmjag commented May 6, 2025

Changes behavior of motor widgets when position outside of motor limits is entered.

If entered position is outside of limits, change the widget style to invalid mode. Block sending the invalid position to the back-end. When focus is lost, restore widget to display motor's real position.

This changes the current behavior, where it's possible to enter and send a position outside of limits. The motor can refuse to move to that position, but the widget will still display the invalid value. Thus the displayed value in the UI will be different from the motor's real position, without any visual indications.

@elmjag elmjag force-pushed the handle-motor-limits branch 3 times, most recently from 8f8c0a5 to 3dd9683 Compare May 6, 2025 08:53
Copy link
Collaborator
@axelboc axelboc left a comment

Choose a reason for hiding this comment

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

The motor can refuse to move to that position, but the widget will still display the invalid value. Thus the displayed value in the UI will be different from the motor's real position, without any visual indications.

I feel like the changes you propose are more of a workaround for this than a fix. Sure, it's always good to avoid making an invalid request, but if this request happens, the error should be dealt with in the UI. In other words, front-end validation should be an enhancement, not a requirement.


To recap the problem: when the back-end receives a value outside of [min, max], it should respond with an error (I assume it already does), and this error should be conveyed somehow to the user.

To do so, the setAttribute Redux thunk should be made asynchronous so that dispatch(setAttribute(attribute, val)) can be awaited and wrapped in try/catch. Then, in MotorInput, you can manage an error state and maybe pass an invalid prop to BaseMotorInput.

To reset this error/invalid state, you could:

  • pass an onBlur prop to BaseMotorInput to reset on blur;
  • start a timer in an effect in MotorInput to reset after a few seconds;
  • leave the field in error state until the user changes the motor value again.

Your choice of resetting on blur seems fine to me in terms of UX.


If this all sounds too obscure, we can have a go at it if you like.

@marcus-oscarsson
Copy link
Member
marcus-oscarsson commented May 6, 2025

We need to be quite careful to make sure that we are consistent across the various underlying implementations (in mxcubecore and below) when we handle these scenarios. We also need to make sure that handle the validation in a way that is logical to the user on the UI side and make the necessary implementation on the backend to prevent incorrect values to be passed on.

I think its a great idea to show that a input is outside of the valid range, it helps the user to understand that the value is indeed out of range.

  • A ValueError is raised (or should be raised) when any AbstractActator receives a value outside of its limits.

The limits of most actuators are available in the UI so we could also add an additional check. Keep in mind that, to complicate things, limits of some actuators can be a function of some other actuators position (i.e resolution). I think thats the only one at the moment.

As @axelboc points out above it should be possible to catch this error in an async handler and take the right actions to make sure that the value is displayed correctly and that a message is given to the user.

@elmjag
Copy link
Contributor Author
elmjag commented May 6, 2025

The back-end does indeed respond with an error if you try to move motor outside of the limits.

I agree with @axelboc that we should catch error responses for motor moves and display some kind of error message in the UI. It's possible for the move to fail due to some other problem, not necessary due to hitting a limit. I'll work on adding that.

However, visually showing that the entered position is invalid is very useful feature for us. We are using MD3Up and it's easy get to the edges of motor limits. Currently it's a bit cryptic why some moves fail, you basically need to read the log.

@marcus-oscarsson
Copy link
Member

However, visually showing that the entered position is invalid is very useful feature for us. We are using MD3Up and it's easy get to the edges of motor limits. Currently it's a bit cryptic why some moves fail, you basically need to read the log.

We completely agree, as mentioned above the limits are available on the UI side so you can easily add client side validation and some nice display of when the user tries to enter a value that is out of range. Our concern was more that this should not replace any server side handling and be done in such a way so that it reflects the actual state of the hardware with the correct message/display. I think that is also what you have in mind ?

The await, try/catch should be there to handle the cases when/if the UI validation fails, for whatever reason.

Changes behavior of motor widgets when position outside of motor
limits is entered.

If entered position is outside of limits, change the widget style to
'invalid' mode. Block sending the 'invalid' position to the backend.

When focus is lost, restore widget to display motor's real position.

This changes the current behavior, where it's possible to enter
and send a position outside of limits. The motor can refuse to move
to that position, but the widget will still display the invalid value.

Thus the displayed value in the UI will be different from the motor's
real position, without any visual indications.
@elmjag elmjag force-pushed the handle-motor-limits branch 2 times, most recently from 0a34141 to b29b5c4 Compare May 8, 2025 10:45
Make the setAttribute action async, this way we can await it and
catch errors.

When issuing 'move motor' action from MotorInput widget, catch
errors thrown by the request. Show the error to the user with the
error panel.
@elmjag elmjag force-pushed the handle-motor-limits branch from b29b5c4 to f0d45fb Compare May 8, 2025 10:53
@elmjag
Copy link
Contributor Author
elmjag commented May 8, 2025

I have added code that catches errors on moving motors. The errors are displayed to the user with the error panel.
elmjag@f0d45fb

To summarize current behavior:

  • if user enters value outside of limits, the widget marks it visually
  • if back-end replies with an error on motor move, the error message will be shown to the user
  • when motor widget loses focus, the displayed position is reset to motor's current position, as reported by the back-end

Is this what you have in mind?

@marcus-oscarsson
Copy link
Member

yeah, that sounds reasonable to me. Do you have a screenshot of the error display ?

@@ -35,6 +36,14 @@ function MotorInput(props) {
return null;
}

async function handleChange(val) {
Copy link
Member

Choose a reason for hiding this comment

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

👍

@elmjag
Copy link
Contributor Author
elmjag commented May 12, 2025

yeah, that sounds reasonable to me. Do you have a screenshot of the error display ?

It shows the standard 'error bubble' with the error message from the back-end:

Screenshot from 2025-05-12 09-07-27

Copy link
Collaborator
@axelboc axelboc left a comment

Choose a reason for hiding this comment

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

Great stuff 💯

@marcus-oscarsson marcus-oscarsson merged commit 84969eb into mxcube:develop May 13, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0