Skip to content

Commit 315d799

Browse files
authored
Revert "feat: create side nav from menu entries (#6957)" (#6967)
This reverts commit e3cb174.
1 parent 80193d6 commit 315d799

File tree

5 files changed

+0
-190
lines changed

5 files changed

+0
-190
lines changed

vaadin-side-nav-flow-parent/vaadin-side-nav-flow/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@
2121
<artifactId>vaadin-flow-components-base</artifactId>
2222
<version>${project.version}</version>
2323
</dependency>
24-
<dependency>
25-
<groupId>com.vaadin</groupId>
26-
<artifactId>vaadin-icons-flow</artifactId>
27-
<version>${project.version}</version>
28-
</dependency>
2924
<dependency>
3025
<groupId>jakarta.platform</groupId>
3126
<artifactId>jakarta.jakartaee-web-api</artifactId>

vaadin-side-nav-flow-parent/vaadin-side-nav-flow/src/main/java/com/vaadin/flow/component/sidenav/SideNav.java

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package com.vaadin.flow.component.sidenav;
1717

1818
import java.io.Serializable;
19-
import java.util.Collection;
2019
import java.util.Objects;
2120

2221
import com.vaadin.flow.component.HasSize;
@@ -27,8 +26,6 @@
2726
import com.vaadin.flow.component.dependency.NpmPackage;
2827
import com.vaadin.flow.dom.Element;
2928
import com.vaadin.flow.internal.JsonSerializer;
30-
import com.vaadin.flow.server.menu.MenuConfiguration;
31-
import com.vaadin.flow.server.menu.MenuEntry;
3229

3330
/**
3431
* A side navigation menu with support for hierarchical and flat menus.
@@ -64,24 +61,6 @@ public SideNav(String label) {
6461
setLabel(label);
6562
}
6663

67-
/**
68-
* Creates a new menu from the given menu entries, which can be retrieved
69-
* from {@link MenuConfiguration}.
70-
*
71-
* @param menuEntries
72-
* the menu entries to add
73-
* @see MenuConfiguration
74-
* @see MenuEntry
75-
* @see SideNavItem#SideNavItem(MenuEntry)
76-
*/
77-
public SideNav(Collection<MenuEntry> menuEntries) {
78-
Objects.requireNonNull(menuEntries, "menuEntries cannot be null");
79-
80-
for (MenuEntry menuEntry : menuEntries) {
81-
addItem(new SideNavItem(menuEntry));
82-
}
83-
}
84-
8564
/**
8665
* Gets the label of this side navigation menu.
8766
*

vaadin-side-nav-flow-parent/vaadin-side-nav-flow/src/main/java/com/vaadin/flow/component/sidenav/SideNavItem.java

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,13 @@
2424
import java.util.function.Function;
2525
import java.util.stream.Collectors;
2626

27-
import org.slf4j.LoggerFactory;
28-
2927
import com.vaadin.flow.component.Component;
3028
import com.vaadin.flow.component.ComponentUtil;
3129
import com.vaadin.flow.component.HasEnabled;
3230
import com.vaadin.flow.component.Synchronize;
3331
import com.vaadin.flow.component.Tag;
3432
import com.vaadin.flow.component.dependency.JsModule;
3533
import com.vaadin.flow.component.dependency.NpmPackage;
36-
import com.vaadin.flow.component.icon.AbstractIcon;
37-
import com.vaadin.flow.component.icon.Icon;
38-
import com.vaadin.flow.component.icon.SvgIcon;
3934
import com.vaadin.flow.component.shared.HasPrefix;
4035
import com.vaadin.flow.component.shared.HasSuffix;
4136
import com.vaadin.flow.dom.Element;
@@ -48,8 +43,6 @@
4843
import com.vaadin.flow.router.RouteParameters;
4944
import com.vaadin.flow.router.internal.ConfigureRoutes;
5045
import com.vaadin.flow.router.internal.HasUrlParameterFormat;
51-
import com.vaadin.flow.server.menu.MenuConfiguration;
52-
import com.vaadin.flow.server.menu.MenuEntry;
5346

5447
import elemental.json.JsonArray;
5548

@@ -204,66 +197,6 @@ public SideNavItem(String label, Class<? extends Component> view,
204197
setPrefixComponent(prefixComponent);
205198
}
206199

207-
/**
208-
* Creates a new menu item from the given {@link MenuEntry}.
209-
* <p>
210-
* If the entry has an icon string, creates an instance of {@link Icon} or
211-
* {@link SvgIcon} based on the icon string and sets it as prefix component.
212-
* Note that only the following icon types are supported:
213-
* <ul>
214-
* <li>Icon set: the icon string contains ":" and is in the format
215-
* "icon-set:icon-name", for example "vaadin:file"</li>
216-
* <li>SVG icon: the icon string ends with ".svg"</li>
217-
* </ul>
218-
*
219-
* @param entry
220-
* the menu entry to create the item from
221-
* @see MenuEntry
222-
* @see MenuConfiguration
223-
*/
224-
public SideNavItem(MenuEntry entry) {
225-
Objects.requireNonNull(entry, "Menu entry cannot be null");
226-
227-
setLabel(entry.title());
228-
229-
// If there is a menu class, use it as the path to also add path aliases
230-
// Client routes have no menu class, so use the path as fallback
231-
if (entry.menuClass() != null) {
232-
setPath(entry.menuClass());
233-
} else {
234-
setPath(entry.path());
235-
}
236-
237-
AbstractIcon<?> icon = createIconFromMenuEntry(entry);
238-
if (icon != null) {
239-
setPrefixComponent(icon);
240-
}
241-
}
242-
243-
private AbstractIcon<? extends AbstractIcon<?>> createIconFromMenuEntry(
244-
MenuEntry entry) {
245-
// No icon
246-
if (entry.icon() == null) {
247-
return null;
248-
}
249-
250-
// Icon set
251-
if (entry.icon().contains(":") && entry.icon().split(":").length == 2) {
252-
return new Icon(entry.icon());
253-
}
254-
255-
// SVG icon
256-
if (entry.icon().endsWith(".svg")) {
257-
return new SvgIcon(entry.icon());
258-
}
259-
260-
// Icon component doesn't support other types of icons, log a warning
261-
LoggerFactory.getLogger(SideNavItem.class)
262-
.warn("Icon type not supported: {}", entry.icon());
263-
264-
return null;
265-
}
266-
267200
@Override
268201
protected void setupSideNavItem(SideNavItem item) {
269202
item.getElement().setAttribute("slot", "children");

vaadin-side-nav-flow-parent/vaadin-side-nav-flow/src/test/java/com/vaadin/flow/component/sidenav/tests/SideNavItemTest.java

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131
import com.vaadin.flow.component.Component;
3232
import com.vaadin.flow.component.ComponentUtil;
3333
import com.vaadin.flow.component.html.Div;
34-
import com.vaadin.flow.component.icon.Icon;
35-
import com.vaadin.flow.component.icon.SvgIcon;
3634
import com.vaadin.flow.component.sidenav.SideNavItem;
3735
import com.vaadin.flow.dom.Element;
3836
import com.vaadin.flow.router.BeforeEvent;
@@ -45,7 +43,6 @@
4543
import com.vaadin.flow.router.RouteParameters;
4644
import com.vaadin.flow.router.Router;
4745
import com.vaadin.flow.server.VaadinContext;
48-
import com.vaadin.flow.server.menu.MenuEntry;
4946
import com.vaadin.flow.server.startup.ApplicationRouteRegistry;
5047

5148
import elemental.json.JsonArray;
@@ -221,75 +218,6 @@ public void createWithPathAndPrefix_pathAndPrefixIsSet() {
221218
Assert.assertEquals(prefixComponent, sideNavItem.getPrefixComponent());
222219
}
223220

224-
@Test(expected = NullPointerException.class)
225-
public void createFromMenuEntry_entryIsNull_throws() {
226-
new SideNavItem((MenuEntry) null);
227-
}
228-
229-
@Test
230-
public void createFromMenuEntry_setsLabelAndPath() {
231-
MenuEntry entry = new MenuEntry("path", "Test label", 0.0, null, null);
232-
SideNavItem sideNavItem = new SideNavItem(entry);
233-
234-
Assert.assertEquals("Test label", sideNavItem.getLabel());
235-
Assert.assertEquals("path", sideNavItem.getPath());
236-
}
237-
238-
@Test
239-
public void createFromMenuEntry_withMenuClass_setsRouteAndAliases() {
240-
runWithMockRouter(() -> {
241-
MenuEntry entry = new MenuEntry("path", "Test label", 0.0, null,
242-
TestRouteWithAliases.class);
243-
SideNavItem sideNavItem = new SideNavItem(entry);
244-
245-
Assert.assertEquals("Test label", sideNavItem.getLabel());
246-
Assert.assertEquals("foo/bar", sideNavItem.getPath());
247-
Assert.assertEquals(Set.of("foo/baz", "foo/qux"),
248-
sideNavItem.getPathAliases());
249-
}, TestRouteWithAliases.class);
250-
}
251-
252-
@Test
253-
public void createFromMenuEntry_withIconSetIcon_setsIcon() {
254-
MenuEntry entry = new MenuEntry("path", "Test label", 0.0,
255-
"vaadin:icon", null);
256-
SideNavItem sideNavItem = new SideNavItem(entry);
257-
258-
Assert.assertNotNull(sideNavItem.getPrefixComponent());
259-
Assert.assertTrue(sideNavItem.getPrefixComponent() instanceof Icon);
260-
Assert.assertEquals("vaadin:icon",
261-
((Icon) sideNavItem.getPrefixComponent()).getIcon());
262-
}
263-
264-
@Test
265-
public void createFromMenuEntry_withSvgIcon_setsIcon() {
266-
MenuEntry entry = new MenuEntry("path", "Test label", 0.0,
267-
"assets/globe.svg", null);
268-
SideNavItem sideNavItem = new SideNavItem(entry);
269-
270-
Assert.assertNotNull(sideNavItem.getPrefixComponent());
271-
Assert.assertTrue(sideNavItem.getPrefixComponent() instanceof SvgIcon);
272-
Assert.assertEquals("assets/globe.svg",
273-
((SvgIcon) sideNavItem.getPrefixComponent()).getSrc());
274-
}
275-
276-
@Test
277-
public void createFromMenuEntry_withoutIcon_noIconSet() {
278-
MenuEntry entry = new MenuEntry("path", "Test label", 0.0, null, null);
279-
SideNavItem sideNavItem = new SideNavItem(entry);
280-
281-
Assert.assertNull(sideNavItem.getPrefixComponent());
282-
}
283-
284-
@Test
285-
public void createFromMenuEntry_unsupportedIcon_noIconSet() {
286-
MenuEntry entry = new MenuEntry("path", "Test label", 0.0,
287-
"assets/globe.png", null);
288-
SideNavItem sideNavItem = new SideNavItem(entry);
289-
290-
Assert.assertNull(sideNavItem.getPrefixComponent());
291-
}
292-
293221
// EXPAND AND COLLAPSE TESTS
294222

295223
@Test

vaadin-side-nav-flow-parent/vaadin-side-nav-flow/src/test/java/com/vaadin/flow/component/sidenav/tests/SideNavTest.java

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import static com.vaadin.flow.component.sidenav.tests.SideNavTest.SetLabelOption.SET_NO_LABEL;
2222

2323
import java.util.ArrayList;
24-
import java.util.Collection;
2524
import java.util.List;
2625
import java.util.Objects;
2726

@@ -32,7 +31,6 @@
3231
import com.vaadin.flow.component.sidenav.SideNav;
3332
import com.vaadin.flow.component.sidenav.SideNavItem;
3433
import com.vaadin.flow.dom.Element;
35-
import com.vaadin.flow.server.menu.MenuEntry;
3634

3735
public class SideNavTest {
3836

@@ -401,29 +399,6 @@ public void removeUnknownItem_nothingHappens() {
401399
Assert.assertEquals(sideNav.getItems(), sideNavItems);
402400
}
403401

404-
@Test
405-
public void createFromMenuEntries_menuEntriesAdded() {
406-
MenuEntry entry1 = new MenuEntry("path1", "Item 1", 0.0, null, null);
407-
MenuEntry entry2 = new MenuEntry("path2", "Item 2", 1.0, null, null);
408-
MenuEntry entry3 = new MenuEntry("path3", "Item 3", 2.0, null, null);
409-
List<MenuEntry> menuEntries = List.of(entry1, entry2, entry3);
410-
411-
SideNav nav = new SideNav(menuEntries);
412-
413-
Assert.assertEquals(3, nav.getItems().size());
414-
Assert.assertEquals("Item 1", nav.getItems().get(0).getLabel());
415-
Assert.assertEquals("path1", nav.getItems().get(0).getPath());
416-
Assert.assertEquals("Item 2", nav.getItems().get(1).getLabel());
417-
Assert.assertEquals("path2", nav.getItems().get(1).getPath());
418-
Assert.assertEquals("Item 3", nav.getItems().get(2).getLabel());
419-
Assert.assertEquals("path3", nav.getItems().get(2).getPath());
420-
}
421-
422-
@Test(expected = NullPointerException.class)
423-
public void createFromNullMenuEntries_throws() {
424-
new SideNav((Collection<MenuEntry>) null);
425-
}
426-
427402
enum SetLabelOption {
428403
SET_NO_LABEL, SET_LABEL_BEFORE_ITEMS_CREATION, SET_LABEL_DURING_ITEMS_CREATION, SET_LABEL_AFTER_ITEMS_CREATION
429404
}

0 commit comments

Comments
 (0)