Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added public/images/cog40t.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/cog50t.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/cog60t.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
120 changes: 81 additions & 39 deletions src/modules/WizardStep.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,24 @@ const WizardStep = (props) => {
return { atEnd: index >= stepProps.length, skip: startIndex !== index, nextIndex: index };
}

useEffect(() => {
if (stepIndex >= 0) {
window.history.replaceState({ stepIndex }, '', window.location.pathname + window.location.search);
}

const onPopState = (event) => {
if (event.state && typeof event.state.stepIndex === 'number') {
setStepIndex(event.state.stepIndex);
}
};

window.addEventListener('popstate', onPopState);

return () => {
window.removeEventListener('popstate', onPopState);
};
}, [stepIndex]);

useEffect(() => {
let nextStepIndex = stepIndex + 1;
const newStepHistory = [...stepHistory, stepIndex];
Expand All @@ -192,10 +210,21 @@ const WizardStep = (props) => {
}, [advanceStep]);

const goBackInHistory = () => {
const newStepIndex = stepHistory[stepHistory.length - 1];
const newStepHistory = stepHistory.slice(0, -1);
setStepHistory(newStepHistory);
setStepIndex(newStepIndex);
const newStepIndex = stepHistory[stepHistory.length - 1];
const newStepHistory = stepHistory.slice(0, -1);
const preservedVariables = new Set();
for (let i = 0; i <= newStepIndex; i++) {
preservedVariables.add(stepProps[i].variable);
}

//add variable to preserved list
['autopa', 'autopaversion', 'stepperlib'].forEach(v => preservedVariables.add(v));
const newConfiguration = configuration.filter(config => preservedVariables.has(config.variable));

setConfiguration(newConfiguration);
setStepHistory(newStepHistory);
setStepIndex(newStepIndex);

}

const download = (filename, lines) => {
Expand Down Expand Up @@ -232,7 +261,14 @@ const WizardStep = (props) => {
}

const onSelect = (index, e) => {
let newConfiguration = configuration.filter(config => config.variable !== stepProps[index].variable)
let newConfiguration;
if (stepProps[index].variable === 'tracker') {
// if user changes tracker, reset configuration
newConfiguration = [];
} else {
// Otherwise, only remove the modified variable
newConfiguration = configuration.filter(config => config.variable !== stepProps[index].variable);
}
let newVariables = [{ variable: stepProps[index].variable, value: e }]

const chosenOption = stepProps[index].control.choices.find(c => c.key === e);
Expand Down Expand Up @@ -263,7 +299,16 @@ const WizardStep = (props) => {
let prop = stepProps[index];
// console.log("Next step: ", prop)
let newConfig = prop.control.choices.map((v) => { return { key: v.key, value: getDefaultValue(v.defaultValue) || '' } });
let newConfiguration = configuration.filter(config => config.variable !== stepProps[index].variable);
const currentVar = stepProps[index].variable;
let newConfiguration;
if (currentVar === 'tracker') {
newConfiguration = [];
} else if (currentVar === 'board') {
const preservedVars = ['tracker', 'board', 'autopa', 'autopaversion', 'stepperlib'];
newConfiguration = configuration.filter(config => preservedVars.includes(config.variable));
} else {
newConfiguration = configuration.filter(config => config.variable !== currentVar);
}
let newVariables = [{ variable: prop.variable, value: newConfig }]
newConfiguration = [...newConfiguration, ...newVariables]
setConfiguration(newConfiguration);
Expand All @@ -275,7 +320,16 @@ const WizardStep = (props) => {
let currentConfig = configuration.find(config => config.variable === stepProps[index].variable) || { value: [] };
let newConfig = currentConfig.value.filter(config => config.key !== key);
newConfig = [...newConfig, { key: key, value: val }];
let newConfiguration = configuration.filter(config => config.variable !== stepProps[index].variable);
const currentVar = stepProps[index].variable;
let newConfiguration;
if (currentVar === 'tracker') {
newConfiguration = [];
} else if (currentVar === 'board') {
const preservedVars = ['tracker', 'board', 'autopa', 'autopaversion', 'stepperlib'];
newConfiguration = configuration.filter(config => preservedVars.includes(config.variable));
} else {
newConfiguration = configuration.filter(config => config.variable !== currentVar);
}
newConfiguration = [...newConfiguration, { variable: stepProps[index].variable, value: newConfig }]
setConfiguration(newConfiguration);
}
Expand Down Expand Up @@ -354,36 +408,27 @@ const WizardStep = (props) => {
return exprResult.bool
})
}

let steps = [];

stepProps.forEach((step, index) => {
let title = step.title;
let description;
if (index < stepIndex) {
let foundConfig = configuration.find(config => config.variable === stepProps[index].variable);
if (foundConfig && !Array.isArray(foundConfig.value)) {
if (stepProps[index].control) {
let foundControl = stepProps[index].control.choices.find(choice => foundConfig.value === choice.key);
if (!foundControl) {
console.log("Could not find control ", foundConfig)
} else {
description = foundControl.value;
}
}
}
}

let skipState = shouldSkipStep(index);
if ((skipState.skip) && (index < stepIndex)) {
description = "N/A, skipped.";
}

if ((!skipState.skip) || (index <= stepIndex)) {
steps.push(<Step size="small" title={title} description={description} />)
}
});

stepProps.forEach((step, index) => {
let title = step.title;
let description = "N/A, skipped.";
let foundConfig = configuration.find(config => config.variable === step.variable);
if (foundConfig) {
if (!Array.isArray(foundConfig.value)) {
const control = step.control;
const foundControl = control?.choices?.find(choice => choice.key === foundConfig.value);
if (foundControl) {
description = foundControl.value;
}
} else {
description = 'Custom Value';
}
let skipState = shouldSkipStep(index);
const showStep = !skipState.skip || index <= stepIndex;
if (showStep) {
steps.push(<Step size="small" title={title} description={description} />);
}
}});
steps.push(<Step title='Completed' />)

if (showResult) {
Expand Down Expand Up @@ -632,9 +677,6 @@ const WizardStep = (props) => {
<div>
{control}
</div>
<div className='back-button' >
<Button type='primary' onClick={() => goBackInHistory()} disabled={stepIndex < 1}>Back</Button>
</div>
</div>
</div>
}
Expand Down
Loading