From 65e5e0524d5ae422490ffbe295585691c6c12b67 Mon Sep 17 00:00:00 2001 From: Brandon Scott Date: Wed, 24 Jun 2020 19:01:11 -0400 Subject: [PATCH] Update to use named exports project-wide and add a missing JSDoc comment --- .../routing/authenticated-route.tsx | 4 ++ src/components/routing/nested-route.tsx | 10 +++- .../routing/nested-routes-by-property.tsx | 4 +- src/components/routing/nested-routes.tsx | 4 +- src/components/routing/redirects.tsx | 2 +- src/index.ts | 58 +++++++++++++++---- src/tests/factories/index.ts | 7 ++- 7 files changed, 72 insertions(+), 17 deletions(-) diff --git a/src/components/routing/authenticated-route.tsx b/src/components/routing/authenticated-route.tsx index aed0d70..7bbc6b2 100644 --- a/src/components/routing/authenticated-route.tsx +++ b/src/components/routing/authenticated-route.tsx @@ -16,6 +16,10 @@ interface AuthenticatedRouteProps // #endregion Interfaces +/** + * Locks a route behind authentication. Can optionally redirect a user to another location if + * attempting to access the route while unauthenticated. + */ const AuthenticatedRoute: React.FC = ( props: AuthenticatedRouteProps ) => { diff --git a/src/components/routing/nested-route.tsx b/src/components/routing/nested-route.tsx index a2729c2..82a8755 100644 --- a/src/components/routing/nested-route.tsx +++ b/src/components/routing/nested-route.tsx @@ -23,7 +23,7 @@ interface NestedRouteProps extends AuthenticatedRoute { * Dynamically renders a route and its subroutes, accounting * for additional custom properties on RouteDefinition */ -export const NestedRoute = (props: NestedRouteProps) => { +const NestedRoute: React.FC = (props: NestedRouteProps) => { const { isAuthenticated, redirectToIfUnauthenticated, route } = props; const RouteComponent: any = route.authRequired ? AuthenticatedRouteComponent @@ -46,3 +46,11 @@ export const NestedRoute = (props: NestedRouteProps) => { }; // #endregion Component + +// ----------------------------------------------------------------------------------------- +// #region Exports +// ----------------------------------------------------------------------------------------- + +export { NestedRoute, NestedRouteProps }; + +// #endregion Exports diff --git a/src/components/routing/nested-routes-by-property.tsx b/src/components/routing/nested-routes-by-property.tsx index b696ee3..3dbd9c8 100644 --- a/src/components/routing/nested-routes-by-property.tsx +++ b/src/components/routing/nested-routes-by-property.tsx @@ -24,7 +24,9 @@ interface NestedRoutesByPropertyProps { /** * Renders Route components mapped to a custom property */ -const NestedRoutesByProperty = (props: NestedRoutesByPropertyProps) => { +const NestedRoutesByProperty: React.FC = ( + props: NestedRoutesByPropertyProps +) => { if (CollectionUtils.isEmpty(props.routes)) { return null; } diff --git a/src/components/routing/nested-routes.tsx b/src/components/routing/nested-routes.tsx index 093b672..6da32d5 100644 --- a/src/components/routing/nested-routes.tsx +++ b/src/components/routing/nested-routes.tsx @@ -24,7 +24,9 @@ interface NestedRoutesProps extends UnmatchedRoute, AuthenticatedRoute { * Component to easily render nested sub-route components from a list of routes. * Commonly used when setting up a layout */ -const NestedRoutes = (props: NestedRoutesProps) => { +const NestedRoutes: React.FC = ( + props: NestedRoutesProps +) => { const { isAuthenticated, redirectToIfNotFound, diff --git a/src/components/routing/redirects.tsx b/src/components/routing/redirects.tsx index bd86ff9..b38454d 100644 --- a/src/components/routing/redirects.tsx +++ b/src/components/routing/redirects.tsx @@ -19,7 +19,7 @@ interface RedirectsProps { /** * Simple way to redirect a flat array of RedirectDefinitions */ -const Redirects = (props: RedirectsProps) => { +const Redirects: React.FC = (props: RedirectsProps) => { const { redirects } = props; // TODO: Remove Fragment when issue fixed https://github.com/microsoft/TypeScript/issues/21699 diff --git a/src/index.ts b/src/index.ts index 7d26743..a91797f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,11 +2,23 @@ // #region Components // ----------------------------------------------------------------------------------------- -export * from "./components/routing/authenticated-route"; -export * from "./components/routing/nested-route"; -export * from "./components/routing/nested-routes"; -export * from "./components/routing/nested-routes-by-property"; -export * from "./components/routing/redirects"; +export { + AuthenticatedRoute, + AuthenticatedRouteProps, +} from "./components/routing/authenticated-route"; +export { + NestedRoute, + NestedRouteProps, +} from "./components/routing/nested-route"; +export { + NestedRoutes, + NestedRoutesProps, +} from "./components/routing/nested-routes"; +export { + NestedRoutesByProperty, + NestedRoutesByPropertyProps, +} from "./components/routing/nested-routes-by-property"; +export { Redirects, RedirectsProps } from "./components/routing/redirects"; //#endregion Components @@ -14,9 +26,9 @@ export * from "./components/routing/redirects"; // #region Interfaces // ----------------------------------------------------------------------------------------- -export * from "./interfaces/redirect-definition"; -export * from "./interfaces/route-definition"; -export * from "./interfaces/route-map"; +export { RedirectDefinition } from "./interfaces/redirect-definition"; +export { RouteDefinition } from "./interfaces/route-definition"; +export { RouteMap } from "./interfaces/route-map"; //#endregion Interfaces @@ -24,7 +36,7 @@ export * from "./interfaces/route-map"; // #region Services // ----------------------------------------------------------------------------------------- -export * from "./services/service-factory"; +export { ServiceFactory } from "./services/service-factory"; //#endregion Services @@ -32,7 +44,7 @@ export * from "./services/service-factory"; // #region Utilities // ----------------------------------------------------------------------------------------- -export * from "./utilities/route-utils"; +export { RouteUtils } from "./utilities/route-utils"; //#endregion Utilities @@ -40,6 +52,30 @@ export * from "./utilities/route-utils"; // #region Vendor // ----------------------------------------------------------------------------------------- -export * from "react-router-dom"; +// Forwarding everything from react-router-dom as-is, just incase a consumer wants to use some +// specific component or function for their own implemention alongside our library. +export { + generatePath, + Prompt, + MemoryRouter, + RedirectProps, + Redirect, + RouteChildrenProps, + RouteComponentProps, + RouteProps, + Route, + Router, + StaticRouter, + SwitchProps, + Switch, + match, + matchPath, + withRouter, + RouterChildContext, + useHistory, + useLocation, + useParams, + useRouteMatch, +} from "react-router-dom"; //#endregion Vendor diff --git a/src/tests/factories/index.ts b/src/tests/factories/index.ts index 708263b..65eb52c 100644 --- a/src/tests/factories/index.ts +++ b/src/tests/factories/index.ts @@ -1,3 +1,6 @@ -export * from "./route-definition-factory"; -export * from "./route-map-factory"; +export { + RouteDefinitionFactory, + RouteDefinitionNestedFactory, +} from "./route-definition-factory"; +export { RouteMapFactory } from "./route-map-factory"; export { StubResourceRecordFactory } from "andculturecode-javascript-testing";