Skip to content

Commit 8dd53e2

Browse files
committed
FIXES: #13473: Wrapper showed buttons when not needed in Case/Therapy tab.
1 parent 95ad045 commit 8dd53e2

File tree

4 files changed

+149
-117
lines changed

4 files changed

+149
-117
lines changed

sormas-ui/src/main/java/de/symeda/sormas/ui/caze/CaseController.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,8 +1423,7 @@ public CommitDiscardWrapperComponent<TherapyForm> getTherapyEditComponent(final
14231423
new TherapyForm(caseDataDto, caseDataDto.getDisease(), caseDataDto.isPseudonymized(), caseDataDto.isInJurisdiction(), isEditAllowed);
14241424
therapyForm.setValue(caseDataDto.getTherapy());
14251425

1426-
CommitDiscardWrapperComponent<TherapyForm> editView =
1427-
new CommitDiscardWrapperComponent<TherapyForm>(therapyForm, UiUtil.permitted(UserRight.CASE_EDIT), therapyForm.getFieldGroup());
1426+
CommitDiscardWrapperComponent<TherapyForm> editView = CommitDiscardWrapperComponent.withoutButtons(therapyForm, therapyForm.getFieldGroup());
14281427

14291428
editView.addCommitListener(() -> {
14301429
CaseDataDto cazeDto = FacadeProvider.getCaseFacade().getCaseDataByUuid(caseUuid);
@@ -1614,14 +1613,14 @@ private PresentCondition getNewPresentConditionFromOutcome(CaseOutcome outcome)
16141613
return PresentCondition.UNKNOWN;
16151614
}
16161615
switch (outcome) {
1617-
case DECEASED:
1618-
return PresentCondition.DEAD;
1619-
case RECOVERED:
1620-
return PresentCondition.ALIVE;
1621-
case NO_OUTCOME:
1622-
case UNKNOWN:
1623-
default:
1624-
return PresentCondition.UNKNOWN;
1616+
case DECEASED:
1617+
return PresentCondition.DEAD;
1618+
case RECOVERED:
1619+
return PresentCondition.ALIVE;
1620+
case NO_OUTCOME:
1621+
case UNKNOWN:
1622+
default:
1623+
return PresentCondition.UNKNOWN;
16251624
}
16261625
}
16271626

sormas-ui/src/main/java/de/symeda/sormas/ui/therapy/PrescriptionGrid.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@
3333
public class PrescriptionGrid extends Grid implements V7AbstractGrid<PrescriptionCriteria> {
3434

3535
private static final String ACTION_BTN_ID = "edit";
36-
private static final String VIEW_BTN_ID = "view";
3736
private static final String DOCUMENT_TREATMENT_BTN_ID = "documentTreatment";
3837

38+
public static final String MIN_ROW_HEIGHT_STYLE_NAME = "min-row-height";
39+
3940
private PrescriptionCriteria prescriptionCriteria = new PrescriptionCriteria();
4041

4142
public PrescriptionGrid(TherapyForm parentView, boolean isPseudonymized, boolean isEditAllowed, boolean isDeleteAllowed) {
@@ -115,6 +116,9 @@ public Class<String> getType() {
115116
.openPrescriptionEditForm((PrescriptionIndexDto) e.getItemId(), this::reload, isEditAllowed, isDeleteAllowed);
116117
}
117118
});
119+
120+
// without this the first time new elements are added they will not be correctly displayed
121+
setStyleName(MIN_ROW_HEIGHT_STYLE_NAME);
118122
}
119123

120124
@SuppressWarnings("unchecked")

sormas-ui/src/main/java/de/symeda/sormas/ui/utils/CommitDiscardWrapperComponent.java

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ public static interface DeleteWithDetailsListener {
141141
private boolean dirty = false;
142142

143143
private boolean shortcutsEnabled = false;
144+
145+
private boolean hideButtons = false;
146+
144147
protected transient List<ClickShortcut> actions;
145148

146149
protected CommitDiscardWrapperComponent() {
@@ -152,12 +155,32 @@ public CommitDiscardWrapperComponent(C component, FieldGroup... fieldGroups) {
152155
}
153156

154157
public CommitDiscardWrapperComponent(C component, Boolean isEditingAllowed, FieldGroup... fieldGroups) {
158+
this(component, isEditingAllowed, false, fieldGroups);
159+
}
160+
161+
public CommitDiscardWrapperComponent(C component, Boolean isEditingAllowed, boolean hideButtons, FieldGroup... fieldGroups) {
162+
this.hideButtons = hideButtons;
155163
setWrappedComponent(component, fieldGroups);
156164
if (isEditingAllowed != null) {
157165
setEnabled(isEditingAllowed);
158166
}
159167
}
160168

169+
/**
170+
* Meant to be used when the wrapper is required due to used API but the inner component(s) already contains the discard/save/delete UI.
171+
*
172+
* @param component
173+
* that will be integrated within the wrapper.
174+
* @param fieldGroups
175+
* additional fields
176+
* @return invisible wrapper: no buttons
177+
* @param <C>
178+
* component type.
179+
*/
180+
public static <C extends Component> CommitDiscardWrapperComponent<C> withoutButtons(C component, FieldGroup... fieldGroups) {
181+
return new CommitDiscardWrapperComponent<>(component, true, true, fieldGroups);
182+
}
183+
161184
protected void setWrappedComponent(C component, FieldGroup... fieldGroups) {
162185

163186
this.wrappedComponent = component;
@@ -178,23 +201,25 @@ protected void setWrappedComponent(C component, FieldGroup... fieldGroups) {
178201
addComponent(contentPanel);
179202
setExpandRatio(contentPanel, 1);
180203

181-
buttonsPanel = new HorizontalLayout();
182-
buttonsPanel.setMargin(false);
183-
buttonsPanel.setSpacing(true);
184-
buttonsPanel.setWidth(100, Unit.PERCENTAGE);
204+
if (!hideButtons) {
205+
buttonsPanel = new HorizontalLayout();
206+
buttonsPanel.setMargin(false);
207+
buttonsPanel.setSpacing(true);
208+
buttonsPanel.setWidth(100, Unit.PERCENTAGE);
185209

186-
Button discardButton = getDiscardButton();
187-
buttonsPanel.addComponent(discardButton);
188-
buttonsPanel.setComponentAlignment(discardButton, Alignment.BOTTOM_RIGHT);
189-
buttonsPanel.setExpandRatio(discardButton, 1);
210+
Button discardButton = getDiscardButton();
211+
buttonsPanel.addComponent(discardButton);
212+
buttonsPanel.setComponentAlignment(discardButton, Alignment.BOTTOM_RIGHT);
213+
buttonsPanel.setExpandRatio(discardButton, 1);
190214

191-
Button commitButton = getCommitButton();
192-
buttonsPanel.addComponent(commitButton);
193-
buttonsPanel.setComponentAlignment(commitButton, Alignment.BOTTOM_RIGHT);
194-
buttonsPanel.setExpandRatio(commitButton, 0);
215+
Button commitButton = getCommitButton();
216+
buttonsPanel.addComponent(commitButton);
217+
buttonsPanel.setComponentAlignment(commitButton, Alignment.BOTTOM_RIGHT);
218+
buttonsPanel.setExpandRatio(commitButton, 0);
195219

196-
addComponent(buttonsPanel);
197-
setComponentAlignment(buttonsPanel, Alignment.BOTTOM_RIGHT);
220+
addComponent(buttonsPanel);
221+
setComponentAlignment(buttonsPanel, Alignment.BOTTOM_RIGHT);
222+
}
198223

199224
setShortcutsEnabled(shortcutsEnabled);
200225

0 commit comments

Comments
 (0)