diff --git a/vaadin-side-nav-flow-parent/vaadin-side-nav-flow/pom.xml b/vaadin-side-nav-flow-parent/vaadin-side-nav-flow/pom.xml index 1bf25d3cbe2..e0a86b8d45c 100644 --- a/vaadin-side-nav-flow-parent/vaadin-side-nav-flow/pom.xml +++ b/vaadin-side-nav-flow-parent/vaadin-side-nav-flow/pom.xml @@ -21,11 +21,6 @@ vaadin-flow-components-base ${project.version} - - com.vaadin - vaadin-icons-flow - ${project.version} - jakarta.platform jakarta.jakartaee-web-api diff --git a/vaadin-side-nav-flow-parent/vaadin-side-nav-flow/src/main/java/com/vaadin/flow/component/sidenav/SideNav.java b/vaadin-side-nav-flow-parent/vaadin-side-nav-flow/src/main/java/com/vaadin/flow/component/sidenav/SideNav.java index 659d6363dba..2ef11d17982 100644 --- a/vaadin-side-nav-flow-parent/vaadin-side-nav-flow/src/main/java/com/vaadin/flow/component/sidenav/SideNav.java +++ b/vaadin-side-nav-flow-parent/vaadin-side-nav-flow/src/main/java/com/vaadin/flow/component/sidenav/SideNav.java @@ -16,7 +16,6 @@ package com.vaadin.flow.component.sidenav; import java.io.Serializable; -import java.util.Collection; import java.util.Objects; import com.vaadin.flow.component.HasSize; @@ -27,8 +26,6 @@ import com.vaadin.flow.component.dependency.NpmPackage; import com.vaadin.flow.dom.Element; import com.vaadin.flow.internal.JsonSerializer; -import com.vaadin.flow.server.menu.MenuConfiguration; -import com.vaadin.flow.server.menu.MenuEntry; /** * A side navigation menu with support for hierarchical and flat menus. @@ -64,24 +61,6 @@ public SideNav(String label) { setLabel(label); } - /** - * Creates a new menu from the given menu entries, which can be retrieved - * from {@link MenuConfiguration}. - * - * @param menuEntries - * the menu entries to add - * @see MenuConfiguration - * @see MenuEntry - * @see SideNavItem#SideNavItem(MenuEntry) - */ - public SideNav(Collection menuEntries) { - Objects.requireNonNull(menuEntries, "menuEntries cannot be null"); - - for (MenuEntry menuEntry : menuEntries) { - addItem(new SideNavItem(menuEntry)); - } - } - /** * Gets the label of this side navigation menu. * diff --git a/vaadin-side-nav-flow-parent/vaadin-side-nav-flow/src/main/java/com/vaadin/flow/component/sidenav/SideNavItem.java b/vaadin-side-nav-flow-parent/vaadin-side-nav-flow/src/main/java/com/vaadin/flow/component/sidenav/SideNavItem.java index 3ee5dc843e1..62a5578406f 100644 --- a/vaadin-side-nav-flow-parent/vaadin-side-nav-flow/src/main/java/com/vaadin/flow/component/sidenav/SideNavItem.java +++ b/vaadin-side-nav-flow-parent/vaadin-side-nav-flow/src/main/java/com/vaadin/flow/component/sidenav/SideNavItem.java @@ -24,8 +24,6 @@ import java.util.function.Function; import java.util.stream.Collectors; -import org.slf4j.LoggerFactory; - import com.vaadin.flow.component.Component; import com.vaadin.flow.component.ComponentUtil; import com.vaadin.flow.component.HasEnabled; @@ -33,9 +31,6 @@ import com.vaadin.flow.component.Tag; import com.vaadin.flow.component.dependency.JsModule; import com.vaadin.flow.component.dependency.NpmPackage; -import com.vaadin.flow.component.icon.AbstractIcon; -import com.vaadin.flow.component.icon.Icon; -import com.vaadin.flow.component.icon.SvgIcon; import com.vaadin.flow.component.shared.HasPrefix; import com.vaadin.flow.component.shared.HasSuffix; import com.vaadin.flow.dom.Element; @@ -48,8 +43,6 @@ import com.vaadin.flow.router.RouteParameters; import com.vaadin.flow.router.internal.ConfigureRoutes; import com.vaadin.flow.router.internal.HasUrlParameterFormat; -import com.vaadin.flow.server.menu.MenuConfiguration; -import com.vaadin.flow.server.menu.MenuEntry; import elemental.json.JsonArray; @@ -204,66 +197,6 @@ public SideNavItem(String label, Class view, setPrefixComponent(prefixComponent); } - /** - * Creates a new menu item from the given {@link MenuEntry}. - *

- * If the entry has an icon string, creates an instance of {@link Icon} or - * {@link SvgIcon} based on the icon string and sets it as prefix component. - * Note that only the following icon types are supported: - *

- * - * @param entry - * the menu entry to create the item from - * @see MenuEntry - * @see MenuConfiguration - */ - public SideNavItem(MenuEntry entry) { - Objects.requireNonNull(entry, "Menu entry cannot be null"); - - setLabel(entry.title()); - - // If there is a menu class, use it as the path to also add path aliases - // Client routes have no menu class, so use the path as fallback - if (entry.menuClass() != null) { - setPath(entry.menuClass()); - } else { - setPath(entry.path()); - } - - AbstractIcon icon = createIconFromMenuEntry(entry); - if (icon != null) { - setPrefixComponent(icon); - } - } - - private AbstractIcon> createIconFromMenuEntry( - MenuEntry entry) { - // No icon - if (entry.icon() == null) { - return null; - } - - // Icon set - if (entry.icon().contains(":") && entry.icon().split(":").length == 2) { - return new Icon(entry.icon()); - } - - // SVG icon - if (entry.icon().endsWith(".svg")) { - return new SvgIcon(entry.icon()); - } - - // Icon component doesn't support other types of icons, log a warning - LoggerFactory.getLogger(SideNavItem.class) - .warn("Icon type not supported: {}", entry.icon()); - - return null; - } - @Override protected void setupSideNavItem(SideNavItem item) { item.getElement().setAttribute("slot", "children"); diff --git a/vaadin-side-nav-flow-parent/vaadin-side-nav-flow/src/test/java/com/vaadin/flow/component/sidenav/tests/SideNavItemTest.java b/vaadin-side-nav-flow-parent/vaadin-side-nav-flow/src/test/java/com/vaadin/flow/component/sidenav/tests/SideNavItemTest.java index 54e3c07ab85..bd11d914d71 100644 --- a/vaadin-side-nav-flow-parent/vaadin-side-nav-flow/src/test/java/com/vaadin/flow/component/sidenav/tests/SideNavItemTest.java +++ b/vaadin-side-nav-flow-parent/vaadin-side-nav-flow/src/test/java/com/vaadin/flow/component/sidenav/tests/SideNavItemTest.java @@ -31,8 +31,6 @@ import com.vaadin.flow.component.Component; import com.vaadin.flow.component.ComponentUtil; import com.vaadin.flow.component.html.Div; -import com.vaadin.flow.component.icon.Icon; -import com.vaadin.flow.component.icon.SvgIcon; import com.vaadin.flow.component.sidenav.SideNavItem; import com.vaadin.flow.dom.Element; import com.vaadin.flow.router.BeforeEvent; @@ -45,7 +43,6 @@ import com.vaadin.flow.router.RouteParameters; import com.vaadin.flow.router.Router; import com.vaadin.flow.server.VaadinContext; -import com.vaadin.flow.server.menu.MenuEntry; import com.vaadin.flow.server.startup.ApplicationRouteRegistry; import elemental.json.JsonArray; @@ -221,75 +218,6 @@ public void createWithPathAndPrefix_pathAndPrefixIsSet() { Assert.assertEquals(prefixComponent, sideNavItem.getPrefixComponent()); } - @Test(expected = NullPointerException.class) - public void createFromMenuEntry_entryIsNull_throws() { - new SideNavItem((MenuEntry) null); - } - - @Test - public void createFromMenuEntry_setsLabelAndPath() { - MenuEntry entry = new MenuEntry("path", "Test label", 0.0, null, null); - SideNavItem sideNavItem = new SideNavItem(entry); - - Assert.assertEquals("Test label", sideNavItem.getLabel()); - Assert.assertEquals("path", sideNavItem.getPath()); - } - - @Test - public void createFromMenuEntry_withMenuClass_setsRouteAndAliases() { - runWithMockRouter(() -> { - MenuEntry entry = new MenuEntry("path", "Test label", 0.0, null, - TestRouteWithAliases.class); - SideNavItem sideNavItem = new SideNavItem(entry); - - Assert.assertEquals("Test label", sideNavItem.getLabel()); - Assert.assertEquals("foo/bar", sideNavItem.getPath()); - Assert.assertEquals(Set.of("foo/baz", "foo/qux"), - sideNavItem.getPathAliases()); - }, TestRouteWithAliases.class); - } - - @Test - public void createFromMenuEntry_withIconSetIcon_setsIcon() { - MenuEntry entry = new MenuEntry("path", "Test label", 0.0, - "vaadin:icon", null); - SideNavItem sideNavItem = new SideNavItem(entry); - - Assert.assertNotNull(sideNavItem.getPrefixComponent()); - Assert.assertTrue(sideNavItem.getPrefixComponent() instanceof Icon); - Assert.assertEquals("vaadin:icon", - ((Icon) sideNavItem.getPrefixComponent()).getIcon()); - } - - @Test - public void createFromMenuEntry_withSvgIcon_setsIcon() { - MenuEntry entry = new MenuEntry("path", "Test label", 0.0, - "assets/globe.svg", null); - SideNavItem sideNavItem = new SideNavItem(entry); - - Assert.assertNotNull(sideNavItem.getPrefixComponent()); - Assert.assertTrue(sideNavItem.getPrefixComponent() instanceof SvgIcon); - Assert.assertEquals("assets/globe.svg", - ((SvgIcon) sideNavItem.getPrefixComponent()).getSrc()); - } - - @Test - public void createFromMenuEntry_withoutIcon_noIconSet() { - MenuEntry entry = new MenuEntry("path", "Test label", 0.0, null, null); - SideNavItem sideNavItem = new SideNavItem(entry); - - Assert.assertNull(sideNavItem.getPrefixComponent()); - } - - @Test - public void createFromMenuEntry_unsupportedIcon_noIconSet() { - MenuEntry entry = new MenuEntry("path", "Test label", 0.0, - "assets/globe.png", null); - SideNavItem sideNavItem = new SideNavItem(entry); - - Assert.assertNull(sideNavItem.getPrefixComponent()); - } - // EXPAND AND COLLAPSE TESTS @Test diff --git a/vaadin-side-nav-flow-parent/vaadin-side-nav-flow/src/test/java/com/vaadin/flow/component/sidenav/tests/SideNavTest.java b/vaadin-side-nav-flow-parent/vaadin-side-nav-flow/src/test/java/com/vaadin/flow/component/sidenav/tests/SideNavTest.java index efd97b1d25f..3d50d210033 100644 --- a/vaadin-side-nav-flow-parent/vaadin-side-nav-flow/src/test/java/com/vaadin/flow/component/sidenav/tests/SideNavTest.java +++ b/vaadin-side-nav-flow-parent/vaadin-side-nav-flow/src/test/java/com/vaadin/flow/component/sidenav/tests/SideNavTest.java @@ -21,7 +21,6 @@ import static com.vaadin.flow.component.sidenav.tests.SideNavTest.SetLabelOption.SET_NO_LABEL; import java.util.ArrayList; -import java.util.Collection; import java.util.List; import java.util.Objects; @@ -32,7 +31,6 @@ import com.vaadin.flow.component.sidenav.SideNav; import com.vaadin.flow.component.sidenav.SideNavItem; import com.vaadin.flow.dom.Element; -import com.vaadin.flow.server.menu.MenuEntry; public class SideNavTest { @@ -401,29 +399,6 @@ public void removeUnknownItem_nothingHappens() { Assert.assertEquals(sideNav.getItems(), sideNavItems); } - @Test - public void createFromMenuEntries_menuEntriesAdded() { - MenuEntry entry1 = new MenuEntry("path1", "Item 1", 0.0, null, null); - MenuEntry entry2 = new MenuEntry("path2", "Item 2", 1.0, null, null); - MenuEntry entry3 = new MenuEntry("path3", "Item 3", 2.0, null, null); - List menuEntries = List.of(entry1, entry2, entry3); - - SideNav nav = new SideNav(menuEntries); - - Assert.assertEquals(3, nav.getItems().size()); - Assert.assertEquals("Item 1", nav.getItems().get(0).getLabel()); - Assert.assertEquals("path1", nav.getItems().get(0).getPath()); - Assert.assertEquals("Item 2", nav.getItems().get(1).getLabel()); - Assert.assertEquals("path2", nav.getItems().get(1).getPath()); - Assert.assertEquals("Item 3", nav.getItems().get(2).getLabel()); - Assert.assertEquals("path3", nav.getItems().get(2).getPath()); - } - - @Test(expected = NullPointerException.class) - public void createFromNullMenuEntries_throws() { - new SideNav((Collection) null); - } - enum SetLabelOption { SET_NO_LABEL, SET_LABEL_BEFORE_ITEMS_CREATION, SET_LABEL_DURING_ITEMS_CREATION, SET_LABEL_AFTER_ITEMS_CREATION }