Skip to content
This repository was archived by the owner on Oct 29, 2019. It is now read-only.
This repository was archived by the owner on Oct 29, 2019. It is now read-only.

"Active" not being set and sub menu collapsing #35

@NatalJR

Description

@NatalJR

Hi, whenever i click an item on the menu it takes me to the page it's supposed to go, but it doesn't set the "active" link and if the item is in a sub-menu, the sub-menu is closed.

At first i thought it was a problem with the store, but it seems to be working just fine.

Then i thought it was the same issue as #26, but activeLinkFromLocation is set.

When an item is selected it behaves like this (first image is when i open the navbar):
menu

I'm not running on server side. And since it is quite possible it's an error on my code, here is what i think is relevant.

index.js

//React
import React from 'react';
import ReactDOM from 'react-dom';
//Components
import App from './App';
import EBox, {EGrid} from './components/Event';
import Death from './components/Death';
import Home from './components/Home';
import Login from './components/Login';
import Management from './components/ManagementReports'
import Statistic from './components/StatisticReports'
//Router
import {browserHistory, IndexRoute, Route, Router} from 'react-router';
//React Toolbox Themer (PostCSS Issues)
import theme from './toolbox/theme';
import ThemeProvider from 'react-toolbox/lib/ThemeProvider';
//Redux
import {applyMiddleware, combineReducers, createStore} from 'redux';
import {Provider} from 'react-redux';
import thunkMiddleware from 'redux-thunk';
//reducers
import {menus} from './reducers/menus';
import {death} from './reducers/death';
import {auth} from './reducers/auth';
import {reports} from './reducers/reports';
import metisMenuReducer from 'react-metismenu/lib/reducers';
//CSS
import './css/wizard.css';
import 'bootstrap/dist/css/bootstrap.css';
import 'bootstrap/dist/css/bootstrap-theme.css';
import './css/font-awesome-4.7.0/css/font-awesome.min.css';
import './css/index.css';
import './css/App.css';
import './toolbox/theme.css';
import 'react-table/react-table.css';

// Create Reducers
const reducers = combineReducers({death, menus, auth, reports, metisMenuReducer});
const store = createStore(reducers, applyMiddleware(thunkMiddleware));

ReactDOM.render(
    (
        <ThemeProvider theme={theme}>
            <Provider store={store}>
                <Router history={browserHistory}>
                    <Route path="/login" component={Login}/>
                    <Route path="/" component={App}>
                        <IndexRoute component={Home}/>
                        <Route path="obitos" component={Death}/>
                        <Route path="abertas" component={EGrid}/>
                        <Route path="fechadas" component={EGrid}/>
                        <Route path="criar" component={EBox}/>
                        <Route path="gerenciais" component={Management}/>
                        <Route path="estatisticos" component={Statistic}/>
                    </Route>
                </Router>
            </Provider>
        </ThemeProvider>
    ),
    document.getElementById('root')
);

mainMenu css

.mainMenu {
    position: fixed;
    width: 100%;
    font-size: 12px;
    bottom: 0;
    left: 0;
    top: 0;
}

App.js

import React, {Component} from "react";
import NavegationApi from './logics/NavigationApi'
import NavDrawer from "react-toolbox/lib/layout/NavDrawer";
import RouterLink from "react-metismenu-router-link";
import Navigation from "react-toolbox/lib/navigation/Navigation";
import Link from "react-toolbox/lib/link/Link";
import AppBar from "react-toolbox/lib/app_bar/AppBar";
import Layout from "react-toolbox/lib/layout/Layout";
import Panel from "react-toolbox/lib/layout/Panel";
import FontIcon from "react-toolbox/lib/font_icon";
import Sidebar from 'react-toolbox/lib/layout/Sidebar';
import IconButton from 'react-toolbox/lib/button/IconButton';
import {connect} from 'react-redux';
import MetisMenu from "react-metismenu";

class App extends Component {

    render() {

        const menu = [
            {
                icon: 'dashboard',
                label: 'Sigtrans',
                to: '/'
            },
            {
                icon: 'bell',
                label: 'Ocorrencias',
                content: [
                    {
                        label: 'Abertas',
                        to: 'abertas'
                    },
                    {
                        label: 'Fechadas',
                        to: 'fechadas'
                    },
                    {
                        label: 'Criar',
                        to: 'criar',
                    }
                ]
            },
            {
                icon: 'ambulance',
                label: 'Ocorrencias fatais',
                to: 'obitos'
            },
            {
                icon: 'area-chart',
                label: 'Relatórios',
                content: [
                    {
                        label: 'Estatisticos',
                        to: 'estatisticos'
                    },
                    {
                        label: 'Gerenciais',
                        to: 'gerenciais'
                    },
                ]
            }
        ];
        return (
            <div id="root">
                <div className="main">
                    <Layout>
                        <NavDrawer pinned={this.props.menus.drawer} permanentAt='xxxl'>
                            <MetisMenu content={menu} LinkComponent={RouterLink}
                                       className='mainMenu'
                                       reduxStoreName={"metisMenuReducer"}
                                       useExternalReduxStore={this.context.store}
                                       activeLinkFromLocation
                            />
                        </NavDrawer>
                        <Panel>

                            <AppBar className="app-bar" title=" " flat
                                    leftIcon={<FontIcon className="md-24 md-light" value='menu'/>}
                                    rightIcon={<FontIcon className="md-24 md-light" value='account_circle'/>}
                                    onLeftIconClick={this.props.toggleDrawer}
                                    onRightIconClick={this.props.toggleSidebar}
                            >
                                <Navigation type="horizontal">
                                    <Link href="#" className='app-bar' label="Mensagens" icon="inbox"/>
                                    <Link href="#" className='app-bar' active label="Perfil" icon="person"/>
                                </Navigation>
                            </AppBar>
                            <div style={{flex: 1, overflowY: 'auto', padding: '1.8rem'}}>
                                <div className="content-interior">
                                    {this.props.children}
                                </div>
                            </div>
                        </Panel>
                        <Sidebar pinned={this.props.menus.sidebar} width={5}>
                            <div><IconButton icon='close' onClick={this.props.toggleSidebar}/></div>
                            <div style={{flex: 1}}>
                                <p>Supplemental content goes here.</p>
                            </div>
                        </Sidebar>
                    </Layout>
                </div>
            </div>
        );
    }

}

App.contextTypes = {
    store: React.PropTypes.object.isRequired
};

const mapStateToProps = (state) => {
    return {
        menus: state.menus,
    }
};

const mapDispatchToProps = dispatch => {
    return {
        toggleDrawer: () => {
            dispatch(NavegationApi.toggleDrawer());
        },
        toggleSidebar: () => {
            dispatch(NavegationApi.toggleSidebar());
        }
    }
};

const AppContainer = connect(mapStateToProps, mapDispatchToProps)(App);

export default AppContainer;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions