Metadata + data transformation for production board. Breaking changes. BOD-71
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import _ from "lodash/";
|
||||
|
||||
const sortByParentId = (arr) => {
|
||||
// return arr.reduce((accumulator, currentValue) => {
|
||||
// //Find the parent item.
|
||||
// let item = accumulator.find((x) => x.id === currentValue.kanbanparent);
|
||||
// //Get index of praent item
|
||||
// let index = accumulator.indexOf(item);
|
||||
|
||||
// index = index !== -1 ? index + 1 : 0;
|
||||
// accumulator.splice(index, 0, currentValue);
|
||||
// return accumulator;
|
||||
// }, []);
|
||||
|
||||
var parentId = null;
|
||||
var sortedList = [];
|
||||
var byParentsIdsList = _.groupBy(arr, "kanbanparent"); // Create a new array with objects indexed by parentId
|
||||
|
||||
while (byParentsIdsList[parentId]) {
|
||||
sortedList.push(byParentsIdsList[parentId][0]);
|
||||
parentId = byParentsIdsList[parentId][0].id;
|
||||
}
|
||||
return sortedList;
|
||||
};
|
||||
|
||||
export const createBoardData = (AllStatuses, Jobs) => {
|
||||
console.log("==========GENERATING BOARD DATA=============");
|
||||
const boardLanes = {
|
||||
lanes: AllStatuses.map((s) => {
|
||||
return {
|
||||
id: s,
|
||||
title: s,
|
||||
//label: "0",
|
||||
cards: [],
|
||||
};
|
||||
}),
|
||||
};
|
||||
const DataGroupedByStatus = _.groupBy(Jobs, (d) => d.status);
|
||||
|
||||
Object.keys(DataGroupedByStatus).map((statusGroupKey) => {
|
||||
boardLanes.lanes.find(
|
||||
(l) => l.id === statusGroupKey
|
||||
).cards = sortByParentId(DataGroupedByStatus[statusGroupKey]);
|
||||
});
|
||||
|
||||
return boardLanes;
|
||||
};
|
||||
Reference in New Issue
Block a user