The Rollout groups legend shows max 7 groups (#705)

* Fix Rollouts Groups legend
* Fix totalTargetAmount display when editing a rollout
* Fix code glitches
* Fix PR review findings

Signed-off-by: Melanie Retter <melanie.retter@bosch-si.com>
This commit is contained in:
Melanie Retter
2018-07-19 08:37:06 +02:00
committed by Stefan Behl
parent 7bd6b41b72
commit 5e9b0fb884
2 changed files with 57 additions and 19 deletions

View File

@@ -656,7 +656,7 @@ public class AddUpdateRolloutWindowLayout extends GridLayout {
UIComponentIdProvider.ROLLOUT_APPROVAL_REMARK_FIELD_ID, Rollout.APPROVAL_REMARK_MAX_SIZE); UIComponentIdProvider.ROLLOUT_APPROVAL_REMARK_FIELD_ID, Rollout.APPROVAL_REMARK_MAX_SIZE);
approvalRemarkField.setWidth(100.0F, Unit.PERCENTAGE); approvalRemarkField.setWidth(100.0F, Unit.PERCENTAGE);
HorizontalLayout layout = new HorizontalLayout(approveButtonsGroup, approvalRemarkField); final HorizontalLayout layout = new HorizontalLayout(approveButtonsGroup, approvalRemarkField);
layout.setWidth(100.0F, Unit.PERCENTAGE); layout.setWidth(100.0F, Unit.PERCENTAGE);
layout.setExpandRatio(approvalRemarkField, 1.0F); layout.setExpandRatio(approvalRemarkField, 1.0F);
return layout; return layout;
@@ -1013,6 +1013,8 @@ public class AddUpdateRolloutWindowLayout extends GridLayout {
groupsDefinitionTabs.setSelectedTab(1); groupsDefinitionTabs.setSelectedTab(1);
window.clearOriginalValues(); window.clearOriginalValues();
totalTargetsCount = targetManagement.countByRsql(rollout.getTargetFilterQuery());
groupsLegendLayout.populateTotalTargets(totalTargetsCount);
} else { } else {
editRolloutEnabled = true; editRolloutEnabled = true;
if (rollout.getStatus() != Rollout.RolloutStatus.READY) { if (rollout.getStatus() != Rollout.RolloutStatus.READY) {
@@ -1043,10 +1045,10 @@ public class AddUpdateRolloutWindowLayout extends GridLayout {
updateGroupsChart(rolloutGroupManagement updateGroupsChart(rolloutGroupManagement
.findByRollout(new PageRequest(0, quotaManagement.getMaxRolloutGroupsPerRollout()), rollout.getId()) .findByRollout(new PageRequest(0, quotaManagement.getMaxRolloutGroupsPerRollout()), rollout.getId())
.getContent(), rollout.getTotalTargets()); .getContent(), rollout.getTotalTargets());
}
totalTargetsCount = targetManagement.countByRsql(rollout.getTargetFilterQuery()); totalTargetsCount = rollout.getTotalTargets();
groupsLegendLayout.populateTotalTargets(totalTargetsCount); groupsLegendLayout.populateTotalTargets(totalTargetsCount);
}
} }
private void disableRequiredFieldsOnEdit() { private void disableRequiredFieldsOnEdit() {

View File

@@ -28,7 +28,9 @@ import com.vaadin.ui.VerticalLayout;
*/ */
public class GroupsLegendLayout extends VerticalLayout { public class GroupsLegendLayout extends VerticalLayout {
private static final long serialVersionUID = 5483206203739308677L; private static final long serialVersionUID = 1L;
private static final int MAX_GROUPS_TO_BE_DISPLAYED = 7;
private final VaadinMessageSource i18n; private final VaadinMessageSource i18n;
@@ -63,9 +65,10 @@ public class GroupsLegendLayout extends VerticalLayout {
addComponent(loadingLabel); addComponent(loadingLabel);
addComponent(unassignedTargetsLabel); addComponent(unassignedTargetsLabel);
addComponent(groupsLegend); addComponent(groupsLegend);
for (int i = 0; i < 8; i++) { for (int i = 0; i < MAX_GROUPS_TO_BE_DISPLAYED; i++) {
groupsLegend.addComponent(createGroupTargetsLabel()); groupsLegend.addComponent(createGroupTargetsLabel());
} }
groupsLegend.addComponent(createToBeContinuedLabel());
} }
@@ -75,6 +78,9 @@ public class GroupsLegendLayout extends VerticalLayout {
public void reset() { public void reset() {
totalTargetsLabel.setVisible(false); totalTargetsLabel.setVisible(false);
populateGroupsLegendByTargetCounts(Collections.emptyList()); populateGroupsLegendByTargetCounts(Collections.emptyList());
if (groupsLegend.getComponentCount() > MAX_GROUPS_TO_BE_DISPLAYED) {
groupsLegend.getComponent(MAX_GROUPS_TO_BE_DISPLAYED).setVisible(false);
}
} }
private static Label createTotalTargetsLabel() { private static Label createTotalTargetsLabel() {
@@ -108,6 +114,10 @@ public class GroupsLegendLayout extends VerticalLayout {
return label; return label;
} }
private static Label createToBeContinuedLabel() {
return new LabelBuilder().caption("...").visible(false).buildLabel();
}
private String getTotalTargetMessage(final long totalTargetsCount) { private String getTotalTargetMessage(final long totalTargetsCount) {
return i18n.getMessage("label.target.filter.count") + totalTargetsCount; return i18n.getMessage("label.target.filter.count") + totalTargetsCount;
} }
@@ -128,7 +138,7 @@ public class GroupsLegendLayout extends VerticalLayout {
* null to hide the label or a count to be displayed as total * null to hide the label or a count to be displayed as total
* targets message * targets message
*/ */
public void populateTotalTargets(Long totalTargets) { public void populateTotalTargets(final Long totalTargets) {
if (totalTargets == null) { if (totalTargets == null) {
totalTargetsLabel.setVisible(false); totalTargetsLabel.setVisible(false);
} else { } else {
@@ -141,19 +151,19 @@ public class GroupsLegendLayout extends VerticalLayout {
* Populates the legend based on a list of anonymous groups. They can't have * Populates the legend based on a list of anonymous groups. They can't have
* unassigned targets. * unassigned targets.
* *
* @param targetsPerGroup * @param listOfTargetCountPerGroup
* list of target counts * list of target counts
*/ */
public void populateGroupsLegendByTargetCounts(final List<Long> targetsPerGroup) { public void populateGroupsLegendByTargetCounts(final List<Long> listOfTargetCountPerGroup) {
loadingLabel.setVisible(false); loadingLabel.setVisible(false);
for (int i = 0; i < groupsLegend.getComponentCount(); i++) { for (int i = 0; i < getGroupsWithoutToBeContinuedLabel(listOfTargetCountPerGroup.size()); i++) {
final Component component = groupsLegend.getComponent(i); final Component component = groupsLegend.getComponent(i);
final Label label = (Label) component; final Label label = (Label) component;
if (targetsPerGroup.size() > i) { if (listOfTargetCountPerGroup.size() > i) {
final Long targetCount = targetsPerGroup.get(i); final Long targetCount = listOfTargetCountPerGroup.get(i);
label.setValue( label.setValue(getTargetsInGroupMessage(targetCount,
getTargetsInGroupMessage(targetCount, i18n.getMessage("textfield.rollout.group.default.name", i + 1))); i18n.getMessage("textfield.rollout.group.default.name", i + 1)));
label.setVisible(true); label.setVisible(true);
} else { } else {
label.setValue(""); label.setValue("");
@@ -161,9 +171,33 @@ public class GroupsLegendLayout extends VerticalLayout {
} }
} }
showOrHideToBeContinueLabel(listOfTargetCountPerGroup);
unassignedTargetsLabel.setValue(""); unassignedTargetsLabel.setValue("");
unassignedTargetsLabel.setVisible(false); unassignedTargetsLabel.setVisible(false);
}
private void showOrHideToBeContinueLabel(final List<?> listOfTargetCountPerGroup) {
if (hasMoreGroupsToShowAsLimit(listOfTargetCountPerGroup)) {
groupsLegend.getComponent(MAX_GROUPS_TO_BE_DISPLAYED).setVisible(true);
} else if (hasLessGroupsToShowAsLimit(listOfTargetCountPerGroup)) {
groupsLegend.getComponent(groupsLegend.getComponentCount() - 1).setVisible(false);
}
}
private boolean hasLessGroupsToShowAsLimit(final List<?> listOfTargetCountPerGroup) {
return groupsLegend.getComponentCount() > listOfTargetCountPerGroup.size();
}
private static boolean hasMoreGroupsToShowAsLimit(final List<?> listOfTargetCountPerGroup) {
return listOfTargetCountPerGroup.size() > MAX_GROUPS_TO_BE_DISPLAYED;
}
private int getGroupsWithoutToBeContinuedLabel(final int amountOfRolloutGroups) {
if (amountOfRolloutGroups < groupsLegend.getComponentCount()) {
return groupsLegend.getComponentCount();
}
return groupsLegend.getComponentCount() - 1;
} }
/** /**
@@ -185,11 +219,11 @@ public class GroupsLegendLayout extends VerticalLayout {
if (validation == null) { if (validation == null) {
return; return;
} }
List<Long> targetsPerGroup = validation.getTargetsPerGroup(); final List<Long> targetsPerGroup = validation.getTargetsPerGroup();
final long unassigned = validation.getTotalTargets() - validation.getTargetsInGroups(); final long unassigned = validation.getTotalTargets() - validation.getTargetsInGroups();
final int labelsToUpdate = (unassigned > 0) ? (groupsLegend.getComponentCount() - 1) final int labelsToUpdate = (unassigned > 0) ? (getGroupsWithoutToBeContinuedLabel(groups.size()) - 1)
: groupsLegend.getComponentCount(); : groupsLegend.getComponentCount();
for (int i = 0; i < groupsLegend.getComponentCount(); i++) { for (int i = 0; i < getGroupsWithoutToBeContinuedLabel(groups.size()); i++) {
final Component component = groupsLegend.getComponent(i); final Component component = groupsLegend.getComponent(i);
final Label label = (Label) component; final Label label = (Label) component;
if (targetsPerGroup.size() > i && groups.size() > i && labelsToUpdate > i) { if (targetsPerGroup.size() > i && groups.size() > i && labelsToUpdate > i) {
@@ -204,6 +238,8 @@ public class GroupsLegendLayout extends VerticalLayout {
} }
} }
showOrHideToBeContinueLabel(groups);
if (unassigned > 0) { if (unassigned > 0) {
unassignedTargetsLabel.setValue(getTargetsInGroupMessage(unassigned, "Unassigned")); unassignedTargetsLabel.setValue(getTargetsInGroupMessage(unassigned, "Unassigned"));
unassignedTargetsLabel.setVisible(true); unassignedTargetsLabel.setVisible(true);
@@ -211,7 +247,6 @@ public class GroupsLegendLayout extends VerticalLayout {
unassignedTargetsLabel.setValue(""); unassignedTargetsLabel.setValue("");
unassignedTargetsLabel.setVisible(false); unassignedTargetsLabel.setVisible(false);
} }
} }
/** /**
@@ -223,7 +258,7 @@ public class GroupsLegendLayout extends VerticalLayout {
public void populateGroupsLegendByGroups(final List<RolloutGroup> groups) { public void populateGroupsLegendByGroups(final List<RolloutGroup> groups) {
loadingLabel.setVisible(false); loadingLabel.setVisible(false);
for (int i = 0; i < groupsLegend.getComponentCount(); i++) { for (int i = 0; i < getGroupsWithoutToBeContinuedLabel(groups.size()); i++) {
final Component component = groupsLegend.getComponent(i); final Component component = groupsLegend.getComponent(i);
final Label label = (Label) component; final Label label = (Label) component;
if (groups.size() > i) { if (groups.size() > i) {
@@ -238,6 +273,7 @@ public class GroupsLegendLayout extends VerticalLayout {
} }
} }
showOrHideToBeContinueLabel(groups);
} }
private String getTargetsInGroupMessage(final Long targets, final String groupName) { private String getTargetsInGroupMessage(final Long targets, final String groupName) {