Skip to content
This repository has been archived by the owner on Dec 13, 2020. It is now read-only.

Commit

Permalink
Merge pull request #633 from metasfresh/dev-130
Browse files Browse the repository at this point in the history
#130 Homemenu fetching switched to lazy approach
  • Loading branch information
damianprzygodzki authored Apr 12, 2017
2 parents 5ff40b8 + e325bd8 commit 388d95b
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 87 deletions.
33 changes: 2 additions & 31 deletions src/actions/MenuActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,6 @@ export function setBreadcrumb(breadcrumb){
}
}

export function setHomeMenu(homemenu){
return {
type: types.SET_HOMEMENU,
homemenu: homemenu
}
}

export function setReferences(references){
return {
type: types.SET_REFERENCES,
references: references
}
}

export function setAttachments(attachments){
return {
type: types.SET_ATTACHMENTS,
attachments: attachments
}
}

export function setActions(actions){
return {
type: types.SET_ACTIONS,
actions: actions
}
}

// THUNK ACTIONS
export function pathRequest(nodeId) {
return () => axios.get(
Expand Down Expand Up @@ -80,11 +52,10 @@ export function rootRequest(limit, depth=0) {
}

export function getRootBreadcrumb() {
return (dispatch) => {
return (dispatch) =>
dispatch(rootRequest(6, 10)).then(root => {
dispatch(setHomeMenu({nodeId: '0', children: root.data}));
return {nodeId: '0', children: root.data.children};
});
}
}

export function getWindowBreadcrumb(id){
Expand Down
4 changes: 2 additions & 2 deletions src/components/header/Breadcrumb.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class Breadcrumb extends Component {

render() {
const {
breadcrumb, homemenu, windowType, docNo, docNoData, docSummaryData,
breadcrumb, windowType, docNo, docNoData, docSummaryData,
dataId, siteName
} = this.props;

Expand All @@ -104,7 +104,7 @@ class Breadcrumb extends Component {
/>
}
<div className="header-breadcrumb">
{this.renderBtn(homemenu, 0)}
{this.renderBtn({nodeId: '0'}, 0)}

{breadcrumb && breadcrumb.map((item, index) =>
this.renderBtn(item, index+1)
Expand Down
25 changes: 3 additions & 22 deletions src/components/header/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ import {
openModal
} from '../../actions/WindowActions';

import {
getRootBreadcrumb
} from '../../actions/MenuActions';

import {
deleteRequest,
openFile
Expand Down Expand Up @@ -52,8 +48,6 @@ class Header extends Component {
}

componentDidMount() {
const {dispatch} = this.props;
dispatch(getRootBreadcrumb());
document.addEventListener('scroll', this.handleScroll);
}

Expand Down Expand Up @@ -245,8 +239,7 @@ class Header extends Component {
const {
docSummaryData, siteName, docNoData, docNo, docStatus,
docStatusData, windowType, dataId, breadcrumb, showSidelist,
references, actions, inbox, homemenu, selected, entity,
query, attachments, showIndicator, isDocumentNotSaved,
inbox, selected, entity, query, showIndicator, isDocumentNotSaved,
selectedWindowType
} = this.props;

Expand Down Expand Up @@ -316,7 +309,6 @@ class Header extends Component {
</div>

<Breadcrumb
homemenu={homemenu}
breadcrumb={breadcrumb}
windowType={windowType}
docNo={docNo}
Expand Down Expand Up @@ -491,9 +483,6 @@ class Header extends Component {

{isSubheaderShow && <Subheader
dataId={dataId}
references={references}
attachments={attachments}
actions={actions}
windowType={windowType}
closeSubheader={() => this.closeOverlays('isSubheaderShow')}
docNo={docNoData && docNoData.value}
Expand Down Expand Up @@ -524,7 +513,7 @@ class Header extends Component {
handleMenuOverlay={isMenuOverlayShow ?
() => this.handleMenuOverlay('', '') :
() => this.closeOverlays('',
()=> this.handleMenuOverlay('', homemenu.nodeId)
()=> this.handleMenuOverlay('', 0)
)
}
handleInboxOpen = {isInboxOpen ?
Expand Down Expand Up @@ -560,25 +549,18 @@ class Header extends Component {
Header.propTypes = {
dispatch: PropTypes.func.isRequired,
selected: PropTypes.array.isRequired,
homemenu: PropTypes.object.isRequired,
inbox: PropTypes.object.isRequired
};

function mapStateToProps(state) {
const {windowHandler, appHandler, menuHandler} = state;
const {windowHandler, appHandler} = state;

const {
inbox
} = appHandler || {
inbox: {}
}

const {
homemenu
} = menuHandler || {
homemenu: []
}

const {
selected,
selectedWindowType
Expand All @@ -590,7 +572,6 @@ function mapStateToProps(state) {
return {
selected,
inbox,
homemenu,
selectedWindowType
}
}
Expand Down
27 changes: 20 additions & 7 deletions src/components/header/MenuOverlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
queryPathsRequest,
pathRequest,
getWindowBreadcrumb,
flattenLastElem
flattenLastElem,
getRootBreadcrumb
} from '../../actions/MenuActions';

class MenuOverlay extends Component {
Expand All @@ -23,10 +24,22 @@ class MenuOverlay extends Component {
deepNode: null,
deepSubNode: null,
path: '',
subPath: ''
subPath: '',
data: {}
};
}

componentDidMount = () => {
const {dispatch, nodeId} = this.props;
if(nodeId == '0'){
dispatch(getRootBreadcrumb()).then(response => {
this.setState({
data: response
})
})
}
}

browseWholeTree = () => {
const {dispatch} = this.props;
dispatch(push('/sitemap'));
Expand Down Expand Up @@ -206,7 +219,7 @@ class MenuOverlay extends Component {
</p>
}
<div className="column-wrapper">
{node && node.children.map((item, index) =>
{node && node.children && node.children.map((item, index) =>
<MenuOverlayContainer
key={index}
handleClickOnFolder={this.handleDeeper}
Expand All @@ -228,7 +241,8 @@ class MenuOverlay extends Component {
renderSubnavigation = (nodeData) => {
return(
<div>
{nodeData && nodeData.children.map((item, index) =>
{(nodeData && nodeData.children) &&
nodeData.children.map((item, index) =>
<span
className="menu-overlay-expanded-link"
key={index}
Expand Down Expand Up @@ -310,13 +324,12 @@ class MenuOverlay extends Component {

render() {
const {
queriedResults, deepNode, deepSubNode, subPath, query
queriedResults, deepNode, deepSubNode, subPath, query, data
} = this.state;
const {
dispatch, nodeId, node, siteName, handleMenuOverlay, openModal
} = this.props;
const nodeData = node.children;

const nodeData = nodeId == '0' ? data : node.children;
return (
<div
className="menu-overlay menu-overlay-primary"
Expand Down
4 changes: 0 additions & 4 deletions src/constants/MenuTypes.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// MENU ACTIONS
export const SET_BREADCRUMB = 'SET_BREADCRUMB';
export const SET_HOMEMENU = 'SET_HOMEMENU';
export const SET_REFERENCES = 'SET_REFERENCES';
export const SET_ACTIONS = 'SET_ACTIONS';
export const SET_ATTACHMENTS = 'SET_ATTACHMENTS';
// END OF MENU ACTIONS
22 changes: 1 addition & 21 deletions src/reducers/menuHandler.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import * as types from '../constants/MenuTypes';

const initialState = {
breadcrumb: [],
references: [],
attachments: [],
actions: [],
homemenu: {}
breadcrumb: []
}

export default function menuHandler(state = initialState, action) {
Expand All @@ -14,22 +10,6 @@ export default function menuHandler(state = initialState, action) {
return Object.assign({}, state, {
breadcrumb: action.breadcrumb
});
case types.SET_HOMEMENU:
return Object.assign({}, state, {
homemenu: action.homemenu
});
case types.SET_REFERENCES:
return Object.assign({}, state, {
references: action.references
});
case types.SET_ACTIONS:
return Object.assign({}, state, {
actions: action.actions
});
case types.SET_ATTACHMENTS:
return Object.assign({}, state, {
attachments: action.attachments
});
case types.SET_GLOBAL_GRID_FILTER:
return Object.assign({}, state, {
globalGridFilter: action.filter
Expand Down

0 comments on commit 388d95b

Please sign in to comment.