Index folderName by parent_id
parent
a1c2b16d67
commit
95e346558c
|
@ -4,10 +4,27 @@ import {
|
|||
RootFolderNode
|
||||
} from "./constants";
|
||||
|
||||
type X = Record
|
||||
type NodeName = Required<FlatNodeName>;
|
||||
type NodeNameIndex = Record<number, NodeName[]>;
|
||||
|
||||
const z: Readonly<NodeNameIndex> = {};
|
||||
|
||||
const mapper =
|
||||
(x: FlatNodeName): NodeName => ({ ...x, parent_id: x.parent_id || -1 });
|
||||
|
||||
const reducer = (accum: NodeNameIndex, item: NodeName): NodeNameIndex => {
|
||||
const { parent_id } = item;
|
||||
const list = (accum[parent_id] || []);
|
||||
|
||||
return { ...accum, [parent_id]: [...list, item] };
|
||||
};
|
||||
|
||||
export function ingest(_folders: FlatNode[], names: FlatNodeName[]): RootFolderNode {
|
||||
const output = { folders: [] };
|
||||
const y = names
|
||||
.map((x: FlatNodeName): Required<FlatNodeName> => ({ ...x, parent_id: x.parent_id || -1 }));
|
||||
// const nameIndex =
|
||||
names.map(mapper).reduce(reducer, z);
|
||||
// const keys: keyof typeof nameIndex =
|
||||
// Object.keys(nameIndex).map(x => parseInt(x, 10)).sort();
|
||||
// keys.
|
||||
return output;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue