Skip to content

Commit

Permalink
#12661 - Checkbox trees don't trigger unsaved changes warning and can…
Browse files Browse the repository at this point in the history
…'t be discarded
  • Loading branch information
sergiupacurariu committed Feb 27, 2024
1 parent b153ebf commit 3aaffe5
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 120 deletions.
25 changes: 11 additions & 14 deletions sormas-ui/src/main/java/de/symeda/sormas/ui/caze/CaseDataForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import java.util.Date;
import java.util.List;

import de.symeda.sormas.api.caze.ReinfectionDetailGroup;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

Expand Down Expand Up @@ -86,6 +85,7 @@
import de.symeda.sormas.api.caze.PreviousCaseDto;
import de.symeda.sormas.api.caze.QuarantineReason;
import de.symeda.sormas.api.caze.ReinfectionDetail;
import de.symeda.sormas.api.caze.ReinfectionDetailGroup;
import de.symeda.sormas.api.caze.classification.DiseaseClassificationCriteriaDto;
import de.symeda.sormas.api.contact.ContactDto;
import de.symeda.sormas.api.contact.FollowUpStatus;
Expand Down Expand Up @@ -129,7 +129,7 @@
import de.symeda.sormas.ui.location.AccessibleTextField;
import de.symeda.sormas.ui.utils.AbstractEditForm;
import de.symeda.sormas.ui.utils.ButtonHelper;
import de.symeda.sormas.ui.utils.CheckBoxTreeUpdated;
import de.symeda.sormas.ui.utils.CheckBoxTree;
import de.symeda.sormas.ui.utils.ComboBoxHelper;
import de.symeda.sormas.ui.utils.ComboBoxWithPlaceholder;
import de.symeda.sormas.ui.utils.ConfirmationComponent;
Expand Down Expand Up @@ -176,7 +176,6 @@ public class CaseDataForm extends AbstractEditForm<CaseDataDto> {
private static final String REINFECTION_DETAILS_COL_1_LOC = "reinfectionDetailsCol1Loc";
private static final String REINFECTION_DETAILS_COL_2_LOC = "reinfectionDetailsCol2Loc";
public static final String CASE_REFER_POINT_OF_ENTRY_BTN_LOC = "caseReferFromPointOfEntryBtnLoc";
public static final String TEST_Heading = "testHeading";

//@formatter:off
private static final String MAIN_HTML_LAYOUT =
Expand Down Expand Up @@ -309,8 +308,6 @@ public class CaseDataForm extends AbstractEditForm<CaseDataDto> {
private FollowUpPeriodDto expectedFollowUpPeriodDto;
private boolean ignoreDifferentPlaceOfStayJurisdiction = false;

private CheckBoxTreeUpdated<ReinfectionDetail> reinfectionDetailGroupCheckBoxTreeUpdated;

public CaseDataForm(
String caseUuid,
PersonDto person,
Expand Down Expand Up @@ -637,16 +634,18 @@ protected void addFields() {
getContent().addComponent(reinfectionInfoLabel, REINFECTION_INFO_LOC);
reinfectionInfoLabel.setVisible(false);

reinfectionDetailGroupCheckBoxTreeUpdated = addField(CaseDataDto.REINFECTION_DETAILS, CheckBoxTreeUpdated.class);
reinfectionDetailGroupCheckBoxTreeUpdated.setEnumType(ReinfectionDetail.class, ReinfectionDetail::getGroup, ReinfectionDetailGroup.class, 2);
CheckBoxTree<ReinfectionDetail> reinfectionDetailGroupCheckBoxTree =
addField(CaseDataDto.REINFECTION_DETAILS, CheckBoxTree.class);
reinfectionDetailGroupCheckBoxTree
.setEnumType(ReinfectionDetail.class, ReinfectionDetail::getGroup, ReinfectionDetailGroup.class, 2);

tfReinfectionStatus.setReadOnly(false);
tfReinfectionStatus.setValue(CaseLogic.calculateReinfectionStatus(reinfectionDetailGroupCheckBoxTreeUpdated.getValue()));
tfReinfectionStatus.setValue(CaseLogic.calculateReinfectionStatus(reinfectionDetailGroupCheckBoxTree.getValue()));
tfReinfectionStatus.setReadOnly(true);

reinfectionDetailGroupCheckBoxTreeUpdated.addValueChangeListener(e->{
reinfectionDetailGroupCheckBoxTree.addValueChangeListener(e -> {
tfReinfectionStatus.setReadOnly(false);
tfReinfectionStatus.setValue(CaseLogic.calculateReinfectionStatus(reinfectionDetailGroupCheckBoxTreeUpdated.getValue()));
tfReinfectionStatus.setValue(CaseLogic.calculateReinfectionStatus(reinfectionDetailGroupCheckBoxTree.getValue()));
tfReinfectionStatus.setReadOnly(true);
});

Expand Down Expand Up @@ -677,11 +676,11 @@ protected void addFields() {
reinfectionInfoLabel.setDescription(null);
reinfectionInfoLabel.setVisible(false);
}
reinfectionDetailGroupCheckBoxTreeUpdated.setVisible(isVisibleAllowed(CaseDataDto.RE_INFECTION));
reinfectionDetailGroupCheckBoxTree.setVisible(isVisibleAllowed(CaseDataDto.RE_INFECTION));
} else {
reinfectionInfoLabel.setDescription(null);
reinfectionInfoLabel.setVisible(false);
reinfectionDetailGroupCheckBoxTreeUpdated.setVisible(false);
reinfectionDetailGroupCheckBoxTree.setVisible(false);
}
});
}
Expand Down Expand Up @@ -1625,8 +1624,6 @@ private void updateFollowUpStatusComponents() {
@Override
public void setValue(CaseDataDto newFieldValue) throws ReadOnlyException, ConversionException {

reinfectionDetailGroupCheckBoxTreeUpdated.setValue(newFieldValue.getReinfectionDetails());

super.setValue(newFieldValue);

ComboBox caseConfirmationBasisCombo = getField(CASE_CONFIRMATION_BASIS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import de.symeda.sormas.ui.UserProvider;
import de.symeda.sormas.ui.location.LocationEditForm;
import de.symeda.sormas.ui.utils.AbstractEditForm;
import de.symeda.sormas.ui.utils.CheckBoxTreeUpdated;
import de.symeda.sormas.ui.utils.CheckBoxTree;
import de.symeda.sormas.ui.utils.CssStyles;
import de.symeda.sormas.ui.utils.FieldHelper;
import de.symeda.sormas.ui.utils.ResizableTextAreaWrapper;
Expand Down Expand Up @@ -65,8 +65,6 @@ public class EnvironmentDataForm extends AbstractEditForm<EnvironmentDto> {
fluidRowLocs(EnvironmentDto.OTHER_DELETION_REASON);
//@formatter:on

CheckBoxTreeUpdated<WaterUse> waterUseCheckBoxTreeUpdated;

public EnvironmentDataForm(boolean isPseudonymized, boolean inJurisdiction, boolean isEditAllowed) {
super(
EnvironmentDto.class,
Expand Down Expand Up @@ -116,10 +114,10 @@ protected void addFields() {
TextField otherWaterUse = addField(EnvironmentDto.OTHER_WATER_USE, TextField.class);
otherWaterUse.setInputPrompt(I18nProperties.getString(Strings.pleaseSpecify));

waterUseCheckBoxTreeUpdated = addField(EnvironmentDto.WATER_USE, CheckBoxTreeUpdated.class);
waterUseCheckBoxTreeUpdated.setEnumType(WaterUse.class, null);
CheckBoxTree<WaterUse> waterUseCheckBoxTree = addField(EnvironmentDto.WATER_USE, CheckBoxTree.class);
waterUseCheckBoxTree.setEnumType(WaterUse.class, null);

waterUseCheckBoxTreeUpdated.addValueChangeListener((e) -> {
waterUseCheckBoxTree.addValueChangeListener((e) -> {
if (e.getProperty().getValue() != null) {
if (Boolean.TRUE.equals(((Map<WaterUse, Boolean>) e.getProperty().getValue()).get(WaterUse.OTHER))) {
otherWaterUse.setVisible(true);
Expand Down Expand Up @@ -204,18 +202,18 @@ protected void addFields() {
if (EnvironmentMedia.WATER.equals(valueChangeEvent.getProperty().getValue())) {
waterType.setVisible(true);
infrastructureDetails.setVisible(true);
waterUseCheckBoxTreeUpdated.setVisible(true);
waterUseCheckBoxTree.setVisible(true);
useOfWaterHeading.setVisible(true);
} else {
useOfWaterHeading.setVisible(false);
waterType.setVisible(false);
infrastructureDetails.setVisible(false);
waterUseCheckBoxTreeUpdated.setVisible(false);
waterUseCheckBoxTree.setVisible(false);
otherWaterUse.setVisible(false);
waterType.clear();
infrastructureDetails.clear();
waterUseCheckBoxTreeUpdated.clear();
waterUseCheckBoxTreeUpdated.clear();
waterUseCheckBoxTree.clear();
waterUseCheckBoxTree.clear();
otherWaterUse.clear();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
import de.symeda.sormas.ui.UserProvider;
import de.symeda.sormas.ui.location.LocationEditForm;
import de.symeda.sormas.ui.utils.AbstractEditForm;
import de.symeda.sormas.ui.utils.CheckBoxTreeUpdated;
import de.symeda.sormas.ui.utils.CheckBoxTree;
import de.symeda.sormas.ui.utils.CssStyles;
import de.symeda.sormas.ui.utils.DateComparisonValidator;
import de.symeda.sormas.ui.utils.DateTimeField;
Expand Down Expand Up @@ -167,8 +167,6 @@ public class EventDataForm extends AbstractEditForm<EventDto> {
private List<UserReferenceDto> regionEventResponsibles = new ArrayList<>();
private List<UserReferenceDto> districtEventResponsibles = new ArrayList<>();
private LocationEditForm locationForm;
private CheckBoxTreeUpdated<EpidemiologicalEvidenceDetail> epidemiologicalEvidenceCheckBoxTreeUpdated;
private CheckBoxTreeUpdated<LaboratoryDiagnosticEvidenceDetail> laboratoryDiagnosticEvidenceDetailCheckBoxTreeUpdated;

public EventDataForm(boolean create, boolean isPseudonymized, boolean inJurisdiction) {
super(
Expand Down Expand Up @@ -280,11 +278,13 @@ protected void addFields() {
final NullableOptionGroup epidemiologicalEvidence = addField(EventDto.EPIDEMIOLOGICAL_EVIDENCE, NullableOptionGroup.class);
final NullableOptionGroup laboratoryDiagnosticEvidence = addField(EventDto.LABORATORY_DIAGNOSTIC_EVIDENCE, NullableOptionGroup.class);

epidemiologicalEvidenceCheckBoxTreeUpdated = addField(EventDto.EPIDEMIOLOGICAL_EVIDENCE_DETAILS, CheckBoxTreeUpdated.class);
epidemiologicalEvidenceCheckBoxTreeUpdated.setEnumType(EpidemiologicalEvidenceDetail.class, EpidemiologicalEvidenceDetail::getParent);
CheckBoxTree<EpidemiologicalEvidenceDetail> epidemiologicalEvidenceCheckBoxTree =
addField(EventDto.EPIDEMIOLOGICAL_EVIDENCE_DETAILS, CheckBoxTree.class);
epidemiologicalEvidenceCheckBoxTree.setEnumType(EpidemiologicalEvidenceDetail.class, EpidemiologicalEvidenceDetail::getParent);

laboratoryDiagnosticEvidenceDetailCheckBoxTreeUpdated = addField(EventDto.LABORATORY_DIAGNOSTIC_EVIDENCE_DETAILS, CheckBoxTreeUpdated.class);
laboratoryDiagnosticEvidenceDetailCheckBoxTreeUpdated
CheckBoxTree<LaboratoryDiagnosticEvidenceDetail> laboratoryDiagnosticEvidenceDetailCheckBoxTree =
addField(EventDto.LABORATORY_DIAGNOSTIC_EVIDENCE_DETAILS, CheckBoxTree.class);
laboratoryDiagnosticEvidenceDetailCheckBoxTree
.setEnumType(LaboratoryDiagnosticEvidenceDetail.class, LaboratoryDiagnosticEvidenceDetail::getParent);

DateField evolutionDateField = addField(EventDto.EVOLUTION_DATE, DateField.class);
Expand Down Expand Up @@ -530,10 +530,10 @@ protected void addFields() {

epidemiologicalEvidence.addValueChangeListener(valueChangeEvent -> {
if (((NullableOptionGroup) valueChangeEvent.getProperty()).getNullableValue() == YesNoUnknown.YES) {
epidemiologicalEvidenceCheckBoxTreeUpdated.setVisible(true);
epidemiologicalEvidenceCheckBoxTree.setVisible(true);
} else {
epidemiologicalEvidenceCheckBoxTreeUpdated.clear();
epidemiologicalEvidenceCheckBoxTreeUpdated.setVisible(false);
epidemiologicalEvidenceCheckBoxTree.clear();
epidemiologicalEvidenceCheckBoxTree.setVisible(false);
}
});
}
Expand All @@ -547,10 +547,10 @@ protected void addFields() {

laboratoryDiagnosticEvidence.addValueChangeListener(valueChangeEvent -> {
if (((NullableOptionGroup) valueChangeEvent.getProperty()).getNullableValue() == YesNoUnknown.YES) {
laboratoryDiagnosticEvidenceDetailCheckBoxTreeUpdated.setVisible(true);
laboratoryDiagnosticEvidenceDetailCheckBoxTree.setVisible(true);
} else {
laboratoryDiagnosticEvidenceDetailCheckBoxTreeUpdated.clear();
laboratoryDiagnosticEvidenceDetailCheckBoxTreeUpdated.setVisible(false);
laboratoryDiagnosticEvidenceDetailCheckBoxTree.clear();
laboratoryDiagnosticEvidenceDetailCheckBoxTree.setVisible(false);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.jetbrains.annotations.NotNull;

import com.vaadin.ui.Label;
import com.vaadin.v7.data.Validator;
import com.vaadin.v7.data.util.converter.Converter;
import com.vaadin.v7.ui.ComboBox;
import com.vaadin.v7.ui.Field;
Expand Down Expand Up @@ -57,7 +56,7 @@
import de.symeda.sormas.ui.UserProvider;
import de.symeda.sormas.ui.location.LocationEditForm;
import de.symeda.sormas.ui.utils.AbstractEditForm;
import de.symeda.sormas.ui.utils.CheckBoxTreeUpdated;
import de.symeda.sormas.ui.utils.CheckBoxTree;
import de.symeda.sormas.ui.utils.CssStyles;
import de.symeda.sormas.ui.utils.DateFormatHelper;
import de.symeda.sormas.ui.utils.FieldHelper;
Expand Down Expand Up @@ -104,8 +103,6 @@ public class EnvironmentSampleEditForm extends AbstractEditForm<EnvironmentSampl
EnvironmentSampleDto.LAB_SAMPLE_ID,
EnvironmentSampleDto.SPECIMEN_CONDITION);

private CheckBoxTreeUpdated<WeatherCondition> weatherConditionCheckBoxTreeUpdated;

private final boolean isCreate;

public EnvironmentSampleEditForm(boolean isPseudonymized, boolean isCreate) {
Expand Down Expand Up @@ -179,8 +176,8 @@ protected void addFields() {
TextField phValueField = addField(EnvironmentSampleDto.PH_VALUE);
phValueField.setConversionError(I18nProperties.getValidationError(Validations.onlyNumbersAllowed, phValueField.getCaption()));

weatherConditionCheckBoxTreeUpdated = addField(EnvironmentSampleDto.WEATHER_CONDITIONS, CheckBoxTreeUpdated.class);
weatherConditionCheckBoxTreeUpdated.setEnumType(WeatherCondition.class, null);
CheckBoxTree<WeatherCondition> weatherConditionCheckBoxTree = addField(EnvironmentSampleDto.WEATHER_CONDITIONS, CheckBoxTree.class);
weatherConditionCheckBoxTree.setEnumType(WeatherCondition.class, null);

addField(EnvironmentSampleDto.HEAVY_RAIN, NullableOptionGroup.class);

Expand Down Expand Up @@ -283,22 +280,11 @@ private void disableFieldsBasedOnRights(EnvironmentSampleDto sample) {
}
}
});
if (!(canEditDispatchField)) {
weatherConditionCheckBoxTreeUpdated.setEnabled(false);
}
}

@Override
public void commit() throws SourceException, Validator.InvalidValueException {
super.commit();
getValue().setWeatherConditions(weatherConditionCheckBoxTreeUpdated.getValue());
}

@Override
public void setValue(EnvironmentSampleDto newFieldValue) throws ReadOnlyException, Converter.ConversionException {
super.setValue(newFieldValue);
weatherConditionCheckBoxTreeUpdated.setValue(newFieldValue.getWeatherConditions());

disableFieldsBasedOnRights(newFieldValue);
}

Expand Down
Loading

0 comments on commit 3aaffe5

Please sign in to comment.