Skip to content

Commit

Permalink
fix routing issues
Browse files Browse the repository at this point in the history
  • Loading branch information
timsuchanek committed Aug 30, 2019
1 parent 1c0890c commit 3dd51d2
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 7 deletions.
7 changes: 6 additions & 1 deletion cli/introspection/src/prompt/components/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface Props {
state?: Partial<InitState>
onSelect?: () => void
backSteps?: number
backTo?: string // pop state as long as needed to go back to that state using lastIndexOf
}

function getSymbol(kind?: LinkKind) {
Expand Down Expand Up @@ -59,7 +60,11 @@ export const Link: React.FC<Props> = props => {
if (props.href) {
routerCtx.setRoute(props.href)
} else {
routerCtx.back(props.backSteps)
if (props.backTo) {
routerCtx.backTo(props.backTo)
} else {
routerCtx.back(props.backSteps)
}
}
}
}
Expand Down
9 changes: 8 additions & 1 deletion cli/introspection/src/prompt/components/Router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,14 @@ class RouterContextClass {
for (let i = 0; i < steps; i++) {
this.stack.pop()
}
this.setRoute(this.stack[this.stack.length - 1])
this.setRoute(this.stack[this.stack.length - 1], true)
}
}
backTo(route: string) {
const index = this.stack.lastIndexOf(route)
if (index > -1) {
this.stack = this.stack.slice(0, index + 1)
this.setRoute(this.stack[this.stack.length - 1], true)
}
}
setDefaultRoute(route: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const Step1MySQLCredentials: React.FC = () => {
router.setRoute('introspection')
}
} else {
router.setRoute('download-example')
router.setRoute(state.useStarterKit ? 'download-example' : 'language-selection')
}
} else {
router.setRoute('choose-database')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const Step1PostgresCredentials: React.FC = () => {
router.setRoute('introspection')
}
} else {
router.setRoute('download-example')
router.setRoute(state.useStarterKit ? 'download-example' : 'language-selection')
}
} else {
router.setRoute('choose-database')
Expand Down
22 changes: 19 additions & 3 deletions cli/introspection/src/prompt/screens/Step22ToolSelection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,24 @@ import { InkLink } from '../components/InkLink'
import { Checkbox } from '../components/inputs/Checkbox'
import { useInitState } from '../components/InitState'
import { useConnector } from '../components/useConnector'
import Step61Success from './Step61Success'
import { RouterContext } from '../components/Router'

const Step22ToolSelection: React.FC = () => {
const [state, { setState }] = useInitState()
const { introspectionResult } = useConnector()
const { introspectionResult, disconnect } = useConnector()

const nextStep = state.usePhoton ? 'language-selection' : 'process-blank'

const backLabel = state.useBlank ? '(Database credentials)' : '(Project options)'

const router = useContext(RouterContext)

const goBack = async () => {
await disconnect()
const backTo = state.selectedDb === 'mysql' ? 'mysql-credentials' : 'postgres-credentials'
router.backTo(backTo)
}

return (
<Box flexDirection="column">
{introspectionResult && (
Expand Down Expand Up @@ -58,7 +68,13 @@ const Step22ToolSelection: React.FC = () => {
</Box>
</BorderBox>
<Link label="Confirm" href={nextStep} tabIndex={2} kind="forward" />
<Link label="Back" description="(Project options)" tabIndex={3} kind="back" />
<Link
label="Back"
onSelect={state.useBlank ? goBack : undefined}
description={backLabel}
tabIndex={3}
kind="back"
/>
</Box>
)
}
Expand Down

0 comments on commit 3dd51d2

Please sign in to comment.