Skip to content

Commit

Permalink
feat: add title API to dashboard widget (#6560)
Browse files Browse the repository at this point in the history
* feat: add title for widget

* chore: run formatter

* refactor: use properties instead of attributes

* docs: fix the widget title property name
  • Loading branch information
ugur-vaadin committed Oct 10, 2024
1 parent c2214cc commit e57495a
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@
<groupId>com.vaadin</groupId>
<artifactId>flow-polymer-template</artifactId>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-dashboard-flow</artifactId>
<version>24.5-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-dashboard-testbench</artifactId>
<version>24.5-SNAPSHOT</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Copyright 2000-2024 Vaadin Ltd.
*
* This program is available under Vaadin Commercial License and Service Terms.
*
* See {@literal <https://vaadin.com/commercial-license-and-service-terms>} 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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* Copyright 2000-2024 Vaadin Ltd.
*
* This program is available under Vaadin Commercial License and Service Terms.
*
* See {@literal <https://vaadin.com/commercial-license-and-service-terms>} 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());
}
}
4 changes: 4 additions & 0 deletions vaadin-dashboard-flow-parent/vaadin-dashboard-flow/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
<artifactId>jakarta.jakartaee-web-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>flow-html-components</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

0 comments on commit e57495a

Please sign in to comment.