Skip to content

Commit

Permalink
feat(collaboration): integrate new shared goal creation function
Browse files Browse the repository at this point in the history
  • Loading branch information
vinaybadgujar102 committed Nov 4, 2024
1 parent 951b8bc commit 4f34812
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const AcceptBtn = ({ typeAtPriority, acceptChanges }: AcceptBtnProps) => {
{typeAtPriority === "restored" && "Restore for me too"}
{typeAtPriority === "deleted" && "Delete for me too"}
{typeAtPriority === "subgoals" && "Add all checked"}
{typeAtPriority === "newGoalMoved" && "Move for me too"}
{typeAtPriority === "modifiedGoals" && "Make all checked changes"}
{typeAtPriority === "moved" && "Move for me too"}
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ const DisplayChangesModal = ({ currentMainGoal }: { currentMainGoal: GoalItem })
return;
}
const removeChanges =
currentDisplay === "subgoals"
currentDisplay === "subgoals" || currentDisplay === "newGoalMoved"
? newGoals.map(({ goal }) => goal.id)
: currentDisplay === "moved"
? [goalUnderReview.id, ...(await getAllDescendants(goalUnderReview.id)).map((goal: GoalItem) => goal.id)]
Expand Down Expand Up @@ -199,7 +199,7 @@ const DisplayChangesModal = ({ currentMainGoal }: { currentMainGoal: GoalItem })
if (currentDisplay === "moved") {
await handleMoveChanges();
}
if (currentDisplay === "subgoals") {
if (currentDisplay === "subgoals" || currentDisplay === "newGoalMoved") {
const goalsToBeSelected = newGoals
.filter(({ goal }) => !unselectedChanges.includes(goal.id))
.map(({ goal }) => goal);
Expand Down Expand Up @@ -266,7 +266,7 @@ const DisplayChangesModal = ({ currentMainGoal }: { currentMainGoal: GoalItem })
if (changedGoal) {
setGoalUnderReview({ ...changedGoal });
// TODO: remove the newGoalsMoved and try handle in subgoal only
if (typeAtPriority === "subgoals") {
if (typeAtPriority === "subgoals" || typeAtPriority === "newGoalMoved") {
setNewGoals(goals || []);
} else if (typeAtPriority === "modifiedGoals") {
setUpdatesIntent(goals[0].intent);
Expand Down Expand Up @@ -370,7 +370,7 @@ const DisplayChangesModal = ({ currentMainGoal }: { currentMainGoal: GoalItem })
)}
{["deleted", "archived", "restored"].includes(currentDisplay) && <div />}
{currentDisplay === "modifiedGoals" && getEditChangesList()}
{currentDisplay === "subgoals" && getSubgoalsList()}
{(currentDisplay === "subgoals" || currentDisplay === "newGoalMoved") && getSubgoalsList()}
{currentDisplay === "moved" && getMovedSubgoalsList(goalUnderReview, oldParentTitle, newParentTitle)}

<div className="d-flex justify-fe gap-20">
Expand Down
6 changes: 6 additions & 0 deletions src/components/GoalsComponents/DisplayChangesModal/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ const Header = ({
{contactName} added to {title}.&nbsp; &nbsp; Add as well ?
</>
);
case "newGoalMoved":
return (
<>
{contactName} moved {title} to {title}.&nbsp; &nbsp; Move as well ?
</>
);
case "modifiedGoals":
return (
<>
Expand Down
12 changes: 11 additions & 1 deletion src/helpers/GoalController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,20 @@ export const getGoalHistoryToRoot = async (goalId: string): Promise<{ goalID: st
export const moveGoalHierarchy = async (goalId: string, newParentGoalId: string) => {
const goalToMove = await getGoal(goalId);
const newParentGoal = await getGoal(newParentGoalId);
if (!goalToMove) return;

if (!goalToMove) {
return;
}

const oldParentId = goalToMove.parentGoalId;
const ancestors = await getGoalHistoryToRoot(goalId);
const ancestorGoalIds = ancestors.map((ele) => ele.goalID);

const ancestorGoalsIdsOfNewParent = await getGoalHistoryToRoot(newParentGoalId);
const ancestorGoalIdsOfNewParent = ancestorGoalsIdsOfNewParent.map((ele) => ele.goalID);

await createSharedGoal(goalToMove, newParentGoalId, ancestorGoalIdsOfNewParent);

await Promise.all([
updateGoal(goalToMove.id, { parentGoalId: newParentGoalId }),
removeGoalFromParentSublist(goalToMove.id, oldParentId),
Expand All @@ -298,6 +306,7 @@ export const moveGoalHierarchy = async (goalId: string, newParentGoalId: string)
]);

const subscribers = await getParticipantsOfGoals(ancestorGoalIds);

subscribers.forEach(async ({ sub, rootGoalId }) => {
await sendUpdatesToSubscriber(sub, rootGoalId, "moved", [
{
Expand All @@ -312,6 +321,7 @@ export const moveGoalHierarchy = async (goalId: string, newParentGoalId: string)
});

const descendants = await getAllDescendants(goalId);

if (descendants.length > 0) {
subscribers.forEach(async ({ sub, rootGoalId }) => {
await sendUpdatesToSubscriber(
Expand Down
6 changes: 4 additions & 2 deletions src/helpers/GoalProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ export const getTypeAtPriority = (goalChanges: IChangesInGoal) => {
typeAtPriority = "restored";
} else if (goalChanges.moved.length > 0) {
typeAtPriority = "moved";
} else if (goalChanges.newGoalMoved.length > 0) {
typeAtPriority = "newGoalMoved";
}
return { typeAtPriority };
};
Expand All @@ -131,15 +133,15 @@ export const jumpToLowestChanges = async (id: string, relId: string) => {
const parentId =
"id" in goalAtPriority
? goalAtPriority.id
: typeAtPriority === "subgoals"
: typeAtPriority === "subgoals" || typeAtPriority === "newGoalMoved"
? goalAtPriority.goal.parentGoalId
: goalAtPriority.goal.id;

if (typeAtPriority === "archived" || typeAtPriority === "deleted") {
const result = { typeAtPriority, parentId, goals: [await getGoal(parentId)] };
return result;
}
if (typeAtPriority === "subgoals") {
if (typeAtPriority === "subgoals" || typeAtPriority === "newGoalMoved") {
goalChanges[typeAtPriority].forEach(({ intent, goal }) => {
if (goal.parentGoalId === parentId) goals.push({ intent, goal });
});
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/InboxProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const handleIncomingChanges = async (payload: Payload, relId: string) =>
console.log("Changes ignored");
return;
}
if (payload.changeType === "subgoals") {
if (payload.changeType === "subgoals" || payload.changeType === "newGoalMoved") {
const changes = [
...payload.changes.map((ele: changesInGoal) => ({ ...ele, goal: fixDateVlauesInGoalObject(ele.goal) })),
];
Expand Down Expand Up @@ -95,7 +95,7 @@ export const handleIncomingChanges = async (payload: Payload, relId: string) =>
}
} else if (["sharer", "suggestion"].includes(payload.type)) {
const { changes, changeType, rootGoalId } = payload;
if (changeType === "subgoals") {
if (changeType === "subgoals" || changeType === "newGoalMoved") {
const rootGoal = await getGoal(rootGoalId);
if (!rootGoal || !rootGoal.participants.find((p) => p.relId === relId && p.following)) {
return;
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/PartnerController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { createGoalObjectFromTags } from "./GoalProcessor";
const sendUpdate = (
subscribers: IParticipant[],
rootGoalId: string,
type: "subgoals" | "modifiedGoals",
type: "subgoals" | "modifiedGoals" | "newGoalMoved",
obj: {
level: number;
goal: GoalItem;
Expand Down
11 changes: 9 additions & 2 deletions src/models/InboxItem.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { GoalItem } from "./GoalItem";

export type typeOfChange = "subgoals" | "modifiedGoals" | "archived" | "deleted" | "restored" | "moved";
export type typeOfChange =
| "subgoals"
| "modifiedGoals"
| "archived"
| "deleted"
| "restored"
| "moved"
| "newGoalMoved";

export type typeOfIntent = "suggestion" | "shared";
export type changesInId = { level: number; id: string; intent: typeOfIntent };
Expand All @@ -13,7 +20,7 @@ export interface IChangesInGoal {
deleted: changesInId[];
restored: changesInId[];
moved: changesInId[];
// newGoalMoved: changesInGoal[];
newGoalMoved: changesInGoal[];
}

export interface InboxItem {
Expand Down
1 change: 1 addition & 0 deletions src/utils/defaultGenerators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ export function getDefaultValueOfGoalChanges() {
deleted: [] as changesInId[],
restored: [] as changesInId[],
moved: [] as changesInId[],
newGoalMoved: [] as changesInGoal[],
};
}

0 comments on commit 4f34812

Please sign in to comment.