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 #1042 from metasfresh/dev-979
Browse files Browse the repository at this point in the history
Optimized breadcrumb handling #979
  • Loading branch information
metas-ts committed Jul 18, 2017
2 parents 36a68ee + 668efa2 commit bb46b39
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 28 deletions.
33 changes: 10 additions & 23 deletions src/actions/MenuActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import axios from 'axios';
// REQUESTS

let breadcrumbsRequested = false;
let breadcrumbsId = null;

export function pathRequest(nodeId) {
return axios.get(
Expand Down Expand Up @@ -80,36 +81,21 @@ export function getRootBreadcrumb() {

export function getWindowBreadcrumb(id){
return dispatch => {
if (!breadcrumbsRequested) {
if (!breadcrumbsRequested && (breadcrumbsId !== id)) {
breadcrumbsRequested = true;

elementPathRequest('window', id).then(response => {
let req = 0;
let pathData = flattenOneLine(response.data);

// promise to get all of the breadcrumb menu options
let breadcrumbProcess = new Promise((resolve) => {

for(let i = 0; i < pathData.length; i++){
const node = pathData[i];
let nodeId = node.nodeId;

breadcrumbRequest(nodeId).then(item => {
node.children = item.data;
req += 1;

if(req === pathData.length){
resolve(pathData);
}
})
}
});

return breadcrumbProcess;
return pathData;
}).then((item) => {
dispatch(setBreadcrumb(item.reverse()));

breadcrumbsId = id;
breadcrumbsRequested = false;
}).catch(() => {
dispatch(setBreadcrumb([]));

breadcrumbsId = null;
breadcrumbsRequested = false;
});
}
Expand Down Expand Up @@ -151,7 +137,8 @@ export function flattenOneLine(node) {
}
result.push({
nodeId: node.nodeId,
caption: node.caption
caption: node.caption,
type: node.type
});
return result;
}
2 changes: 1 addition & 1 deletion src/components/header/Breadcrumb.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Breadcrumb extends Component {
handleMenuOverlay, windowType
} = this.props;

const noChildNodes = menu && menu.children && (menu.children.length === 0);
const noChildNodes = menu && ((menu.type === 'window') || (menu.children && (menu.children.length === 0)));

if(menu && (menu.elementId || noChildNodes)) {
(windowType) && this.linkToPage(windowType);
Expand Down
9 changes: 5 additions & 4 deletions src/components/header/MenuOverlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,19 @@ class MenuOverlay extends Component {

componentDidMount = () => {


const {
nodeId
} = this.props;
if(nodeId == 0){

if (nodeId == 0){
getRootBreadcrumb().then(response => {
this.setState({
data: response
})
})
}else {
if (this.props.node) {
}
else {
if (this.props.node && this.props.node.children) {
this.setState({
data: this.props.node
})
Expand Down

0 comments on commit bb46b39

Please sign in to comment.