Skip to content

Commit

Permalink
Merge pull request #2310 from influxdata/onboarding/stop-header-skipping
Browse files Browse the repository at this point in the history
fix(ui/onboarding): Prevent unskippable steps from being skipped with progress bar
  • Loading branch information
ischolten authored Jan 8, 2019
2 parents b69f647 + bb93b36 commit 99a2b91
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 4 deletions.
4 changes: 4 additions & 0 deletions ui/src/clockface/components/wizard/ProgressBar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@
}
}

.unclickable {
cursor: default;
}

.wizard--progress-connector {
min-width: 20px;
width: 100%;
Expand Down
47 changes: 44 additions & 3 deletions ui/src/clockface/components/wizard/ProgressBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface Props {
handleSetCurrentStep: (stepNumber: number) => void
stepStatuses: StepStatus[]
stepTitles: string[]
stepSkippable: boolean[]
}

@ErrorHandling
Expand All @@ -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

Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion ui/src/onboarding/containers/OnboardingWizard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -190,6 +190,7 @@ class OnboardingWizard extends PureComponent<Props> {
handleSetCurrentStep={onSetCurrentStepIndex}
stepStatuses={stepStatuses}
stepTitles={this.stepTitles}
stepSkippable={this.stepSkippable}
/>
</WizardProgressHeader>
)
Expand Down

0 comments on commit 99a2b91

Please sign in to comment.