Skip to content

Commit

Permalink
Fixes according to Code Review
Browse files Browse the repository at this point in the history
  • Loading branch information
tischsoic committed Feb 28, 2019
1 parent 247093b commit 435e76b
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Resources/public/js/ContentTree.module.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Resources/public/js/ContentTree.module.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Resources/public/js/MultiFileUpload.module.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Resources/public/js/SubItems.module.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Resources/public/js/UniversalDiscovery.module.js.map

Large diffs are not rendered by default.

19 changes: 7 additions & 12 deletions src/modules/content-tree/content.tree.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@ export default class ContentTreeModule extends Component {
const savedSubtree = localStorage.getItem(KEY_CONTENT_TREE_SUBTREE);

this.items = props.preloadedLocations;

try {
this.subtree = savedSubtree ? JSON.parse(savedSubtree) : null;
} catch (e) {
this.subtree = null;
}
this.subtree = savedSubtree ? JSON.parse(savedSubtree) : null;
}

componentDidMount() {
Expand Down Expand Up @@ -90,7 +85,7 @@ export default class ContentTreeModule extends Component {
}

addItemToSubtree(subtree, item, path) {
const parentSubtree = this.findParentSubtree(subtree, item, path);
const parentSubtree = this.findParentSubtree(subtree, path);

if (!parentSubtree) {
return;
Expand All @@ -108,21 +103,21 @@ export default class ContentTreeModule extends Component {
}

removeItemFromSubtree(subtree, item, path) {
const parentSubtree = this.findParentSubtree(subtree, item, path);
const parentSubtree = this.findParentSubtree(subtree, path);

if (!parentSubtree) {
return;
}

const index = parentSubtree.children.findIndex((element) => parseInt(element.locationId, 10) === parseInt(path[1], 10));
const index = parentSubtree.children.findIndex((element) => element.locationId === parseInt(path[1], 10));

if (index > -1) {
parentSubtree.children.splice(index, 1);
}
}

updateItemInSubtree(subtree, item, path) {
const parentSubtree = this.findParentSubtree(subtree, item, path);
const parentSubtree = this.findParentSubtree(subtree, path);

if (!parentSubtree) {
return;
Expand All @@ -139,7 +134,7 @@ export default class ContentTreeModule extends Component {
localStorage.setItem(KEY_CONTENT_TREE_SUBTREE, JSON.stringify(this.subtree));
}

findParentSubtree(subtree, item, path) {
findParentSubtree(subtree, path) {
if (path.length < 2) {
return;
}
Expand All @@ -154,7 +149,7 @@ export default class ContentTreeModule extends Component {

path.shift();

return this.findParentSubtree(subtreeSubtree, item, path);
return this.findParentSubtree(subtreeSubtree, path);
}

generateSubtree(items) {
Expand Down
17 changes: 5 additions & 12 deletions src/modules/content-tree/services/content.tree.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@ export const loadSubtree = ({ token, siteaccess }, subtree, callback) => {
credentials: 'same-origin',
body: JSON.stringify({
LoadSubtreeRequest: {
"_media-type": "application/vnd.ez.api.ContentTreeLoadSubtreeRequest",
'_media-type': 'application/vnd.ez.api.ContentTreeLoadSubtreeRequest',
nodes: subtree,
},
}),

headers: {
Accept: 'application/vnd.ez.api.ContentTreeRoot+json',
'Content-Type': 'application/vnd.ez.api.ContentTreeLoadSubtreeRequest+json',
Expand All @@ -58,23 +57,17 @@ export const loadSubtree = ({ token, siteaccess }, subtree, callback) => {
.catch(showErrorNotification);
};

const mapChildrenToSubitemsDeep = (tree) => {
const parsedSubtree = [];

for (const subtree of tree) {
const mapChildrenToSubitemsDeep = (tree) =>
tree.map((subtree) => {
mapChildrenToSubitems(subtree);
subtree.subitems = mapChildrenToSubitemsDeep(subtree.subitems);

parsedSubtree.push(subtree);
}

return parsedSubtree;
};
return subtree;
});

const mapChildrenToSubitems = (location) => {
location.totalSubitemsCount = location.totalChildrenCount;
location.subitems = location.children;
location.totalSubitemsCount = location.totalChildrenCount;

delete location.totalChildrenCount;
delete location.children;
Expand Down

0 comments on commit 435e76b

Please sign in to comment.