fix: if any step has error, the first step could not be expanded (#85)
* fix: if any error occured, the first step could not be expanded * chore: renamed `condition` attribute to `isOk`
This commit is contained in:
@@ -29,7 +29,7 @@ const useStyles = makeStyles((theme: Theme) =>
|
|||||||
|
|
||||||
interface Step {
|
interface Step {
|
||||||
label: string
|
label: string
|
||||||
condition: boolean
|
isOk: boolean
|
||||||
isLoading: boolean
|
isLoading: boolean
|
||||||
component: ReactElement
|
component: ReactElement
|
||||||
}
|
}
|
||||||
@@ -57,37 +57,37 @@ export default function NodeSetupWorkflow({
|
|||||||
const steps: Step[] = [
|
const steps: Step[] = [
|
||||||
{
|
{
|
||||||
label: 'Connected to Node DebugAPI',
|
label: 'Connected to Node DebugAPI',
|
||||||
condition: debugApiConnection.isOk,
|
isOk: debugApiConnection.isOk,
|
||||||
isLoading: debugApiConnection.isLoading,
|
isLoading: debugApiConnection.isLoading,
|
||||||
component: <DebugConnectionCheck {...debugApiConnection} />,
|
component: <DebugConnectionCheck {...debugApiConnection} />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Running latest Bee version',
|
label: 'Running latest Bee version',
|
||||||
condition: nodeVersion.isOk,
|
isOk: nodeVersion.isOk,
|
||||||
isLoading: nodeVersion.isLoading,
|
isLoading: nodeVersion.isLoading,
|
||||||
component: <VersionCheck {...nodeVersion} />,
|
component: <VersionCheck {...nodeVersion} />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Connected to Ethereum Blockchain',
|
label: 'Connected to Ethereum Blockchain',
|
||||||
condition: ethereumConnection.isOk,
|
isOk: ethereumConnection.isOk,
|
||||||
isLoading: ethereumConnection.isLoading,
|
isLoading: ethereumConnection.isLoading,
|
||||||
component: <EthereumConnectionCheck {...ethereumConnection} />,
|
component: <EthereumConnectionCheck {...ethereumConnection} />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Deployed and Funded Chequebook',
|
label: 'Deployed and Funded Chequebook',
|
||||||
condition: chequebook.isOk,
|
isOk: chequebook.isOk,
|
||||||
isLoading: chequebook.isLoading,
|
isLoading: chequebook.isLoading,
|
||||||
component: <ChequebookDeployFund ethereumAddress={ethereumConnection.nodeAddresses?.ethereum} {...chequebook} />,
|
component: <ChequebookDeployFund ethereumAddress={ethereumConnection.nodeAddresses?.ethereum} {...chequebook} />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Connected to Node API',
|
label: 'Connected to Node API',
|
||||||
condition: apiConnection.isOk,
|
isOk: apiConnection.isOk,
|
||||||
isLoading: apiConnection.isLoading,
|
isLoading: apiConnection.isLoading,
|
||||||
component: <NodeConnectionCheck {...apiConnection} />,
|
component: <NodeConnectionCheck {...apiConnection} />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Connected to Peers',
|
label: 'Connected to Peers',
|
||||||
condition: topology.isOk,
|
isOk: topology.isOk,
|
||||||
isLoading: topology.isLoading,
|
isLoading: topology.isLoading,
|
||||||
component: <PeerConnection {...topology} />,
|
component: <PeerConnection {...topology} />,
|
||||||
},
|
},
|
||||||
@@ -95,11 +95,15 @@ export default function NodeSetupWorkflow({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// If the user already changed the active step we don't want to overwrite it
|
// If the user already changed the active step we don't want to overwrite it
|
||||||
if (activeStep > 0 && activeStep < steps.length) return
|
if (activeStep >= 0 && activeStep < steps.length) return
|
||||||
|
|
||||||
|
// If any step is not fully loaded yet return
|
||||||
|
if (!steps.every(step => !step.isLoading)) return
|
||||||
|
|
||||||
// Select first step that is not OK
|
// Select first step that is not OK
|
||||||
|
// This is deliberately a for loop (and not forEach) so that we can terminate the useEffect from within the cycle
|
||||||
for (let i = 0; i < steps.length; ++i) {
|
for (let i = 0; i < steps.length; ++i) {
|
||||||
if (!steps[i].condition) {
|
if (!steps[i].isOk) {
|
||||||
setActiveStep(i)
|
setActiveStep(i)
|
||||||
|
|
||||||
return
|
return
|
||||||
@@ -127,7 +131,7 @@ export default function NodeSetupWorkflow({
|
|||||||
</span>
|
</span>
|
||||||
</Typography>
|
</Typography>
|
||||||
<Stepper nonLinear activeStep={activeStep} orientation="vertical">
|
<Stepper nonLinear activeStep={activeStep} orientation="vertical">
|
||||||
{steps.map(({ label, condition, component, isLoading }, index) => (
|
{steps.map(({ label, isOk, component, isLoading }, index) => (
|
||||||
<Step key={label}>
|
<Step key={label}>
|
||||||
<StepLabel
|
<StepLabel
|
||||||
disabled={isLoading}
|
disabled={isLoading}
|
||||||
@@ -135,7 +139,7 @@ export default function NodeSetupWorkflow({
|
|||||||
StepIconComponent={() => {
|
StepIconComponent={() => {
|
||||||
if (isLoading) return <Autorenew style={{ height: '25px', cursor: 'pointer' }} />
|
if (isLoading) return <Autorenew style={{ height: '25px', cursor: 'pointer' }} />
|
||||||
|
|
||||||
if (condition) return <CheckCircle style={{ color: '#32c48d', height: '25px', cursor: 'pointer' }} />
|
if (isOk) return <CheckCircle style={{ color: '#32c48d', height: '25px', cursor: 'pointer' }} />
|
||||||
|
|
||||||
return <Error style={{ color: '#c9201f', height: '25px', cursor: 'pointer' }} />
|
return <Error style={{ color: '#c9201f', height: '25px', cursor: 'pointer' }} />
|
||||||
}}
|
}}
|
||||||
|
|||||||
Reference in New Issue
Block a user