src/app/components/AppRouter/index.tsx
last analyzed

Complexity

Total Complexity 0
Complexity/F 0

Size

Lines of Code 54
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 0
eloc 43
mnd 0
bc 0
fnc 0
dl 0
loc 54
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
ccs 15
cts 15
cp 1
1 1
import React from "react";
2
3
import { History } from "history";
4
5 1
import { useSelector } from "react-redux";
6
7 1
import { getHomePage, getPages } from "@cianciarusocataldo/modular-engine";
8
9 1
import { Redirect, Route, RouteProps, Router, Switch } from "react-router-dom";
10
import { ThemeField } from "../../types";
11
12 1
const AppRouter = ({
13 1
  history,
14 1
  renderCallback,
15 1
  theme,
16
}: {
17
  history: History;
18
  renderCallback: (route: string) => RouteProps["component"];
19
  theme?: ThemeField;
20
}) => {
21 1
  const PAGES = useSelector(getPages);
22 1
  const HOME = useSelector(getHomePage);
23 1
  const ALL_PAGES: Record<string, string> = {
24
    ...PAGES,
25
    HOME_PAGE: HOME,
26
  };
27 2
  const routerStyle = theme.override || theme.style;
28
29 1
  return (
30
    <div
31
      style={{ ...routerStyle, width: "100%", overflow: "auto" }}
32
      className={theme.className}
33
    >
34
      <Router history={history}>
35
        <Switch>
36
          {Object.keys(ALL_PAGES).map((route) => {
37 1
            return (
38
              <Route
39
                component={renderCallback(route)}
40
                key={route}
41
                exact
42
                path={PAGES[route]}
43
              />
44
            );
45
          })}
46
          <Redirect to={HOME} />
47
        </Switch>
48
      </Router>
49
    </div>
50
  );
51
};
52
53
export default AppRouter;
54