From e57495a0e548fb6d96e8c9137428b69569fcbddd Mon Sep 17 00:00:00 2001
From: Ugur Saglam <106508695+ugur-vaadin@users.noreply.github.com>
Date: Wed, 21 Aug 2024 14:24:54 +0300
Subject: [PATCH] feat: add title API to dashboard widget (#6560)
* feat: add title for widget
* chore: run formatter
* refactor: use properties instead of attributes
* docs: fix the widget title property name
---
.../pom.xml | 12 ++++++
.../dashboard/tests/DashboardWidgetPage.java | 26 +++++++++++++
.../dashboard/tests/DashboardWidgetIT.java | 37 +++++++++++++++++++
.../vaadin-dashboard-flow/pom.xml | 4 ++
.../component/dashboard/DashboardWidget.java | 19 ++++++++++
.../testbench/DashboardWidgetElement.java | 9 +++++
6 files changed, 107 insertions(+)
create mode 100644 vaadin-dashboard-flow-parent/vaadin-dashboard-flow-integration-tests/src/main/java/com/vaadin/flow/component/dashboard/tests/DashboardWidgetPage.java
create mode 100644 vaadin-dashboard-flow-parent/vaadin-dashboard-flow-integration-tests/src/test/java/com/vaadin/flow/component/dashboard/tests/DashboardWidgetIT.java
diff --git a/vaadin-dashboard-flow-parent/vaadin-dashboard-flow-integration-tests/pom.xml b/vaadin-dashboard-flow-parent/vaadin-dashboard-flow-integration-tests/pom.xml
index 59155d632aa..ee0df3328d0 100644
--- a/vaadin-dashboard-flow-parent/vaadin-dashboard-flow-integration-tests/pom.xml
+++ b/vaadin-dashboard-flow-parent/vaadin-dashboard-flow-integration-tests/pom.xml
@@ -59,6 +59,18 @@
com.vaadin
flow-polymer-template
+
+ com.vaadin
+ vaadin-dashboard-flow
+ 24.5-SNAPSHOT
+ compile
+
+
+ com.vaadin
+ vaadin-dashboard-testbench
+ 24.5-SNAPSHOT
+ test
+
diff --git a/vaadin-dashboard-flow-parent/vaadin-dashboard-flow-integration-tests/src/main/java/com/vaadin/flow/component/dashboard/tests/DashboardWidgetPage.java b/vaadin-dashboard-flow-parent/vaadin-dashboard-flow-integration-tests/src/main/java/com/vaadin/flow/component/dashboard/tests/DashboardWidgetPage.java
new file mode 100644
index 00000000000..38f107b52ff
--- /dev/null
+++ b/vaadin-dashboard-flow-parent/vaadin-dashboard-flow-integration-tests/src/main/java/com/vaadin/flow/component/dashboard/tests/DashboardWidgetPage.java
@@ -0,0 +1,26 @@
+/**
+ * Copyright 2000-2024 Vaadin Ltd.
+ *
+ * This program is available under Vaadin Commercial License and Service Terms.
+ *
+ * See {@literal } for the full
+ * license.
+ */
+package com.vaadin.flow.component.dashboard.tests;
+
+import com.vaadin.flow.component.dashboard.DashboardWidget;
+import com.vaadin.flow.component.html.Div;
+import com.vaadin.flow.router.Route;
+
+/**
+ * @author Vaadin Ltd
+ */
+@Route("vaadin-dashboard-widget")
+public class DashboardWidgetPage extends Div {
+
+ public DashboardWidgetPage() {
+ DashboardWidget widget = new DashboardWidget();
+ widget.setTitle("Widget");
+ add(widget);
+ }
+}
diff --git a/vaadin-dashboard-flow-parent/vaadin-dashboard-flow-integration-tests/src/test/java/com/vaadin/flow/component/dashboard/tests/DashboardWidgetIT.java b/vaadin-dashboard-flow-parent/vaadin-dashboard-flow-integration-tests/src/test/java/com/vaadin/flow/component/dashboard/tests/DashboardWidgetIT.java
new file mode 100644
index 00000000000..d48f1dac051
--- /dev/null
+++ b/vaadin-dashboard-flow-parent/vaadin-dashboard-flow-integration-tests/src/test/java/com/vaadin/flow/component/dashboard/tests/DashboardWidgetIT.java
@@ -0,0 +1,37 @@
+/**
+ * Copyright 2000-2024 Vaadin Ltd.
+ *
+ * This program is available under Vaadin Commercial License and Service Terms.
+ *
+ * See {@literal } for the full
+ * license.
+ */
+package com.vaadin.flow.component.dashboard.tests;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.vaadin.flow.component.dashboard.testbench.DashboardWidgetElement;
+import com.vaadin.flow.testutil.TestPath;
+import com.vaadin.tests.AbstractComponentIT;
+
+/**
+ * @author Vaadin Ltd
+ */
+@TestPath("vaadin-dashboard-widget")
+public class DashboardWidgetIT extends AbstractComponentIT {
+
+ private DashboardWidgetElement widget;
+
+ @Before
+ public void init() {
+ open();
+ widget = $(DashboardWidgetElement.class).waitForFirst();
+ }
+
+ @Test
+ public void titleIsSetCorrectly() {
+ Assert.assertEquals("Widget", widget.getTitle());
+ }
+}
diff --git a/vaadin-dashboard-flow-parent/vaadin-dashboard-flow/pom.xml b/vaadin-dashboard-flow-parent/vaadin-dashboard-flow/pom.xml
index 3c9778e08dc..aac38f7d4d4 100644
--- a/vaadin-dashboard-flow-parent/vaadin-dashboard-flow/pom.xml
+++ b/vaadin-dashboard-flow-parent/vaadin-dashboard-flow/pom.xml
@@ -50,6 +50,10 @@
jakarta.jakartaee-web-api
test
+
+ com.vaadin
+ flow-html-components
+
diff --git a/vaadin-dashboard-flow-parent/vaadin-dashboard-flow/src/main/java/com/vaadin/flow/component/dashboard/DashboardWidget.java b/vaadin-dashboard-flow-parent/vaadin-dashboard-flow/src/main/java/com/vaadin/flow/component/dashboard/DashboardWidget.java
index 9198a9d8dcf..270963d93ad 100644
--- a/vaadin-dashboard-flow-parent/vaadin-dashboard-flow/src/main/java/com/vaadin/flow/component/dashboard/DashboardWidget.java
+++ b/vaadin-dashboard-flow-parent/vaadin-dashboard-flow/src/main/java/com/vaadin/flow/component/dashboard/DashboardWidget.java
@@ -22,4 +22,23 @@
@JsModule("@vaadin/dashboard/src/vaadin-dashboard-widget.js")
// @NpmPackage(value = "@vaadin/dashboard", version = "24.6.0-alpha0")
public class DashboardWidget extends Component {
+
+ /**
+ * Returns the title of the widget.
+ *
+ * @return the {@code widgetTitle} property from the web component
+ */
+ public String getTitle() {
+ return getElement().getProperty("widgetTitle");
+ }
+
+ /**
+ * Sets the title of the widget.
+ *
+ * @param title
+ * the title to set
+ */
+ public void setTitle(String title) {
+ getElement().setProperty("widgetTitle", title == null ? "" : title);
+ }
}
diff --git a/vaadin-dashboard-flow-parent/vaadin-dashboard-testbench/src/main/java/com/vaadin/flow/component/dashboard/testbench/DashboardWidgetElement.java b/vaadin-dashboard-flow-parent/vaadin-dashboard-testbench/src/main/java/com/vaadin/flow/component/dashboard/testbench/DashboardWidgetElement.java
index 8dd67498b6e..cffaee9d1e0 100644
--- a/vaadin-dashboard-flow-parent/vaadin-dashboard-testbench/src/main/java/com/vaadin/flow/component/dashboard/testbench/DashboardWidgetElement.java
+++ b/vaadin-dashboard-flow-parent/vaadin-dashboard-testbench/src/main/java/com/vaadin/flow/component/dashboard/testbench/DashboardWidgetElement.java
@@ -16,4 +16,13 @@
*/
@Element("vaadin-dashboard-widget")
public class DashboardWidgetElement extends TestBenchElement {
+
+ /**
+ * Returns the title of the widget.
+ *
+ * @return the {@code widgetTitle} property from the web component
+ */
+ public String getTitle() {
+ return getPropertyString("widgetTitle");
+ }
}