Remove react-router

pull/991/head
Rick Carlino 2018-09-14 07:58:59 -05:00
parent 6fae68a9d2
commit 168927b407
7 changed files with 21 additions and 263 deletions

View File

@ -33,7 +33,6 @@
"@blueprintjs/select": "^2.0.1",
"@types/enzyme": "3.1.13",
"@types/fastclick": "^1.0.28",
"@types/history": "4.7.0",
"@types/i18next": "8.4.5",
"@types/jest": "23.3.1",
"@types/lodash": "4.14.116",
@ -44,7 +43,6 @@
"@types/react-color": "2.13.5",
"@types/react-dom": "16.0.5",
"@types/react-redux": "6.0.0",
"@types/react-router": "3.0.15",
"axios": "^0.18.0",
"boxed_value": "^1.0.0",
"browser-speech": "1.1.1",
@ -74,7 +72,6 @@
"react-color": "2.14.1",
"react-dom": "16.4.2",
"react-redux": "^5.0.6",
"react-router": "^3",
"react-test-renderer": "16.4.2",
"react-transition-group": "^2.3.1",
"redux": "4.0.0",
@ -98,9 +95,7 @@
"yarn": "1.9.4"
},
"devDependencies": {
"jscpd": "0.6.22",
"webpack-cli": "3.1.0",
"webpack-notifier": "^1.5.0"
"webpack-cli": "3.1.0"
},
"jest": {
"clearMocks": true,

View File

@ -1,47 +0,0 @@
jest.mock("fastclick", () => ({ attach: jest.fn() }));
import {
topLevelRoutes,
designerRoutes,
maybeReplaceDesignerModules
} from "../route_config";
import { noop } from "lodash";
import { RouterState, RedirectFunction } from "react-router";
async function makeSureTheyAreRoutes(input: typeof topLevelRoutes.childRoutes) {
const cb = jest.fn();
const all = (input || []);
await Promise.all(all.map(route =>
(route.getComponent || noop)({} as RouterState, cb)));
expect(cb).toHaveBeenCalled();
expect(cb).toHaveBeenCalledTimes(all.length);
cb.mock.calls.map(x => expect(!!x[1]).toBeTruthy());
}
describe("top level routes", () => {
it("generates all of them",
() => makeSureTheyAreRoutes(topLevelRoutes.childRoutes));
});
describe("designer routes", () => {
it("generates all of them",
() => makeSureTheyAreRoutes(designerRoutes.childRoutes));
});
describe("maybeReplaceDesignerModules", () => {
it("does replace the route", () => {
const pathname = "/app/designer";
const next = { location: { pathname } } as RouterState;
const replace = jest.fn() as RedirectFunction;
maybeReplaceDesignerModules(next, replace);
expect(replace).toHaveBeenCalledWith(`${pathname}/plants`);
});
it("does not replace the route", () => {
const pathname = "/app/nope";
const next = { location: { pathname } } as RouterState;
const replace = jest.fn() as RedirectFunction;
maybeReplaceDesignerModules(next, replace);
expect(replace).not.toHaveBeenCalled();
});
});

View File

@ -1,7 +1,11 @@
import { browserHistory } from "react-router";
export let history = browserHistory;
export let push = (url: string) => history.push(url);
import { navigate } from "takeme";
export let push = (url: string) => navigate(url);
/** This is a stub from the `react-router`.
* Don't use it anymore. */
export let history = { push, getCurrentLocation: () => window.location };
export function getPathArray() {
return history.getCurrentLocation().pathname.split("/");
return location.pathname.split("/");
}

View File

@ -1,15 +1,15 @@
import * as React from "react";
const a = <p />;
import { html5LinkOnClick } from "takeme";
type AnchorProps = typeof a["props"];
interface LinkProps extends AnchorProps {
interface LinkProps extends React.AnchorHTMLAttributes<HTMLAnchorElement> {
to: string;
children: React.ReactChild | React.ReactChild[];
style?: React.CSSProperties;
className?: string;
}
export function Link({ children }: LinkProps) {
return <a onClick={() => alert("FIXME")}>{children}</a>;
}
export const Link: React.SFC<LinkProps> =
(props) => <a onClick={(e) => html5LinkOnClick({ event: e.nativeEvent })}
href={props.href}
target={props.target}
children={props.children} />;

View File

@ -26,7 +26,7 @@ export interface NavBarState {
accountMenuOpen: boolean;
}
type ToggleEventHandler = (e: React.MouseEvent<HTMLDivElement>) => void;
type ToggleEventHandler = (e: React.MouseEvent<HTMLElement>) => void;
export interface MobileMenuProps {
close: (property: keyof NavBarState) => ToggleEventHandler;

View File

@ -1,127 +0,0 @@
import { App } from "./app";
import { crashPage } from "./crash_page";
import { RouterState, RedirectFunction, PlainRoute } from "react-router";
/** These methods are a way to determine how to load certain modules
* based on the device (mobile or desktop) for optimization/css purposes.
*/
export function maybeReplaceDesignerModules(next: RouterState,
replace: RedirectFunction) {
if (next.location.pathname === "/app/designer") {
replace(`${next.location.pathname}/plants`);
}
}
/** Create a react router config for a specific route. */
function page<T>(path: string,
getter: () => Promise<T>,
key: keyof T): PlainRoute {
return {
path,
getComponent(_, cb): void {
// tslint:disable-next-line:no-any
const ok = (mod: T) => cb(undefined, mod[key] as any);
const no = (e: object) => cb(undefined, crashPage(e));
/** Whatever you do, make sure this function stays void or you will get a
* bunch of silent errors. - RC*/
getter().then(ok, no);
}
};
}
const controlsRoute: PlainRoute =
page("app/controls",
() => import("./controls/controls"), "Controls");
export const designerRoutes: PlainRoute = {
path: "app/designer",
getComponent(_, cb) {
import("./farm_designer/index")
.then(module => cb(undefined, module.FarmDesigner))
.catch((e: object) => cb(undefined, crashPage(e)));
},
childRoutes: [
page("plants",
() => import("./farm_designer/plants/plant_inventory"),
"Plants"),
page("plants/crop_search",
() => import("./farm_designer/plants/crop_catalog"),
"CropCatalog"),
page("plants/crop_search/:crop",
() => import("./farm_designer/plants/crop_info"),
"CropInfo"),
page("plants/crop_search/:crop/add",
() => import("./farm_designer/plants/add_plant"),
"AddPlant"),
page("plants/select",
() => import("./farm_designer/plants/select_plants"),
"SelectPlants"),
page("plants/move_to",
() => import("./farm_designer/plants/move_to"),
"MoveTo"),
page("plants/create_point",
() => import("./farm_designer/plants/create_points"),
"CreatePoints"),
page("plants/saved_gardens",
() => import("./farm_designer/saved_gardens/saved_gardens"),
"SavedGardens"),
page("plants/:plant_id",
() => import("./farm_designer/plants/plant_info"),
"PlantInfo"),
page("plants/:plant_id/edit",
() => import("./farm_designer/plants/edit_plant_info"),
"EditPlantInfo"),
page("farm_events",
() => import("./farm_designer/farm_events/farm_events"),
"FarmEvents"),
page("farm_events/add",
() => import("./farm_designer/farm_events/add_farm_event"),
"AddFarmEvent"),
page("farm_events/:farm_event_id",
() => import("./farm_designer/farm_events/edit_farm_event"),
"EditFarmEvent"),
]
};
export const topLevelRoutes: PlainRoute = {
component: App,
indexRoute: controlsRoute,
childRoutes: [
page("app/account",
() => import("./account/index"),
"Account"),
controlsRoute,
page("app/device",
() => import("./devices/devices"),
"Devices"),
page("app/farmware",
() => import("./farmware/index"),
"FarmwarePage"),
page("app/farmware/:farmware",
() => import("./farmware/index"),
"FarmwarePage"),
designerRoutes,
page("app/regimens",
() => import("./regimens/index"),
"Regimens"),
page("app/regimens/:regimen",
() => import("./regimens/index"),
"Regimens"),
page("app/sequences",
() => import("./sequences/sequences"),
"Sequences"),
page("app/sequences/:sequence",
() => import("./sequences/sequences"),
"Sequences"),
page("app/tools",
() => import("./tools/index"),
"Tools"),
page("app/logs",
() => import("./logs/index"),
"Logs"),
page("*",
() => import("./404"),
"FourOhFour"),
]
};

View File

@ -72,14 +72,6 @@
version "1.0.28"
resolved "https://registry.yarnpkg.com/@types/fastclick/-/fastclick-1.0.28.tgz#db4b3f6f079235324b264338e229f9cdd98a6c4e"
"@types/history@4.7.0":
version "4.7.0"
resolved "https://registry.yarnpkg.com/@types/history/-/history-4.7.0.tgz#2fac51050c68f7d6f96c5aafc631132522f4aa3f"
"@types/history@^3":
version "3.2.2"
resolved "https://registry.yarnpkg.com/@types/history/-/history-3.2.2.tgz#b6affa240cb10b5f841c6443d8a24d7f3fc8bb0c"
"@types/i18next@8.4.5":
version "8.4.5"
resolved "https://registry.yarnpkg.com/@types/i18next/-/i18next-8.4.5.tgz#d6c0cb594258815219c70006e9f5cd65ad6d797f"
@ -130,13 +122,6 @@
"@types/react" "*"
redux "^4.0.0"
"@types/react-router@3.0.15":
version "3.0.15"
resolved "https://registry.yarnpkg.com/@types/react-router/-/react-router-3.0.15.tgz#b55b0dc5ad8f6fa66b609f0efc390b191381d082"
dependencies:
"@types/history" "^3"
"@types/react" "*"
"@types/react@*", "@types/react@16.3.14":
version "16.3.14"
resolved "https://registry.yarnpkg.com/@types/react/-/react-16.3.14.tgz#f90ac6834de172e13ecca430dcb6814744225d36"
@ -1475,14 +1460,6 @@ create-hmac@^1.1.0, create-hmac@^1.1.2, create-hmac@^1.1.4:
safe-buffer "^5.0.1"
sha.js "^2.4.8"
create-react-class@^15.5.1:
version "15.6.3"
resolved "https://registry.yarnpkg.com/create-react-class/-/create-react-class-15.6.3.tgz#2d73237fb3f970ae6ebe011a9e66f46dbca80036"
dependencies:
fbjs "^0.8.9"
loose-envify "^1.3.1"
object-assign "^4.1.1"
cross-spawn@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-3.0.1.tgz#1256037ecb9f0c5f79e3d6ef135e30770184b982"
@ -2415,18 +2392,6 @@ fbjs@^0.8.16:
setimmediate "^1.0.5"
ua-parser-js "^0.7.18"
fbjs@^0.8.9:
version "0.8.16"
resolved "https://registry.yarnpkg.com/fbjs/-/fbjs-0.8.16.tgz#5e67432f550dc41b572bf55847b8aca64e5337db"
dependencies:
core-js "^1.0.0"
isomorphic-fetch "^2.1.1"
loose-envify "^1.0.0"
object-assign "^4.1.0"
promise "^7.1.1"
setimmediate "^1.0.5"
ua-parser-js "^0.7.9"
figures@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/figures/-/figures-2.0.0.tgz#3ab1a2d2a62c8bfb431a0c94cb797a2fce27c962"
@ -2913,15 +2878,6 @@ hex-color-regex@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/hex-color-regex/-/hex-color-regex-1.1.0.tgz#4c06fccb4602fe2602b3c93df82d7e7dbf1a8a8e"
history@^3.0.0:
version "3.3.0"
resolved "https://registry.yarnpkg.com/history/-/history-3.3.0.tgz#fcedcce8f12975371545d735461033579a6dae9c"
dependencies:
invariant "^2.2.1"
loose-envify "^1.2.0"
query-string "^4.2.2"
warning "^3.0.0"
hmac-drbg@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/hmac-drbg/-/hmac-drbg-1.0.1.tgz#d2745701025a6c775a6c545793ed502fc0c649a1"
@ -2930,7 +2886,7 @@ hmac-drbg@^1.0.0:
minimalistic-assert "^1.0.0"
minimalistic-crypto-utils "^1.0.1"
hoist-non-react-statics@^2.3.1, hoist-non-react-statics@^2.5.0:
hoist-non-react-statics@^2.5.0:
version "2.5.0"
resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-2.5.0.tgz#d2ca2dfc19c5a91c5a6615ce8e564ef0347e2a40"
@ -3164,7 +3120,7 @@ interpret@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/interpret/-/interpret-1.1.0.tgz#7ed1b1410c6a0e0f78cf95d3b8440c63f78b8614"
invariant@^2.0.0, invariant@^2.1.0, invariant@^2.2.1, invariant@^2.2.2, invariant@^2.2.4:
invariant@^2.0.0, invariant@^2.1.0, invariant@^2.2.2, invariant@^2.2.4:
version "2.2.4"
resolved "https://registry.yarnpkg.com/invariant/-/invariant-2.2.4.tgz#610f3c92c9359ce1db616e538008d23ff35158e6"
dependencies:
@ -4218,7 +4174,7 @@ loose-envify@^1.0.0, loose-envify@^1.3.1:
dependencies:
js-tokens "^3.0.0 || ^4.0.0"
loose-envify@^1.1.0, loose-envify@^1.2.0:
loose-envify@^1.1.0:
version "1.3.1"
resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.3.1.tgz#d1a8ad33fa9ce0e713d65fdd0ac8b748d478c848"
dependencies:
@ -5643,13 +5599,6 @@ qs@6.5.1:
version "6.5.2"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.2.tgz#cb3ae806e8740444584ef154ce8ee98d403f3e36"
query-string@^4.2.2:
version "4.3.4"
resolved "https://registry.yarnpkg.com/query-string/-/query-string-4.3.4.tgz#bbb693b9ca915c232515b228b1a02b609043dbeb"
dependencies:
object-assign "^4.1.0"
strict-uri-encode "^1.0.0"
querystring-es3@^0.2.0:
version "0.2.1"
resolved "https://registry.yarnpkg.com/querystring-es3/-/querystring-es3-0.2.1.tgz#9ec61f79049875707d69414596fd907a4d711e73"
@ -5787,18 +5736,6 @@ react-redux@^5.0.6:
loose-envify "^1.1.0"
prop-types "^15.6.0"
react-router@^3:
version "3.2.1"
resolved "https://registry.yarnpkg.com/react-router/-/react-router-3.2.1.tgz#b9a3279962bdfbe684c8bd0482b81ef288f0f244"
dependencies:
create-react-class "^15.5.1"
history "^3.0.0"
hoist-non-react-statics "^2.3.1"
invariant "^2.2.1"
loose-envify "^1.2.0"
prop-types "^15.5.6"
warning "^3.0.0"
react-test-renderer@16.4.2:
version "16.4.2"
resolved "https://registry.yarnpkg.com/react-test-renderer/-/react-test-renderer-16.4.2.tgz#4e03eca9359bb3210d4373f7547d1364218ef74e"
@ -6636,10 +6573,6 @@ stream-shift@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/stream-shift/-/stream-shift-1.0.0.tgz#d5c752825e5367e786f78e18e445ea223a155952"
strict-uri-encode@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/strict-uri-encode/-/strict-uri-encode-1.1.0.tgz#279b225df1d582b1f54e65addd4352e18faa0713"
string-length@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/string-length/-/string-length-2.0.0.tgz#d40dbb686a3ace960c1cffca562bf2c45f8363ed"
@ -7034,7 +6967,7 @@ typescript@^2.0.9, typescript@^2.3.4:
version "2.8.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.8.3.tgz#5d817f9b6f31bb871835f4edf0089f21abe6c170"
ua-parser-js@^0.7.18, ua-parser-js@^0.7.9:
ua-parser-js@^0.7.18:
version "0.7.18"
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.18.tgz#a7bfd92f56edfb117083b69e31d2aa8882d4b1ed"