Skip to content

Commit

Permalink
[feature] use internal router tool to handle routing to the statistic…
Browse files Browse the repository at this point in the history
…s page
  • Loading branch information
shellyear committed May 16, 2024
1 parent 94098ac commit 9a090ca
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
19 changes: 12 additions & 7 deletions src/components/MainView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { isAdmin } from "../utils/SecurityUtils";
import Messages from "./message/Messages";
import Footer from "../Footer";
import PropTypes from "prop-types";
import { ANALYTICS_URL } from "../../config/index.js";

class MainView extends React.Component {
constructor(props) {
Expand Down Expand Up @@ -61,6 +62,14 @@ class MainView extends React.Component {
}
}

showStatistics = () => {
if (ANALYTICS_URL === "") {
transitionTo(routes.statistics);
} else {
window.location.href = ANALYTICS_URL;
}
};

render() {
if (this.props.status === ACTION_STATUS.PENDING) {
return <LoaderMask />;
Expand Down Expand Up @@ -120,14 +129,10 @@ class MainView extends React.Component {
</NavItem>
</IfGranted>
<IfGranted expected={ROLE.ADMIN} actual={user.role}>
<NavItem>
<NavLink
className="nav-link"
isActive={() => path.startsWith(Routes.statistics.path)}
to={Routes.statistics.path}
>
<NavItem style={{ cursor: "pointer" }}>
<div className="nav-link" onClick={() => this.showStatistics()}>
{this.i18n("statistics.panel-title")}
</NavLink>
</div>
</NavItem>
</IfGranted>
<IfGranted expected={ROLE.ADMIN} actual={user.role}>
Expand Down
2 changes: 0 additions & 2 deletions src/utils/Routes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import requireAuth from "../components/misc/hoc/RequireAuth";
import UsersController from "../components/user/UsersController";
import UserController from "../components/user/UserController";
import PasswordChangeController from "../components/user/PasswordChangeController";
import Statistics from "../components/statistics/Statistics";
import InstitutionsController from "../components/institution/InstitutionsController";
import InstitutionController from "../components/institution/InstitutionController";
import RecordsController from "../components/record/RecordsController";
Expand All @@ -35,7 +34,6 @@ export const authRoutes = (
<Route exact path={Routes.createUser.path} component={requireAuth(UserController)} />
<Route exact path={Routes.editUser.path} component={requireAuth(UserController)} />
<Route exact path={Routes.passwordChange.path} component={requireAuth(PasswordChangeController)} />
<Route exact path={Routes.statistics.path} component={requireAuth(Statistics)} />
<Route exact path={Routes.institutions.path} component={requireAuth(InstitutionsController)} />
<Route exact path={Routes.createInstitution.path} component={requireAuth(InstitutionController)} />
<Route exact path={Routes.editInstitution.path} component={requireAuth(InstitutionController)} />
Expand Down

0 comments on commit 9a090ca

Please sign in to comment.