forked from Cloud-Pipelines/pipeline-editor
-
Notifications
You must be signed in to change notification settings - Fork 6
feat: Onboarding Pill #2440
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
Open
camielvs
wants to merge
1
commit into
06-17-feat_onboarding_checklist
Choose a base branch
from
06-18-feat_onboarding_pill
base: 06-17-feat_onboarding_checklist
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.
Open
feat: Onboarding Pill #2440
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import { cleanup, render, screen } from "@testing-library/react"; | ||
| import type { ReactNode } from "react"; | ||
| import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; | ||
|
|
||
| import { OnboardingNavPill } from "./OnboardingNavPill"; | ||
|
|
||
| vi.mock("@tanstack/react-router", () => ({ | ||
| Link: ({ children }: { children: ReactNode }) => <a>{children}</a>, | ||
| })); | ||
|
|
||
| let onboarding = { | ||
| steps: [], | ||
| completedCount: 1, | ||
| total: 4, | ||
| isComplete: false, | ||
| dismissed: false, | ||
| isResolved: true, | ||
| markDocsRead: vi.fn(), | ||
| }; | ||
| vi.mock("@/providers/OnboardingProvider/OnboardingProvider", () => ({ | ||
| useOnboarding: () => onboarding, | ||
| })); | ||
|
|
||
| function resetState() { | ||
| onboarding = { | ||
| steps: [], | ||
| completedCount: 1, | ||
| total: 4, | ||
| isComplete: false, | ||
| dismissed: false, | ||
| isResolved: true, | ||
| markDocsRead: vi.fn(), | ||
| }; | ||
| } | ||
|
|
||
| beforeEach(resetState); | ||
| afterEach(cleanup); | ||
|
|
||
| const pill = () => screen.queryByText(/Onboarding/); | ||
|
|
||
| describe("OnboardingNavPill", () => { | ||
| it("shows progress while onboarding is in progress", () => { | ||
| render(<OnboardingNavPill />); | ||
| expect(pill()).toHaveTextContent("Onboarding · 1/4"); | ||
| }); | ||
|
|
||
| it("is hidden once onboarding is complete", () => { | ||
| onboarding.isComplete = true; | ||
| render(<OnboardingNavPill />); | ||
| expect(pill()).toBeNull(); | ||
| }); | ||
|
|
||
| it("is hidden once onboarding is dismissed", () => { | ||
| onboarding.dismissed = true; | ||
| render(<OnboardingNavPill />); | ||
| expect(pill()).toBeNull(); | ||
| }); | ||
| }); |
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 |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import { OnboardingChecklist } from "@/components/Onboarding/OnboardingChecklist"; | ||
| import { Button } from "@/components/ui/button"; | ||
| import { Icon } from "@/components/ui/icon"; | ||
| import { BlockStack } from "@/components/ui/layout"; | ||
| import { | ||
| Popover, | ||
| PopoverContent, | ||
| PopoverTrigger, | ||
| } from "@/components/ui/popover"; | ||
| import { Heading } from "@/components/ui/typography"; | ||
| import { useOnboarding } from "@/providers/OnboardingProvider/OnboardingProvider"; | ||
| import { tracking } from "@/utils/tracking"; | ||
|
|
||
| export function OnboardingNavPill() { | ||
| const { completedCount, total, isComplete, dismissed, isResolved } = | ||
| useOnboarding(); | ||
|
|
||
| if (!isResolved || isComplete || dismissed) { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <Popover> | ||
| <PopoverTrigger asChild {...tracking("navigation.onboarding_pill")}> | ||
| <Button variant="nav" size="sm" shape="pill"> | ||
| <Icon name="Rocket" size="sm" aria-hidden="true" /> | ||
| Onboarding · {completedCount}/{total} | ||
| </Button> | ||
| </PopoverTrigger> | ||
| <PopoverContent align="end" className="w-96"> | ||
| <BlockStack gap="3"> | ||
| <Heading level={3}>Get started with Tangle</Heading> | ||
| <OnboardingChecklist /> | ||
| </BlockStack> | ||
| </PopoverContent> | ||
| </Popover> | ||
| ); | ||
| } |
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
57 changes: 57 additions & 0 deletions
57
src/providers/OnboardingProvider/onboardingCompletion.test.ts
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 |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
|
|
||
| import { | ||
| completedStepIds, | ||
| newlyCompletedIds, | ||
| stepLabel, | ||
| } from "./onboardingCompletion"; | ||
| import { ONBOARDING_STEPS } from "./steps"; | ||
|
|
||
| describe("completedStepIds", () => { | ||
| it("returns completed ids in canonical order", () => { | ||
| expect( | ||
| completedStepIds({ | ||
| read_docs: true, | ||
| complete_tour: false, | ||
| create_pipeline: true, | ||
| execute_run: false, | ||
| }), | ||
| ).toEqual(["read_docs", "create_pipeline"]); | ||
| }); | ||
|
|
||
| it("returns an empty array when nothing is complete", () => { | ||
| expect( | ||
| completedStepIds({ | ||
| read_docs: false, | ||
| complete_tour: false, | ||
| create_pipeline: false, | ||
| execute_run: false, | ||
| }), | ||
| ).toEqual([]); | ||
| }); | ||
| }); | ||
|
|
||
| describe("newlyCompletedIds", () => { | ||
| it("returns ids present in current but not previous", () => { | ||
| expect( | ||
| newlyCompletedIds( | ||
| new Set(["read_docs"]), | ||
| new Set(["read_docs", "execute_run"]), | ||
| ), | ||
| ).toEqual(["execute_run"]); | ||
| }); | ||
|
|
||
| it("returns empty when nothing newly completed", () => { | ||
| expect( | ||
| newlyCompletedIds(new Set(["read_docs"]), new Set(["read_docs"])), | ||
| ).toEqual([]); | ||
| }); | ||
| }); | ||
|
|
||
| describe("stepLabel", () => { | ||
| it("resolves the label for a known step", () => { | ||
| expect(stepLabel("read_docs")).toBe( | ||
| ONBOARDING_STEPS.find((step) => step.id === "read_docs")?.label, | ||
| ); | ||
| }); | ||
| }); |
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 |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import type { OnboardingSteps } from "./onboardingProgress"; | ||
| import { | ||
| ONBOARDING_STEP_IDS, | ||
| ONBOARDING_STEPS, | ||
| type OnboardingStepId, | ||
| } from "./steps"; | ||
|
|
||
| export function completedStepIds(steps: OnboardingSteps): OnboardingStepId[] { | ||
| return ONBOARDING_STEP_IDS.filter((id) => steps[id]); | ||
| } | ||
|
|
||
| export function newlyCompletedIds( | ||
| previous: ReadonlySet<OnboardingStepId>, | ||
| current: ReadonlySet<OnboardingStepId>, | ||
| ): OnboardingStepId[] { | ||
| return [...current].filter((id) => !previous.has(id)); | ||
| } | ||
|
|
||
| export function stepLabel(id: OnboardingStepId): string | undefined { | ||
| return ONBOARDING_STEPS.find((step) => step.id === id)?.label; | ||
| } |
51 changes: 51 additions & 0 deletions
51
src/providers/OnboardingProvider/useStepCompletionToasts.ts
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 |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import { useEffect, useRef } from "react"; | ||
|
|
||
| import useToastNotification from "@/hooks/useToastNotification"; | ||
|
|
||
| import { | ||
| completedStepIds, | ||
| newlyCompletedIds, | ||
| stepLabel, | ||
| } from "./onboardingCompletion"; | ||
| import type { OnboardingSteps } from "./onboardingProgress"; | ||
| import type { OnboardingStepId } from "./steps"; | ||
|
|
||
| interface UseStepCompletionToastsArgs { | ||
| isResolved: boolean; | ||
| desiredSteps: OnboardingSteps; | ||
| isComplete: boolean; | ||
| } | ||
|
|
||
| /** | ||
| * Fires a toast the first time each step flips to complete (and a single | ||
| * "all set up" toast once everything is done). The first resolved render | ||
| * only seeds the baseline, so already-complete steps don't toast on mount. | ||
| */ | ||
| export function useStepCompletionToasts({ | ||
| isResolved, | ||
| desiredSteps, | ||
| isComplete, | ||
| }: UseStepCompletionToastsArgs) { | ||
| const notify = useToastNotification(); | ||
| const previousRef = useRef<Set<OnboardingStepId> | null>(null); | ||
|
|
||
| useEffect(() => { | ||
| if (!isResolved) return; | ||
| const current = new Set(completedStepIds(desiredSteps)); | ||
| const previous = previousRef.current; | ||
| previousRef.current = current; | ||
| if (previous === null) return; | ||
|
|
||
| const newly = newlyCompletedIds(previous, current); | ||
| if (newly.length === 0) return; | ||
|
|
||
| if (isComplete) { | ||
| notify("You're all set up - onboarding complete!", "success"); | ||
| return; | ||
| } | ||
| for (const id of newly) { | ||
| const label = stepLabel(id); | ||
| if (label) notify(`Completed: ${label}`, "success"); | ||
| } | ||
| }, [isResolved, desiredSteps, isComplete, notify]); | ||
| } |
Oops, something went wrong.
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.