mirror of
https://github.com/bellingcat/datasheet-server.git
synced 2026-06-10 20:38:32 +03:00
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.
44 lines
864 B
JavaScript
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
|
|
}
|