Skip to content

Commit

Permalink
Bug fix: Keeping the newly selected ensembles in dialog when loading …
Browse files Browse the repository at this point in the history
…from backend (#480)
  • Loading branch information
rubenthoms authored Nov 16, 2023
1 parent 7da32a3 commit eaba110
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions frontend/src/framework/internal/components/NavBar/navBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const NavBarDivider: React.FC = () => {

export const NavBar: React.FC<NavBarProps> = (props) => {
const [ensembleDialogOpen, setEnsembleDialogOpen] = React.useState<boolean>(false);
const [newSelectedEnsembles, setNewSelectedEnsembles] = React.useState<EnsembleItem[]>([]);
const [layoutEmpty, setLayoutEmpty] = React.useState<boolean>(props.workbench.getLayout().length === 0);
const [expanded, setExpanded] = React.useState<boolean>(localStorage.getItem("navBarExpanded") === "true");
const loadingEnsembleSet = useIsEnsembleSetLoading(props.workbench.getWorkbenchSession());
Expand Down Expand Up @@ -108,19 +109,25 @@ export const NavBar: React.FC<NavBarProps> = (props) => {
localStorage.setItem("navBarExpanded", (!expanded).toString());
}

const selectedEnsembles = ensembleSet.getEnsembleArr().map((ens) => ({
const selectedEnsembles: EnsembleItem[] = ensembleSet.getEnsembleArr().map((ens) => ({
caseUuid: ens.getCaseUuid(),
caseName: ens.getCaseName(),
ensembleName: ens.getEnsembleName(),
}));

function loadAndSetupEnsembles(selectedEnsembles: EnsembleItem[]): Promise<void> {
setNewSelectedEnsembles(selectedEnsembles);
const selectedEnsembleIdents = selectedEnsembles.map(
(ens) => new EnsembleIdent(ens.caseUuid, ens.ensembleName)
);
return props.workbench.loadAndSetupEnsembleSetInSession(queryClient, selectedEnsembleIdents);
}

let fixedSelectedEnsembles = selectedEnsembles;
if (loadingEnsembleSet) {
fixedSelectedEnsembles = newSelectedEnsembles;
}

return (
<div
className={resolveClassNames(
Expand Down Expand Up @@ -244,7 +251,7 @@ export const NavBar: React.FC<NavBarProps> = (props) => {
{ensembleDialogOpen && (
<SelectEnsemblesDialog
loadAndSetupEnsembles={loadAndSetupEnsembles}
selectedEnsembles={selectedEnsembles}
selectedEnsembles={fixedSelectedEnsembles}
onClose={handleEnsembleDialogClose}
/>
)}
Expand Down

0 comments on commit eaba110

Please sign in to comment.