Skip to content
Snippets Groups Projects
Commit 95b0d4f1 authored by Esko Ikkala's avatar Esko Ikkala
Browse files

Use react-sortable-tree

parent 24863a46
No related branches found
No related tags found
No related merge requests found
...@@ -100,15 +100,15 @@ export const mapCount = (sparqlBindings) => { ...@@ -100,15 +100,15 @@ export const mapCount = (sparqlBindings) => {
export const mapFacet = (sparqlBindings) => { export const mapFacet = (sparqlBindings) => {
const results = sparqlBindings.map(b => { const results = sparqlBindings.map(b => {
return { return {
key: b.value.value,
title: b.facet_text.value, title: b.facet_text.value,
id: _.has(b, 'value',) ? b.value.value : 'no_selection',
cnt: b.cnt.value, cnt: b.cnt.value,
parent: _.has(b, 'parent',) ? b.parent.value : '0', parent: _.has(b, 'parent',) ? b.parent.value : '0',
}; };
}); });
const treeData = getTreeFromFlatData({ const treeData = getTreeFromFlatData({
flatData: results, flatData: results,
getKey: node => node.key, // resolve a node's key getKey: node => node.id, // resolve a node's key
getParentKey: node => node.parent, // resolve node's parent's key getParentKey: node => node.parent, // resolve node's parent's key
rootKey: 0, // The value of the parent key when there is no parent (i.e., at root level) rootKey: 0, // The value of the parent key when there is no parent (i.e., at root level)
}); });
...@@ -162,27 +162,9 @@ const getTreeFromFlatData = ({ ...@@ -162,27 +162,9 @@ const getTreeFromFlatData = ({
return { ...parent }; return { ...parent };
}; };
const comparator = (a, b) => a.title.localeCompare(b.title); return childrenToParents[rootKey].map(child => trav(child));
const recursiveSort = nodes => {
nodes.sort(comparator);
nodes.forEach(node => {
if (_.has(node, 'children')) {
recursiveSort(node.children);
}
});
return nodes;
};
const unsortedTreeData = childrenToParents[rootKey].map(child => trav(child));
return recursiveSort(unsortedTreeData);
}; };
export const mapAllResults = (results) => groupBy(results, 'id'); export const mapAllResults = (results) => groupBy(results, 'id');
export const mergeFederatedResults = (results) => { export const mergeFederatedResults = (results) => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment