fix(ui/onboarding): Prevent unskippable steps from being skipped with progress bar

pull/10616/head
Iris Scholten 2019-01-07 16:33:55 -08:00
parent 01a836a995
commit bb93b3608d
3 changed files with 50 additions and 4 deletions

View File

@ -84,6 +84,10 @@
}
}
.unclickable {
cursor: default;
}
.wizard--progress-connector {
min-width: 20px;
width: 100%;

View File

@ -13,6 +13,7 @@ interface Props {
handleSetCurrentStep: (stepNumber: number) => void
stepStatuses: StepStatus[]
stepTitles: string[]
stepSkippable: boolean[]
}
@ErrorHandling
@ -21,11 +22,51 @@ class ProgressBar extends PureComponent<Props, null> {
return <div className="wizard--progress-bar">{this.WizardProgress}</div>
}
private handleSetCurrentStep = i => () => {
const {handleSetCurrentStep} = this.props
private handleSetCurrentStep = (i: number) => () => {
const {handleSetCurrentStep, currentStepIndex} = this.props
const isAfterCurrentUnskippableStep =
!this.isStepSkippable && i > currentStepIndex
const isAfterNextUnskippableStep =
this.nextNonSkippableStep !== -1 && i > this.nextNonSkippableStep
const preventSkip =
isAfterCurrentUnskippableStep || isAfterNextUnskippableStep
if (preventSkip) {
return
}
handleSetCurrentStep(i)
}
private get nextNonSkippableStep(): number {
const {currentStepIndex, stepSkippable, stepStatuses} = this.props
return _.findIndex(stepSkippable, (isSkippable, i) => {
return (
!isSkippable &&
i > currentStepIndex &&
stepStatuses[i] !== StepStatus.Complete
)
})
}
private get isStepSkippable(): boolean {
const {stepSkippable, stepStatuses, currentStepIndex} = this.props
return (
stepSkippable[currentStepIndex] ||
stepStatuses[currentStepIndex] === StepStatus.Complete
)
}
private getStepClass(i: number): string {
if (!this.isStepSkippable && i > this.props.currentStepIndex) {
return 'wizard--progress-button unclickable'
}
return 'wizard--progress-button'
}
private get WizardProgress(): JSX.Element[] {
const {stepStatuses, stepTitles, currentStepIndex} = this.props
@ -47,7 +88,7 @@ class ProgressBar extends PureComponent<Props, null> {
const stepEle = (
<div
key={`stepEle${i}`}
className="wizard--progress-button"
className={this.getStepClass(i)}
onClick={this.handleSetCurrentStep(i)}
>
<span

View File

@ -105,7 +105,7 @@ class OnboardingWizard extends PureComponent<Props> {
'Complete',
]
public stepSkippable = [false, false, false, false, false, false]
public stepSkippable = [true, false, true, true, true, true]
constructor(props: Props) {
super(props)
@ -190,6 +190,7 @@ class OnboardingWizard extends PureComponent<Props> {
handleSetCurrentStep={onSetCurrentStepIndex}
stepStatuses={stepStatuses}
stepTitles={this.stepTitles}
stepSkippable={this.stepSkippable}
/>
</WizardProgressHeader>
)