Files
datasheet-server/src/blueprinters/tree.js
Lachlan Kermode 5431b2be3f abstract generic logic from blueprinters to blueprinters.js
The logic in the files in the 'blueprinters' folder is now _only_ the data transformation logic. Instead of taking in arguments like the sheetId, the tabName, and the sheetName, the function now takes a single argument: the list of lists that represents the raw data from the sheet.

This setup gives datasheet-server greater value, as it allows developers to only specify the transformation logic, and not worry about the other stuff that datasheet server is doing.
2018-12-13 15:56:54 +00:00

44 lines
864 B
JavaScript

import R from 'ramda'
import { fmtObj } from '../lib/util'
/**
* Each resource item is inserted into a tree. TODO: describe layout.
*
* @param {type} data list of lists representing sheet data.
* @return {type} Array the structured data.
*/
export default (data) => {
const tree = {
key: 'tags',
children: {}
}
data.forEach(path => {
const root = path[0]
if (!tree.children[root]) {
tree.children[root] = {
key: root,
children: {}
}
}
let depth = 1
let parentNode = tree.children[root]
while (depth < path.length) {
const node = path[depth]
if (!parentNode.children[node]) {
parentNode.children[node] = {
key: node,
children: {}
}
}
parentNode = parentNode.children[node]
depth++
}
})
return tree
}