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

mrc-5443 Copy variable on drag if Ctrl key is pressed #214

Merged
merged 7 commits into from
Aug 16, 2024

Conversation

EmmaLRussell
Copy link
Contributor

@EmmaLRussell EmmaLRussell commented Aug 2, 2024

If user presses Ctrl (or ⌘) key when dragging variabe to another graph, this makes a copy so graph is retained in the source as well as being added to target.

Dragging to or from Hidden variables ignore Ctrl key.

Now that we can have variables on multiple graphs, this also means that we have to make good on the text "Drag variables here to hide them on all graphs" on Hidden variables, so we search all graph configs for variable to hide rather than just removing from source.

It's not very clear to me why, but I found I now had to specify start and end positions in the e2e drag variable tests. Perhaps something to do with the text change in the drop area meaning the text wraps and height is increased in the default page size? Very odd!

@EmmaLRussell EmmaLRussell changed the base branch from mrc-5545 to mrc-5490 August 6, 2024 08:19
@EmmaLRussell EmmaLRussell marked this pull request as ready for review August 6, 2024 08:47
@@ -19,11 +19,13 @@ export default (
const thisSrcGraphConfig = hasHiddenVariables ? "hidden" : graphIndex!.toString();

const startDrag = (evt: DragEvent, variable: string) => {
const { dataTransfer } = evt;
const { dataTransfer, ctrlKey, metaKey } = evt;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I dislike having to think to work out what abbreviations stand for - had to go back a line to decipher whether evt meant event or environment

Comment on lines 97 to 102
expect(setData.mock.calls[0][0]).toBe("variable");
expect(setData.mock.calls[0][1]).toStrictEqual("S");
expect(setData.mock.calls[1][0]).toStrictEqual("srcGraphConfig");
expect(setData.mock.calls[1][1]).toStrictEqual("0");
expect(setData.mock.calls[2][0]).toBe("copyVar");
expect(setData.mock.calls[2][1]).toBe("false");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
expect(setData.mock.calls[0][0]).toBe("variable");
expect(setData.mock.calls[0][1]).toStrictEqual("S");
expect(setData.mock.calls[1][0]).toStrictEqual("srcGraphConfig");
expect(setData.mock.calls[1][1]).toStrictEqual("0");
expect(setData.mock.calls[2][0]).toBe("copyVar");
expect(setData.mock.calls[2][1]).toBe("false");
expect(setData.mock.calls[0].slice(0, 2)).toBe(["variable", "S"]);
expect(setData.mock.calls[1].slice(0, 2)).toBe(["srcGraphConfig", "0"]);
expect(setData.mock.calls[2].slice(0, 2)).toBe(["copyVar", "false"]);

Easier to read, if it works? Now I can see that copyVar is meant to relate to "false".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That doesn't quite work, but toHaveBeenNthCalledWith gives us much the same thing, so switching to that.

Comment on lines 157 to 168
if (s === "copyVar") return "false";
return null;
}
};
const dropPanel = wrapper.find(".graph-config-panel");
await dropPanel.trigger("drop", { dataTransfer });
expect(mockUpdateSelectedVariables.mock.calls.length).toBe(1);
expect(mockUpdateSelectedVariables.mock.calls[0][1]).toStrictEqual({
graphIndex: 0,
selectedVariables: ["S", "R", "I"]
});
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we hold down a ctrl/meta key here, to show that trying to copy a hidden variable on dragging doesn't end up with it existing in both places (hiddens and drag target)

Copy link
Collaborator

@M-Kusumgar M-Kusumgar left a comment

Choose a reason for hiding this comment

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

This works well and feels very intuitive to use. Also had no idea that key was called meta

@EmmaLRussell EmmaLRussell merged commit e9bb88c into mrc-5490 Aug 16, 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.

3 participants