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

Add "Hide Done" Option for Tutorials #10248

Merged
merged 5 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
8 changes: 8 additions & 0 deletions docs/writing-docs/tutorials/control-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ For text-based tutorials, you can choose to hide the toolbox altogether. This is
### @hideToolbox true
```

### Hide Done

If you do not wish for your tutorial's final step to display a "Done" button, which sends the user back to the main editor, you can hide it by specifying **@hideDone** in the metadata. The default is ``false``.

```
### @hideDone true
```

## Special blocks

### Templates
Expand Down
1 change: 1 addition & 0 deletions localtypings/pxtarget.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1205,6 +1205,7 @@ declare namespace pxt.tutorial {
codeStop?: string; // command to run when code stops (MINECRAFT HOC ONLY)
autoexpandOff?: boolean; // INTERNAL TESTING ONLY
preferredEditor?: string; // preferred editor for opening the tutorial
hideDone?: boolean; // Do not show a "Done" button at the end of the tutorial
}

interface TutorialBlockConfigEntry {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@
"test:err": "gulp testerr",
"test:fmt": "gulp testfmt",
"test:lang": "gulp testlang",
"test:tutorials": "gulp testtutorials",
"update": "gulp update",
"watch-streamer": "cd docs/static/streamer && tsc -t es6 --watch",
"prepare": "node ./scripts/npm-prepare.js",
Expand Down
23 changes: 23 additions & 0 deletions tests/tutorial-test/baselines/hideDone.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"editor": "blocksprj",
"title": "Hide Done",
"steps": [
{
"contentMd": "Tutorials can choose to hide the done button on the final step. This metadata is parsed and removed.",
"headerContentMd": "Tutorials can choose to hide the done button on the final step. This metadata is parsed and removed."
},
{
"contentMd": "Tutorial parsing for hints, steps, etc should function exactly as before.\n\n```blocks\nlet x = 8;\nlet y = x + 2;\n```",
"headerContentMd": "Tutorial parsing for hints, steps, etc should function exactly as before.",
"hintContentMd": "```blocks\nlet x = 8;\nlet y = x + 2;\n```"
}
],
"activities": null,
"code": [
"{\nlet x = 8;\nlet y = x + 2;\n}",
"{\nbasic.showIcon(IconNames.Square)\n}"
],
"metadata": {
"hideDone": true
}
}
23 changes: 23 additions & 0 deletions tests/tutorial-test/baselines/hideToolbox.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"editor": "blocksprj",
"title": "Hide Toolbox",
"steps": [
{
"contentMd": "Tutorials can choose to hide the toolbox. This metadata is parsed and removed.",
"headerContentMd": "Tutorials can choose to hide the toolbox. This metadata is parsed and removed."
},
{
"contentMd": "Tutorial parsing for hints, steps, etc should function exactly as before.\n\n```blocks\nlet x = 8;\nlet y = x + 2;\n```",
"headerContentMd": "Tutorial parsing for hints, steps, etc should function exactly as before.",
"hintContentMd": "```blocks\nlet x = 8;\nlet y = x + 2;\n```"
}
],
"activities": null,
"code": [
"{\nlet x = 8;\nlet y = x + 2;\n}",
"{\nbasic.showIcon(IconNames.Square)\n}"
],
"metadata": {
"hideToolbox": true
}
}
20 changes: 20 additions & 0 deletions tests/tutorial-test/cases/hideDone.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Hide Done

### @hideDone true

## Introduction

Tutorials can choose to hide the done button on the final step. This metadata is parsed and removed.

## Step with hint

Tutorial parsing for hints, steps, etc should function exactly as before.

```blocks
let x = 8;
let y = x + 2;
```

```ghost
basic.showIcon(IconNames.Square)
```
20 changes: 20 additions & 0 deletions tests/tutorial-test/cases/hideToolbox.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Hide Toolbox

### @hideToolbox true

## Introduction

Tutorials can choose to hide the toolbox. This metadata is parsed and removed.

## Step with hint

Tutorial parsing for hints, steps, etc should function exactly as before.

```blocks
let x = 8;
let y = x + 2;
```

```ghost
basic.showIcon(IconNames.Square)
```
12 changes: 7 additions & 5 deletions webapp/src/components/tutorial/TutorialContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ interface TutorialContainerProps {
hasTemplate?: boolean;
preferredEditor?: string;
hasBeenResized?: boolean;
hideDone?: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit torn about this. I see that we created shortcuts for other tutorialOptions.metadata fields before, but I'm not sure of the benefit here. Since we're adding hideDone to the metadata, could we just grab it from the tutorial options? The hideDone flag definitely belongs in the metadata, but it feels a bit different to me than the other metadata fields that we decided to pass directly into the TutorialContainer. I don't feel strongly about this, especially for this case, but I wanted to bring it up to have a conversation of if there are things that we want to customize about tutorials in the future, should we add an optional prop to the TutorialContainer, or should we leave it in the tutorialOptions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm okay to just read it from metadata (which is already passed in), so I'll make that change.

I could see a theoretical argument towards making TutorialContainer useable without all our tutorial & tutorial metadata classes, but I don't see that being useful in practicality and it's a moot point anyway since we also already pass in the metadata itself.


tutorialOptions?: pxt.tutorial.TutorialOptions; // TODO (shakao) pass in only necessary subset
tutorialSimSidebar?: boolean;
Expand All @@ -37,7 +38,7 @@ const MAX_HEIGHT = 194;

export function TutorialContainer(props: TutorialContainerProps) {
const { parent, tutorialId, name, steps, hideIteration, hasTemplate,
preferredEditor, tutorialOptions, onTutorialStepChange, onTutorialComplete,
preferredEditor, tutorialOptions, hideDone, onTutorialStepChange, onTutorialComplete,
setParentHeight } = props;
const [ currentStep, setCurrentStep ] = React.useState(props.currentStep || 0);
const [ stepErrorAttemptCount, setStepErrorAttemptCount ] = React.useState(0);
Expand All @@ -49,7 +50,7 @@ export function TutorialContainer(props: TutorialContainerProps) {

const showBack = currentStep !== 0;
const showNext = currentStep !== steps.length - 1;
const showDone = !showNext && !pxt.appTarget.appTheme.lockedEditor && !hideIteration;
const isDone = !showNext && !pxt.appTarget.appTheme.lockedEditor && !hideIteration;
const showImmersiveReader = pxt.appTarget.appTheme.immersiveReader;
const isHorizontal = props.tutorialSimSidebar || pxt.BrowserUtils.isTabletSize();

Expand Down Expand Up @@ -237,8 +238,8 @@ export function TutorialContainer(props: TutorialContainerProps) {

const doneButtonLabel = lf("Finish the tutorial.");
const nextButtonLabel = lf("Go to the next step of the tutorial.");
const nextButton = showDone
? <Button icon="check circle" title={doneButtonLabel} ariaLabel={doneButtonLabel} text={lf("Done")} onClick={onTutorialComplete} />
const nextButton = isDone
? hideDone ? null : <Button icon="check circle" title={doneButtonLabel} ariaLabel={doneButtonLabel} text={lf("Done")} onClick={onTutorialComplete} />
: <Button icon="arrow circle right" title={nextButtonLabel} ariaLabel={nextButtonLabel} disabled={!showNext} text={lf("Next")} onClick={() => validateTutorialStep()} />;

const stepCounter = <TutorialStepCounter
Expand All @@ -247,6 +248,7 @@ export function TutorialContainer(props: TutorialContainerProps) {
totalSteps={steps.length}
title={name}
isHorizontal={isHorizontal}
hideDone={hideDone}
setTutorialStep={handleStepCounterSetStep}
onDone={onTutorialComplete} />;
const hasHint = !!hintMarkdown;
Expand Down Expand Up @@ -290,4 +292,4 @@ export function TutorialContainer(props: TutorialContainerProps) {
<MarkedContent markdown={currentStepInfo.contentMd} parent={parent} />
</Modal>}
</div>
}
}
8 changes: 5 additions & 3 deletions webapp/src/components/tutorial/TutorialStepCounter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ interface TutorialStepCounterProps {
totalSteps: number;
title?: string;
isHorizontal?: boolean;
hideDone?: boolean;
setTutorialStep: (step: number) => void;
onDone: () => void;
}
Expand Down Expand Up @@ -42,6 +43,7 @@ export function TutorialStepCounter(props: TutorialStepCounterProps) {

const lastStep = currentStep == totalSteps - 1;
const nextButtonTitle = lastStep ? lf("Finish the tutorial.") : lf("Go to the next step of the tutorial.");
const showNextButton = !lastStep || !props.hideDone;

return <div className="tutorial-step-counter">
<div className="tutorial-step-label">
Expand All @@ -68,13 +70,13 @@ export function TutorialStepCounter(props: TutorialStepCounterProps) {
label={stepNum === currentStep ? `${stepNum + 1}` : undefined}
/>
})}
<Button
{showNextButton && <Button
className={props.isHorizontal ? "ui button counter-next-button" : "square-button"}
leftIcon={`icon ${lastStep ? "check" : props.isHorizontal ? "arrow circle right" : "right chevron"}`}
onClick={lastStep ? props.onDone : handleNextStep}
aria-label={nextButtonTitle}
title={nextButtonTitle}
label={props.isHorizontal ? lastStep ? lf("Done") : lf("Next") : ""} />
label={props.isHorizontal ? lastStep ? lf("Done") : lf("Next") : ""} />}
</div>
</div>
}
}
1 change: 1 addition & 0 deletions webapp/src/sidepanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ export class Sidepanel extends data.Component<SidepanelProps, SidepanelState> {
preferredEditor={tutorialOptions.metadata?.preferredEditor}
tutorialSimSidebar={this.props.tutorialSimSidebar}
hasBeenResized={this.state.resized && this.state.shouldResize}
hideDone={tutorialOptions.metadata?.hideDone}
onTutorialStepChange={onTutorialStepChange}
onTutorialComplete={onTutorialComplete}
setParentHeight={newSize => this.setComponentHeight(newSize, false)} /> : undefined;
Expand Down
3 changes: 2 additions & 1 deletion webapp/src/tutorial.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -674,9 +674,10 @@ export class TutorialCard extends data.Component<TutorialCardProps, TutorialCard
const currentStep = tutorialStep;
const maxSteps = tutorialStepInfo.length;
const hideIteration = metadata && metadata.hideIteration;
const hideDone = metadata && metadata.hideDone;
const hasPrevious = tutorialReady && currentStep != 0 && !hideIteration;
const hasNext = tutorialReady && currentStep != maxSteps - 1 && !hideIteration;
const hasFinish = !lockedEditor && currentStep == maxSteps - 1 && !hideIteration;
const hasFinish = !lockedEditor && currentStep == maxSteps - 1 && !hideIteration && !hideDone;
const hasHint = this.hasHint();
const tutorialCardContent = stepInfo.headerContentMd;
const showDialog = stepInfo.showDialog;
Expand Down