From 9051806be2f59b3d3eed79a66a96cae2a3a702d5 Mon Sep 17 00:00:00 2001 From: Momo Bel Date: Fri, 23 Jan 2026 09:59:54 +0100 Subject: [PATCH] ui: Make item selection during creation smoother (#2878) Rollout creation and target assignment easier with full lazy loading - Use a ComboBox to be able to search through items - Ensure all items are displayed Signed-off-by: Mohamed Belaouad --- .../eclipse/hawkbit/ui/view/RolloutView.java | 27 ++++++++----------- .../eclipse/hawkbit/ui/view/TargetView.java | 14 ++++------ .../eclipse/hawkbit/ui/view/util/Utils.java | 14 ++++++++++ 3 files changed, 30 insertions(+), 25 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/view/RolloutView.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/view/RolloutView.java index 2c91d11ce..34068910c 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/view/RolloutView.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/view/RolloutView.java @@ -25,6 +25,7 @@ import com.vaadin.flow.component.Text; import com.vaadin.flow.component.button.Button; import com.vaadin.flow.component.button.ButtonVariant; import com.vaadin.flow.component.checkbox.Checkbox; +import com.vaadin.flow.component.combobox.ComboBox; import com.vaadin.flow.component.datetimepicker.DateTimePicker; import com.vaadin.flow.component.dependency.Uses; import com.vaadin.flow.component.formlayout.FormLayout; @@ -283,8 +284,8 @@ public class RolloutView extends TableView { private static class CreateDialog extends Utils.BaseDialog { private final TextField name; - private final Select distributionSet; - private final Select targetFilter; + private final ComboBox distributionSet; + private final ComboBox targetFilter; private final TextArea description; private final Select actionType; private final DateTimePicker forceTime = new DateTimePicker("Force Time"); @@ -301,27 +302,21 @@ public class RolloutView extends TableView { name = Utils.textField("Name", this::readyToCreate); name.focus(); - distributionSet = new Select<>( + distributionSet = Utils.nameComboBox( "Distribution Set", this::readyToCreate, - Optional.ofNullable( - hawkbitClient.getDistributionSetRestApi() - .getDistributionSets(null, 0, 30, Constants.CREATED_AT_DESC) - .getBody()) - .map(body -> body.getContent().toArray(new MgmtDistributionSet[0])) - .orElseGet(() -> new MgmtDistributionSet[0])); + query -> hawkbitClient.getDistributionSetRestApi() + .getDistributionSets(query.getFilter().orElse(null), query.getOffset(), query.getPageSize(), Constants.NAME_ASC) + .getBody().getContent().stream()); distributionSet.setRequiredIndicatorVisible(true); distributionSet.setItemLabelGenerator(distributionSetO -> distributionSetO.getName() + ":" + distributionSetO.getVersion()); distributionSet.setWidthFull(); - targetFilter = new Select<>( + targetFilter = Utils.nameComboBox( "Target Filter", this::readyToCreate, - Optional.ofNullable( - hawkbitClient.getTargetFilterQueryRestApi() - .getFilters(null, 0, 30, Constants.NAME_ASC, null) - .getBody()) - .map(body -> body.getContent().toArray(new MgmtTargetFilterQuery[0])) - .orElseGet(() -> new MgmtTargetFilterQuery[0])); + query -> hawkbitClient.getTargetFilterQueryRestApi() + .getFilters(query.getFilter().orElse(null), query.getOffset(), query.getPageSize(), Constants.NAME_ASC, null) + .getBody().getContent().stream()); targetFilter.setRequiredIndicatorVisible(true); targetFilter.setItemLabelGenerator(MgmtTargetFilterQuery::getName); targetFilter.setWidthFull(); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/view/TargetView.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/view/TargetView.java index 920de88a3..2a7d556df 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/view/TargetView.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/view/TargetView.java @@ -843,7 +843,7 @@ public class TargetView extends TableView { private static class AssignDialog extends Utils.BaseDialog { - private final Select distributionSet; + private final ComboBox distributionSet; private final Select actionType; private final DateTimePicker forceTime = new DateTimePicker("Force Time"); private final Button assign = new Button("Assign"); @@ -851,16 +851,12 @@ public class TargetView extends TableView { private AssignDialog(final HawkbitMgmtClient hawkbitClient, Set selectedTargets) { super("Assign Distribution Set"); - distributionSet = new Select<>( + distributionSet = Utils.nameComboBox( "Distribution Set", this::readyToAssign, - Optional.ofNullable( - hawkbitClient.getDistributionSetRestApi() - .getDistributionSets(null, 0, 500, Constants.CREATED_AT_DESC) - .getBody()) - .map(body -> body.getContent().toArray(new MgmtDistributionSet[0])) - .orElseGet(() -> new MgmtDistributionSet[0]) - ); + query -> hawkbitClient.getDistributionSetRestApi() + .getDistributionSets(query.getFilter().orElse(null), query.getOffset(), query.getPageSize(), Constants.NAME_ASC) + .getBody().getContent().stream()); distributionSet.setRequiredIndicatorVisible(true); distributionSet.setItemLabelGenerator(distributionSetO -> distributionSetO.getName() + ":" + distributionSetO.getVersion()); distributionSet.setWidthFull(); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/view/util/Utils.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/view/util/Utils.java index 2aa544724..714f37857 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/view/util/Utils.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/view/util/Utils.java @@ -35,6 +35,7 @@ import com.vaadin.flow.component.UI; import com.vaadin.flow.component.Unit; import com.vaadin.flow.component.button.Button; import com.vaadin.flow.component.button.ButtonVariant; +import com.vaadin.flow.component.combobox.ComboBox; import com.vaadin.flow.component.confirmdialog.ConfirmDialog; import com.vaadin.flow.component.datetimepicker.DateTimePicker; import com.vaadin.flow.component.dialog.Dialog; @@ -51,6 +52,7 @@ import com.vaadin.flow.component.shared.Tooltip; import com.vaadin.flow.component.textfield.NumberField; import com.vaadin.flow.component.textfield.TextField; import com.vaadin.flow.data.provider.QuerySortOrder; +import com.vaadin.flow.data.provider.CallbackDataProvider.FetchCallback; import com.vaadin.flow.data.provider.SortDirection; import com.vaadin.flow.data.renderer.ComponentRenderer; import com.vaadin.flow.data.renderer.LocalDateTimeRenderer; @@ -67,6 +69,8 @@ public class Utils { // prevent initialization } + public static final String COMBO_NAME_ALLOWED_CHARS = "[0-9a-zA-Z-_./]"; + public static TextField textField(final String label) { return textField(label, null); } @@ -99,6 +103,16 @@ public class Utils { return numberField; } + public static ComboBox nameComboBox( + final String label, + final Consumer> changeListener, + final FetchCallback listHandler) { + final ComboBox combo = new ComboBox(label, changeListener::accept); + combo.setAllowedCharPattern(Utils.COMBO_NAME_ALLOWED_CHARS); + combo.setItemsWithFilterConverter(listHandler, nameFilter -> "name==*" + nameFilter + "*"); + return combo; + } + @SuppressWarnings("java:S119") // better readability public static HorizontalLayout addRemoveControls( final Function, CompletionStage> addHandler,