Compare commits

...

2 Commits

Author SHA1 Message Date
Anmol Singh Bhatia
3e60d39ee3 chore: code refactor 2024-08-01 18:16:52 +05:30
Anmol Singh Bhatia
2cd9662f84 fix: issue peek overview activity 2024-08-01 18:12:54 +05:30
3 changed files with 73 additions and 24 deletions

View File

@@ -66,7 +66,7 @@ export const IssuePeekOverview: FC<IIssuePeekOverview> = observer((props) => {
update: async (workspaceSlug: string, projectId: string, issueId: string, data: Partial<TIssue>) => {
issues?.updateIssue &&
(await issues
.updateIssue(workspaceSlug, projectId, issueId, data)
.updateIssue(workspaceSlug, projectId, issueId, data, true)
.then(() => {
captureIssueEvent({
eventName: ISSUE_UPDATED,
@@ -161,7 +161,7 @@ export const IssuePeekOverview: FC<IIssuePeekOverview> = observer((props) => {
},
addCycleToIssue: async (workspaceSlug: string, projectId: string, cycleId: string, issueId: string) => {
try {
await issues.addCycleToIssue(workspaceSlug, projectId, cycleId, issueId);
await issues.addCycleToIssue(workspaceSlug, projectId, cycleId, issueId, true);
captureIssueEvent({
eventName: ISSUE_UPDATED,
payload: { issueId, state: "SUCCESS", element: "Issue peek-overview" },
@@ -190,7 +190,7 @@ export const IssuePeekOverview: FC<IIssuePeekOverview> = observer((props) => {
},
addIssueToCycle: async (workspaceSlug: string, projectId: string, cycleId: string, issueIds: string[]) => {
try {
await issues.addIssueToCycle(workspaceSlug, projectId, cycleId, issueIds);
await issues.addIssueToCycle(workspaceSlug, projectId, cycleId, issueIds, true);
captureIssueEvent({
eventName: ISSUE_UPDATED,
payload: { ...issueIds, state: "SUCCESS", element: "Issue peek-overview" },
@@ -219,7 +219,7 @@ export const IssuePeekOverview: FC<IIssuePeekOverview> = observer((props) => {
},
removeIssueFromCycle: async (workspaceSlug: string, projectId: string, cycleId: string, issueId: string) => {
try {
const removeFromCyclePromise = issues.removeIssueFromCycle(workspaceSlug, projectId, cycleId, issueId);
const removeFromCyclePromise = issues.removeIssueFromCycle(workspaceSlug, projectId, cycleId, issueId, true);
setPromiseToast(removeFromCyclePromise, {
loading: "Removing issue from the cycle...",
success: {
@@ -265,7 +265,8 @@ export const IssuePeekOverview: FC<IIssuePeekOverview> = observer((props) => {
projectId,
issueId,
addModuleIds,
removeModuleIds
removeModuleIds,
true
);
captureIssueEvent({
eventName: ISSUE_UPDATED,
@@ -280,7 +281,13 @@ export const IssuePeekOverview: FC<IIssuePeekOverview> = observer((props) => {
},
removeIssueFromModule: async (workspaceSlug: string, projectId: string, moduleId: string, issueId: string) => {
try {
const removeFromModulePromise = issues.removeIssuesFromModule(workspaceSlug, projectId, moduleId, [issueId]);
const removeFromModulePromise = issues.removeIssuesFromModule(
workspaceSlug,
projectId,
moduleId,
[issueId],
true
);
setPromiseToast(removeFromModulePromise, {
loading: "Removing issue from the module...",
success: {

View File

@@ -81,10 +81,23 @@ export interface IBaseIssuesStore {
projectId: string,
cycleId: string,
issueIds: string[],
fetchAddedIssues?: boolean
fetchAddedIssues?: boolean,
shouldSync?: boolean
) => Promise<void>;
removeIssueFromCycle: (
workspaceSlug: string,
projectId: string,
cycleId: string,
issueId: string,
shouldSync?: boolean
) => Promise<void>;
addCycleToIssue: (
workspaceSlug: string,
projectId: string,
cycleId: string,
issueId: string,
shouldSync?: boolean
) => Promise<void>;
removeIssueFromCycle: (workspaceSlug: string, projectId: string, cycleId: string, issueId: string) => Promise<void>;
addCycleToIssue: (workspaceSlug: string, projectId: string, cycleId: string, issueId: string) => Promise<void>;
removeCycleFromIssue: (workspaceSlug: string, projectId: string, issueId: string) => Promise<void>;
addIssuesToModule: (
@@ -98,14 +111,16 @@ export interface IBaseIssuesStore {
workspaceSlug: string,
projectId: string,
moduleId: string,
issueIds: string[]
issueIds: string[],
shouldSync?: boolean
) => Promise<void>;
changeModulesInIssue(
workspaceSlug: string,
projectId: string,
issueId: string,
addModuleIds: string[],
removeModuleIds: string[]
removeModuleIds: string[],
shouldSync?: boolean
): Promise<void>;
}
@@ -562,6 +577,7 @@ export abstract class BaseIssuesStore implements IBaseIssuesStore {
// call fetch Parent Stats
this.fetchParentStats(workspaceSlug, projectId);
this.rootIssueStore.issueDetail.activity.fetchActivities(workspaceSlug, projectId, issueId);
} catch (error) {
// If errored out update store again to revert the change
this.rootIssueStore.issues.updateIssue(issueId, issueBeforeUpdate ?? {});
@@ -832,7 +848,8 @@ export abstract class BaseIssuesStore implements IBaseIssuesStore {
projectId: string,
cycleId: string,
issueIds: string[],
fetchAddedIssues = true
fetchAddedIssues = true,
shouldSync: boolean = false
) {
try {
// Perform an APi call to add issue to cycle
@@ -856,7 +873,7 @@ export abstract class BaseIssuesStore implements IBaseIssuesStore {
// For Each issue update cycle Id by calling current store's update Issue, without making an API call
issueIds.forEach((issueId) => {
this.issueUpdate(workspaceSlug, projectId, issueId, { cycle_id: cycleId }, false);
this.issueUpdate(workspaceSlug, projectId, issueId, { cycle_id: cycleId }, shouldSync);
});
} catch (error) {
throw error;
@@ -870,7 +887,13 @@ export abstract class BaseIssuesStore implements IBaseIssuesStore {
* @param cycleId
* @param issueId
*/
async removeIssueFromCycle(workspaceSlug: string, projectId: string, cycleId: string, issueId: string) {
async removeIssueFromCycle(
workspaceSlug: string,
projectId: string,
cycleId: string,
issueId: string,
shouldSync: boolean = false
) {
try {
// Perform an APi call to remove issue from cycle
await this.issueService.removeIssueFromCycle(workspaceSlug, projectId, cycleId, issueId);
@@ -884,13 +907,19 @@ export abstract class BaseIssuesStore implements IBaseIssuesStore {
});
// update Issue cycle Id to null by calling current store's update Issue, without making an API call
this.issueUpdate(workspaceSlug, projectId, issueId, { cycle_id: null }, false);
this.issueUpdate(workspaceSlug, projectId, issueId, { cycle_id: null }, shouldSync);
} catch (error) {
throw error;
}
}
addCycleToIssue = async (workspaceSlug: string, projectId: string, cycleId: string, issueId: string) => {
addCycleToIssue = async (
workspaceSlug: string,
projectId: string,
cycleId: string,
issueId: string,
shouldSync: boolean = false
) => {
const issueCycleId = this.rootIssueStore.issues.getIssueById(issueId)?.cycle_id;
if (issueCycleId === cycleId) return;
@@ -903,7 +932,7 @@ export abstract class BaseIssuesStore implements IBaseIssuesStore {
// If cycle Id is the current cycle Id, then, add issue to list of issueIds
if (this.cycleId === cycleId) this.addIssueToList(issueId);
// For Each issue update cycle Id by calling current store's update Issue, without making an API call
this.issueUpdate(workspaceSlug, projectId, issueId, { cycle_id: cycleId }, false);
this.issueUpdate(workspaceSlug, projectId, issueId, { cycle_id: cycleId }, shouldSync);
});
await this.issueService.addIssueToCycle(workspaceSlug, projectId, cycleId, {
@@ -918,7 +947,7 @@ export abstract class BaseIssuesStore implements IBaseIssuesStore {
// If cycle Id is the current cycle Id, then, remove issue to list of issueIds
if (this.cycleId === cycleId) this.removeIssueFromList(issueId);
// For Each issue update cycle Id to previous value by calling current store's update Issue, without making an API call
this.issueUpdate(workspaceSlug, projectId, issueId, { cycle_id: issueCycleId }, false);
this.issueUpdate(workspaceSlug, projectId, issueId, { cycle_id: issueCycleId }, shouldSync);
});
throw error;
@@ -1014,7 +1043,13 @@ export abstract class BaseIssuesStore implements IBaseIssuesStore {
* @param issueIds
* @returns
*/
async removeIssuesFromModule(workspaceSlug: string, projectId: string, moduleId: string, issueIds: string[]) {
async removeIssuesFromModule(
workspaceSlug: string,
projectId: string,
moduleId: string,
issueIds: string[],
shouldSync: boolean = false
) {
try {
// Perform an APi call to remove issue to module
const response = await this.moduleService.removeIssuesFromModuleBulk(
@@ -1037,7 +1072,7 @@ export abstract class BaseIssuesStore implements IBaseIssuesStore {
issueIds.forEach((issueId) => {
const issueModuleIds = get(this.rootIssueStore.issues.issuesMap, [issueId, "module_ids"]) ?? [];
const updatedIssueModuleIds = pull(issueModuleIds, moduleId);
this.issueUpdate(workspaceSlug, projectId, issueId, { module_ids: updatedIssueModuleIds }, false);
this.issueUpdate(workspaceSlug, projectId, issueId, { module_ids: updatedIssueModuleIds }, shouldSync);
});
});
@@ -1097,7 +1132,8 @@ export abstract class BaseIssuesStore implements IBaseIssuesStore {
projectId: string,
issueId: string,
addModuleIds: string[],
removeModuleIds: string[]
removeModuleIds: string[],
shouldSync: boolean = false
) {
// keep a copy of the original module ids
const originalModuleIds = get(this.rootIssueStore.issues.issuesMap, [issueId, "module_ids"]) ?? [];
@@ -1117,7 +1153,7 @@ export abstract class BaseIssuesStore implements IBaseIssuesStore {
currentModuleIds = uniq(concat([...currentModuleIds], addModuleIds));
// For current Issue, update module Ids by calling current store's update Issue, without making an API call
this.issueUpdate(workspaceSlug, projectId, issueId, { module_ids: currentModuleIds }, false);
this.issueUpdate(workspaceSlug, projectId, issueId, { module_ids: currentModuleIds }, shouldSync);
});
//Perform API call
@@ -1138,7 +1174,7 @@ export abstract class BaseIssuesStore implements IBaseIssuesStore {
if (removeModuleIds.includes(this.moduleId ?? "")) this.addIssueToList(issueId);
// For current Issue, update module Ids by calling current store's update Issue, without making an API call
this.issueUpdate(workspaceSlug, projectId, issueId, { module_ids: originalModuleIds }, false);
this.issueUpdate(workspaceSlug, projectId, issueId, { module_ids: originalModuleIds }, shouldSync);
});
throw error;

View File

@@ -37,7 +37,13 @@ export interface IProjectIssues extends IBaseIssuesStore {
) => Promise<TIssuesResponse | undefined>;
createIssue: (workspaceSlug: string, projectId: string, data: Partial<TIssue>) => Promise<TIssue>;
updateIssue: (workspaceSlug: string, projectId: string, issueId: string, data: Partial<TIssue>) => Promise<void>;
updateIssue: (
workspaceSlug: string,
projectId: string,
issueId: string,
data: Partial<TIssue>,
shouldSync?: boolean | undefined
) => Promise<void>;
archiveIssue: (workspaceSlug: string, projectId: string, issueId: string) => Promise<void>;
quickAddIssue: (workspaceSlug: string, projectId: string, data: TIssue) => Promise<TIssue | undefined>;
removeBulkIssues: (workspaceSlug: string, projectId: string, issueIds: string[]) => Promise<void>;