forked from Cloud-Pipelines/pipeline-editor
-
Notifications
You must be signed in to change notification settings - Fork 6
feat: Guided Tours Framework (Navigating the Editor) #2299
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
Draft
camielvs
wants to merge
1
commit into
05-28-feat_save_and_resume_paused_tours
Choose a base branch
from
05-20-feat_learning_hub_tour_framework_and_first_tour
base: 05-28-feat_save_and_resume_paused_tours
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+198
−7
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
178 changes: 178 additions & 0 deletions
178
src/routes/v2/pages/Editor/components/EditorTourBridge.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,181 @@ | ||
| import { useTour } from "@reactour/tour"; | ||
| import { reaction } from "mobx"; | ||
| import { useEffect } from "react"; | ||
|
|
||
| import type { TourStep } from "@/components/Learn/tours/registry"; | ||
| import { useTourProgress } from "@/providers/TourProvider/TourProgressContext"; | ||
| import { useSharedStores } from "@/routes/v2/shared/store/SharedStoreContext"; | ||
| import type { WindowStoreImpl } from "@/routes/v2/shared/windows/windowStore"; | ||
|
|
||
| function followWindowPosition( | ||
| windows: WindowStoreImpl, | ||
| targetWindowId: string | undefined, | ||
| ): () => void { | ||
| if (!targetWindowId) return () => undefined; | ||
|
|
||
| let rafId: number | null = null; | ||
| const dispose = reaction( | ||
| () => { | ||
| const w = windows.getWindowById(targetWindowId); | ||
| return w ? `${w.position.x},${w.position.y}` : ""; | ||
| }, | ||
| () => { | ||
| if (rafId !== null) return; | ||
| rafId = requestAnimationFrame(() => { | ||
| rafId = null; | ||
| window.dispatchEvent(new Event("resize")); | ||
| }); | ||
| }, | ||
| ); | ||
|
|
||
| return () => { | ||
| dispose(); | ||
| if (rafId !== null) cancelAnimationFrame(rafId); | ||
| }; | ||
| } | ||
|
|
||
| function trackDockStateTransition( | ||
| windows: WindowStoreImpl, | ||
| matchInitial: (w: { dockState: string }) => boolean, | ||
| matchTransition: (w: { dockState: string }) => boolean, | ||
| targetWindowId?: string, | ||
| ): { didTransition: () => boolean; dispose: () => void } { | ||
| const baseline = new Set<string>(); | ||
| for (const w of windows.getAllWindows()) { | ||
| if (targetWindowId ? w.id === targetWindowId : matchInitial(w)) { | ||
| baseline.add(w.id); | ||
| } | ||
| } | ||
| let fired = false; | ||
|
|
||
| const stateReaction = reaction( | ||
| () => | ||
| windows | ||
| .getAllWindows() | ||
| .map((w) => `${w.id}:${w.dockState}`) | ||
| .join("|"), | ||
| () => { | ||
| for (const w of windows.getAllWindows()) { | ||
| if (targetWindowId) { | ||
| if (w.id === targetWindowId && matchTransition(w)) { | ||
| fired = true; | ||
| } | ||
| continue; | ||
| } | ||
| if (matchInitial(w)) { | ||
| baseline.add(w.id); | ||
| } else if (baseline.has(w.id) && matchTransition(w)) { | ||
| fired = true; | ||
| } | ||
| } | ||
| }, | ||
| ); | ||
|
|
||
| return { | ||
| didTransition: () => fired, | ||
| dispose: stateReaction, | ||
| }; | ||
| } | ||
|
|
||
| export function EditorTourBridge() { | ||
| const { steps, currentStep, isOpen } = useTour(); | ||
| const { windows } = useSharedStores(); | ||
| const { markStepComplete } = useTourProgress(); | ||
|
|
||
| const step = steps[currentStep] as TourStep | undefined; | ||
| const interaction = step?.interaction; | ||
| const targetWindowId = step?.targetWindowId; | ||
|
|
||
| useEffect(() => { | ||
| if (!isOpen) return undefined; | ||
|
|
||
| // Run outside the interaction branch so informational/fallback steps that | ||
| // target a floating window still track its position. | ||
| const stopFollow = followWindowPosition(windows, targetWindowId); | ||
|
|
||
| if (!interaction) return stopFollow; | ||
|
|
||
| // Gated progression: completing the interaction (or finding it already | ||
| // satisfied on entry) marks the step done so "Next" enables. Advancing is | ||
| // the user's click, handled by the popover. | ||
| const advance = () => markStepComplete(currentStep); | ||
| const skip = () => markStepComplete(currentStep); | ||
| const skipWithFallback = (_step: TourStep) => markStepComplete(currentStep); | ||
|
camielvs marked this conversation as resolved.
|
||
|
|
||
| if (interaction === "undock-window" || interaction === "redock-window") { | ||
| const isDocked = (w: { dockState: string }) => w.dockState !== "none"; | ||
| const isUndocked = (w: { dockState: string }) => w.dockState === "none"; | ||
| const matchInitial = | ||
| interaction === "undock-window" ? isDocked : isUndocked; | ||
| const matchTransition = | ||
| interaction === "undock-window" ? isUndocked : isDocked; | ||
|
|
||
| if (targetWindowId) { | ||
| const target = windows.getWindowById(targetWindowId); | ||
| if (!target || matchTransition(target)) { | ||
| skipWithFallback(step); | ||
| return stopFollow; | ||
| } | ||
| } else { | ||
| const hasSourceWindow = windows | ||
| .getAllWindows() | ||
| .some((w) => w.state !== "hidden" && matchInitial(w)); | ||
| if (!hasSourceWindow) { | ||
| if (step) skipWithFallback(step); | ||
| else skip(); | ||
| return stopFollow; | ||
| } | ||
| } | ||
|
|
||
| const tracker = trackDockStateTransition( | ||
| windows, | ||
| matchInitial, | ||
| matchTransition, | ||
| targetWindowId, | ||
| ); | ||
|
|
||
| let pendingCheck: ReturnType<typeof setTimeout> | null = null; | ||
| const handleMouseUp = () => { | ||
| if (pendingCheck !== null) clearTimeout(pendingCheck); | ||
| pendingCheck = setTimeout(() => { | ||
| pendingCheck = null; | ||
| if (tracker.didTransition()) advance(); | ||
| }, 0); | ||
| }; | ||
| document.addEventListener("mouseup", handleMouseUp); | ||
|
|
||
| return () => { | ||
| stopFollow(); | ||
| tracker.dispose(); | ||
| if (pendingCheck !== null) clearTimeout(pendingCheck); | ||
| document.removeEventListener("mouseup", handleMouseUp); | ||
| }; | ||
| } | ||
|
|
||
| if (interaction === "select-task") { | ||
| const handleClick = (event: MouseEvent) => { | ||
| const target = event.target as Element | null; | ||
| if (target?.closest(".react-flow__node")) { | ||
|
camielvs marked this conversation as resolved.
|
||
| advance(); | ||
| } | ||
| }; | ||
| document.addEventListener("click", handleClick); | ||
| return () => { | ||
| stopFollow(); | ||
| document.removeEventListener("click", handleClick); | ||
| }; | ||
| } | ||
|
|
||
| return stopFollow; | ||
| }, [ | ||
| isOpen, | ||
| interaction, | ||
| targetWindowId, | ||
| step, | ||
| windows, | ||
| markStepComplete, | ||
| currentStep, | ||
| ]); | ||
|
|
||
| return null; | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.