Skip to content

Commit

Permalink
User can see the button in the spreadsheet layout independent of numb…
Browse files Browse the repository at this point in the history
…er of rows (#357)

* Adapt css so spreadsheet buttons are always visible

* Adapt spreadsheet generation to ensure no orphan values are added
  • Loading branch information
Steffengreiner authored Aug 30, 2023
1 parent 4d8c158 commit e21ff05
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 50 deletions.
15 changes: 12 additions & 3 deletions vaadinfrontend/frontend/themes/datamanager/components/dialog.css
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -54,7 +60,6 @@ vaadin-dialog-overlay::part(title) {

.batch-registration-dialog .batch-content .data-type-information {
display: flex;
height: inherit;
flex-direction: column;
}

Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -141,28 +142,43 @@ 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();
}

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() {
Expand Down Expand Up @@ -208,9 +224,8 @@ public void resetAndClose() {
}

private void reset() {

batchInformationLayout.reset();
sampleSpreadsheetLayout.resetLayout();
sampleSpreadsheetLayout.reset();
tabStepper.setSelectedTab(batchInformationTab);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> conditions = conditionsToReplicates.keySet();
for(String condition : conditions) {
for (String condition : conditions) {
List<String> 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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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 {
Expand All @@ -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<Void, InvalidSpreadsheetInput> content = sampleRegistrationSpreadsheet.areInputsValid();
if (content.isValue()) {
hideErrorInstructions();
resetErrorInstructions();
}
return content.onError(error -> displayErrorInstructions(error.getInvalidationReason()))
.isValue();
Expand All @@ -188,7 +201,7 @@ private void displayErrorInstructions(String instructions) {
errorInstructionSpan.add(errorSpan);
}

private void hideErrorInstructions() {
private void resetErrorInstructions() {
errorInstructionSpan.removeAll();
}

Expand Down

0 comments on commit e21ff05

Please sign in to comment.