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

Bug 1826962: Limit the amount a user can zoom in/out in topology #5160

Merged

Conversation

jeff-phillips-18
Copy link
Member

Fixes:
https://issues.redhat.com/browse/ODC-3490

Analysis / Root cause:
The graph scale did not include any zoom extent boundaries so the zoom buttons allowed for infinite zoom in/out.

Solution Description:
Add zoomExtents to the BaseGraph to prevent setting the scale out of the extent boundaries.

/kind bug

@openshift-ci-robot openshift-ci-robot added kind/bug Categorizes issue or PR as related to a bug. bugzilla/unspecified labels Apr 22, 2020
@openshift-ci-robot
Copy link
Contributor

@jeff-phillips-18: This pull request references Bugzilla bug 1826962, which is valid. The bug has been moved to the POST state. The bug has been updated to refer to the pull request using the external bug tracker.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target release (4.5.0) matches configured target release for branch (4.5.0)
  • bug is in the state ASSIGNED, which is one of the valid states (NEW, ASSIGNED, ON_DEV, POST, POST)

In response to this:

Bug 1826962: Limit the amount a user can zoom in/out in topology

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openshift-ci-robot openshift-ci-robot added the bugzilla/valid-bug Indicates that a referenced Bugzilla bug is valid for the branch this PR is targeting. label Apr 22, 2020
@openshift-ci-robot openshift-ci-robot added the component/dev-console Related to dev-console label Apr 22, 2020
Copy link
Contributor

@andrewballantyne andrewballantyne left a comment

Choose a reason for hiding this comment

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

/assign

const zoomExtents: [number, number] = [this.zoomExtents[0], this.zoomExtents[1]];
let updateExtents = false;
if ('minZoom' in model && typeof model.minZoom === 'number') {
zoomExtents[0] = +model.minZoom;
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't +variable a cast to number? Wouldn't your if-statement typeof check and types make this check redundant?

@@ -238,6 +248,19 @@ export default class BaseGraph<E extends GraphModel = GraphModel, D = any> exten
if ('layout' in model) {
this.setLayout(model.layout);
}
const zoomExtents: [number, number] = [this.zoomExtents[0], this.zoomExtents[1]];
let updateExtents = false;
if ('minZoom' in model && typeof model.minZoom === 'number') {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a little taken-back by the usage of the type and this check. I agree it's good to be safe, but I wonder if we are crutching at the wrong spot? Can you make the model setter a little more stable so it's either undefined or a number?

@@ -25,6 +25,8 @@ export default class BaseGraph<E extends GraphModel = GraphModel, D = any> exten

private currentLayout?: Layout;

private zoomExtents: [number, number] = [0.25, 4];
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we want to type the [number, number]... you use it frequently. Would it make sense to type it?

@@ -59,7 +60,7 @@ export const useDragNode = <
React.useMemo(() => {
const sourceSpec: DragSourceSpec<any, any, any, any, Props> = {
item: (spec && spec.item) || { type: '#useDragNode#' },
operation: (monitor, p) => {
operation: (monitor: DragSourceMonitor, p: any) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume p is Props... you have a Props type, does that align?

@jeff-phillips-18
Copy link
Member Author

/retest

@@ -25,6 +25,8 @@ export default class BaseGraph<E extends GraphModel = GraphModel, D = any> exten

private currentLayout?: Layout;

private zoomExtent: [number, number] = [0.25, 4];
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a type here? What are the two numbers representing? Min & Max? Maybe a type of ZoomBounds?

Copy link
Contributor

@andrewballantyne andrewballantyne left a comment

Choose a reason for hiding this comment

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

/lgtm

Minor suggestion to shift the type to the hook.

export type PanZoomRef = (node: SVGGElement | null) => void;

// Used to send events prevented by d3.zoom to the document allowing modals, dropdowns, etc, to close
const propagatePanZoomMouseEvent = (e: Event): void => {
document.dispatchEvent(new MouseEvent(e.type, e));
};

export const usePanZoom = (zoomExtent: [number, number] = ZOOM_EXTENT): PanZoomRef => {
export const usePanZoom = (): PanZoomRef => {
const element = React.useContext(ElementContext);
if (!isGraph(element)) {
throw new Error('usePanZoom must be used within the scope of a Graph');
}
const elementRef = React.useRef(element);
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure you need to do the as Graph on the current. You can just type the useRef and the isGraph does the type-guard.

Suggested change
const elementRef = React.useRef(element);
const elementRef = React.useRef<Graph>(element);

@openshift-ci-robot openshift-ci-robot added lgtm Indicates that a PR is ready to be merged. bugzilla/severity-unspecified Referenced Bugzilla bug's severity is unspecified for the PR. and removed bugzilla/unspecified labels Apr 23, 2020
}
const zoom = d3
.zoom()
.scaleExtent([elementRef.current.getMinScale(), elementRef.current.getMaxScale()])
Copy link
Contributor

Choose a reason for hiding this comment

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

This behavior needs to track changes to the min and max scales and ensure that the new extent is set when one of these values change.

Comment on lines 140 to 143
setScale(scale: number): void {
this.scale = scale;
this.scale = Math.max(Math.min(scale, this.maxScale), this.minScale);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Thought we decided that a user should be able to set the scale to anything.
Currently if we use the fit to screen option on a very spread out visualization, panning the graph will reset the scale because the behavior is using setScale.

Comment on lines 28 to 30
private minScale: number = 0.25;

private maxScale: number = 4;
Copy link
Contributor

Choose a reason for hiding this comment

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

These need to be observable

Comment on lines 58 to 60
setMinScale(min: number): void {
this.minScale = min;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we ensure that min < max?
Although this kind of validation may be problematic when using two separate values vs an array extent such as [number, number] because when trying to set new values, you'll have to pay attention to the order in which they are set otherwise an error can be thrown ;/

Still unsure if i prefer an array extent over individual values.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmmm... guess it would be better to make it an array.

@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Apr 30, 2020
@christianvogt
Copy link
Contributor

/lgtm
/approve

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Apr 30, 2020
@openshift-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: andrewballantyne, christianvogt, jeff-phillips-18

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 30, 2020
@openshift-merge-robot openshift-merge-robot merged commit da555f1 into openshift:master Apr 30, 2020
@openshift-ci-robot
Copy link
Contributor

@jeff-phillips-18: All pull requests linked via external trackers have merged: openshift/console#5160. Bugzilla bug 1826962 has been moved to the MODIFIED state.

In response to this:

Bug 1826962: Limit the amount a user can zoom in/out in topology

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openshift-ci-robot
Copy link
Contributor

@jeff-phillips-18: The following test failed, say /retest to rerun all failed tests:

Test name Commit Details Rerun command
ci/prow/e2e-gcp-console 5fa8d41 link /test e2e-gcp-console

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@spadgett spadgett added this to the v4.5 milestone May 1, 2020
@jeff-phillips-18 jeff-phillips-18 deleted the zoom-extents branch December 2, 2020 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. bugzilla/severity-unspecified Referenced Bugzilla bug's severity is unspecified for the PR. bugzilla/valid-bug Indicates that a referenced Bugzilla bug is valid for the branch this PR is targeting. component/dev-console Related to dev-console kind/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants