Skip to content

Commit 0d74b95

Browse files
committed
Breaking: Rename NavItem method getDestination to getRoute
Since the destination property in v2 is normalized to always be a route it no longer makes sense to have a divergent name for it.
1 parent e6c8cc2 commit 0d74b95

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

packages/framework/resources/views/components/docs/sidebar-item.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
: 'active bg-black/5 dark:bg-black/10' => $item->isCurrent()
55
]) role="listitem">
66
@if($item->isCurrent())
7-
<a href="{{ $item->getDestination() }}" aria-current="true" @class([$grouped
7+
<a href="{{ $item->getRoute() }}" aria-current="true" @class([$grouped
88
? '-ml-8 pl-4 py-1 px-2 block text-indigo-600 dark:text-indigo-400 dark:font-medium border-l-[0.325rem] border-indigo-500 transition-colors duration-300 ease-in-out hover:bg-black/10'
99
: '-ml-4 p-2 block hover:bg-black/5 dark:hover:bg-black/10 text-indigo-600 dark:text-indigo-400 dark:font-medium border-l-[0.325rem] border-indigo-500 transition-colors duration-300 ease-in-out'
1010
])>
@@ -16,7 +16,7 @@
1616
{!! $page->getTableOfContents() !!}
1717
@endif
1818
@else
19-
<a href="{{ $item->getDestination() }}" @class([$grouped
19+
<a href="{{ $item->getRoute() }}" @class([$grouped
2020
? '-ml-8 pl-4 py-1 px-2 block border-l-[0.325rem] border-transparent transition-colors duration-300 ease-in-out hover:bg-black/10'
2121
: 'block -ml-4 p-2 border-l-[0.325rem] border-transparent hover:bg-black/5 dark:hover:bg-black/10'
2222
])>

packages/framework/src/Framework/Features/Navigation/NavItem.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public function __toString(): string
116116
/**
117117
* Get the destination route of the navigation item. For dropdowns, this will return null.
118118
*/
119-
public function getDestination(): ?Route
119+
public function getRoute(): ?Route
120120
{
121121
return $this->route;
122122
}
@@ -144,7 +144,7 @@ public function getLabel(): string
144144
*/
145145
public function getPriority(): int
146146
{
147-
if ($this->hasChildren() && $this->children[0]->getDestination()->getPageClass() === DocumentationPage::class) {
147+
if ($this->hasChildren() && $this->children[0]->getRoute()->getPageClass() === DocumentationPage::class) {
148148
return min($this->priority, collect($this->getChildren())->min(fn (NavItem $child): int => $child->getPriority()));
149149
}
150150

packages/framework/tests/Unit/NavItemTest.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,36 +44,36 @@ public function testConstruct()
4444
$route = new Route(new MarkdownPage());
4545
$item = new NavItem($route, 'Test', 500);
4646

47-
$this->assertSame($route, $item->getDestination());
47+
$this->assertSame($route, $item->getRoute());
4848
}
4949

5050
public function testPassingRouteInstanceToConstructorUsesRouteInstance()
5151
{
5252
$route = new Route(new MarkdownPage());
53-
$this->assertSame($route, (new NavItem($route, 'Home'))->getDestination());
53+
$this->assertSame($route, (new NavItem($route, 'Home'))->getRoute());
5454
}
5555

5656
public function testPassingRouteKeyToConstructorUsesRouteInstance()
5757
{
5858
$route = Routes::get('index');
5959

60-
$this->assertSame($route, (new NavItem('index', 'Home'))->getDestination());
60+
$this->assertSame($route, (new NavItem('index', 'Home'))->getRoute());
6161
}
6262

6363
public function testPassingUrlToConstructorUsesExternalRoute()
6464
{
6565
$item = new NavItem('https://example.com', 'Home');
66-
$this->assertInstanceOf(ExternalRoute::class, $item->getDestination());
67-
$this->assertEquals(new ExternalRoute('https://example.com'), $item->getDestination());
68-
$this->assertSame('https://example.com', (string) $item->getDestination());
66+
$this->assertInstanceOf(ExternalRoute::class, $item->getRoute());
67+
$this->assertEquals(new ExternalRoute('https://example.com'), $item->getRoute());
68+
$this->assertSame('https://example.com', (string) $item->getRoute());
6969
}
7070

7171
public function testPassingUnknownRouteKeyToConstructorUsesExternalRoute()
7272
{
7373
$item = new NavItem('foo', 'Home');
74-
$this->assertInstanceOf(ExternalRoute::class, $item->getDestination());
75-
$this->assertEquals(new ExternalRoute('foo'), $item->getDestination());
76-
$this->assertSame('foo', (string) $item->getDestination());
74+
$this->assertInstanceOf(ExternalRoute::class, $item->getRoute());
75+
$this->assertEquals(new ExternalRoute('foo'), $item->getRoute());
76+
$this->assertSame('foo', (string) $item->getRoute());
7777
}
7878

7979
public function testCanConstructWithChildren()
@@ -86,7 +86,7 @@ public function testCanConstructWithChildren()
8686
$item = new NavItem($route, 'Test', 500, null, $children);
8787

8888
$this->assertSame('Test', $item->getLabel());
89-
$this->assertNull($item->getDestination());
89+
$this->assertNull($item->getRoute());
9090
$this->assertSame(500, $item->getPriority());
9191

9292
$this->assertCount(2, $item->getChildren());
@@ -111,7 +111,7 @@ public function testCanConstructWithChildrenWithoutRoute()
111111
$item = new NavItem('', 'Test', 500, null, $children);
112112

113113
$this->assertSame('Test', $item->getLabel());
114-
$this->assertNull($item->getDestination());
114+
$this->assertNull($item->getRoute());
115115

116116
$this->assertCount(2, $item->getChildren());
117117
$this->assertSame($children, $item->getChildren());
@@ -122,7 +122,7 @@ public function testGetDestination()
122122
$route = new Route(new InMemoryPage('foo'));
123123
$navItem = new NavItem($route, 'Page', 500);
124124

125-
$this->assertSame($route, $navItem->getDestination());
125+
$this->assertSame($route, $navItem->getRoute());
126126
}
127127

128128
public function testGetLink()
@@ -171,7 +171,7 @@ public function testFromRoute()
171171
$route = new Route(new MarkdownPage());
172172
$item = NavItem::forRoute($route);
173173

174-
$this->assertSame($route, $item->getDestination());
174+
$this->assertSame($route, $item->getRoute());
175175
}
176176

177177
public function testToString()
@@ -185,7 +185,7 @@ public function testForLink()
185185
{
186186
$item = NavItem::forLink('foo', 'bar');
187187

188-
$this->assertEquals(new ExternalRoute('foo'), $item->getDestination());
188+
$this->assertEquals(new ExternalRoute('foo'), $item->getRoute());
189189
$this->assertSame('bar', $item->getLabel());
190190
$this->assertSame(500, $item->getPriority());
191191
}
@@ -200,7 +200,7 @@ public function testForRoute()
200200
$route = Routes::get('404');
201201
$item = NavItem::forRoute($route, 'foo');
202202

203-
$this->assertSame($route, $item->getDestination());
203+
$this->assertSame($route, $item->getRoute());
204204
$this->assertSame('foo', $item->getLabel());
205205
$this->assertSame(999, $item->getPriority());
206206
}
@@ -210,7 +210,7 @@ public function testForIndexRoute()
210210
$route = Routes::get('index');
211211
$item = NavItem::forRoute($route, 'foo');
212212

213-
$this->assertSame($route, $item->getDestination());
213+
$this->assertSame($route, $item->getRoute());
214214
$this->assertSame('foo', $item->getLabel());
215215
$this->assertSame(0, $item->getPriority());
216216
}

0 commit comments

Comments
 (0)