Skip to content

Commit 4efc049

Browse files
ryantremCopilot
andauthored
Add an option to disable teaching moments (BabylonJS#18508)
> 🤖 *This PR was created by the create-pr skill.* Adds a new `disableTeachingMoments` option to `ModularToolOptions` (and therefore `InspectorOptions`) that suppresses all teaching moments rendered by the modular tool, regardless of each teaching moment's individual `suppress` state. ## Changes - New `TeachingMomentsContext` (in `sharedUiComponents/src/modularTool/contexts/teachingMomentsContext.ts`) exposing a `disabled` flag. - `MakeModularTool` now accepts a `disableTeachingMoments?: boolean` option and wraps the rendered tree in a `TeachingMomentsContext.Provider`. - `MakeTeachingMoment` consumes the context and ORs the context's `disabled` flag with the caller-provided `suppress` flag. - `ShowInspector` forwards `options.disableTeachingMoments` through to `MakeModularTool` so inspector hosts can opt out of teaching moments. ## Motivation Addresses a forum request from a user embedding the inspector in their own app who wants a parameter in `ShowInspector` to turn off the teaching-moment "bubbles" that appear the first time the inspector opens in a session: https://forum.babylonjs.com/t/introducing-inspector-v2/60937/223 With this option, host apps can call `ShowInspector(scene, { disableTeachingMoments: true })` to globally suppress teaching moments. --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 4c80d48 commit 4efc049

4 files changed

Lines changed: 139 additions & 108 deletions

File tree

packages/dev/inspector-v2/src/inspector.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@ export function ShowInspector(scene: Scene, options: Partial<InspectorOptions> =
430430
sidePaneRemapper: options.sidePaneRemapper,
431431
leftPaneDefaultCollapsed: options.leftPaneDefaultCollapsed,
432432
rightPaneDefaultCollapsed: options.rightPaneDefaultCollapsed,
433+
disableTeachingMoments: options.disableTeachingMoments,
433434
});
434435
disposeActions.push(async () => await modularTool.dispose());
435436

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { createContext, useContext } from "react";
2+
3+
type TeachingMomentsContext = {
4+
/**
5+
* When true, all teaching moments are suppressed regardless of any caller-supplied
6+
* `suppress` argument and regardless of whether the user has previously dismissed
7+
* the teaching moment.
8+
*/
9+
disabled: boolean;
10+
};
11+
12+
export const TeachingMomentsContext = createContext<TeachingMomentsContext>({ disabled: false });
13+
14+
/**
15+
* Returns the teaching moments context provided by the surrounding modular tool framework.
16+
* @returns The current teaching moments context.
17+
*/
18+
export function useTeachingMomentsContext(): TeachingMomentsContext {
19+
return useContext(TeachingMomentsContext);
20+
}

packages/dev/sharedUiComponents/src/modularTool/hooks/teachingMomentHooks.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { type OnOpenChangeData, type PositioningImperativeRef } from "@fluentui/
44

55
import { useCallback, useEffect, useRef, useState } from "react";
66
import { useSetting } from "./settingsHooks";
7+
import { useTeachingMomentsContext } from "../contexts/teachingMomentsContext";
78

89
import { AsyncLock } from "core/Misc/asyncLock";
910
import { Deferred } from "core/Misc/deferred";
@@ -17,6 +18,8 @@ const SequencerLock = new AsyncLock();
1718
*/
1819
export function MakeTeachingMoment(name: string) {
1920
return (suppress?: boolean) => {
21+
const { disabled } = useTeachingMomentsContext();
22+
suppress = suppress || disabled;
2023
const [hasDisplayed, setHasDisplayed, resetDisplayed] = useSetting({ key: `TeachingMoments/${name}`, defaultValue: false });
2124
const [shouldDisplay, setShouldDisplay] = useState(false);
2225

0 commit comments

Comments
 (0)