Skip to content

Commit

Permalink
feat(provider): ordering folders before bookmarks
Browse files Browse the repository at this point in the history
Recursive function little trick

fix #96
  • Loading branch information
julienfrcds committed Apr 21, 2021
1 parent c1f5a5f commit 4650ec2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
14 changes: 9 additions & 5 deletions src/js/strapi/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,24 @@ import StrapiHttpClient from "./api";
*/
const mapServerFolder = folder => {
const { id, name, bookmarks, children } = folder;
let childrens = [];
childrens = bookmarks.map(bookmark => ({
let childrensBookmarks = [];
const childrensFolders = [];

const childrenMapped = children ? children.map(mapServerFolder) : [];
childrensFolders.push(...childrenMapped);

childrensBookmarks = bookmarks.map(bookmark => ({
id: bookmark.id,
title: bookmark.title,
url: bookmark.url,
type: "bookmark",
}));
const childrenMapped = children ? children.map(mapServerFolder) : [];
childrens.push(...childrenMapped);

return {
id,
type: "directory",
title: name,
children: childrens,
children: [...childrensFolders, ...childrensBookmarks],
};
};

Expand Down
6 changes: 3 additions & 3 deletions test/strapi/data.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,22 +168,22 @@ export const classicalFoldersExpectedResult = [
type: "directory",
title: "A",
children: [
{ id: 1, title: "B1", url: "http://dzad.fr", type: "bookmark" },
{
id: 2,
type: "directory",
title: "B",
children: [
{ id: 2, title: "B2", url: "http://fezfzefz.fez", type: "bookmark" },
{ id: 3, title: "B3", url: "http://dadazdaf.fre", type: "bookmark" },
{
id: 4,
type: "directory",
title: "D",
children: [{ id: 2, title: "B2", url: "http://fezfzefz.fez", type: "bookmark" }],
},
{ id: 2, title: "B2", url: "http://fezfzefz.fez", type: "bookmark" },
{ id: 3, title: "B3", url: "http://dadazdaf.fre", type: "bookmark" },
],
},
{ id: 1, title: "B1", url: "http://dzad.fr", type: "bookmark" },
],
},
{
Expand Down

0 comments on commit 4650ec2

Please sign in to comment.