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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions core/flyout_base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -570,9 +570,9 @@ export abstract class Flyout extends DeleteArea implements IFlyout {
this.workspace_.removeChangeListener(this.reflowWrapper_);
this.reflowWrapper_ = null;
}
// Do NOT delete the blocks here. Wait until Flyout.show.
// https://neil.fraser.name/news/2014/08/09/
}
// Do NOT delete the blocks here. Wait until Flyout.show.
// https://neil.fraser.name/news/2014/08/09/

/**
* Show and populate the flyout.
Expand Down Expand Up @@ -630,49 +630,50 @@ export abstract class Flyout extends DeleteArea implements IFlyout {
const gaps: number[] = [];
this.permanentlyDisabled_.length = 0;
const defaultGap = this.horizontalLayout ? this.GAP_X : this.GAP_Y;
for (let i = 0, contentInfo; contentInfo = parsedContent[i]; i++) {
if ('custom' in contentInfo) {
const customInfo = (contentInfo as toolbox.DynamicCategoryInfo);
for (const info of parsedContent) {
if ('custom' in info) {
const customInfo = (info as toolbox.DynamicCategoryInfo);
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)!

contentInfo = parsedContent[i];
const {contents: dynamicContents, gaps: dynamicGaps} =
this.createFlyoutInfo_(parsedDynamicContent);
contents.push(...dynamicContents);
gaps.push(...dynamicGaps);
}

switch (contentInfo['kind'].toUpperCase()) {
switch (info['kind'].toUpperCase()) {
case 'BLOCK': {
const blockInfo = (contentInfo as toolbox.BlockInfo);
const blockInfo = (info as toolbox.BlockInfo);
const block = this.createFlyoutBlock_(blockInfo);
contents.push({type: FlyoutItemType.BLOCK, block: block});
this.addBlockGap_(blockInfo, gaps, defaultGap);
break;
}
case 'SEP': {
const sepInfo = (contentInfo as toolbox.SeparatorInfo);
const sepInfo = (info as toolbox.SeparatorInfo);
this.addSeparatorGap_(sepInfo, gaps, defaultGap);
break;
}
case 'LABEL': {
const labelInfo = (contentInfo as toolbox.LabelInfo);
const labelInfo = (info as toolbox.LabelInfo);
// A label is a button with different styling.
const label = this.createButton_(labelInfo, /** isLabel */ true);
contents.push({type: FlyoutItemType.BUTTON, button: label});
gaps.push(defaultGap);
break;
}
case 'BUTTON': {
const buttonInfo = (contentInfo as toolbox.ButtonInfo);
const buttonInfo = (info as toolbox.ButtonInfo);
const button = this.createButton_(buttonInfo, /** isLabel */ false);
contents.push({type: FlyoutItemType.BUTTON, button: button});
gaps.push(defaultGap);
break;
}
}
}

return {contents: contents, gaps: gaps};
}

Expand Down