From e21ff0551764860c227cec4e5cf930d1c187e67e Mon Sep 17 00:00:00 2001 From: Steffengreiner Date: Wed, 30 Aug 2023 15:37:25 +0200 Subject: [PATCH] User can see the button in the spreadsheet layout independent of number of rows (#357) * Adapt css so spreadsheet buttons are always visible * Adapt spreadsheet generation to ensure no orphan values are added --- .../themes/datamanager/components/dialog.css | 15 +++++-- .../batch/BatchRegistrationDialog.java | 43 +++++++++++++------ .../batch/SampleRegistrationSpreadsheet.java | 22 ++-------- .../batch/SampleSpreadsheetLayout.java | 43 ++++++++++++------- 4 files changed, 73 insertions(+), 50 deletions(-) diff --git a/vaadinfrontend/frontend/themes/datamanager/components/dialog.css b/vaadinfrontend/frontend/themes/datamanager/components/dialog.css index a4b105212..a80424b7f 100644 --- a/vaadinfrontend/frontend/themes/datamanager/components/dialog.css +++ b/vaadinfrontend/frontend/themes/datamanager/components/dialog.css @@ -27,8 +27,14 @@ vaadin-dialog-overlay::part(title) { height: 100% } +.batch-registration-dialog vaadin-tabsheet { + height: 100%; + width: 100%; +} + .batch-registration-dialog::part(overlay) { min-width: 66vw; + height: 100%; } .batch-registration-dialog .stepper vaadin-tabs { @@ -54,7 +60,6 @@ vaadin-dialog-overlay::part(title) { .batch-registration-dialog .batch-content .data-type-information { display: flex; - height: inherit; flex-direction: column; } @@ -86,10 +91,14 @@ vaadin-dialog-overlay::part(title) { gap: var(--lumo-space-s); } +.batch-registration-dialog .sample-spreadsheet-container { + width: 100%; + height: 100%; +} + .batch-registration-dialog .sample-spreadsheet { - /*Todo Find solution on how to let spreadsheet set its size*/ width: 100%; - height: 60vh; + height: 100%; } .create-project-dialog .content { diff --git a/vaadinfrontend/src/main/java/life/qbic/datamanager/views/projects/project/samples/registration/batch/BatchRegistrationDialog.java b/vaadinfrontend/src/main/java/life/qbic/datamanager/views/projects/project/samples/registration/batch/BatchRegistrationDialog.java index 52755532f..90db4d346 100644 --- a/vaadinfrontend/src/main/java/life/qbic/datamanager/views/projects/project/samples/registration/batch/BatchRegistrationDialog.java +++ b/vaadinfrontend/src/main/java/life/qbic/datamanager/views/projects/project/samples/registration/batch/BatchRegistrationDialog.java @@ -31,6 +31,7 @@ public class BatchRegistrationDialog extends DialogWindow { private final BatchInformationLayout batchInformationLayout = new BatchInformationLayout(); private final SampleSpreadsheetLayout sampleSpreadsheetLayout = new SampleSpreadsheetLayout(); private final transient RegisterBatchDialogHandler registerBatchDialogHandler; + private boolean wasPrefillPreviouslySelected = false; public BatchRegistrationDialog() { addClassName("batch-registration-dialog"); @@ -141,19 +142,27 @@ private void setTabSelectionListener() { private void generateSampleRegistrationLayout() { //we always set the batch name, as it can change without affecting the rest of the spreadsheet sampleSpreadsheetLayout.setBatchName(batchInformationLayout.batchNameField.getValue()); - //we need to reset the layout, if the experiment has changed - if (hasExperimentInformationChanged()) { - sampleSpreadsheetLayout.resetLayout(); - } - //We need to build the spreadsheet upon initialization or if the user changed the experiment - if (sampleSpreadsheetLayout.getExperiment() == null || hasExperimentInformationChanged()) { - sampleSpreadsheetLayout.setExperiment(batchInformationLayout.experimentSelect.getValue()); + + //We reset the spreadsheet independent on which selection was changed + if (hasPrefillStatusChanged() || hasExperimentInformationChanged()) { + sampleSpreadsheetLayout.resetSpreadSheet(); + //If the user changes the experiment or selects one for the first time the spreadsheet has to be generated anew + if (hasExperimentInformationChanged()) { + sampleSpreadsheetLayout.resetExperimentInformation(); + sampleSpreadsheetLayout.setExperiment(batchInformationLayout.experimentSelect.getValue()); + } sampleSpreadsheetLayout.generateSampleRegistrationSheet( batchInformationLayout.dataTypeSelection.getValue()); + //If the user changed the prefill selection the fields have to be filled dependent on if the checkbox was checked or not + if (hasPrefillStatusChanged()) { + boolean isPrefillSelected = batchInformationLayout.prefillSelection.getValue(); + if (isPrefillSelected) { + sampleSpreadsheetLayout.prefillConditionsAndReplicates(); + } + wasPrefillPreviouslySelected = isPrefillSelected; + } } - //With the spreadsheet prepared, we can fill the prefilled information in the spreadsheet - sampleSpreadsheetLayout.prefillConditionsAndReplicates( - batchInformationLayout.prefillSelection.getValue()); + //rerender spreadsheet sampleSpreadsheetLayout.reloadSpreadsheet(); } @@ -161,8 +170,15 @@ private boolean hasExperimentInformationChanged() { ExperimentId previouslySelectedExperiment = sampleSpreadsheetLayout.getExperiment(); ExperimentId selectedExperiment = batchInformationLayout.experimentSelect.getValue() .experimentId(); - return previouslySelectedExperiment != null && !previouslySelectedExperiment.equals( - selectedExperiment); + if (previouslySelectedExperiment == null) { + return true; + } else { + return !previouslySelectedExperiment.equals(selectedExperiment); + } + } + + private boolean hasPrefillStatusChanged() { + return wasPrefillPreviouslySelected != batchInformationLayout.prefillSelection.getValue(); } private void setSubmissionListeners() { @@ -208,9 +224,8 @@ public void resetAndClose() { } private void reset() { - batchInformationLayout.reset(); - sampleSpreadsheetLayout.resetLayout(); + sampleSpreadsheetLayout.reset(); tabStepper.setSelectedTab(batchInformationTab); } diff --git a/vaadinfrontend/src/main/java/life/qbic/datamanager/views/projects/project/samples/registration/batch/SampleRegistrationSpreadsheet.java b/vaadinfrontend/src/main/java/life/qbic/datamanager/views/projects/project/samples/registration/batch/SampleRegistrationSpreadsheet.java index 4ee6a3f4b..fdd0e019e 100644 --- a/vaadinfrontend/src/main/java/life/qbic/datamanager/views/projects/project/samples/registration/batch/SampleRegistrationSpreadsheet.java +++ b/vaadinfrontend/src/main/java/life/qbic/datamanager/views/projects/project/samples/registration/batch/SampleRegistrationSpreadsheet.java @@ -622,34 +622,20 @@ private BiologicalReplicateId retrieveBiologicalReplicateId(String replicateLabe return biologicalReplicateId; } - public void prefillConditionsAndReplicates(boolean isPrefilled) { + public void prefillConditionsAndReplicates() { int conditionColIndex = header.indexOf(SamplesheetHeaderName.CONDITION); int replicateColIndex = header.indexOf(SamplesheetHeaderName.BIOLOGICAL_REPLICATE_ID); int rowIndex = 0; Set conditions = conditionsToReplicates.keySet(); - for(String condition : conditions) { + for (String condition : conditions) { List sortedLabels = conditionsToReplicates.get(condition).stream() .sorted(new LexicographicLabelComparator()).map(BiologicalReplicate::label).toList(); for (String label : sortedLabels) { rowIndex++; Cell replicateCell = this.getCell(rowIndex, replicateColIndex); Cell conditionCell = this.getCell(rowIndex, conditionColIndex); - if (isPrefilled) { - //prefill cells - replicateCell.setCellValue(label); - conditionCell.setCellValue(condition); - } else { - //remove prefilled info, except if there is only one condition or replicate - String neutralValue = ""; - if (conditions.size() == 1) { - neutralValue = condition; - } - conditionCell.setCellValue(neutralValue); - if (sortedLabels.size() == 1) { - neutralValue = label; - } - replicateCell.setCellValue(neutralValue); - } + replicateCell.setCellValue(label); + conditionCell.setCellValue(condition); } } } diff --git a/vaadinfrontend/src/main/java/life/qbic/datamanager/views/projects/project/samples/registration/batch/SampleSpreadsheetLayout.java b/vaadinfrontend/src/main/java/life/qbic/datamanager/views/projects/project/samples/registration/batch/SampleSpreadsheetLayout.java index fcdf3b17a..990d2ab2e 100644 --- a/vaadinfrontend/src/main/java/life/qbic/datamanager/views/projects/project/samples/registration/batch/SampleSpreadsheetLayout.java +++ b/vaadinfrontend/src/main/java/life/qbic/datamanager/views/projects/project/samples/registration/batch/SampleSpreadsheetLayout.java @@ -55,7 +55,7 @@ class SampleSpreadsheetLayout extends Div { private void initContent() { initHeaderAndInstruction(); Div sampleSpreadSheetContainer = new Div(); - sampleSpreadSheetContainer.addClassName("sample-spreadsheet"); + sampleSpreadSheetContainer.addClassName("sample-spreadsheet-container"); sampleSpreadSheetContainer.add(sampleRegistrationSpreadsheet); add(sampleSpreadSheetContainer); styleSampleRegistrationSpreadSheet(); @@ -111,10 +111,20 @@ public void generateSampleRegistrationSheet(MetadataType metaDataType) { sampleRegistrationSpreadsheet.addSheetToSpreadsheet(metaDataType); } - public void resetLayout() { - sampleRegistrationSpreadsheet.getCellSelectionManager().clear(); + public void reset() { sampleInformationLayoutHandler.reset(); - experiment = null; + } + + public void resetBatchInformation() { + sampleInformationLayoutHandler.resetBatchInformation(); + } + + public void resetExperimentInformation() { + sampleInformationLayoutHandler.resetExperimentInformation(); + } + + public void resetSpreadSheet() { + sampleInformationLayoutHandler.resetSpreadSheet(); } public void reloadSpreadsheet() { @@ -143,8 +153,8 @@ public ExperimentId getExperiment() { return experiment; } - public void prefillConditionsAndReplicates(boolean isPrefilled) { - sampleRegistrationSpreadsheet.prefillConditionsAndReplicates(isPrefilled); + public void prefillConditionsAndReplicates() { + sampleRegistrationSpreadsheet.prefillConditionsAndReplicates(); } private class SampleInformationLayoutHandler implements Serializable { @@ -153,28 +163,31 @@ private class SampleInformationLayoutHandler implements Serializable { private static final long serialVersionUID = 2837608401189525502L; private void reset() { - resetChildValues(); - } - - private void resetChildValues() { - resetInstructions(); + resetBatchInformation(); + resetExperimentInformation(); resetSpreadSheet(); - hideErrorInstructions(); } - private void resetInstructions() { + private void resetBatchInformation() { batchName.setText(""); + } + + private void resetExperimentInformation() { + experiment = null; experimentName.setText(""); + resetErrorInstructions(); } private void resetSpreadSheet() { sampleRegistrationSpreadsheet.reset(); + sampleRegistrationSpreadsheet.getCellSelectionManager().clear(); + } private boolean isInputValid() { Result content = sampleRegistrationSpreadsheet.areInputsValid(); if (content.isValue()) { - hideErrorInstructions(); + resetErrorInstructions(); } return content.onError(error -> displayErrorInstructions(error.getInvalidationReason())) .isValue(); @@ -188,7 +201,7 @@ private void displayErrorInstructions(String instructions) { errorInstructionSpan.add(errorSpan); } - private void hideErrorInstructions() { + private void resetErrorInstructions() { errorInstructionSpan.removeAll(); }