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

Store sampleview coords in context menu state #1489

Merged
merged 3 commits into from
Nov 12, 2024

Conversation

axelboc
Copy link
Collaborator

@axelboc axelboc commented Nov 4, 2024

I now store e.offset<X|Y> / imageRatio instead of just e.offset<X|Y> in the state, which saves ContextMenu from having to do this calculation in a couple of places.

I've made a couple of additional commits to move some logic around, inline some methods, etc., and to let the right-clicked shape be undefined in the state (instead of storing a fake shape object { type: 'NONE' }).

@@ -486,7 +479,7 @@ export default class ContextMenu extends React.Component {
const menuOptions = this.menuOptions();
let optionList = [];

if (this.props.sampleID !== undefined) {
Copy link
Collaborator Author

@axelboc axelboc Nov 4, 2024

Choose a reason for hiding this comment

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

I've kept this condition for now, but I don't find it ideal. If there's no sample mounted and you right-click on a shape, you get a completely different context menu than if you right-click on the same shape and there's a sample mounted. Actions that don't require a sample to be mounted, like Delete Line, could very well be shown when right-clicking on a line regardless of the presence of a sample.

I would prefer for context menu actions that require a sample to be mounted to be conditionally rendered individually.

Copy link
Member

@marcus-oscarsson marcus-oscarsson Nov 4, 2024

Choose a reason for hiding this comment

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

I would prefer for context menu actions that require a sample to be mounted to be conditionally rendered individually or to show an error to the user when used.

Yes, the context menu on a shape without a sample mounted should give an error, just like we can't create a point/shape without a sample

Copy link
Collaborator Author

@axelboc axelboc Nov 4, 2024

Choose a reason for hiding this comment

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

Sorry, I've edited my comment to clarify my thought: I think that actions that don't require a sample to be mounted, like Delete Point should be shown when right-clicking on a shape regardless of the presence of a sample.

That's because when you mount a sample, perform 3-click centring, save the created point, and unmount the sample, the point remains on the sample view, so you can still right-click on it. At the moment, when you're in this situation, you basically can't delete anything via the context menu (you still can by pressing Delete):

image

Copy link
Member

@marcus-oscarsson marcus-oscarsson Nov 4, 2024

Choose a reason for hiding this comment

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

Hm, yes makes sense from that "point" (no pun intended :) ) of view. But all the shapes should actually be cleared when a sample is unmounted, because they are not valid any longer. We should look at that if its not the case

Copy link
Member

Choose a reason for hiding this comment

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

On the beamlines, at least ours, the shapes are removed at unmount, I guess its just a event that is not registered properly in some mockup.

@@ -34,24 +33,6 @@ export default class ContextMenu extends React.Component {
grid: [],
none: [],
};
let twoDPoints = [];

if (this.props.enable2DPoints) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've inlined the condition below.

],
};

if (this.props.enableNativeMesh) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Also inlined above.

@axelboc
Copy link
Collaborator Author

axelboc commented Nov 5, 2024

Replacing the dummy shape { type: 'NONE' } with undefined in the context menu state seems to have caused some issues in the showModal method. Apologies, I'll investigate.

@axelboc axelboc marked this pull request as ready for review November 5, 2024 09:44
@axelboc
Copy link
Collaborator Author

axelboc commented Nov 5, 2024

I've used optional chaining in showModal to handle an undefined shape. In the other methods, the shape prop is always defined.

Comment on lines +433 to +439
const { sampleViewX, sampleViewY } = this.props;

this.props.sampleViewActions.add2DPoint(
sampleViewX,
sampleViewY,
'SAVED',
(shape) => this.showModal(name, {}, shape, extraParams),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe you already thought about it and want to do that in a different PR, but related to #1490: Couldn't we just prevent the drawing of a point when no sample is mounted by adding a check for sampleData (similar to how it is done in showModal)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Indeed, the check for the mounted sample could just come before the creation of the point. But we could also hide or disable the context menu option.

Copy link
Collaborator

Choose a reason for hiding this comment

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

You are correct, that might be a more elegant solution to the problem. Sorry, It seems that I misunderstood the other comment, the first time I read it

@marcus-oscarsson marcus-oscarsson merged commit fd9886b into develop Nov 12, 2024
19 checks passed
@marcus-oscarsson marcus-oscarsson deleted the ab-context-menu-2 branch November 12, 2024 15:39
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.

3 participants