- Touch point for working kanbanparents
Signed-off-by: Dave Richer <dave@imexsystems.ca>
This commit is contained in:
@@ -100,23 +100,28 @@ function ProductionBoardKanbanComponent({ data, bodyshop, refetch, insertAuditTr
|
|||||||
const targetLane = boardLanes.lanes.find((lane) => lane.id === destination.droppableId);
|
const targetLane = boardLanes.lanes.find((lane) => lane.id === destination.droppableId);
|
||||||
const sourceLane = boardLanes.lanes.find((lane) => lane.id === source.droppableId);
|
const sourceLane = boardLanes.lanes.find((lane) => lane.id === source.droppableId);
|
||||||
|
|
||||||
|
if (!targetLane || !sourceLane) {
|
||||||
|
setIsMoving(false);
|
||||||
|
console.error("Invalid source or destination lane");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const sameColumnTransfer = source.droppableId === destination.droppableId;
|
const sameColumnTransfer = source.droppableId === destination.droppableId;
|
||||||
const sourceCard = getCardByID(boardLanes, draggableId);
|
const sourceCard = getCardByID(boardLanes, draggableId);
|
||||||
|
|
||||||
const movedCardWillBeFirst = destination.index === 0;
|
const movedCardWillBeFirst = destination.index === 0;
|
||||||
const movedCardWillBeLast = destination.index > targetLane.cards.length - 1;
|
const movedCardWillBeLast = destination.index >= targetLane.cards.length - 1;
|
||||||
|
|
||||||
const lastCardInTargetLane = targetLane.cards[targetLane.cards.length - 1];
|
const lastCardInTargetLane = targetLane.cards[targetLane.cards.length - 1];
|
||||||
|
const oldChildCard = sourceLane.cards[source.index + 1];
|
||||||
const oldChildCard = sourceLane.cards[destination.index + 1];
|
|
||||||
|
|
||||||
const newChildCard = movedCardWillBeLast
|
const newChildCard = movedCardWillBeLast
|
||||||
? null
|
? null
|
||||||
: targetLane.cards[
|
: targetLane.cards[
|
||||||
sameColumnTransfer
|
sameColumnTransfer
|
||||||
? destination.index - destination.index > 0
|
? source.index < destination.index
|
||||||
? destination.index
|
? destination.index + 1
|
||||||
: destination.index + 1
|
: destination.index
|
||||||
: destination.index
|
: destination.index
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -127,12 +132,25 @@ function ProductionBoardKanbanComponent({ data, bodyshop, refetch, insertAuditTr
|
|||||||
movedCardNewKanbanParent = "-1";
|
movedCardNewKanbanParent = "-1";
|
||||||
} else if (movedCardWillBeLast) {
|
} else if (movedCardWillBeLast) {
|
||||||
movedCardNewKanbanParent = lastCardInTargetLane.id;
|
movedCardNewKanbanParent = lastCardInTargetLane.id;
|
||||||
} else if (!!newChildCard) {
|
} else if (newChildCard) {
|
||||||
movedCardNewKanbanParent = newChildCard.metadata.kanbanparent;
|
movedCardNewKanbanParent = newChildCard.metadata.kanbanparent;
|
||||||
} else {
|
} else {
|
||||||
console.log("==> !!!!!!Couldn't find a parent.!!!! <==");
|
console.error("==> !!!!!!Couldn't find a parent.!!!! <==");
|
||||||
}
|
}
|
||||||
|
|
||||||
const newChildCardNewParent = newChildCard ? draggableId : null;
|
const newChildCardNewParent = newChildCard ? draggableId : null;
|
||||||
|
|
||||||
|
console.log({
|
||||||
|
oldChildCard,
|
||||||
|
newChildCard,
|
||||||
|
oldChildCardNewParent,
|
||||||
|
newChildCardNewParent,
|
||||||
|
movedCardNewKanbanParent,
|
||||||
|
sameColumnTransfer,
|
||||||
|
movedCardWillBeFirst,
|
||||||
|
movedCardWillBeLast
|
||||||
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const update = await client.mutate({
|
const update = await client.mutate({
|
||||||
mutation: generate_UPDATE_JOB_KANBAN(
|
mutation: generate_UPDATE_JOB_KANBAN(
|
||||||
|
|||||||
@@ -1,128 +1,91 @@
|
|||||||
import { groupBy } from "lodash";
|
import { groupBy } from "lodash";
|
||||||
|
|
||||||
|
// Function to sort an array of objects by parentId
|
||||||
const sortByParentId = (arr) => {
|
const sortByParentId = (arr) => {
|
||||||
// return arr.reduce((accumulator, currentValue) => {
|
|
||||||
// //Find the parent item.
|
|
||||||
// let item = accumulator.find((x) => x.id === currentValue.kanbanparent);
|
|
||||||
// //Get index of parent item
|
|
||||||
// let index = accumulator.indexOf(item);
|
|
||||||
|
|
||||||
// index = index !== -1 ? index + 1 : 0;
|
|
||||||
// accumulator.splice(index, 0, currentValue);
|
|
||||||
// return accumulator;
|
|
||||||
// }, []);
|
|
||||||
|
|
||||||
let parentId = "-1";
|
let parentId = "-1";
|
||||||
const sortedList = [];
|
const sortedList = [];
|
||||||
const byParentsIdsList = groupBy(arr, "kanbanparent"); // Create a new array with objects indexed by parentId
|
const byParentsIdsList = groupBy(arr, "kanbanparent");
|
||||||
//console.log("sortByParentId -> byParentsIdsList", byParentsIdsList);
|
|
||||||
|
|
||||||
while (byParentsIdsList[parentId]) {
|
while (byParentsIdsList[parentId]) {
|
||||||
sortedList.push(...byParentsIdsList[parentId]); //Spread in the whole list in case several items have the same parents.
|
sortedList.push(...byParentsIdsList[parentId]);
|
||||||
parentId = byParentsIdsList[parentId][byParentsIdsList[parentId].length - 1].id; //Grab the ID from the last one.
|
parentId = byParentsIdsList[parentId][byParentsIdsList[parentId].length - 1].id;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (byParentsIdsList["null"]) byParentsIdsList["null"].map((i) => sortedList.push(i));
|
if (byParentsIdsList["null"]) {
|
||||||
|
sortedList.push(...byParentsIdsList["null"]);
|
||||||
|
}
|
||||||
|
|
||||||
//Validate that the 2 arrays are of the same length and no children are missing.
|
// Ensure all items are included in the sorted list
|
||||||
if (arr.length !== sortedList.length) {
|
if (arr.length !== sortedList.length) {
|
||||||
arr.map((origItem) => {
|
arr.forEach((origItem) => {
|
||||||
if (!!!sortedList.find((s) => s.id === origItem.id)) {
|
if (!sortedList.some((s) => s.id === origItem.id)) {
|
||||||
sortedList.push(origItem);
|
sortedList.push(origItem);
|
||||||
console.log("DATA CONSISTENCY ERROR: ", origItem.ro_number);
|
|
||||||
}
|
}
|
||||||
return 1;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return sortedList;
|
return sortedList;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Function to create board data based on statuses and jobs, with optional filtering
|
||||||
export const createBoardData = (AllStatuses, Jobs, filter) => {
|
export const createBoardData = (AllStatuses, Jobs, filter) => {
|
||||||
const { search, employeeId } = filter;
|
const { search, employeeId } = filter;
|
||||||
const lanes = AllStatuses.map((s) => {
|
const lanes = AllStatuses.map((status) => ({
|
||||||
return {
|
id: status,
|
||||||
id: s,
|
title: status,
|
||||||
title: s,
|
cards: []
|
||||||
cards: []
|
}));
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
const filteredJobs =
|
const filteredJobs =
|
||||||
(search === "" || !search) && !employeeId
|
(search === "" || !search) && !employeeId ? Jobs : Jobs.filter((job) => checkFilter(search, employeeId, job));
|
||||||
? Jobs
|
|
||||||
: Jobs.filter((j) => {
|
|
||||||
let include = false;
|
|
||||||
if (search && search !== "") {
|
|
||||||
include = CheckSearch(search, j);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!!employeeId) {
|
const DataGroupedByStatus = groupBy(filteredJobs, "status");
|
||||||
include =
|
|
||||||
include ||
|
|
||||||
j.employee_body === employeeId ||
|
|
||||||
j.employee_prep === employeeId ||
|
|
||||||
j.employee_csr === employeeId ||
|
|
||||||
j.employee_refinish === employeeId;
|
|
||||||
}
|
|
||||||
|
|
||||||
return include;
|
Object.keys(DataGroupedByStatus).forEach((statusGroupKey) => {
|
||||||
});
|
|
||||||
|
|
||||||
const DataGroupedByStatus = groupBy(filteredJobs, (d) => d.status);
|
|
||||||
|
|
||||||
Object.keys(DataGroupedByStatus).map((statusGroupKey) => {
|
|
||||||
try {
|
try {
|
||||||
const lane = lanes.find((l) => l.id === statusGroupKey);
|
const lane = lanes.find((l) => l.id === statusGroupKey);
|
||||||
if (!lane?.cards) return null;
|
if (!lane) return;
|
||||||
|
|
||||||
lane.cards = sortByParentId(DataGroupedByStatus[statusGroupKey]).map((job) => {
|
lane.cards = sortByParentId(DataGroupedByStatus[statusGroupKey]).map((job) => {
|
||||||
const { id, title, description, due_date, ...metadata } = job;
|
const { id, title, description, due_date, ...metadata } = job;
|
||||||
return {
|
return {
|
||||||
id,
|
id,
|
||||||
title,
|
title,
|
||||||
description,
|
description,
|
||||||
label: job.due_date || "",
|
label: due_date || "",
|
||||||
metadata
|
metadata
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log("Error while creating board card", error);
|
console.error("Error while creating board card", error);
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return { lanes };
|
return { lanes };
|
||||||
};
|
};
|
||||||
|
|
||||||
const CheckSearch = (search, job) => {
|
// Function to check if a job matches the search and/or employeeId filter
|
||||||
return (
|
const checkFilter = (search, employeeId, job) => {
|
||||||
(job.ro_number || "").toLowerCase().includes(search.toLowerCase()) ||
|
const lowerSearch = search?.toLowerCase() || "";
|
||||||
(job.ownr_fn || "").toLowerCase().includes(search.toLowerCase()) ||
|
|
||||||
(job.ownr_co_nm || "").toLowerCase().includes(search.toLowerCase()) ||
|
const matchesSearch =
|
||||||
(job.ownr_ln || "").toLowerCase().includes(search.toLowerCase()) ||
|
lowerSearch &&
|
||||||
(job.status || "").toLowerCase().includes(search.toLowerCase()) ||
|
((job.ro_number || "").toLowerCase().includes(lowerSearch) ||
|
||||||
(job.v_make_desc || "").toLowerCase().includes(search.toLowerCase()) ||
|
(job.ownr_fn || "").toLowerCase().includes(lowerSearch) ||
|
||||||
(job.v_model_desc || "").toLowerCase().includes(search.toLowerCase()) ||
|
(job.ownr_co_nm || "").toLowerCase().includes(lowerSearch) ||
|
||||||
(job.clm_no || "").toLowerCase().includes(search.toLowerCase()) ||
|
(job.ownr_ln || "").toLowerCase().includes(lowerSearch) ||
|
||||||
(job.plate_no || "").toLowerCase().includes(search.toLowerCase())
|
(job.status || "").toLowerCase().includes(lowerSearch) ||
|
||||||
);
|
(job.v_make_desc || "").toLowerCase().includes(lowerSearch) ||
|
||||||
|
(job.v_model_desc || "").toLowerCase().includes(lowerSearch) ||
|
||||||
|
(job.clm_no || "").toLowerCase().includes(lowerSearch) ||
|
||||||
|
(job.plate_no || "").toLowerCase().includes(lowerSearch));
|
||||||
|
|
||||||
|
const matchesEmployeeId =
|
||||||
|
employeeId &&
|
||||||
|
(job.employee_body === employeeId ||
|
||||||
|
job.employee_prep === employeeId ||
|
||||||
|
job.employee_csr === employeeId ||
|
||||||
|
job.employee_refinish === employeeId);
|
||||||
|
|
||||||
|
return matchesSearch || matchesEmployeeId;
|
||||||
};
|
};
|
||||||
|
|
||||||
// export const updateBoardOnMove = (board, card, source, destination) => {
|
|
||||||
// //Slice from source
|
|
||||||
|
|
||||||
// const sourceCardList = board.columns.find((x) => x.id === source.fromColumnId)
|
|
||||||
// .cards;
|
|
||||||
// sourceCardList.slice(source.fromPosition, 0);
|
|
||||||
|
|
||||||
// //Splice into destination.
|
|
||||||
// const destCardList = board.columns.find(
|
|
||||||
// (x) => x.id === destination.toColumnId
|
|
||||||
// ).cards;
|
|
||||||
// console.log("updateBoardOnMove -> destCardList", destCardList);
|
|
||||||
|
|
||||||
// destCardList.splice(destination.toPosition, 0, card);
|
|
||||||
// console.log("updateBoardOnMove -> destCardList", destCardList);
|
|
||||||
// console.log("board", board);
|
|
||||||
// return board;
|
|
||||||
// };
|
|
||||||
|
|||||||
Reference in New Issue
Block a user