mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
efd3ebf067
* refactor: updated preloaded function for the list view quick add * fix: resolved bug in the assignee dropdown * chore: issue sidebar link improvement * fix: resolved subscription store bug * chore: updated preloaded function for the kanban layout quick add * chore: resolved issues in the list filters and component * chore: filter store updated * fix: issue serializer changed * chore: quick add preload function updated * fix: build error * fix: serializer changed * fix: minor request change * chore: resolved build issues and updated the prepopulated data in the quick add issue. * fix: build fix and code refactor * fix: spreadsheet layout quick add fix * fix: issue peek overview link section updated * fix: cycle status bug fix * fix: serializer changes * fix: assignee and labels listing * chore: issue modal parent_id default value updated * fix: cycle and module issue serializer change * fix: cycle list serializer changed * chore: prepopulated validation in both list and kanban for quick add and group header add issues * chore: group header validation added * fix: issue response payload change * dev: make cycle and module issue create response simillar * chore: custom control link component added * dev: make issue create and update response simillar to list and retrieve * fix: build error * chore: control link component improvement * chore: globalise issue peek overview * chore: control link component improvement * chore: made changes and optimised the issue peek overview root * build-error: resolved build erros for issueId dependancy from issue detail store * chore: peek overview link fix * dev: update state nullable rule --------- Co-authored-by: gurusainath <gurusainath007@gmail.com> Co-authored-by: NarayanBavisetti <narayan3119@gmail.com> Co-authored-by: pablohashescobar <nikhilschacko@gmail.com>
150 lines
4.2 KiB
TypeScript
150 lines
4.2 KiB
TypeScript
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.peekIssue?.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;
|
|
}
|
|
};
|
|
}
|