From 2a40705c275afd0322a4aa53561e362089da8b8f Mon Sep 17 00:00:00 2001 From: Mikael Grankvist Date: Wed, 14 Aug 2024 09:14:21 +0300 Subject: [PATCH 01/10] Add layout to configuration --- packages/ts/file-router/src/types.d.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/ts/file-router/src/types.d.ts b/packages/ts/file-router/src/types.d.ts index 819937dbee..dc01969e6d 100644 --- a/packages/ts/file-router/src/types.d.ts +++ b/packages/ts/file-router/src/types.d.ts @@ -25,6 +25,12 @@ export type ViewConfig = Readonly<{ */ route?: string; + /** + * Allows giving a layout identifier for using a server side parent layout + * annotated with the Layout annotation. + */ + layout?: string; + menu?: Readonly<{ /** * Title to use in the menu. Falls back the title property of the view From efcf2ff396ed5dd79b46e1d9636e685ee9edba3f Mon Sep 17 00:00:00 2001 From: Mikael Grankvist Date: Mon, 19 Aug 2024 11:17:39 +0300 Subject: [PATCH 02/10] Add withLayouts to RouterConfigurationBuilder rename layout String to flowLayout boolean --- .../com/vaadin/hilla/route/RouteUtilTest.java | 18 ++++----- .../src/runtime/RouterConfigurationBuilder.ts | 38 +++++++++++++++++++ packages/ts/file-router/src/types.d.ts | 4 +- 3 files changed, 49 insertions(+), 11 deletions(-) diff --git a/packages/java/endpoint/src/test/java/com/vaadin/hilla/route/RouteUtilTest.java b/packages/java/endpoint/src/test/java/com/vaadin/hilla/route/RouteUtilTest.java index 6da3a03860..444b481025 100644 --- a/packages/java/endpoint/src/test/java/com/vaadin/hilla/route/RouteUtilTest.java +++ b/packages/java/endpoint/src/test/java/com/vaadin/hilla/route/RouteUtilTest.java @@ -36,7 +36,7 @@ public void test_role_allowed() { AvailableViewInfo config = new AvailableViewInfo("Test", new String[] { "ROLE_ADMIN" }, false, "/test", false, false, - null, null, null); + null, null, null, false); routeUtil.setRoutes(Collections.singletonMap("/test", config)); Assert.assertTrue("Route should be allowed for ADMIN role.", @@ -52,7 +52,7 @@ public void test_role_not_allowed() { AvailableViewInfo config = new AvailableViewInfo("Test", new String[] { "ROLE_ADMIN" }, false, "/test", false, false, - null, null, null); + null, null, null, false); routeUtil.setRoutes(Collections.singletonMap("/test", config)); Assert.assertFalse("USER role should not allow ADMIN route.", @@ -67,7 +67,7 @@ public void test_login_required() { request.setUserPrincipal(Mockito.mock(Principal.class)); AvailableViewInfo config = new AvailableViewInfo("Test", null, true, - "/test", false, false, null, null, null); + "/test", false, false, null, null, null, false); routeUtil.setRoutes(Collections.singletonMap("/test", config)); Assert.assertTrue("Request with user principal should be allowed", @@ -82,7 +82,7 @@ public void test_login_required_failed() { request.setUserPrincipal(null); AvailableViewInfo config = new AvailableViewInfo("Test", null, true, - "/test", false, false, null, null, null); + "/test", false, false, null, null, null, false); routeUtil.setRoutes(Collections.singletonMap("/test", config)); Assert.assertFalse("No login should be denied access", @@ -97,11 +97,11 @@ public void test_login_required_on_layout() { request.setUserPrincipal(null); AvailableViewInfo pageWithoutLogin = new AvailableViewInfo("Test Page", - null, false, "/test", false, false, null, null, null); + null, false, "/test", false, false, null, null, null, false); AvailableViewInfo layoutWithLogin = new AvailableViewInfo("Test Layout", null, true, "", false, false, null, - Collections.singletonList(pageWithoutLogin), null); + Collections.singletonList(pageWithoutLogin), null, false); routeUtil.setRoutes(Map.ofEntries(entry("/test", pageWithoutLogin), entry("", layoutWithLogin))); @@ -118,11 +118,11 @@ public void test_login_required_on_page() { request.setUserPrincipal(null); AvailableViewInfo pageWithLogin = new AvailableViewInfo("Test Page", - null, true, "/test", false, false, null, null, null); + null, true, "/test", false, false, null, null, null, false); AvailableViewInfo layoutWithoutLogin = new AvailableViewInfo( "Test Layout", null, false, "", false, false, null, - Collections.singletonList(pageWithLogin), null); + Collections.singletonList(pageWithLogin), null, false); routeUtil.setRoutes(Map.ofEntries(entry("/test", pageWithLogin), entry("", layoutWithoutLogin))); @@ -142,7 +142,7 @@ public void test_login_not_required_on_root() { request.setUserPrincipal(null); AvailableViewInfo config = new AvailableViewInfo("Root", null, false, - "", false, false, null, null, null); + "", false, false, null, null, null, false); routeUtil.setRoutes(Collections.singletonMap("", config)); Assert.assertTrue("Login no required should allow access", diff --git a/packages/ts/file-router/src/runtime/RouterConfigurationBuilder.ts b/packages/ts/file-router/src/runtime/RouterConfigurationBuilder.ts index 396339a55d..0a5e0cf43e 100644 --- a/packages/ts/file-router/src/runtime/RouterConfigurationBuilder.ts +++ b/packages/ts/file-router/src/runtime/RouterConfigurationBuilder.ts @@ -143,6 +143,44 @@ export class RouterConfigurationBuilder { return this; } + withLayouts(layoutComponent: ComponentType): this { + function applyLayouts(routes: readonly RouteObject[]): readonly RouteObject[] { + const nestedRoutes = routes.map((route) => { + if (route.children === undefined) { + return route; + } + + return { + ...route, + children: applyLayouts(route.children), + } as RouteObject; + }); + return [ + { + element: createElement(layoutComponent), + children: nestedRoutes, + }, + ]; + } + + this.#modifiers.push((routes: readonly RouteObject[] | undefined) => { + if (!routes) { + return routes; + } + const withLayout = routes.filter( + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + (route) => typeof route.handle === 'object' && 'flowLayout' in route.handle && route.handle.flowLayout, + ); + const allRoutes = routes.filter((route) => !withLayout.includes(route)); + withLayout.push(routes[routes.length - 1]); // Add * fallback to all child routes + + allRoutes.unshift(...applyLayouts(withLayout)); + return allRoutes; + }); + + return this; + } + /** * Protects all the routes that require authentication. For more details see * {@link @vaadin/hilla-react-auth#protectRoutes} function. diff --git a/packages/ts/file-router/src/types.d.ts b/packages/ts/file-router/src/types.d.ts index dc01969e6d..32d9fc27f4 100644 --- a/packages/ts/file-router/src/types.d.ts +++ b/packages/ts/file-router/src/types.d.ts @@ -26,10 +26,10 @@ export type ViewConfig = Readonly<{ route?: string; /** - * Allows giving a layout identifier for using a server side parent layout + * Allows giving marking view as using server side parent layout * annotated with the Layout annotation. */ - layout?: string; + flowLayout?: boolean; menu?: Readonly<{ /** From b564a21cc20fa1a44438e4b4a0c86f4f24f1ac76 Mon Sep 17 00:00:00 2001 From: Mikael Grankvist Date: Mon, 19 Aug 2024 11:25:07 +0300 Subject: [PATCH 03/10] method doc --- .../ts/file-router/src/runtime/RouterConfigurationBuilder.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/ts/file-router/src/runtime/RouterConfigurationBuilder.ts b/packages/ts/file-router/src/runtime/RouterConfigurationBuilder.ts index 0a5e0cf43e..cebe66dbb1 100644 --- a/packages/ts/file-router/src/runtime/RouterConfigurationBuilder.ts +++ b/packages/ts/file-router/src/runtime/RouterConfigurationBuilder.ts @@ -143,6 +143,11 @@ export class RouterConfigurationBuilder { return this; } + /** + * Adds the layoutComponent as the parent layout to views with the flowLayouts ViewConfiguration set. + * + * @param layoutComponent - layout component to use, usually Flow + */ withLayouts(layoutComponent: ComponentType): this { function applyLayouts(routes: readonly RouteObject[]): readonly RouteObject[] { const nestedRoutes = routes.map((route) => { From b4f8c78cb8b225691717c0796eb7e54b5e156d66 Mon Sep 17 00:00:00 2001 From: caalador Date: Wed, 21 Aug 2024 06:38:53 +0300 Subject: [PATCH 04/10] Better explanation Co-authored-by: Soroosh Taefi --- packages/ts/file-router/src/types.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ts/file-router/src/types.d.ts b/packages/ts/file-router/src/types.d.ts index 32d9fc27f4..c5e013bfcb 100644 --- a/packages/ts/file-router/src/types.d.ts +++ b/packages/ts/file-router/src/types.d.ts @@ -26,7 +26,7 @@ export type ViewConfig = Readonly<{ route?: string; /** - * Allows giving marking view as using server side parent layout + * Set to true to indicate that the view as using server side parent layout * annotated with the Layout annotation. */ flowLayout?: boolean; From ebac3be42745b7acddc99f211337b13eda9dbb36 Mon Sep 17 00:00:00 2001 From: Mikael Grankvist Date: Wed, 21 Aug 2024 13:15:39 +0300 Subject: [PATCH 05/10] Add test for withLayouts --- .../src/runtime/RouterConfigurationBuilder.ts | 12 ++-- .../RouterConfigurationBuilder.spec.tsx | 63 +++++++++++++++++++ 2 files changed, 71 insertions(+), 4 deletions(-) diff --git a/packages/ts/file-router/src/runtime/RouterConfigurationBuilder.ts b/packages/ts/file-router/src/runtime/RouterConfigurationBuilder.ts index cebe66dbb1..6171b37ecd 100644 --- a/packages/ts/file-router/src/runtime/RouterConfigurationBuilder.ts +++ b/packages/ts/file-router/src/runtime/RouterConfigurationBuilder.ts @@ -172,12 +172,16 @@ export class RouterConfigurationBuilder { if (!routes) { return routes; } - const withLayout = routes.filter( + const withLayout = routes.filter((route) => { // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access - (route) => typeof route.handle === 'object' && 'flowLayout' in route.handle && route.handle.flowLayout, - ); + const layout = typeof route.handle === 'object' && 'flowLayout' in route.handle && route.handle.flowLayout; + return layout; + }); const allRoutes = routes.filter((route) => !withLayout.includes(route)); - withLayout.push(routes[routes.length - 1]); // Add * fallback to all child routes + const catchAll = routes.filter((route) => route.path === '*'); + if (catchAll.length > 0) { + withLayout.push(...catchAll); // Add * fallback to all child routes + } allRoutes.unshift(...applyLayouts(withLayout)); return allRoutes; diff --git a/packages/ts/file-router/test/runtime/RouterConfigurationBuilder.spec.tsx b/packages/ts/file-router/test/runtime/RouterConfigurationBuilder.spec.tsx index b3f955f48b..3f6cea4ec5 100644 --- a/packages/ts/file-router/test/runtime/RouterConfigurationBuilder.spec.tsx +++ b/packages/ts/file-router/test/runtime/RouterConfigurationBuilder.spec.tsx @@ -1,5 +1,6 @@ import { expect, use } from '@esm-bundle/chai'; import chaiLike from 'chai-like'; +import { createElement } from 'react'; import sinonChai from 'sinon-chai'; import { RouterConfigurationBuilder } from '../../src/runtime/RouterConfigurationBuilder.js'; import { mockDocumentBaseURI } from '../mocks/dom.js'; @@ -81,6 +82,68 @@ describe('RouterBuilder', () => { ]); }); + it('should add layout routes under layout component', () => { + const serverWildcard = { + path: '*', + element: , + handle: { title: 'Server' }, + }; + const serverIndex = { + index: true, + element: , + handle: { title: 'Server' }, + }; + + const serverRoutes = [serverWildcard, serverIndex]; + + const { routes } = builder + .withReactRoutes([ + { + path: '', + handle: { + flowLayout: true, + }, + }, + { + path: '/test', + handle: { + flowLayout: true, + }, + }, + ]) + .withLayouts(Server) + .build(); + + expect(routes).to.be.like([ + { + children: [ + { + path: '', + handle: { + flowLayout: true, + }, + }, + { + path: '/test', + handle: { + flowLayout: true, + }, + }, + ], + element: createElement(Server), + }, + { + children: [ + { + path: '/test', + element:
Test
, + }, + ], + path: '', + }, + ]); + }); + it('should merge file routes deeply', () => { const { routes } = builder .withFileRoutes([ From 220bd58e78ccc5ccfb7a321af55cf4e68c07d207 Mon Sep 17 00:00:00 2001 From: Mikael Grankvist Date: Thu, 22 Aug 2024 15:06:01 +0300 Subject: [PATCH 06/10] add child route --- .../src/runtime/RouterConfigurationBuilder.ts | 6 ++---- .../runtime/RouterConfigurationBuilder.spec.tsx | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/packages/ts/file-router/src/runtime/RouterConfigurationBuilder.ts b/packages/ts/file-router/src/runtime/RouterConfigurationBuilder.ts index 6171b37ecd..407d4ce6ff 100644 --- a/packages/ts/file-router/src/runtime/RouterConfigurationBuilder.ts +++ b/packages/ts/file-router/src/runtime/RouterConfigurationBuilder.ts @@ -178,10 +178,8 @@ export class RouterConfigurationBuilder { return layout; }); const allRoutes = routes.filter((route) => !withLayout.includes(route)); - const catchAll = routes.filter((route) => route.path === '*'); - if (catchAll.length > 0) { - withLayout.push(...catchAll); // Add * fallback to all child routes - } + const catchAll = [routes.find((route) => route.path === '*')].filter((route) => route !== undefined); + withLayout.push(...catchAll); // Add * fallback to all child routes allRoutes.unshift(...applyLayouts(withLayout)); return allRoutes; diff --git a/packages/ts/file-router/test/runtime/RouterConfigurationBuilder.spec.tsx b/packages/ts/file-router/test/runtime/RouterConfigurationBuilder.spec.tsx index 3f6cea4ec5..3daa8b4f8c 100644 --- a/packages/ts/file-router/test/runtime/RouterConfigurationBuilder.spec.tsx +++ b/packages/ts/file-router/test/runtime/RouterConfigurationBuilder.spec.tsx @@ -109,6 +109,11 @@ describe('RouterBuilder', () => { handle: { flowLayout: true, }, + children: [ + { + path: '/child', + }, + ], }, ]) .withLayouts(Server) @@ -124,6 +129,16 @@ describe('RouterBuilder', () => { }, }, { + children: [ + { + children: [ + { + path: '/child', + }, + ], + element: createElement(Server), + }, + ], path: '/test', handle: { flowLayout: true, From 07fdfdef42b57841a781b170a660cce89b7ad1eb Mon Sep 17 00:00:00 2001 From: Mikael Grankvist Date: Fri, 23 Aug 2024 14:11:30 +0300 Subject: [PATCH 07/10] add test for no routes path in withLayouts --- .../test/runtime/RouterConfigurationBuilder.spec.tsx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/ts/file-router/test/runtime/RouterConfigurationBuilder.spec.tsx b/packages/ts/file-router/test/runtime/RouterConfigurationBuilder.spec.tsx index 3daa8b4f8c..cc3bb97dc4 100644 --- a/packages/ts/file-router/test/runtime/RouterConfigurationBuilder.spec.tsx +++ b/packages/ts/file-router/test/runtime/RouterConfigurationBuilder.spec.tsx @@ -159,6 +159,12 @@ describe('RouterBuilder', () => { ]); }); + it('no routes should not throw', () => { + const { routes } = new RouterConfigurationBuilder().withLayouts(Server).build(); + + expect(routes).to.be.like([]); + }); + it('should merge file routes deeply', () => { const { routes } = builder .withFileRoutes([ From 193679785cdb3f31b026190f24b38f937f290b76 Mon Sep 17 00:00:00 2001 From: Mikael Grankvist Date: Mon, 26 Aug 2024 07:23:23 +0300 Subject: [PATCH 08/10] Add new field --- .../VAADIN/available-views-admin.json | 24 ++++++++++++------- .../VAADIN/available-views-anonymous.json | 21 ++++++++++------ .../META-INF/VAADIN/available-views-user.json | 24 ++++++++++++------- .../META-INF/VAADIN/only-client-views.json | 12 ++++++---- .../VAADIN/server-and-client-views.json | 18 +++++++++----- 5 files changed, 66 insertions(+), 33 deletions(-) diff --git a/packages/java/endpoint/src/test/resources/META-INF/VAADIN/available-views-admin.json b/packages/java/endpoint/src/test/resources/META-INF/VAADIN/available-views-admin.json index 0bb1fa0c80..8b18d71b81 100644 --- a/packages/java/endpoint/src/test/resources/META-INF/VAADIN/available-views-admin.json +++ b/packages/java/endpoint/src/test/resources/META-INF/VAADIN/available-views-admin.json @@ -7,7 +7,8 @@ "route": "/foo", "lazy": false, "register": false, - "menu": null + "menu": null, + "flowLayout":false }, "/bar": { "params": {}, @@ -17,7 +18,8 @@ "route": "/bar", "lazy": false, "register": false, - "menu": null + "menu": null, + "flowLayout":false }, "/home": { "params": {}, @@ -27,7 +29,8 @@ "route": "/home", "lazy": false, "register": false, - "menu": null + "menu": null, + "flowLayout":false }, "/wildcard": { "params": { @@ -39,7 +42,8 @@ "route": "/wildcard", "lazy": false, "register": false, - "menu": null + "menu": null, + "flowLayout":false }, "/comments": { "params": { @@ -51,7 +55,8 @@ "route": "/comments", "lazy": false, "register": false, - "menu": null + "menu": null, + "flowLayout":false }, "/profile": { "params": {}, @@ -64,7 +69,8 @@ "route": "/profile", "lazy": false, "register": false, - "menu": null + "menu": null, + "flowLayout":false }, "/": { "params": {}, @@ -74,7 +80,8 @@ "route": "/", "lazy": false, "register": false, - "menu": null + "menu": null, + "flowLayout":false }, "/orders": { "params": {}, @@ -84,6 +91,7 @@ "route": "/orders", "lazy": false, "register": false, - "menu": null + "menu": null, + "flowLayout":false } } diff --git a/packages/java/endpoint/src/test/resources/META-INF/VAADIN/available-views-anonymous.json b/packages/java/endpoint/src/test/resources/META-INF/VAADIN/available-views-anonymous.json index 9f2bce8153..a51782d242 100644 --- a/packages/java/endpoint/src/test/resources/META-INF/VAADIN/available-views-anonymous.json +++ b/packages/java/endpoint/src/test/resources/META-INF/VAADIN/available-views-anonymous.json @@ -7,7 +7,8 @@ "route": "/home", "lazy": false, "register": false, - "menu": null + "menu": null, + "flowLayout":false }, "/foo": { "params": {}, @@ -17,7 +18,8 @@ "route": "/foo", "lazy": false, "register": false, - "menu": null + "menu": null, + "flowLayout":false }, "/wildcard": { "params": { @@ -29,7 +31,8 @@ "route": "/wildcard", "lazy": false, "register": false, - "menu": null + "menu": null, + "flowLayout":false }, "/bar": { "params": {}, @@ -39,7 +42,8 @@ "route": "/bar", "lazy": false, "register": false, - "menu": null + "menu": null, + "flowLayout":false }, "/comments": { "params": { @@ -51,7 +55,8 @@ "route": "/comments", "lazy": false, "register": false, - "menu": null + "menu": null, + "flowLayout":false }, "/": { "params": {}, @@ -61,7 +66,8 @@ "route": "/", "lazy": false, "register": false, - "menu": null + "menu": null, + "flowLayout":false }, "/orders": { "params": {}, @@ -71,6 +77,7 @@ "route": "/orders", "lazy": false, "register": false, - "menu": null + "menu": null, + "flowLayout":false } } diff --git a/packages/java/endpoint/src/test/resources/META-INF/VAADIN/available-views-user.json b/packages/java/endpoint/src/test/resources/META-INF/VAADIN/available-views-user.json index 0bb1fa0c80..8b18d71b81 100644 --- a/packages/java/endpoint/src/test/resources/META-INF/VAADIN/available-views-user.json +++ b/packages/java/endpoint/src/test/resources/META-INF/VAADIN/available-views-user.json @@ -7,7 +7,8 @@ "route": "/foo", "lazy": false, "register": false, - "menu": null + "menu": null, + "flowLayout":false }, "/bar": { "params": {}, @@ -17,7 +18,8 @@ "route": "/bar", "lazy": false, "register": false, - "menu": null + "menu": null, + "flowLayout":false }, "/home": { "params": {}, @@ -27,7 +29,8 @@ "route": "/home", "lazy": false, "register": false, - "menu": null + "menu": null, + "flowLayout":false }, "/wildcard": { "params": { @@ -39,7 +42,8 @@ "route": "/wildcard", "lazy": false, "register": false, - "menu": null + "menu": null, + "flowLayout":false }, "/comments": { "params": { @@ -51,7 +55,8 @@ "route": "/comments", "lazy": false, "register": false, - "menu": null + "menu": null, + "flowLayout":false }, "/profile": { "params": {}, @@ -64,7 +69,8 @@ "route": "/profile", "lazy": false, "register": false, - "menu": null + "menu": null, + "flowLayout":false }, "/": { "params": {}, @@ -74,7 +80,8 @@ "route": "/", "lazy": false, "register": false, - "menu": null + "menu": null, + "flowLayout":false }, "/orders": { "params": {}, @@ -84,6 +91,7 @@ "route": "/orders", "lazy": false, "register": false, - "menu": null + "menu": null, + "flowLayout":false } } diff --git a/packages/java/endpoint/src/test/resources/META-INF/VAADIN/only-client-views.json b/packages/java/endpoint/src/test/resources/META-INF/VAADIN/only-client-views.json index cc28c73ceb..c25c900683 100644 --- a/packages/java/endpoint/src/test/resources/META-INF/VAADIN/only-client-views.json +++ b/packages/java/endpoint/src/test/resources/META-INF/VAADIN/only-client-views.json @@ -7,7 +7,8 @@ "route": "/home", "lazy": false, "register": false, - "menu": null + "menu": null, + "flowLayout":false }, "/profile": { "params": {}, @@ -20,7 +21,8 @@ "route": "/profile", "lazy": false, "register": false, - "menu": null + "menu": null, + "flowLayout":false }, "/": { "params": {}, @@ -30,7 +32,8 @@ "route": "/", "lazy": false, "register": false, - "menu": null + "menu": null, + "flowLayout":false }, "/orders": { "params": {}, @@ -40,6 +43,7 @@ "route": "/orders", "lazy": false, "register": false, - "menu": null + "menu": null, + "flowLayout":false } } diff --git a/packages/java/endpoint/src/test/resources/META-INF/VAADIN/server-and-client-views.json b/packages/java/endpoint/src/test/resources/META-INF/VAADIN/server-and-client-views.json index 6ee29cb291..bb5dad1178 100644 --- a/packages/java/endpoint/src/test/resources/META-INF/VAADIN/server-and-client-views.json +++ b/packages/java/endpoint/src/test/resources/META-INF/VAADIN/server-and-client-views.json @@ -7,7 +7,8 @@ "route": "/foo", "lazy": false, "register": false, - "menu": null + "menu": null, + "flowLayout":false }, "/bar": { "params": {}, @@ -17,7 +18,8 @@ "route": "/bar", "lazy": false, "register": false, - "menu": null + "menu": null, + "flowLayout":false }, "/home": { "params": {}, @@ -27,7 +29,8 @@ "route": "/home", "lazy": false, "register": false, - "menu": null + "menu": null, + "flowLayout":false }, "/comments": { "params": { @@ -39,7 +42,8 @@ "route": "/comments", "lazy": false, "register": false, - "menu": null + "menu": null, + "flowLayout":false }, "/wildcard": { "params": { @@ -51,7 +55,8 @@ "route": "/wildcard", "lazy": false, "register": false, - "menu": null + "menu": null, + "flowLayout":false }, "/profile": { "params": {}, @@ -64,6 +69,7 @@ "route": "/profile", "lazy": false, "register": false, - "menu": null + "menu": null, + "flowLayout":false } } From c278cf1616ac4070038d531ebe8bb9bc3093e1cc Mon Sep 17 00:00:00 2001 From: caalador Date: Tue, 27 Aug 2024 08:10:27 +0300 Subject: [PATCH 09/10] Apply suggestions from code review Co-authored-by: Soroosh Taefi --- packages/ts/file-router/src/types.d.ts | 2 +- .../test/runtime/RouterConfigurationBuilder.spec.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/ts/file-router/src/types.d.ts b/packages/ts/file-router/src/types.d.ts index c5e013bfcb..deff5b0436 100644 --- a/packages/ts/file-router/src/types.d.ts +++ b/packages/ts/file-router/src/types.d.ts @@ -26,7 +26,7 @@ export type ViewConfig = Readonly<{ route?: string; /** - * Set to true to indicate that the view as using server side parent layout + * Set to true to indicate that the view is using server side parent layout * annotated with the Layout annotation. */ flowLayout?: boolean; diff --git a/packages/ts/file-router/test/runtime/RouterConfigurationBuilder.spec.tsx b/packages/ts/file-router/test/runtime/RouterConfigurationBuilder.spec.tsx index cc3bb97dc4..af1ed75656 100644 --- a/packages/ts/file-router/test/runtime/RouterConfigurationBuilder.spec.tsx +++ b/packages/ts/file-router/test/runtime/RouterConfigurationBuilder.spec.tsx @@ -159,7 +159,7 @@ describe('RouterBuilder', () => { ]); }); - it('no routes should not throw', () => { + it('should not throw when no routes', () => { const { routes } = new RouterConfigurationBuilder().withLayouts(Server).build(); expect(routes).to.be.like([]); From 614736bc00197ed83bd86957ab25473e9c4ae2ca Mon Sep 17 00:00:00 2001 From: Mikael Grankvist Date: Tue, 27 Aug 2024 08:12:35 +0300 Subject: [PATCH 10/10] Changfe to layout from layouts --- .../ts/file-router/src/runtime/RouterConfigurationBuilder.ts | 2 +- .../test/runtime/RouterConfigurationBuilder.spec.tsx | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/ts/file-router/src/runtime/RouterConfigurationBuilder.ts b/packages/ts/file-router/src/runtime/RouterConfigurationBuilder.ts index 407d4ce6ff..693b073da5 100644 --- a/packages/ts/file-router/src/runtime/RouterConfigurationBuilder.ts +++ b/packages/ts/file-router/src/runtime/RouterConfigurationBuilder.ts @@ -148,7 +148,7 @@ export class RouterConfigurationBuilder { * * @param layoutComponent - layout component to use, usually Flow */ - withLayouts(layoutComponent: ComponentType): this { + withLayout(layoutComponent: ComponentType): this { function applyLayouts(routes: readonly RouteObject[]): readonly RouteObject[] { const nestedRoutes = routes.map((route) => { if (route.children === undefined) { diff --git a/packages/ts/file-router/test/runtime/RouterConfigurationBuilder.spec.tsx b/packages/ts/file-router/test/runtime/RouterConfigurationBuilder.spec.tsx index af1ed75656..edb3480c74 100644 --- a/packages/ts/file-router/test/runtime/RouterConfigurationBuilder.spec.tsx +++ b/packages/ts/file-router/test/runtime/RouterConfigurationBuilder.spec.tsx @@ -116,7 +116,7 @@ describe('RouterBuilder', () => { ], }, ]) - .withLayouts(Server) + .withLayout(Server) .build(); expect(routes).to.be.like([ @@ -160,7 +160,7 @@ describe('RouterBuilder', () => { }); it('should not throw when no routes', () => { - const { routes } = new RouterConfigurationBuilder().withLayouts(Server).build(); + const { routes } = new RouterConfigurationBuilder().withLayout(Server).build(); expect(routes).to.be.like([]); });