Skip to content

Commit d6e5148

Browse files
authored
fix error help on collapsed (microsoft#11075)
* fix targetting for error help when block is collapsed * actually just uncollapse block to show where it's pointing * forgot to push pxtarget.d.ts
1 parent e62c465 commit d6e5148

3 files changed

Lines changed: 29 additions & 4 deletions

File tree

‎localtypings/pxtarget.d.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,6 +1374,7 @@ declare namespace pxt.tour {
13741374
sansQuery?: string; // Use this to exclude an element from the cutout
13751375
sansLocation?: BubbleLocation; // relative location of element to exclude
13761376
onStepBegin?: () => void;
1377+
onStepEnd?: () => void;
13771378
bubbleStyle?: "yellow"; // Currently just have default (unset) & yellow styles. May add more in the future...
13781379
}
13791380
interface TourConfig {

‎react-common/components/controls/TeachingBubble.tsx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ export const TeachingBubble = (props: TeachingBubbleProps) => {
7272
positionBubbleAndCutout();
7373
window.addEventListener("resize", positionBubbleAndCutout);
7474
return () => {
75+
if (targetContent.onStepEnd) {
76+
targetContent.onStepEnd();
77+
}
7578
window.removeEventListener("resize", positionBubbleAndCutout);
7679
}
7780
}, [stepNumber, targetContent]);

‎webapp/src/blocks.tsx‎

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,8 +1200,6 @@ export class Editor extends toolboxeditor.ToolboxEditor {
12001200
* ensuring all provided ids are valid and setting up the corresponding target queries.
12011201
*/
12021202
private createTourFromResponse = (response: ErrorHelpTourResponse): pxt.tour.TourConfig => {
1203-
const validBlockIds = this.parent.getBlocks().map((b) => b.id);
1204-
12051203
const tourSteps: pxt.tour.BubbleStep[] = [];
12061204
let invalidBlockIdCount = 0;
12071205
for (const step of response.explanationSteps) {
@@ -1213,10 +1211,24 @@ export class Editor extends toolboxeditor.ToolboxEditor {
12131211
} as pxt.tour.BubbleStep;
12141212

12151213
if (step.elementId) {
1216-
if (validBlockIds.includes(step.elementId)) {
1214+
const targetBlock = this.editor?.getBlockById(step.elementId);
1215+
if (targetBlock) {
1216+
const targetBlockRoot = targetBlock.getRootBlock();
1217+
const isInsideCollapsedBlock = targetBlockRoot.isCollapsed() && targetBlockRoot.id !== step.elementId;
12171218
tourStep.targetQuery = `g[data-id="${step.elementId}"]:not(.blocklyFlyout g)`;
12181219
tourStep.location = pxt.tour.BubbleLocation.Right;
1219-
tourStep.onStepBegin = () => this.editor.centerOnBlock(step.elementId, true);
1220+
1221+
tourStep.onStepBegin = () => {
1222+
if (isInsideCollapsedBlock) {
1223+
targetBlockRoot.setCollapsed(false);
1224+
targetBlockRoot.bringToFront();
1225+
targetBlockRoot.render();
1226+
}
1227+
this.editor.centerOnBlock(step.elementId, true);
1228+
};
1229+
if (isInsideCollapsedBlock) {
1230+
tourStep.onStepEnd = () => targetBlockRoot.setCollapsed(true);
1231+
}
12201232
} else {
12211233
// Do not add the tour target, but keep the step in case it's still helpful.
12221234
pxt.tickEvent("errorHelp.invalidBlockId");
@@ -1239,6 +1251,15 @@ export class Editor extends toolboxeditor.ToolboxEditor {
12391251
};
12401252
}
12411253

1254+
private getVisibleBlockAncestorId(blockId: string): string | undefined {
1255+
const block = this.editor?.getBlockById(blockId) as Blockly.BlockSvg;
1256+
const rootBlock = block?.getRootBlock() as Blockly.BlockSvg;
1257+
if (!block || !rootBlock) {
1258+
return undefined;
1259+
}
1260+
return rootBlock.isCollapsed() ? rootBlock.id : blockId;
1261+
}
1262+
12421263
private handleErrorHelpFeedback(positive: boolean, responseData: any) {
12431264
pxt.tickEvent("errorHelp.feedback", { ...responseData, positive: positive + "" });
12441265
}

0 commit comments

Comments
 (0)