forked from github/plane
03e5f4a5bd
* dev: add is_subscriber to issue details endpoint * dev: remove is_subscribed annotation from detail serializers * dev: update issue details endpoint * dev: inbox issue create * dev: issue detail serializer * dev: optimize and add extra fields for issue details * dev: remove data from issue updates * dev: add fields for issue link and attachment * remove expecting a issue response while updating and deleting an issue * change link, attachment and reaction types and modify store to recieve their data from within the issue detail API call * make changes for subscription store to recieve data from issue detail API call * dev: add issue reaction id * add query prarms for archived issue --------- Co-authored-by: rahulramesha <rahulramesham@gmail.com>
144 lines
4.4 KiB
TypeScript
144 lines
4.4 KiB
TypeScript
import { action, observable, makeObservable, computed, runInAction } from "mobx";
|
|
import set from "lodash/set";
|
|
// base class
|
|
import { IssueHelperStore } from "../helpers/issue-helper.store";
|
|
// services
|
|
import { IssueArchiveService } from "services/issue";
|
|
// types
|
|
import { IIssueRootStore } from "../root.store";
|
|
import { TIssue, TLoader, TGroupedIssues, TSubGroupedIssues, TUnGroupedIssues, ViewFlags } from "@plane/types";
|
|
|
|
export interface IArchivedIssues {
|
|
// observable
|
|
loader: TLoader;
|
|
issues: { [project_id: string]: string[] };
|
|
viewFlags: ViewFlags;
|
|
// computed
|
|
groupedIssueIds: TGroupedIssues | TSubGroupedIssues | TUnGroupedIssues | undefined;
|
|
// actions
|
|
fetchIssues: (workspaceSlug: string, projectId: string, loadType: TLoader) => Promise<TIssue>;
|
|
removeIssue: (workspaceSlug: string, projectId: string, issueId: string) => Promise<void>;
|
|
removeIssueFromArchived: (workspaceSlug: string, projectId: string, issueId: string) => Promise<void>;
|
|
quickAddIssue: undefined;
|
|
}
|
|
|
|
export class ArchivedIssues extends IssueHelperStore implements IArchivedIssues {
|
|
loader: TLoader = "init-loader";
|
|
issues: { [project_id: string]: string[] } = {};
|
|
// root store
|
|
rootIssueStore: IIssueRootStore;
|
|
// services
|
|
archivedIssueService;
|
|
|
|
//viewData
|
|
viewFlags = {
|
|
enableQuickAdd: false,
|
|
enableIssueCreation: false,
|
|
enableInlineEditing: true,
|
|
};
|
|
|
|
constructor(_rootStore: IIssueRootStore) {
|
|
super(_rootStore);
|
|
makeObservable(this, {
|
|
// observable
|
|
loader: observable.ref,
|
|
issues: observable,
|
|
// computed
|
|
groupedIssueIds: computed,
|
|
// action
|
|
fetchIssues: action,
|
|
removeIssue: action,
|
|
removeIssueFromArchived: action,
|
|
});
|
|
// root store
|
|
this.rootIssueStore = _rootStore;
|
|
// services
|
|
this.archivedIssueService = new IssueArchiveService();
|
|
}
|
|
|
|
get groupedIssueIds() {
|
|
const projectId = this.rootIssueStore.projectId;
|
|
if (!projectId) return undefined;
|
|
|
|
const displayFilters = this.rootIssueStore?.archivedIssuesFilter?.issueFilters?.displayFilters;
|
|
if (!displayFilters) return undefined;
|
|
|
|
const groupBy = displayFilters?.group_by;
|
|
const orderBy = displayFilters?.order_by;
|
|
const layout = displayFilters?.layout;
|
|
|
|
const archivedIssueIds = this.issues[projectId];
|
|
if (!archivedIssueIds) return undefined;
|
|
|
|
const _issues = this.rootIssueStore.issues.getIssuesByIds(archivedIssueIds);
|
|
if (!_issues) return [];
|
|
|
|
let issues: TGroupedIssues | TSubGroupedIssues | TUnGroupedIssues | undefined = undefined;
|
|
|
|
if (layout === "list" && orderBy) {
|
|
if (groupBy) issues = this.groupedIssues(groupBy, orderBy, _issues);
|
|
else issues = this.unGroupedIssues(orderBy, _issues);
|
|
}
|
|
|
|
return issues;
|
|
}
|
|
|
|
fetchIssues = async (workspaceSlug: string, projectId: string, loadType: TLoader = "init-loader") => {
|
|
try {
|
|
this.loader = loadType;
|
|
|
|
const params = this.rootIssueStore?.archivedIssuesFilter?.appliedFilters;
|
|
const response = await this.archivedIssueService.getArchivedIssues(workspaceSlug, projectId, params);
|
|
|
|
runInAction(() => {
|
|
set(
|
|
this.issues,
|
|
[projectId],
|
|
response.map((issue: TIssue) => issue.id)
|
|
);
|
|
this.loader = undefined;
|
|
});
|
|
|
|
this.rootIssueStore.issues.addIssue(response);
|
|
|
|
return response;
|
|
} catch (error) {
|
|
console.error(error);
|
|
this.loader = undefined;
|
|
throw error;
|
|
}
|
|
};
|
|
|
|
removeIssue = async (workspaceSlug: string, projectId: string, issueId: string) => {
|
|
try {
|
|
await this.rootIssueStore.projectIssues.removeIssue(workspaceSlug, projectId, issueId);
|
|
|
|
const issueIndex = this.issues[projectId].findIndex((_issueId) => _issueId === issueId);
|
|
if (issueIndex >= 0)
|
|
runInAction(() => {
|
|
this.issues[projectId].splice(issueIndex, 1);
|
|
});
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
};
|
|
|
|
removeIssueFromArchived = async (workspaceSlug: string, projectId: string, issueId: string) => {
|
|
try {
|
|
const response = await this.archivedIssueService.unarchiveIssue(workspaceSlug, projectId, issueId);
|
|
|
|
const issueIndex = this.issues[projectId]?.findIndex((_issueId) => _issueId === issueId);
|
|
if (issueIndex && issueIndex >= 0)
|
|
runInAction(() => {
|
|
this.issues[projectId].splice(issueIndex, 1);
|
|
});
|
|
|
|
return response;
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
};
|
|
|
|
quickAddIssue: undefined;
|
|
}
|