CreateImageWizard: fix add all packages

When adding all packages we no longer depend on the state update.
Instead, we initialize an object with the chosen packages and pass that
to both the step's state and the form's state. Using the step state to
set the form's state was causing the form's state to be set from the
prior step state and not the state with the new package list.
This commit is contained in:
Jacob Kozol 2021-11-21 12:56:50 +01:00 committed by Sanne Raymaekers
parent 940e40409c
commit dd895e014e

View file

@ -143,16 +143,19 @@ const Packages = ({ defaultArch, ...props }) => {
// move all packages
const moveAll = (fromAvailable) => {
let chosenPackages = [];
if (fromAvailable) {
setPackagesChosen([ ...packagesAvailable.filter(pack => !pack.isHidden), ...packagesChosen ]);
chosenPackages = [ ...packagesAvailable.filter(pack => !pack.isHidden), ...packagesChosen ];
setPackagesChosen(chosenPackages);
sortPackages([ ...packagesAvailable.filter(pack => pack.isHidden) ]);
} else {
chosenPackages = [ ...packagesChosen.filter(pack => pack.isHidden) ];
sortPackages([ ...packagesChosen.filter(pack => !pack.isHidden), ...packagesAvailable ]);
setPackagesChosen([ ...packagesChosen.filter(pack => pack.isHidden) ]);
setPackagesChosen(chosenPackages);
}
// set the steps field to the current chosen packages list
change(input.name, removePackagesDisplayFields(packagesChosen));
change(input.name, removePackagesDisplayFields(chosenPackages));
};
const onOptionSelect = (event, index, isChosen) => {