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

Checking that there is indeed a selection before scrolling #257

Merged
merged 11 commits into from
Feb 20, 2024

Conversation

guzmanvig
Copy link
Collaborator

Same as before but now I check that the start and end the selection are different. It seems that when you click on some row, the selection prop gets populated with the index you clicked on in start and end

@guzmanvig guzmanvig requested a review from jjti January 16, 2024 12:36
@jjti
Copy link
Collaborator

jjti commented Feb 13, 2024

@guzmanvig what is the intended behavior? I'm not sure what's happening now is desirable, clicking on any element, even if it's already in full view of the Linear Viewer, scrolls the Linear viewer so that element is at the top of the viewer. I prefer it the way it is now without that auto-scrolling behavior

@guzmanvig
Copy link
Collaborator Author

@guzmanvig what is the intended behavior? I'm not sure what's happening now is desirable, clicking on any element, even if it's already in full view of the Linear Viewer, scrolls the Linear viewer so that element is at the top of the viewer. I prefer it the way it is now without that auto-scrolling behavior

Screencast.from.02-13-2024.11.51.37.AM.webm

@jjti The intended behavior is for when the user programmatically sets a selection. In our application, the user clicks on a list of indices, which when clicked, they are selected in Seqviz. However, currently, the selection may not be visible and the user needs to manually scroll Seqviz to find it. This would fix that as it would automatically scroll to whatever is selected.

Would you want me to apply this logic only for programatic selection and not for when the user clicks? Or should I check that the selection is not visible before scrolling? Not sure if the latter is possible

@jjti
Copy link
Collaborator

jjti commented Feb 13, 2024

Would you want me to apply this logic only for programatic selection and not for when the user clicks?

I think this is the way to go imo. Selections set from clicks on elements differ from the selection that users pass in. They have more fields like type (which is not publicly documented):

export interface Selection {

So maybe check whether that .type field is set and only update state if it is?

@guzmanvig
Copy link
Collaborator Author

guzmanvig commented Feb 14, 2024

@jjti your solution worked, but with one caveat. The selection prop type was just { clockwise?: boolean; end: number; start: number; }, so the type field didn't exist in it. I added an | Selection to the type to fix this, and then a type guard to be able to check for the type field. What I couldn't figure out was why selecting by clicking updates the props. Shouldn't it just update the state? Maybe that's something that's wrong somewhere else, and we need to fix that instead of doing this. Let me know and I can look into it.

src/SeqViewerContainer.tsx Outdated Show resolved Hide resolved
end: number;
start: number;
};
selection?:
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we need to change this one. This is the prop that can only be passed from the public prop. It's the state on the component, and the func args, that need that enhancement

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That was my understanding as well, but for some reason the functioncomponentDidUpdate = (prevProps: SeqViewerContainerProps) gets called when a user clicks on an element, and in this.props.selection you see the selection with type and the other fields.

In any case, I removed this since the type guard takes care of checking if it's a Selection or not.

Comment on lines 148 to 153
| {
clockwise?: boolean;
end: number;
start: number;
}
| Selection
Copy link
Collaborator

Choose a reason for hiding this comment

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

this doesn't need to change either, it's 1:1 w/ the prop that users pass in so it doesn't have those other fields.

Looking thru it quickly, a few lines (maybe more) that need to change:

Copy link
Collaborator Author

@guzmanvig guzmanvig Feb 14, 2024

Choose a reason for hiding this comment

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

I'm not sure this is right, the selection in the state has to be a Selection because it is then use everywhere else by passing it in <SelectionContext.Provider value={mergedSelection}>. And the getSelection function purpose is to convert the selection in props to a Selection:

  getSelection = (state: Selection, prop?: ExternalSelection): Selection => {
    if (prop) {
      return { ...prop, clockwise: typeof prop.clockwise === "undefined" || !!prop.clockwise, type: "" };
    }
    return state;
  };

I've added an ExternalSelection interface now to make it clearer, let me know what you think.

@guzmanvig guzmanvig merged commit ea4cb1c into develop Feb 20, 2024
2 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.

2 participants