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

feat: Add 'reason' field to move event #6996

Merged
merged 3 commits into from
Apr 25, 2023
Merged

feat: Add 'reason' field to move event #6996

merged 3 commits into from
Apr 25, 2023

Conversation

NeilFraser
Copy link
Contributor

There are many types of move. This addition allows one to detect what the reason for each move is.

There are many types of move.  This addition allows one to detect what the reason for each move is.
@NeilFraser NeilFraser requested a review from a team as a code owner April 20, 2023 18:16
@NeilFraser NeilFraser requested a review from maribethb April 20, 2023 18:16
@github-actions github-actions bot added the PR: feature Adds a feature label Apr 20, 2023
And unsaved editor tabs.
* 'cleanup' -- Workspace aligned top-level blocks.
* Reasons may become comma separated if move events merge ('drag,bump,snap').
*/
reason?: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we make the list of reasons an enum? It would mean we get compile-time errors if we e.g. misspell inbounds or try to add a variation like in-bounds, plus give us autocomplete.

Also, can we have the reason property in the event be an array of reasons, instead of a single string with commas? That would be simpler for consumers of this property instead of having to parse the string into an array themselves.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think an enum would allow developers to create new reasons. Imagine an extension or application which, say, shuffled blocks around randomly to create a puzzle. They should be able to create a custom reason (e.g. 'shuffle').

Changed all reasons to be arrays.

* 'inbounds' -- Block got pushed back into a non-scrolling workspace.
* 'connect' -- Block got connected to another block.
* 'disconnect' -- Block got disconnected from another block.
* 'create' -- Block created via XML.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Block created via deserialization? (since I assume this would also apply for blocks created json?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I assumed the same, but there are no move events fired when deserializing from JSON, just when using XML.

@@ -290,6 +290,17 @@ export function filter(queueIn: Abstract[], forward: boolean): Abstract[] {
lastEvent.newParentId = moveEvent.newParentId;
lastEvent.newInputName = moveEvent.newInputName;
lastEvent.newCoordinate = moveEvent.newCoordinate;
if (moveEvent.reason) {
if (lastEvent.reason) {
// Contatenate reasons into a comma separated string
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Concatenate (if this comment still exists pending comment re: using an array)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@NeilFraser NeilFraser merged commit 64aa3e7 into develop Apr 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: feature Adds a feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants