fixed issue with automatic start causing it to add interactions repeatedly
This commit is contained in:
parent
8ec08b0c36
commit
a225f02795
2 changed files with 24 additions and 21 deletions
|
|
@ -436,7 +436,9 @@ if (!selectedDevice) return;
|
||||||
}
|
}
|
||||||
stage1.steps.push(newStep);
|
stage1.steps.push(newStep);
|
||||||
});
|
});
|
||||||
stages.push(stage1)
|
if(stage1.steps.length > 0){
|
||||||
|
stages.push(stage1)
|
||||||
|
}
|
||||||
//stage two is to add the new interactions
|
//stage two is to add the new interactions
|
||||||
let stage2: Stage = {
|
let stage2: Stage = {
|
||||||
title: "Add New Interactions",
|
title: "Add New Interactions",
|
||||||
|
|
@ -447,7 +449,9 @@ if (!selectedDevice) return;
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
stages.push(stage2)
|
if(stage2.steps.length > 0){
|
||||||
|
stages.push(stage2)
|
||||||
|
}
|
||||||
|
|
||||||
//stage three is to update the controller components
|
//stage three is to update the controller components
|
||||||
let stage3: Stage = {
|
let stage3: Stage = {
|
||||||
|
|
@ -463,7 +467,9 @@ if (!selectedDevice) return;
|
||||||
stage3.steps.push(newStep)
|
stage3.steps.push(newStep)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
stages.push(stage3)
|
if(stage3.steps.length > 0){
|
||||||
|
stages.push(stage3)
|
||||||
|
}
|
||||||
//set those stages to a state variable
|
//set those stages to a state variable
|
||||||
setPromiseStages(stages)
|
setPromiseStages(stages)
|
||||||
}
|
}
|
||||||
|
|
@ -721,7 +727,7 @@ if (!selectedDevice) return;
|
||||||
<Box>
|
<Box>
|
||||||
<PromiseProgress
|
<PromiseProgress
|
||||||
stages={promiseStages}
|
stages={promiseStages}
|
||||||
automaticStart
|
description="These are the changes that will occur in order to change your bin mode with the given options. Press start to begin."
|
||||||
failFast
|
failFast
|
||||||
onStart={() => {
|
onStart={() => {
|
||||||
startChange()
|
startChange()
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { AxiosResponse } from "axios"
|
import { AxiosResponse } from "axios"
|
||||||
import { Box, Button, CircularProgress, DialogActions, DialogContent, DialogTitle, Typography } from "@mui/material"
|
import { Box, Button, CircularProgress, DialogActions, DialogContent, DialogTitle, Divider, Typography } from "@mui/material"
|
||||||
import { useEffect, useState } from "react"
|
import { useEffect, useState } from "react"
|
||||||
import { CheckCircle, Error, Pending } from "@mui/icons-material"
|
import { CheckCircle, Error, Pending } from "@mui/icons-material"
|
||||||
import React from "react"
|
import React from "react"
|
||||||
|
|
@ -18,7 +18,7 @@ export interface Step {
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
stages: Stage[]
|
stages: Stage[]
|
||||||
automaticStart: boolean
|
description?: string
|
||||||
failFast?: boolean
|
failFast?: boolean
|
||||||
onStart?: () => void
|
onStart?: () => void
|
||||||
onComplete?: () => void
|
onComplete?: () => void
|
||||||
|
|
@ -32,10 +32,11 @@ enum progress {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function PromiseProgress(props: Props){
|
export function PromiseProgress(props: Props){
|
||||||
const {stages, failFast, onStart, onComplete, automaticStart} = props
|
const {stages, failFast, onStart, onComplete, description } = props
|
||||||
const [completion, setCompletion] = useState<Map<string, progress>>(new Map())
|
const [completion, setCompletion] = useState<Map<string, progress>>(new Map())
|
||||||
|
|
||||||
const execute = () => {
|
const execute = () => {
|
||||||
|
console.log("executing")
|
||||||
let completionMap: Map<string, progress> = new Map()
|
let completionMap: Map<string, progress> = new Map()
|
||||||
stages.forEach((stage, i) => {
|
stages.forEach((stage, i) => {
|
||||||
stage.steps.forEach((_, k) => {
|
stage.steps.forEach((_, k) => {
|
||||||
|
|
@ -47,6 +48,7 @@ export function PromiseProgress(props: Props){
|
||||||
const runStages = async () => {
|
const runStages = async () => {
|
||||||
let progMap = new Map(completionMap)
|
let progMap = new Map(completionMap)
|
||||||
for (const [i, stage] of stages.entries()) {
|
for (const [i, stage] of stages.entries()) {
|
||||||
|
console.log("the for loop:" + i)
|
||||||
// For each stage, map the steps into their own promise chains
|
// For each stage, map the steps into their own promise chains
|
||||||
const stepPromises = stage.steps.map((step, k) => {
|
const stepPromises = stage.steps.map((step, k) => {
|
||||||
// mark step as in progress
|
// mark step as in progress
|
||||||
|
|
@ -84,12 +86,6 @@ export function PromiseProgress(props: Props){
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if(automaticStart){
|
|
||||||
execute()
|
|
||||||
}
|
|
||||||
},[automaticStart, execute])
|
|
||||||
|
|
||||||
const getCompletion = (completion?: progress) => {
|
const getCompletion = (completion?: progress) => {
|
||||||
switch(completion){
|
switch(completion){
|
||||||
case progress.InProgress:
|
case progress.InProgress:
|
||||||
|
|
@ -123,16 +119,17 @@ export function PromiseProgress(props: Props){
|
||||||
Progress
|
Progress
|
||||||
</DialogTitle>
|
</DialogTitle>
|
||||||
<DialogContent>
|
<DialogContent>
|
||||||
{stages.map((stage, number) => displayStage(stage, number))}
|
<Typography>{description}</Typography>
|
||||||
|
<Box marginTop={2}>
|
||||||
|
{stages.map((stage, number) => displayStage(stage, number))}
|
||||||
|
</Box>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
<DialogActions>
|
<DialogActions>
|
||||||
{!automaticStart &&
|
<Button variant="contained" color="primary" onClick={() => {
|
||||||
<Button onClick={() => {
|
execute()
|
||||||
execute()
|
}}>
|
||||||
}}>
|
Start
|
||||||
Start
|
</Button>
|
||||||
</Button>
|
|
||||||
}
|
|
||||||
</DialogActions>
|
</DialogActions>
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue