refactor: MobX store structure (#3228)

* query params from router as computed

* chore: setup workspace store and sub-stores

* chore: update router query store

* chore: update store types

* fix: pages store changes

* change observables and retain object reference

* fix build errors

* chore: changed the structure of workspace, project, cycle, module and pages

* fix: pages fixes

* fix: merge conflicts resolved

* chore: fixed workspace list

* chore: update workspace store accroding to the new response

* fix: adding page details to store

* fix: adding new contexts and providers

* dev: issues store and filters in new store

* dev: optimised the issue fetching in issue base store

* chore: project views id mapped

* update lodash set to directly run inside runInaction since it mutates the object

* fix: context changes

* code refactor kanban for better mainatinability

* optimize Kanban for performance

* chore: implemented hooks for all the created stores

* chore: removed bridge id

* css change and refactor

* chore: update cycle store structure

* chore: implement the new label root store

* chore: removed object structure

* chore: implement project view hook

* Kanban new store implementation for project issues

* fix project root for kanban

* feat: workspace and project members endpoint (#3092)

* fix: merge conflicts resolved

* issue properties optimization

* chore: user stores

* chore: create new store context and update hooks

* chore: setup inbox store and implement router store

* chore: initialize and implement project estimate store

* chore: initialize global view store

* kanban and list view optimization

* chore: use new cycle and module store. (#3172)

* chore: use new cycle and module store.

* chore: minor improvements.

* Revert "chore: merge develop"

This reverts commit 9d2e0e29e7370b55b48fc2fee4fd126093a6cc48, reversing
changes made to 9595493c42be3ea0ddd17b23a0b124555075c062.

* chore: implement useGlobalView hook

* refactor: projects & inbox store instances (#3179)

* refactor: projects & inbox store instances

* fix: formatting

* fix: action usage

* chore: implement useProjectState hook. (#3185)

* dev: issue, cycle store optimiation

* fix build for code

* dev: removed dummy variables

* dev: issue store

* fix: adding todos

* chore: removing legacy store

* dev: issues store types and typos

* chore: cycle module user properties

* fix legacy store deletion issues

* chore: change POST to PATCH

* fix issues rendering for project root

* chore: removed workspace details in workpsaceinvite

* chore: created models for display properties

* chore: setup member store and implement it everywhere

* refactor: module store (#3202)

* refactor: cycle store (#3192)

* refator: cycle store

* some more improvements.

* chore: implement useLabel hook. (#3190)

* refactor: inbox & project related stores. (#3193)

* refactor: inbox -> filter, issues, inoxes & project -> publish, projects store

* refactor: workspace-project-id name

* fix kanban dropdown overlapping issue

* fix kanban layout minor re rendering

* chore: implement useMember store everywhere

* chore: create and implement editor mention store

* chore: removed the issue view user property

* chore: created at id changed

* dev: segway intgegration (#3132)

* feat: implemented rabbitmq

* dev: initialize segway with queue setup

* dev: import refactors

* dev: create communication with the segway server

* dev: create new workers

* dev: create celery node queue for consuming messages from django

* dev: node to celery connection

* dev: setup segway and django connection

* dev: refactor the structure and add database integration to the app

* dev: add external id and source added

---------

Co-authored-by: NarayanBavisetti <narayan3119@gmail.com>

* dev: github importer (#3205)

* dev: initiate github import

* dev: github importer all issues import

* dev: github comments and links for the imported issues

* dev: update controller to use logger and spread the resultData in getAllEntities

* dev: removed console log

* dev: update code structure and sync functions

* dev: updated retry logic when exception

* dev: add imported data as well

* dev: update logger and repo fetch

* dev: update jira integration to new structure

* dev: update migrations

* dev: update the reason field

* chore: workspace object id removed

* chore: view's creation fixed

* refactor: mobx store improvements. (#3213)

* fix: state and label errors

* chore: remove legacy code

* fix: branch build fix (#3214)

* branch build fix for release-* in case of space,backend,proxy

* fixes

* chore: update store names and types

* fix - file size limit not work on plane.settings.production (#3160)

* fix - file size limit not work on plane.settings.production

* fix - file size limit not work on plane.settings.production

* fix - file size limit not work on plane.settings.production, move to common.py

---------

Co-authored-by: luanduongtel4vn <hoangluan@tel4vn.com>
Co-authored-by: sriram veeraghanta <veeraghanta.sriram@gmail.com>

* style: instance admin email settings ui & ux update. (#3186)

* refactor: use-user-auth hook (#3215)

* refactor: use-user-auth hook

* fix: user store currentUserLoader

* refactor: project-view & application related stores (#3207)

* refactor: project-view & application related stores

* rename: projectViews -> projectViewIds

* fix: project-view favourite state in store

* chore: remove unnecessary hooks and contexts (#3217)

* chore: update issue assignee property component

* chore: bug fixes & improvement (#3218)

* chore: draft issue validation added to prevent saving empty or whitespace title

* chore: resolve scrolling issue in page empty state

* chore: kanban layout quick add issue improvement

* fix: bugs & improvements (#3189)

* fix: workspace invitation modal form values reset

* fix: profile sidebar avatar letter

* [refactor] Editor code refactoring (#3194)

* removed relative imports from editor core

* Update issue widget file paths and imports to use kebab case instead of camel case, to align with coding conventions and improve consistency.

* Update Tiptap core and extensions versions to 2.1.13 and Tiptap React version to 2.1.13. Update Tiptap table imports to use the new location in package @tiptap/pm/tables. Update AlertLabel component to use the new type definition for LucideIcon.

* updated lock file

* removed default exports from editor/core

* fixed injecting css into the core package itself

* seperated css code to have single source of origin wrt to the package

* removed default imports from document editor

* all instances using index as key while mapping fixed

* Update Lite Text Editor package.json to remove @plane/editor-types as a dependency.

Update Lite Text Editor index.ts to update the import of IMentionSuggestion and IMentionHighlight from @plane/editor-types to @plane/editor-core.

Update Lite Text Editor ui/index.tsx to update the import of UploadImage, DeleteImage, IMentionSuggestion, and RestoreImage from @plane/editor-types to @plane/editor-core.

Update Lite Text Editor ui/menus/fixed-menu/index.tsx to update the import of UploadImage from @plane/editor-types to @plane/editor-core.

Update turbo.json to remove @plane/editor-types#build as a dependency for @plane/lite-text-editor#build, @plane/rich-text-editor#build, and @plane/document-editor#build.

* Remove deprecated import and adjust tippy.js usage in the slash-commands.tsx file of the editor extensions package.

* Update dependencies in `rich-text-editor/package.json`, remove `@plane/editor-types` and add `@plane/editor-core` in `rich-text-editor/src/index.ts`, and update imports in `rich-text-editor/src/ui/extensions/index.tsx` and `rich-text-editor/src/ui/index.tsx` to use `@plane/editor-core` instead of `@plane/editor-types`.

* Update package.json dependencies and add new types for image deletion, upload, restore, mention highlight, mention suggestion, and slash command item.

* Update import statements in various files to use the new package "@plane/editor-core" instead of "@plane/editor-types".

* fixed document editor to follow conventions

* Refactor imports in the Rich Text Editor package to use relative paths instead of absolute paths.

- Updated imports in `index.ts`, `ui/index.tsx`, and `ui/menus/bubble-menu/index.tsx` to use relative paths.
- Updated `tsconfig.json` to include the `baseUrl` compiler option and adjust the `include` and `exclude` paths.

* Refactor Lite Text Editor code to use relative import paths instead of absolute import paths.

* Added LucideIconType to the exports in index.ts for use in other files.
Created a new file lucide-icon.ts which contains the type LucideIconType.
Updated the icon type in HeadingOneItem in menu-items/index.tsx to use LucideIconType.
Updated the Icon type in AlertLabel in alert-label.tsx to use LucideIconType.
Updated the Icon type in VerticalDropdownItemProps in vertical-dropdown-menu.tsx to use LucideIconType.
Updated the Icon type in BubbleMenuItem in fixed-menu/index.tsx to use LucideIconType.
Deleted the file tooltip.tsx since it is no longer used.
Updated the Icon type in BubbleMenuItem in bubble-menu/index.tsx to use LucideIconType.

* ♻️ refactor: simplify rendering logic in slash-commands.tsx

The rendering logic in the file "slash-commands.tsx" has been simplified. Previously, the code used inline positioning for the popup, but it has now been removed. Instead of appending the popup to the document body, it is now appended to the element with the ID "tiptap-container". The "flip" option has also been removed. These changes have improved the readability and maintainability of the code.

* fixed build errors caused due to core's internal imports

* regression: fixed pages not saving issue and not duplicating with proper content issue

* build: Update @tiptap dependencies

Updated the @tiptap dependencies in the package.json files of `document-editor`, `extensions`, and `rich-text-editor` packages to version 2.1.13.

* 🚑 fix: Correct appendTo selector in slash-commands.tsx

Update the `appendTo` function call in `slash-commands.tsx` to use the correct selector `#editor-container` instead of `#tiptap-container`. This ensures that the component is appended to the appropriate container in the editor extension.

Note: The commit message assumes that the change is a fix for an issue or error. If it's not a fix, please provide more context so that an appropriate commit type can be determined.

* style: email placeholder changed across the platform (#3206)

* style: email placeholder changed across the platform

* fix: placeholder text

* dev: updated new filter endpoints and restructured issue and issue filters store

* implement issues and replace useMobxStore

* remove all store legacy references

* dev: updated the orderby and subgroupby filters data

* dev:added projectId in issue filters for consistency

* fix more build errors

* dev: updated profile issues

* dev: removed store legacy

* dev: active cycle issues in the cycle issue store

* fix additional build errors and memoize issueActions in each layout component

* change store enums

* remove all useMobxStore references

* fix more build errors

* dev: reverted workspace invitation

* fix: build errors and warnings

* fix: optimistic update for instant operations (#3221)

* fix: update functions failed case

* fix: typo

* chore: revert back to optimistic update approach for all `update related actions` (#3219)

* fix: merge conflicts resolved

* chore: update memberMap logic in components

* add assignees to kanban groups and properties

* dev: migration fixes

* final bit of optimization on list view

* change all TODOs that are to be done before this release to FIXME

* change base Kanban TODOs that are to be done before this release to FIXME

* dev: add fields and expand for app serializers

* dev: issue detail store

* dev: update issue serializer to return object ids

* fix: Instance key added in settings and converted issues list api to arry instead of dict

* fix: removing segway files

* dev: control expand through query parameters

* revert: github importer

* Revert "dev: segway intgegration (#3132)"

This reverts commit 1cc18a09156d1790d114061dbac8c901e0f2754c.

* dev: remove migrations for segway

* dev: issue structure change and created workspacebasemodel

* dev: issue detail serializer

* fix: changed workspace dict

* dev: updated new issue structure

* chore: build fix

* dev: issue detail store refactor

* dev: created list endpoint for issue-relation

* dev: added issue attachments in issue detail store

* dev: added issue activity computed

* fix: build error

* chore: peek overview modal context added

* chore: build error fix

* dev: added sub_issues in issue details store

* dev: added complete issue serializer for sub issues

* dev: resolved type errors in issue root store

* dev: changed the issue relation structure

* chore: new global dropdowns

* chore: build error fix

* chore: cycle and module selection if disabled

* dev: removed unnecessary code from the workspace root

* chore: build error fix

* chore: issue relation remove endpoint

* fix: build error

* dev: typos and implemented issue relation store

* fix: yarn lock updated

* style: update the UI of all the dropdowns

* fix: state store fixes

* fix: key issue

* fix: state store console logs removed

* refactor: member dropdowns

* fix: moving types to packages

* fix: dropdown arrow positioning

* dev: removed logs

* style: label dropdown

* chore: restrict description notifications

* chore: description changes

* chore: update spreadsheet layout dropdowns

* fix: build errors

* chore: duplicate key change

* fix: ui bugs

* chore: relation activity change

* chore: comment activity changes

* chore: blocking issue removal

* chore: added project_id for relation

* chore: issue relation store and component

* chore: issue redirection issue in the issue realtion in detail page

* chore: created activity changed

* chore: issue links new store implementation on the issue detail

* chore: issue relation deletion acitivity changed

* chore: issue attachments new store implementation on the issue detail

* chore: workspace level issues

* fix: build errors

---------

Co-authored-by: rahulramesha <rahulramesham@gmail.com>
Co-authored-by: gurusainath <gurusainath007@gmail.com>
Co-authored-by: sriram veeraghanta <veeraghanta.sriram@gmail.com>
Co-authored-by: NarayanBavisetti <narayan3119@gmail.com>
Co-authored-by: Bavisetti Narayan <72156168+NarayanBavisetti@users.noreply.github.com>
Co-authored-by: Prateek Shourya <prateekshourya29@gmail.com>
Co-authored-by: Lakhan Baheti <94619783+1akhanBaheti@users.noreply.github.com>
Co-authored-by: Nikhil <118773738+pablohashescobar@users.noreply.github.com>
Co-authored-by: Manish Gupta <59428681+mguptahub@users.noreply.github.com>
Co-authored-by: Hoang Luan <luandnh98@gmail.com>
Co-authored-by: luanduongtel4vn <hoangluan@tel4vn.com>
Co-authored-by: Anmol Singh Bhatia <121005188+anmolsinghbhatia@users.noreply.github.com>
Co-authored-by: M. Palanikannan <73993394+Palanikannan1437@users.noreply.github.com>
Co-authored-by: pablohashescobar <nikhilschacko@gmail.com>
Co-authored-by: Anmol Singh Bhatia <anmolsinghbhatia@plane.so>
This commit is contained in:
Aaryan Khandelwal 2024-01-02 18:12:55 +05:30 committed by GitHub
parent 1539340113
commit 804b7d8663
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
940 changed files with 26378 additions and 34411 deletions

View file

@ -0,0 +1,86 @@
import { action, computed, makeObservable, observable, runInAction } from "mobx";
import set from "lodash/set";
// services
import { IssueService } from "services/issue";
// types
import { IIssueDetail } from "./root.store";
import { TIssueActivity, TIssueActivityIdMap, TIssueActivityMap } from "@plane/types";
export interface IIssueActivityStoreActions {
// actions
fetchActivities: (workspaceSlug: string, projectId: string, issueId: string) => Promise<TIssueActivity[]>;
}
export interface IIssueActivityStore extends IIssueActivityStoreActions {
// observables
activities: TIssueActivityIdMap;
activityMap: TIssueActivityMap;
// computed
issueActivities: string[] | undefined;
// helper methods
getActivitiesByIssueId: (issueId: string) => string[] | undefined;
getActivityById: (activityId: string) => TIssueActivity | undefined;
}
export class IssueActivityStore implements IIssueActivityStore {
// observables
activities: TIssueActivityIdMap = {};
activityMap: TIssueActivityMap = {};
// root store
rootIssueDetailStore: IIssueDetail;
// services
issueService;
constructor(rootStore: IIssueDetail) {
makeObservable(this, {
// observables
activities: observable,
activityMap: observable,
// computed
issueActivities: computed,
// actions
fetchActivities: action,
});
// root store
this.rootIssueDetailStore = rootStore;
// services
this.issueService = new IssueService();
}
// computed
get issueActivities() {
const issueId = this.rootIssueDetailStore.issueId;
if (!issueId) return undefined;
return this.activities[issueId] ?? undefined;
}
// helper methods
getActivitiesByIssueId = (issueId: string) => {
if (!issueId) return undefined;
return this.activities[issueId] ?? undefined;
};
getActivityById = (activityId: string) => {
if (!activityId) return undefined;
return this.activityMap[activityId] ?? undefined;
};
// actions
fetchActivities = async (workspaceSlug: string, projectId: string, issueId: string) => {
try {
const activities = await this.issueService.getIssueActivities(workspaceSlug, projectId, issueId);
const activityIds = activities.map((activity) => activity.id);
runInAction(() => {
set(this.activities, issueId, activityIds);
activities.forEach((activity) => {
set(this.activityMap, activity.id, activity);
});
});
return activities;
} catch (error) {
throw error;
}
};
}

View file

@ -0,0 +1,133 @@
import { action, computed, makeObservable, observable, runInAction } from "mobx";
import set from "lodash/set";
// services
import { IssueAttachmentService } from "services/issue";
// types
import { IIssueDetail } from "./root.store";
import { TIssueAttachment, TIssueAttachmentMap, TIssueAttachmentIdMap } from "@plane/types";
export interface IIssueAttachmentStoreActions {
fetchAttachments: (workspaceSlug: string, projectId: string, issueId: string) => Promise<TIssueAttachment[]>;
createAttachment: (
workspaceSlug: string,
projectId: string,
issueId: string,
data: FormData
) => Promise<TIssueAttachment>;
removeAttachment: (
workspaceSlug: string,
projectId: string,
issueId: string,
attachmentId: string
) => Promise<TIssueAttachment>;
}
export interface IIssueAttachmentStore extends IIssueAttachmentStoreActions {
// observables
attachments: TIssueAttachmentIdMap;
attachmentMap: TIssueAttachmentMap;
// computed
issueAttachments: string[] | undefined;
// helper methods
getAttachmentsByIssueId: (issueId: string) => string[] | undefined;
getAttachmentById: (attachmentId: string) => TIssueAttachment | undefined;
}
export class IssueAttachmentStore implements IIssueAttachmentStore {
// observables
attachments: TIssueAttachmentIdMap = {};
attachmentMap: TIssueAttachmentMap = {};
// root store
rootIssueDetailStore: IIssueDetail;
// services
issueAttachmentService;
constructor(rootStore: IIssueDetail) {
makeObservable(this, {
// observables
attachments: observable,
attachmentMap: observable,
// computed
issueAttachments: computed,
// actions
fetchAttachments: action,
createAttachment: action,
removeAttachment: action,
});
// root store
this.rootIssueDetailStore = rootStore;
// services
this.issueAttachmentService = new IssueAttachmentService();
}
// computed
get issueAttachments() {
const issueId = this.rootIssueDetailStore.issueId;
if (!issueId) return undefined;
return this.attachments[issueId] ?? undefined;
}
// helper methods
getAttachmentsByIssueId = (issueId: string) => {
if (!issueId) return undefined;
return this.attachments[issueId] ?? undefined;
};
getAttachmentById = (attachmentId: string) => {
if (!attachmentId) return undefined;
return this.attachmentMap[attachmentId] ?? undefined;
};
// actions
fetchAttachments = async (workspaceSlug: string, projectId: string, issueId: string) => {
try {
const response = await this.issueAttachmentService.getIssueAttachment(workspaceSlug, projectId, issueId);
runInAction(() => {
this.attachments[issueId] = response.map((attachment) => attachment.id);
response.forEach((attachment) => set(this.attachmentMap, attachment.id, attachment));
});
return response;
} catch (error) {
throw error;
}
};
createAttachment = async (workspaceSlug: string, projectId: string, issueId: string, data: FormData) => {
try {
const response = await this.issueAttachmentService.uploadIssueAttachment(workspaceSlug, projectId, issueId, data);
runInAction(() => {
this.attachments[issueId].push(response.id);
set(this.attachmentMap, response.id, response);
});
return response;
} catch (error) {
throw error;
}
};
removeAttachment = async (workspaceSlug: string, projectId: string, issueId: string, attachmentId: string) => {
try {
const response = await this.issueAttachmentService.deleteIssueAttachment(
workspaceSlug,
projectId,
issueId,
attachmentId
);
const reactionIndex = this.attachments[issueId].findIndex((_comment) => _comment === attachmentId);
if (reactionIndex >= 0)
runInAction(() => {
this.attachments[issueId].splice(reactionIndex, 1);
delete this.attachmentMap[attachmentId];
});
return response;
} catch (error) {
throw error;
}
};
}

View file

@ -0,0 +1,109 @@
import { action, makeObservable, runInAction } from "mobx";
import set from "lodash/set";
// services
import { IssueCommentService } from "services/issue";
// types
import { IIssueDetail } from "./root.store";
import { TIssueActivity } from "@plane/types";
export interface IIssueCommentStoreActions {
createComment: (
workspaceSlug: string,
projectId: string,
issueId: string,
data: Partial<TIssueActivity>
) => Promise<any>;
updateComment: (
workspaceSlug: string,
projectId: string,
issueId: string,
commentId: string,
data: Partial<TIssueActivity>
) => Promise<any>;
removeComment: (workspaceSlug: string, projectId: string, issueId: string, commentId: string) => Promise<any>;
}
export interface IIssueCommentStore extends IIssueCommentStoreActions {}
export class IssueCommentStore implements IIssueCommentStore {
// root store
rootIssueDetail: IIssueDetail;
// services
issueCommentService;
constructor(rootStore: IIssueDetail) {
makeObservable(this, {
// actions
createComment: action,
updateComment: action,
removeComment: action,
});
// root store
this.rootIssueDetail = rootStore;
// services
this.issueCommentService = new IssueCommentService();
}
createComment = async (workspaceSlug: string, projectId: string, issueId: string, data: Partial<TIssueActivity>) => {
try {
const response = await this.issueCommentService.createIssueComment(workspaceSlug, projectId, issueId, data);
runInAction(() => {
this.rootIssueDetail.activity.activities[issueId].push(response.id);
set(this.rootIssueDetail.activity.activityMap, response.id, response);
});
return response;
} catch (error) {
throw error;
}
};
updateComment = async (
workspaceSlug: string,
projectId: string,
issueId: string,
commentId: string,
data: Partial<TIssueActivity>
) => {
try {
runInAction(() => {
Object.keys(data).forEach((key) => {
set(this.rootIssueDetail.activity.activityMap, [commentId, key], data[key as keyof TIssueActivity]);
});
});
const response = await this.issueCommentService.patchIssueComment(
workspaceSlug,
projectId,
issueId,
commentId,
data
);
return response;
} catch (error) {
this.rootIssueDetail.activity.fetchActivities(workspaceSlug, projectId, issueId);
throw error;
}
};
removeComment = async (workspaceSlug: string, projectId: string, issueId: string, commentId: string) => {
try {
const response = await this.issueCommentService.deleteIssueComment(workspaceSlug, projectId, issueId, commentId);
const reactionIndex = this.rootIssueDetail.activity.activities[issueId].findIndex(
(_comment) => _comment === commentId
);
if (reactionIndex >= 0)
runInAction(() => {
this.rootIssueDetail.activity.activities[issueId].splice(reactionIndex, 1);
delete this.rootIssueDetail.activity.activityMap[commentId];
});
return response;
} catch (error) {
throw error;
}
};
}

View file

@ -0,0 +1,133 @@
import { action, makeObservable, observable, runInAction } from "mobx";
import set from "lodash/set";
// services
import { IssueReactionService } from "services/issue";
// types
import { IIssueDetail } from "./root.store";
import { TIssueCommentReaction, TIssueCommentReactionIdMap, TIssueCommentReactionMap } from "@plane/types";
export interface IIssueCommentReactionStoreActions {
// actions
fetchCommentReactions: (
workspaceSlug: string,
projectId: string,
commentId: string
) => Promise<TIssueCommentReaction[]>;
createCommentReaction: (
workspaceSlug: string,
projectId: string,
commentId: string,
reaction: string
) => Promise<any>;
removeCommentReaction: (
workspaceSlug: string,
projectId: string,
commentId: string,
reaction: string
) => Promise<any>;
}
export interface IIssueCommentReactionStore extends IIssueCommentReactionStoreActions {
// observables
commentReactions: TIssueCommentReactionIdMap;
commentReactionMap: TIssueCommentReactionMap;
// helper methods
getCommentReactionsByCommentId: (commentId: string) => string[] | undefined;
getCommentReactionById: (reactionId: string) => TIssueCommentReaction | undefined;
}
export class IssueCommentReactionStore implements IIssueCommentReactionStore {
// observables
commentReactions: TIssueCommentReactionIdMap = {};
commentReactionMap: TIssueCommentReactionMap = {};
// root store
rootIssueDetailStore: IIssueDetail;
// services
issueReactionService;
constructor(rootStore: IIssueDetail) {
makeObservable(this, {
// observables
commentReactions: observable,
commentReactionMap: observable,
// actions
fetchCommentReactions: action,
createCommentReaction: action,
removeCommentReaction: action,
});
// root store
this.rootIssueDetailStore = rootStore;
// services
this.issueReactionService = new IssueReactionService();
}
// helper methods
getCommentReactionsByCommentId = (commentId: string) => {
if (!commentId) return undefined;
return this.commentReactions[commentId] ?? undefined;
};
getCommentReactionById = (reactionId: string) => {
if (!reactionId) return undefined;
return this.commentReactionMap[reactionId] ?? undefined;
};
// actions
fetchCommentReactions = async (workspaceSlug: string, projectId: string, commentId: string) => {
try {
const reactions = await this.issueReactionService.listIssueCommentReactions(workspaceSlug, projectId, commentId);
const reactionIds = reactions.map((reaction) => reaction.id);
runInAction(() => {
set(this.commentReactions, commentId, reactionIds);
reactions.forEach((reaction) => {
set(this.commentReactionMap, reaction.id, reaction);
});
});
return reactions;
} catch (error) {
throw error;
}
};
createCommentReaction = async (workspaceSlug: string, projectId: string, commentId: string, reaction: string) => {
try {
const response = await this.issueReactionService.createIssueCommentReaction(workspaceSlug, projectId, commentId, {
reaction,
});
runInAction(() => {
this.commentReactions[commentId].push(response.id);
set(this.commentReactionMap, response.id, response);
});
return response;
} catch (error) {
throw error;
}
};
removeCommentReaction = async (workspaceSlug: string, projectId: string, commentId: string, reaction: string) => {
try {
const reactionIndex = this.commentReactions[commentId].findIndex((_reaction) => _reaction === reaction);
if (reactionIndex >= 0)
runInAction(() => {
this.commentReactions[commentId].splice(reactionIndex, 1);
delete this.commentReactionMap[reaction];
});
const response = await this.issueReactionService.deleteIssueCommentReaction(
workspaceSlug,
projectId,
commentId,
reaction
);
return response;
} catch (error) {
this.fetchCommentReactions(workspaceSlug, projectId, commentId);
throw error;
}
};
}

View file

@ -0,0 +1,116 @@
import { makeObservable } from "mobx";
// services
import { IssueService } from "services/issue";
// types
import { IIssueDetail } from "./root.store";
import { TIssue } from "@plane/types";
export interface IIssueStoreActions {
// actions
fetchIssue: (workspaceSlug: string, projectId: string, issueId: string) => Promise<TIssue>;
updateIssue: (workspaceSlug: string, projectId: string, issueId: string, data: Partial<TIssue>) => Promise<TIssue>;
removeIssue: (workspaceSlug: string, projectId: string, issueId: string) => Promise<TIssue>;
addIssueToCycle: (workspaceSlug: string, projectId: string, cycleId: string, issueIds: string[]) => Promise<TIssue>;
removeIssueFromCycle: (workspaceSlug: string, projectId: string, cycleId: string, issueId: string) => Promise<TIssue>;
addIssueToModule: (workspaceSlug: string, projectId: string, moduleId: string, issueIds: string[]) => Promise<any>;
removeIssueFromModule: (
workspaceSlug: string,
projectId: string,
moduleId: string,
issueId: string
) => Promise<TIssue>;
}
export interface IIssueStore extends IIssueStoreActions {
// helper methods
getIssueById: (issueId: string) => TIssue | undefined;
}
export class IssueStore implements IIssueStore {
// root store
rootIssueDetailStore: IIssueDetail;
// services
issueService;
constructor(rootStore: IIssueDetail) {
makeObservable(this, {});
// root store
this.rootIssueDetailStore = rootStore;
// services
this.issueService = new IssueService();
}
// helper methods
getIssueById = (issueId: string) => {
if (!issueId) return undefined;
return this.rootIssueDetailStore.rootIssueStore.issues.getIssueById(issueId) ?? undefined;
};
// actions
fetchIssue = async (workspaceSlug: string, projectId: string, issueId: string) => {
try {
const issue = await this.issueService.retrieve(workspaceSlug, projectId, issueId);
if (!issue) throw new Error("Issue not found");
this.rootIssueDetailStore.rootIssueStore.issues.addIssue([issue]);
// issue reactions
this.rootIssueDetailStore.reaction.fetchReactions(workspaceSlug, projectId, issueId);
// fetch issue links
this.rootIssueDetailStore.link.fetchLinks(workspaceSlug, projectId, issueId);
// fetch issue attachments
this.rootIssueDetailStore.attachment.fetchAttachments(workspaceSlug, projectId, issueId);
// fetch issue activity
this.rootIssueDetailStore.activity.fetchActivities(workspaceSlug, projectId, issueId);
// fetch issue subscription
this.rootIssueDetailStore.subscription.fetchSubscriptions(workspaceSlug, projectId, issueId);
// fetch sub issues
this.rootIssueDetailStore.subIssues.fetchSubIssues(workspaceSlug, projectId, issueId);
// fetch issue relations
this.rootIssueDetailStore.relation.fetchRelations(workspaceSlug, projectId, issueId);
return issue;
} catch (error) {
throw error;
}
};
updateIssue = async (workspaceSlug: string, projectId: string, issueId: string, data: Partial<TIssue>) =>
this.rootIssueDetailStore.rootIssueStore.projectIssues.updateIssue(workspaceSlug, projectId, issueId, data);
removeIssue = async (workspaceSlug: string, projectId: string, issueId: string) =>
this.rootIssueDetailStore.rootIssueStore.projectIssues.removeIssue(workspaceSlug, projectId, issueId);
addIssueToCycle = async (workspaceSlug: string, projectId: string, cycleId: string, issueIds: string[]) =>
this.rootIssueDetailStore.rootIssueStore.cycleIssues.addIssueToCycle(workspaceSlug, projectId, cycleId, issueIds);
removeIssueFromCycle = async (workspaceSlug: string, projectId: string, cycleId: string, issueId: string) =>
this.rootIssueDetailStore.rootIssueStore.cycleIssues.removeIssueFromCycle(
workspaceSlug,
projectId,
cycleId,
issueId
);
addIssueToModule = async (workspaceSlug: string, projectId: string, moduleId: string, issueIds: string[]) =>
this.rootIssueDetailStore.rootIssueStore.moduleIssues.addIssueToModule(
workspaceSlug,
projectId,
moduleId,
issueIds
);
removeIssueFromModule = async (workspaceSlug: string, projectId: string, moduleId: string, issueId: string) =>
this.rootIssueDetailStore.rootIssueStore.moduleIssues.removeIssueFromModule(
workspaceSlug,
projectId,
moduleId,
issueId
);
}

View file

@ -0,0 +1,149 @@
import { action, computed, makeObservable, observable, runInAction } from "mobx";
import set from "lodash/set";
// services
import { IssueService } from "services/issue";
// types
import { IIssueDetail } from "./root.store";
import { TIssueLink, TIssueLinkMap, TIssueLinkIdMap } from "@plane/types";
export interface IIssueLinkStoreActions {
fetchLinks: (workspaceSlug: string, projectId: string, issueId: string) => Promise<TIssueLink[]>;
createLink: (workspaceSlug: string, projectId: string, issueId: string, data: Partial<TIssueLink>) => Promise<any>;
updateLink: (
workspaceSlug: string,
projectId: string,
issueId: string,
linkId: string,
data: Partial<TIssueLink>
) => Promise<any>;
removeLink: (workspaceSlug: string, projectId: string, issueId: string, linkId: string) => Promise<any>;
}
export interface IIssueLinkStore extends IIssueLinkStoreActions {
// observables
links: TIssueLinkIdMap;
linkMap: TIssueLinkMap;
// computed
issueLinks: string[] | undefined;
// helper methods
getLinksByIssueId: (issueId: string) => string[] | undefined;
getLinkById: (linkId: string) => TIssueLink | undefined;
}
export class IssueLinkStore implements IIssueLinkStore {
// observables
links: TIssueLinkIdMap = {};
linkMap: TIssueLinkMap = {};
// root store
rootIssueDetailStore: IIssueDetail;
// services
issueService;
constructor(rootStore: IIssueDetail) {
makeObservable(this, {
// observables
links: observable,
linkMap: observable,
// computed
issueLinks: computed,
// actions
fetchLinks: action,
createLink: action,
updateLink: action,
removeLink: action,
});
// root store
this.rootIssueDetailStore = rootStore;
// services
this.issueService = new IssueService();
}
// computed
get issueLinks() {
const issueId = this.rootIssueDetailStore.issueId;
if (!issueId) return undefined;
return this.links[issueId] ?? undefined;
}
// helper methods
getLinksByIssueId = (issueId: string) => {
if (!issueId) return undefined;
return this.links[issueId] ?? undefined;
};
getLinkById = (linkId: string) => {
if (!linkId) return undefined;
return this.linkMap[linkId] ?? undefined;
};
// actions
fetchLinks = async (workspaceSlug: string, projectId: string, issueId: string) => {
try {
const response = await this.issueService.fetchIssueLinks(workspaceSlug, projectId, issueId);
runInAction(() => {
this.links[issueId] = response.map((link) => link.id);
response.forEach((link) => set(this.linkMap, link.id, link));
});
return response;
} catch (error) {
throw error;
}
};
createLink = async (workspaceSlug: string, projectId: string, issueId: string, data: Partial<TIssueLink>) => {
try {
const response = await this.issueService.createIssueLink(workspaceSlug, projectId, issueId, data);
runInAction(() => {
this.links[issueId].push(response.id);
set(this.linkMap, response.id, response);
});
return response;
} catch (error) {
throw error;
}
};
updateLink = async (
workspaceSlug: string,
projectId: string,
issueId: string,
linkId: string,
data: Partial<TIssueLink>
) => {
try {
runInAction(() => {
Object.keys(data).forEach((key) => {
set(this.linkMap, [linkId, key], data[key as keyof TIssueLink]);
});
});
const response = await this.issueService.updateIssueLink(workspaceSlug, projectId, issueId, linkId, data);
return response;
} catch (error) {
// TODO: fetch issue detail
throw error;
}
};
removeLink = async (workspaceSlug: string, projectId: string, issueId: string, linkId: string) => {
try {
const response = await this.issueService.deleteIssueLink(workspaceSlug, projectId, issueId, linkId);
const reactionIndex = this.links[issueId].findIndex((_comment) => _comment === linkId);
if (reactionIndex >= 0)
runInAction(() => {
this.links[issueId].splice(reactionIndex, 1);
delete this.linkMap[linkId];
});
return response;
} catch (error) {
throw error;
}
};
}

View file

@ -0,0 +1,123 @@
import { action, computed, makeObservable, observable, runInAction } from "mobx";
import set from "lodash/set";
// services
import { IssueReactionService } from "services/issue";
// types
import { IIssueDetail } from "./root.store";
import { TIssueReaction, TIssueReactionMap, TIssueReactionIdMap } from "@plane/types";
export interface IIssueReactionStoreActions {
// actions
fetchReactions: (workspaceSlug: string, projectId: string, issueId: string) => Promise<TIssueReaction[]>;
createReaction: (workspaceSlug: string, projectId: string, issueId: string, reaction: string) => Promise<any>;
removeReaction: (workspaceSlug: string, projectId: string, issueId: string, reaction: string) => Promise<any>;
}
export interface IIssueReactionStore extends IIssueReactionStoreActions {
// observables
reactions: TIssueReactionIdMap;
reactionMap: TIssueReactionMap;
// computed
issueReactions: string[] | undefined;
// helper methods
getReactionsByIssueId: (issueId: string) => string[] | undefined;
getReactionById: (reactionId: string) => TIssueReaction | undefined;
}
export class IssueReactionStore implements IIssueReactionStore {
// observables
reactions: TIssueReactionIdMap = {};
reactionMap: TIssueReactionMap = {};
// root store
rootIssueDetailStore: IIssueDetail;
// services
issueReactionService;
constructor(rootStore: IIssueDetail) {
makeObservable(this, {
// observables
reactions: observable,
reactionMap: observable,
// computed
issueReactions: computed,
// actions
fetchReactions: action,
createReaction: action,
removeReaction: action,
});
// root store
this.rootIssueDetailStore = rootStore;
// services
this.issueReactionService = new IssueReactionService();
}
// computed
get issueReactions() {
const issueId = this.rootIssueDetailStore.issueId;
if (!issueId) return undefined;
return this.reactions[issueId] ?? undefined;
}
// helper methods
getReactionsByIssueId = (issueId: string) => {
if (!issueId) return undefined;
return this.reactions[issueId] ?? undefined;
};
getReactionById = (reactionId: string) => {
if (!reactionId) return undefined;
return this.reactionMap[reactionId] ?? undefined;
};
// actions
fetchReactions = async (workspaceSlug: string, projectId: string, issueId: string) => {
try {
const response = await this.issueReactionService.listIssueReactions(workspaceSlug, projectId, issueId);
runInAction(() => {
this.reactions[issueId] = response.map((reaction) => reaction.id);
response.forEach((reaction) => set(this.reactionMap, reaction.id, reaction));
});
return response;
} catch (error) {
throw error;
}
};
createReaction = async (workspaceSlug: string, projectId: string, issueId: string, reaction: string) => {
try {
const response = await this.issueReactionService.createIssueReaction(workspaceSlug, projectId, issueId, {
reaction,
});
runInAction(() => {
this.reactions[issueId].push(response.id);
set(this.reactionMap, response.id, response);
});
return response;
} catch (error) {
throw error;
}
};
removeReaction = async (workspaceSlug: string, projectId: string, issueId: string, reaction: string) => {
try {
const reactionIndex = this.reactions[issueId].findIndex((_reaction) => _reaction === reaction);
if (reactionIndex >= 0)
runInAction(() => {
this.reactions[issueId].splice(reactionIndex, 1);
delete this.reactionMap[reaction];
});
const response = await this.issueReactionService.deleteIssueReaction(workspaceSlug, projectId, issueId, reaction);
return response;
} catch (error) {
// TODO: Replace with fetch issue details
// this.fetchReactions(workspaceSlug, projectId, issueId);
throw error;
}
};
}

View file

@ -0,0 +1,164 @@
import { action, computed, makeObservable, observable, runInAction } from "mobx";
import set from "lodash/set";
// services
import { IssueRelationService } from "services/issue";
// types
import { IIssueDetail } from "./root.store";
import {
TIssueRelationIdMap,
TIssueRelationMap,
TIssueRelationTypes,
TIssueRelation,
TIssueRelationObject,
} from "@plane/types";
export interface IIssueRelationStoreActions {
// actions
fetchRelations: (workspaceSlug: string, projectId: string, issueId: string) => Promise<TIssueRelation>;
createRelation: (
workspaceSlug: string,
projectId: string,
issueId: string,
relationType: TIssueRelationTypes,
issues: string[]
) => Promise<TIssueRelationObject[]>;
removeRelation: (
workspaceSlug: string,
projectId: string,
issueId: string,
relationType: TIssueRelationTypes,
related_issue: string
) => Promise<any>;
}
export interface IIssueRelationStore extends IIssueRelationStoreActions {
// observables
relationMap: TIssueRelationMap; // Record defines relationType as key and reactions as value
// computed
issueRelations: TIssueRelationIdMap | undefined;
// helper methods
getRelationsByIssueId: (issueId: string) => TIssueRelationIdMap | undefined;
getRelationByIssueIdRelationType: (issueId: string, relationType: TIssueRelationTypes) => string[] | undefined;
}
export class IssueRelationStore implements IIssueRelationStore {
// observables
relationMap: TIssueRelationMap = {};
// root store
rootIssueDetailStore: IIssueDetail;
// services
issueRelationService;
constructor(rootStore: IIssueDetail) {
makeObservable(this, {
// observables
relationMap: observable,
// computed
issueRelations: computed,
// actions
fetchRelations: action,
createRelation: action,
removeRelation: action,
});
// root store
this.rootIssueDetailStore = rootStore;
// services
this.issueRelationService = new IssueRelationService();
}
// computed
get issueRelations() {
const issueId = this.rootIssueDetailStore.issueId;
if (!issueId) return undefined;
return this.relationMap?.[issueId] ?? undefined;
}
// // helper methods
getRelationsByIssueId = (issueId: string) => {
if (!issueId) return undefined;
return this.relationMap?.[issueId] ?? undefined;
};
getRelationByIssueIdRelationType = (issueId: string, relationType: TIssueRelationTypes) => {
if (!issueId || !relationType) return undefined;
return this.relationMap?.[issueId]?.[relationType] ?? undefined;
};
// actions
fetchRelations = async (workspaceSlug: string, projectId: string, issueId: string) => {
try {
const response = await this.issueRelationService.listIssueRelations(workspaceSlug, projectId, issueId);
runInAction(() => {
Object.keys(response).forEach((key) => {
const relation_key = key as TIssueRelationTypes;
const relation_issues = response[relation_key];
const issues = relation_issues.flat().map((issue) => issue.issue_detail);
if (issues && issues.length > 0) this.rootIssueDetailStore.rootIssueStore.issues.addIssue(issues);
set(
this.relationMap,
[issueId, relation_key],
issues && issues.length > 0 ? issues.map((issue) => issue.id) : []
);
});
});
return response;
} catch (error) {
throw error;
}
};
createRelation = async (
workspaceSlug: string,
projectId: string,
issueId: string,
relationType: TIssueRelationTypes,
issues: string[]
) => {
try {
const response = await this.issueRelationService.createIssueRelations(workspaceSlug, projectId, issueId, {
relation_type: relationType,
issues,
});
if (response && response.length > 0)
runInAction(() => {
response.forEach((issue) => {
this.rootIssueDetailStore.rootIssueStore.issues.addIssue([issue?.issue_detail]);
this.relationMap[issueId][relationType].push(issue.issue_detail.id);
});
});
return response;
} catch (error) {
throw error;
}
};
removeRelation = async (
workspaceSlug: string,
projectId: string,
issueId: string,
relationType: TIssueRelationTypes,
related_issue: string
) => {
try {
const relationIndex = this.relationMap[issueId][relationType].findIndex((_issueId) => _issueId === related_issue);
if (relationIndex >= 0)
runInAction(() => {
this.relationMap[issueId][relationType].splice(relationIndex, 1);
});
const response = await this.issueRelationService.deleteIssueRelation(workspaceSlug, projectId, issueId, {
relation_type: relationType,
related_issue,
});
return response;
} catch (error) {
this.fetchRelations(workspaceSlug, projectId, issueId);
throw error;
}
};
}

View file

@ -0,0 +1,223 @@
import { action, computed, makeObservable, observable } from "mobx";
// types
import { IIssueRootStore } from "../root.store";
import { IIssueStore, IssueStore, IIssueStoreActions } from "./issue.store";
import { IIssueReactionStore, IssueReactionStore, IIssueReactionStoreActions } from "./reaction.store";
import { IIssueActivityStore, IssueActivityStore, IIssueActivityStoreActions } from "./activity.store";
import { IIssueCommentStore, IssueCommentStore, IIssueCommentStoreActions } from "./comment.store";
import {
IIssueCommentReactionStore,
IssueCommentReactionStore,
IIssueCommentReactionStoreActions,
} from "./comment_reaction.store";
import { IIssueLinkStore, IssueLinkStore, IIssueLinkStoreActions } from "./link.store";
import { IIssueSubscriptionStore, IssueSubscriptionStore, IIssueSubscriptionStoreActions } from "./subscription.store";
import { IIssueAttachmentStore, IssueAttachmentStore, IIssueAttachmentStoreActions } from "./attachment.store";
import { IIssueSubIssuesStore, IssueSubIssuesStore, IIssueSubIssuesStoreActions } from "./sub_issues.store";
import { IIssueRelationStore, IssueRelationStore, IIssueRelationStoreActions } from "./relation.store";
import { TIssue, IIssueActivity, TIssueLink, TIssueRelationTypes } from "@plane/types";
export interface IIssueDetail
extends IIssueStoreActions,
IIssueReactionStoreActions,
IIssueActivityStoreActions,
IIssueCommentStoreActions,
IIssueCommentReactionStoreActions,
IIssueLinkStoreActions,
IIssueSubIssuesStoreActions,
IIssueSubscriptionStoreActions,
IIssueAttachmentStoreActions,
IIssueRelationStoreActions {
// observables
issueId: string | undefined;
isIssueLinkModalOpen: boolean;
isParentIssueModalOpen: boolean;
isDeleteIssueModalOpen: boolean;
// computed
isAnyModalOpen: boolean;
// actions
setIssueId: (issueId: string | undefined) => void;
toggleIssueLinkModal: (value: boolean) => void;
toggleParentIssueModal: (value: boolean) => void;
toggleDeleteIssueModal: (value: boolean) => void;
// store
rootIssueStore: IIssueRootStore;
issue: IIssueStore;
reaction: IIssueReactionStore;
attachment: IIssueAttachmentStore;
activity: IIssueActivityStore;
comment: IIssueCommentStore;
commentReaction: IIssueCommentReactionStore;
subIssues: IIssueSubIssuesStore;
link: IIssueLinkStore;
subscription: IIssueSubscriptionStore;
relation: IIssueRelationStore;
}
export class IssueDetail implements IIssueDetail {
// observables
issueId: string | undefined = undefined;
isIssueLinkModalOpen: boolean = false;
isParentIssueModalOpen: boolean = false;
isDeleteIssueModalOpen: boolean = false;
// store
rootIssueStore: IIssueRootStore;
issue: IIssueStore;
reaction: IIssueReactionStore;
attachment: IIssueAttachmentStore;
activity: IIssueActivityStore;
comment: IIssueCommentStore;
commentReaction: IIssueCommentReactionStore;
subIssues: IIssueSubIssuesStore;
link: IIssueLinkStore;
subscription: IIssueSubscriptionStore;
relation: IIssueRelationStore;
constructor(rootStore: IIssueRootStore) {
makeObservable(this, {
// observables
issueId: observable.ref,
isIssueLinkModalOpen: observable.ref,
isParentIssueModalOpen: observable.ref,
isDeleteIssueModalOpen: observable.ref,
// computed
isAnyModalOpen: computed,
// action
setIssueId: action,
toggleIssueLinkModal: action,
toggleParentIssueModal: action,
toggleDeleteIssueModal: action,
});
// store
this.rootIssueStore = rootStore;
this.issue = new IssueStore(this);
this.reaction = new IssueReactionStore(this);
this.attachment = new IssueAttachmentStore(this);
this.activity = new IssueActivityStore(this);
this.comment = new IssueCommentStore(this);
this.commentReaction = new IssueCommentReactionStore(this);
this.subIssues = new IssueSubIssuesStore(this);
this.link = new IssueLinkStore(this);
this.subscription = new IssueSubscriptionStore(this);
this.relation = new IssueRelationStore(this);
}
// computed
get isAnyModalOpen() {
return this.isIssueLinkModalOpen || this.isParentIssueModalOpen || this.isDeleteIssueModalOpen;
}
// actions
setIssueId = (issueId: string | undefined) => (this.issueId = issueId);
toggleIssueLinkModal = (value: boolean) => (this.isIssueLinkModalOpen = value);
toggleParentIssueModal = (value: boolean) => (this.isParentIssueModalOpen = value);
toggleDeleteIssueModal = (value: boolean) => (this.isDeleteIssueModalOpen = value);
// issue
fetchIssue = async (workspaceSlug: string, projectId: string, issueId: string) => {
this.issueId = issueId;
return this.issue.fetchIssue(workspaceSlug, projectId, issueId);
};
updateIssue = async (workspaceSlug: string, projectId: string, issueId: string, data: Partial<TIssue>) =>
this.issue.updateIssue(workspaceSlug, projectId, issueId, data);
removeIssue = async (workspaceSlug: string, projectId: string, issueId: string) =>
this.issue.removeIssue(workspaceSlug, projectId, issueId);
addIssueToCycle = async (workspaceSlug: string, projectId: string, cycleId: string, issueIds: string[]) =>
this.issue.addIssueToCycle(workspaceSlug, projectId, cycleId, issueIds);
removeIssueFromCycle = async (workspaceSlug: string, projectId: string, cycleId: string, issueId: string) =>
this.issue.removeIssueFromCycle(workspaceSlug, projectId, cycleId, issueId);
addIssueToModule = async (workspaceSlug: string, projectId: string, moduleId: string, issueIds: string[]) =>
this.issue.addIssueToModule(workspaceSlug, projectId, moduleId, issueIds);
removeIssueFromModule = async (workspaceSlug: string, projectId: string, moduleId: string, issueId: string) =>
this.issue.removeIssueFromModule(workspaceSlug, projectId, moduleId, issueId);
// reactions
fetchReactions = async (workspaceSlug: string, projectId: string, issueId: string) =>
this.reaction.fetchReactions(workspaceSlug, projectId, issueId);
createReaction = async (workspaceSlug: string, projectId: string, issueId: string, reaction: string) =>
this.reaction.createReaction(workspaceSlug, projectId, issueId, reaction);
removeReaction = async (workspaceSlug: string, projectId: string, issueId: string, reaction: string) =>
this.reaction.removeReaction(workspaceSlug, projectId, issueId, reaction);
// activity
fetchActivities = async (workspaceSlug: string, projectId: string, issueId: string) =>
this.activity.fetchActivities(workspaceSlug, projectId, issueId);
// comment
createComment = async (workspaceSlug: string, projectId: string, issueId: string, data: Partial<IIssueActivity>) =>
this.comment.createComment(workspaceSlug, projectId, issueId, data);
updateComment = async (
workspaceSlug: string,
projectId: string,
issueId: string,
commentId: string,
data: Partial<IIssueActivity>
) => this.comment.updateComment(workspaceSlug, projectId, issueId, commentId, data);
removeComment = async (workspaceSlug: string, projectId: string, issueId: string, commentId: string) =>
this.comment.removeComment(workspaceSlug, projectId, issueId, commentId);
// comment reaction
fetchCommentReactions = async (workspaceSlug: string, projectId: string, commentId: string) =>
this.commentReaction.fetchCommentReactions(workspaceSlug, projectId, commentId);
createCommentReaction = async (workspaceSlug: string, projectId: string, commentId: string, reaction: string) =>
this.commentReaction.createCommentReaction(workspaceSlug, projectId, commentId, reaction);
removeCommentReaction = async (workspaceSlug: string, projectId: string, commentId: string, reaction: string) =>
this.commentReaction.removeCommentReaction(workspaceSlug, projectId, commentId, reaction);
// attachments
fetchAttachments = async (workspaceSlug: string, projectId: string, issueId: string) =>
this.attachment.fetchAttachments(workspaceSlug, projectId, issueId);
createAttachment = async (workspaceSlug: string, projectId: string, issueId: string, data: FormData) =>
this.attachment.createAttachment(workspaceSlug, projectId, issueId, data);
removeAttachment = async (workspaceSlug: string, projectId: string, issueId: string, attachmentId: string) =>
this.attachment.removeAttachment(workspaceSlug, projectId, issueId, attachmentId);
// link
fetchLinks = async (workspaceSlug: string, projectId: string, issueId: string) =>
this.link.fetchLinks(workspaceSlug, projectId, issueId);
createLink = async (workspaceSlug: string, projectId: string, issueId: string, data: Partial<TIssueLink>) =>
this.link.createLink(workspaceSlug, projectId, issueId, data);
updateLink = async (
workspaceSlug: string,
projectId: string,
issueId: string,
linkId: string,
data: Partial<TIssueLink>
) => this.link.updateLink(workspaceSlug, projectId, issueId, linkId, data);
removeLink = async (workspaceSlug: string, projectId: string, issueId: string, linkId: string) =>
this.link.removeLink(workspaceSlug, projectId, issueId, linkId);
// sub issues
fetchSubIssues = async (workspaceSlug: string, projectId: string, issueId: string) =>
this.subIssues.fetchSubIssues(workspaceSlug, projectId, issueId);
createSubIssues = async (workspaceSlug: string, projectId: string, issueId: string, data: string[]) =>
this.subIssues.createSubIssues(workspaceSlug, projectId, issueId, data);
// subscription
fetchSubscriptions = async (workspaceSlug: string, projectId: string, issueId: string) =>
this.subscription.fetchSubscriptions(workspaceSlug, projectId, issueId);
createSubscription = async (workspaceSlug: string, projectId: string, issueId: string) =>
this.subscription.createSubscription(workspaceSlug, projectId, issueId);
removeSubscription = async (workspaceSlug: string, projectId: string, issueId: string) =>
this.subscription.removeSubscription(workspaceSlug, projectId, issueId);
// relations
fetchRelations = async (workspaceSlug: string, projectId: string, issueId: string) =>
this.relation.fetchRelations(workspaceSlug, projectId, issueId);
createRelation = async (
workspaceSlug: string,
projectId: string,
issueId: string,
relationType: TIssueRelationTypes,
issues: string[]
) => this.relation.createRelation(workspaceSlug, projectId, issueId, relationType, issues);
removeRelation = async (
workspaceSlug: string,
projectId: string,
issueId: string,
relationType: TIssueRelationTypes,
relatedIssue: string
) => this.relation.removeRelation(workspaceSlug, projectId, issueId, relationType, relatedIssue);
}

View file

@ -0,0 +1,116 @@
import { action, makeObservable, observable, runInAction } from "mobx";
import set from "lodash/set";
// services
import { IssueService } from "services/issue";
// types
import { IIssueDetail } from "./root.store";
import {
TIssue,
TIssueSubIssues,
TIssueSubIssuesStateDistributionMap,
TIssueSubIssuesIdMap,
TSubIssuesStateDistribution,
} from "@plane/types";
export interface IIssueSubIssuesStoreActions {
fetchSubIssues: (workspaceSlug: string, projectId: string, issueId: string) => Promise<TIssueSubIssues>;
createSubIssues: (
workspaceSlug: string,
projectId: string,
issueId: string,
data: string[]
) => Promise<TIssueSubIssues>;
}
export interface IIssueSubIssuesStore extends IIssueSubIssuesStoreActions {
// observables
subIssuesStateDistribution: TIssueSubIssuesStateDistributionMap;
subIssues: TIssueSubIssuesIdMap;
// helper methods
stateDistributionByIssueId: (issueId: string) => TSubIssuesStateDistribution | undefined;
subIssuesByIssueId: (issueId: string) => string[] | undefined;
}
export class IssueSubIssuesStore implements IIssueSubIssuesStore {
// observables
subIssuesStateDistribution: TIssueSubIssuesStateDistributionMap = {};
subIssues: TIssueSubIssuesIdMap = {};
// root store
rootIssueDetailStore: IIssueDetail;
// services
issueService;
constructor(rootStore: IIssueDetail) {
makeObservable(this, {
// observables
subIssuesStateDistribution: observable,
subIssues: observable,
// actions
fetchSubIssues: action,
createSubIssues: action,
});
// root store
this.rootIssueDetailStore = rootStore;
// services
this.issueService = new IssueService();
}
// helper methods
stateDistributionByIssueId = (issueId: string) => {
if (!issueId) return undefined;
return this.subIssuesStateDistribution[issueId] ?? undefined;
};
subIssuesByIssueId = (issueId: string) => {
if (!issueId) return undefined;
return this.subIssues[issueId] ?? undefined;
};
// actions
fetchSubIssues = async (workspaceSlug: string, projectId: string, issueId: string) => {
try {
const response = await this.issueService.subIssues(workspaceSlug, projectId, issueId);
const subIssuesStateDistribution = response?.state_distribution ?? {};
const subIssues = (response.sub_issues ?? []) as TIssue[];
this.rootIssueDetailStore.rootIssueStore.issues.addIssue(subIssues);
if (subIssues.length > 0) {
runInAction(() => {
set(this.subIssuesStateDistribution, issueId, subIssuesStateDistribution);
set(
this.subIssues,
issueId,
subIssues.map((issue) => issue.id)
);
});
}
return response;
} catch (error) {
throw error;
}
};
createSubIssues = async (workspaceSlug: string, projectId: string, issueId: string, data: string[]) => {
try {
const response = await this.issueService.addSubIssues(workspaceSlug, projectId, issueId, { sub_issue_ids: data });
const subIssuesStateDistribution = response?.state_distribution;
const subIssues = response.sub_issues as TIssue[];
this.rootIssueDetailStore.rootIssueStore.issues.addIssue(subIssues);
runInAction(() => {
Object.keys(subIssuesStateDistribution).forEach((key) => {
const stateGroup = key as keyof TSubIssuesStateDistribution;
set(this.subIssuesStateDistribution, [issueId, key], subIssuesStateDistribution[stateGroup]);
});
set(this.subIssuesStateDistribution, issueId, data);
});
return response;
} catch (error) {
throw error;
}
};
}

View file

@ -0,0 +1,112 @@
import { action, makeObservable, observable, runInAction } from "mobx";
import set from "lodash/set";
// services
import { NotificationService } from "services/notification.service";
// types
import { IIssueDetail } from "./root.store";
export interface IIssueSubscriptionStoreActions {
fetchSubscriptions: (workspaceSlug: string, projectId: string, issueId: string) => Promise<any>;
createSubscription: (workspaceSlug: string, projectId: string, issueId: string) => Promise<any>;
removeSubscription: (workspaceSlug: string, projectId: string, issueId: string) => Promise<any>;
}
export interface IIssueSubscriptionStore extends IIssueSubscriptionStoreActions {
// observables
subscriptionMap: Record<string, Record<string, Record<string, boolean>>>; // Record defines subscriptionId as key and link as value
// helper methods
getSubscriptionByIssueId: (issueId: string) => Record<string, boolean> | undefined;
}
export class IssueSubscriptionStore implements IIssueSubscriptionStore {
// observables
subscriptionMap: Record<string, Record<string, Record<string, boolean>>> = {};
// root store
rootIssueDetail: IIssueDetail;
// services
notificationService;
constructor(rootStore: IIssueDetail) {
makeObservable(this, {
// observables
subscriptionMap: observable,
// actions
fetchSubscriptions: action,
createSubscription: action,
removeSubscription: action,
});
// root store
this.rootIssueDetail = rootStore;
// services
this.notificationService = new NotificationService();
}
// helper methods
getSubscriptionByIssueId = (issueId: string) => {
if (!issueId) return undefined;
const currentUserId = this.rootIssueDetail.rootIssueStore.currentUserId;
if (!currentUserId) return undefined;
return this.subscriptionMap[issueId][currentUserId] ?? undefined;
};
fetchSubscriptions = async (workspaceSlug: string, projectId: string, issueId: string) => {
try {
const currentUserId = this.rootIssueDetail.rootIssueStore.currentUserId;
if (!currentUserId) throw new Error("user id not available");
const subscription = await this.notificationService.getIssueNotificationSubscriptionStatus(
workspaceSlug,
projectId,
issueId
);
runInAction(() => {
set(this.subscriptionMap, [issueId, currentUserId], subscription);
});
return subscription;
} catch (error) {
throw error;
}
};
createSubscription = async (workspaceSlug: string, projectId: string, issueId: string) => {
try {
const currentUserId = this.rootIssueDetail.rootIssueStore.currentUserId;
if (!currentUserId) throw new Error("user id not available");
runInAction(() => {
set(this.subscriptionMap, [issueId, currentUserId], { subscribed: true });
});
const response = await this.notificationService.subscribeToIssueNotifications(workspaceSlug, projectId, issueId);
return response;
} catch (error) {
this.fetchSubscriptions(workspaceSlug, projectId, issueId);
throw error;
}
};
removeSubscription = async (workspaceSlug: string, projectId: string, issueId: string) => {
try {
const currentUserId = this.rootIssueDetail.rootIssueStore.currentUserId;
if (!currentUserId) throw new Error("user id not available");
runInAction(() => {
set(this.subscriptionMap, [issueId, currentUserId], { subscribed: false });
});
const response = await this.notificationService.unsubscribeFromIssueNotifications(
workspaceSlug,
projectId,
issueId
);
return response;
} catch (error) {
this.fetchSubscriptions(workspaceSlug, projectId, issueId);
throw error;
}
};
}