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

fix: overwriting flyout def with dynamic categories #6913

Merged
merged 3 commits into from
Mar 22, 2023

Conversation

BeksOmega
Copy link
Collaborator

The basics

  • I branched from develop
  • My pull request is against develop
  • My code follows the style guide
  • I ran npm run format and npm run lint

The details

Resolves

Fixes #4443

Proposed Changes

Stops mutating the toolbox definition when parsing dynamic categories.

Reason for Changes

See explanation in #4443

Test Coverage

Manual testing.

Can add unit testing after we confirm this is the behavior we actually want.

Documentation

N/A

Additional Information

Do we actually want flyout toolboxes to parse the dynamic categories? I kind of understand it in that you might want to embed variables / procedures in your flyout toolbox. But it also just seems.... weird?

Just want to confirm this before adding unit tests / merging.

@BeksOmega BeksOmega requested a review from a team as a code owner March 20, 2023 22:13
@BeksOmega BeksOmega requested a review from cpcallen March 20, 2023 22:13
@github-actions github-actions bot added the PR: fix Fixes a bug label Mar 20, 2023
Copy link
Contributor

@cpcallen cpcallen left a comment

Choose a reason for hiding this comment

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

This looks fine, though it took me far too long to understand what was going on: my brain misparsed things and matched the } following return; at the end of the first if block in createItem as if it was the end of createItem, and I was deeply confused about why this helper function seemed to neither return a value nor have side effects.

I'm not sure if there's a good way to improve this code without breaking compatibility, but I think ideally there'd only be a single (top-level) function which recurses by calling itself.

Failing that, some comments noting that createFlyoutInfo_ is more or less just a nonrecursive wrapper for createInfo, and that the latter does all the heavy lifting, might make this easier for newcomers to understand.

const categoryName = customInfo['custom'];
const flyoutDef = this.getDynamicCategoryContents_(categoryName);
const parsedDynamicContent =
toolbox.convertFlyoutDefToJsonArray(flyoutDef);
// Replace the element at i with the dynamic content it represents.
parsedContent.splice.apply(
parsedContent, [i, 1, ...parsedDynamicContent]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Aaaargh! I'm glad this monstrosity is gone. I can understand how we got here, but who decided to keep the apply around once we got the spread operator??: parsedContent.splice(i, 1, ...parsedDynamicContent)!

@BeksOmega BeksOmega merged commit 01ecf54 into google:develop Mar 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: fix Fixes a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Flyout.show changes flyout definition.
2 participants