Skip to content

Commit

Permalink
move routing util code to separate package #13
Browse files Browse the repository at this point in the history
  • Loading branch information
DominikHorn committed Feb 27, 2020
1 parent b242ef1 commit 25eff2a
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 12 deletions.
3 changes: 2 additions & 1 deletion packages/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"react-router": "^5.1.2",
"react-router-dom": "^5.1.2",
"elite-feature-flags": "^1.0.0",
"elite-configuration": "^1.0.0"
"elite-configuration": "^1.0.0",
"elite-routing": "^1.0.0"
}
}
6 changes: 4 additions & 2 deletions packages/frontend/src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import history from '../util/history';
import { FeatureFlagsProvider } from 'elite-feature-flags';
import { Configuration } from 'elite-types';
import { getConfiguration } from 'elite-configuration';
import { getAllRegisteredAppRoutes } from '../util/routing';
import { getAllRegisteredAppRoutes } from 'elite-routing';
import { AppPaths } from '../util/routes';

// Files must be required (early!) for decorator to work
// TODO: move to routes.ts
require('../components/pages/HomePage');
require('../components/pages/LinkPage');

Expand All @@ -22,7 +24,7 @@ export const AppComponent = () => (
<Route key={index} {...routeProps} />
))}
{/* Error 404 Fallback */}
<Redirect to={'/home'} />
<Redirect to={AppPaths.HOME} />
</Switch>
</Router>
</FeatureFlagsProvider>
Expand Down
5 changes: 3 additions & 2 deletions packages/frontend/src/components/pages/HomePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { RouteComponentProps } from 'react-router';
import { LinkDirectory } from './support/LinkDirectory';
import { Divider } from '@material-ui/core';
import { FeatureFlag } from 'elite-feature-flags';
import { Routed } from '../../util/routing';
import { Routed } from 'elite-routing';
import { AppPaths } from '../../util/routes';

export interface HomePageProps extends RouteComponentProps {}

@Routed({ path: '/home', displayName: 'Home' })
@Routed({ path: AppPaths.HOME, displayName: 'Home' })
export class HomePage extends React.PureComponent<HomePageProps> {
render() {
return (
Expand Down
5 changes: 3 additions & 2 deletions packages/frontend/src/components/pages/LinkPage.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { Divider, List } from '@material-ui/core';
import * as React from 'react';
import { RouteComponentProps } from 'react-router';
import { Routed } from '../../util/routing';
import { Routed } from 'elite-routing';
import { AppPaths } from '../../util/routes';
import { LinkListItem } from '../general/LinkListItem';
import { LinkDirectory } from './support/LinkDirectory';

export interface LinkPageProps extends RouteComponentProps {}

@Routed({ path: '/link', displayName: 'Useful Links' })
@Routed({ path: AppPaths.LINK, displayName: 'Useful Links' })
export class LinkPage extends React.PureComponent<LinkPageProps> {
render() {
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { Link } from 'react-router-dom';
import { getLinkForRoute, getDisplayNameForRoute, getAllRegisteredAppRoutes } from '../../../util/routing';
import { getLinkForRoute, getDisplayNameForRoute, getAllRegisteredAppRoutes } from 'elite-routing';

export const LinkDirectory = () => (
<ul>
Expand Down
4 changes: 4 additions & 0 deletions packages/frontend/src/util/routes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export enum AppPaths {
HOME = '/home',
LINK = '/link',
}
6 changes: 4 additions & 2 deletions packages/frontend/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
"baseUrl": "src",
"experimentalDecorators": true
"baseUrl": "src"
},
"include": ["src/**/*"],
"references": [
Expand All @@ -14,6 +13,9 @@
{
"path": "../feature-flags"
},
{
"path": "../routing"
},
{
"path": "../types"
}
Expand Down
21 changes: 21 additions & 0 deletions packages/routing/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "elite-routing",
"version": "1.0.0",
"private": true,
"publishConfig": {
"access": "public"
},
"types": "dist/index.d.ts",
"main": "dist/index.js",
"scripts": {
"clean": "rm -rf dist/ node_modules/ tsconfig.tsbuildinfo"
},
"devDependencies": {
"@types/react": "^16.9.11",
"@types/react-router": "^5.1.3",
"elite-types": "^1.0.0"
},
"dependencies": {
"react": "^16.12.0"
}
}
1 change: 1 addition & 0 deletions packages/routing/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './routing';
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ export function registerAppRoute(props: AppRouteProps & Required<Pick<AppRoutePr
console.log('added route ', props.path);
}

// TODO: replace with proper container/service class
/**
* Retrieves the url which other pages can use
* to link to a certain route
Expand All @@ -73,7 +72,6 @@ export function getLinkForRoute(route: AppRouteProps): LinkType {
return route.link || route.path;
}

// TODO: replace with proper container/service class
/**
* Retrieves the humand readable link title/displayed name
* for a given route
Expand Down
14 changes: 14 additions & 0 deletions packages/routing/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
"baseUrl": "src"
},
"include": ["src/**/*"],
"references": [
{
"path": "../types"
}
]
}

0 comments on commit 25eff2a

Please sign in to comment.