Skip to content

Commit

Permalink
Close upload dialog on navigation change
Browse files Browse the repository at this point in the history
  • Loading branch information
sven1103 committed Jan 17, 2025
1 parent 756c23d commit dc7f5a6
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import com.vaadin.flow.dom.Style.Visibility;
import com.vaadin.flow.router.BeforeEnterEvent;
import com.vaadin.flow.router.BeforeEnterObserver;
import com.vaadin.flow.router.BeforeLeaveEvent;
import com.vaadin.flow.router.BeforeLeaveObserver;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.spring.annotation.SpringComponent;
import com.vaadin.flow.spring.annotation.UIScope;
Expand Down Expand Up @@ -50,6 +52,7 @@
import life.qbic.logging.api.Logger;
import life.qbic.logging.service.LoggerFactory;
import life.qbic.projectmanagement.application.ProjectInformationService;
import life.qbic.projectmanagement.application.measurement.MeasurementMetadata;
import life.qbic.projectmanagement.application.measurement.MeasurementService;
import life.qbic.projectmanagement.application.measurement.MeasurementService.MeasurementDeletionException;
import life.qbic.projectmanagement.application.measurement.validation.MeasurementValidationService;
Expand All @@ -76,7 +79,7 @@
@UIScope
@Route(value = "projects/:projectId?/experiments/:experimentId?/measurements", layout = ExperimentMainLayout.class)
@PermitAll
public class MeasurementMain extends Main implements BeforeEnterObserver {
public class MeasurementMain extends Main implements BeforeEnterObserver, BeforeLeaveObserver {

public static final String PROJECT_ID_ROUTE_PARAMETER = "projectId";
public static final String EXPERIMENT_ID_ROUTE_PARAMETER = "experimentId";
Expand All @@ -103,6 +106,7 @@ public class MeasurementMain extends Main implements BeforeEnterObserver {
private final transient ProjectInformationService projectInformationService;
private final transient CancelConfirmationDialogFactory cancelConfirmationDialogFactory;
private final transient MessageSourceNotificationFactory messageFactory;
private MeasurementMetadataUploadDialog dialog;
private transient Context context;

public MeasurementMain(
Expand Down Expand Up @@ -157,7 +161,6 @@ public MeasurementMain(
getClass().getSimpleName(), System.identityHashCode(this),
measurementTemplateListComponent.getClass().getSimpleName(),
System.identityHashCode(measurementTemplateListComponent)));

}

private static String convertErrorCodeToMessage(MeasurementService.ErrorCode errorCode) {
Expand Down Expand Up @@ -359,7 +362,7 @@ private void triggerMeasurementRegistration(
}

private void openEditMeasurementDialog() {
var dialog = new MeasurementMetadataUploadDialog(measurementValidationService,
this.dialog = new MeasurementMetadataUploadDialog(measurementValidationService,
cancelConfirmationDialogFactory,
MODE.EDIT,
context.projectId().orElse(null));
Expand Down Expand Up @@ -601,4 +604,10 @@ static class HandledException extends RuntimeException {
}

}

@Override
public void beforeLeave(BeforeLeaveEvent event) {
Optional.ofNullable(this.dialog).ifPresent(Dialog::close);
}

}

0 comments on commit dc7f5a6

Please sign in to comment.