mirror of
https://github.com/makeplane/plane.git
synced 2026-07-13 05:49:40 +02:00
[WEB-3309] fix: project stats and attributes and code cleanup (#2391)
This commit is contained in:
@@ -457,7 +457,7 @@ class ProjectStatsEndpoint(BaseAPIView):
|
||||
@allow_permission([ROLE.ADMIN, ROLE.MEMBER, ROLE.GUEST], level="WORKSPACE")
|
||||
def get(self, request, slug):
|
||||
fields = request.GET.get("fields", "").split(",")
|
||||
project_ids = request.GET.get("project_ids", "").split(",")
|
||||
project_ids = request.GET.get("project_ids", "")
|
||||
|
||||
valid_fields = {
|
||||
"total_issues",
|
||||
@@ -472,9 +472,8 @@ class ProjectStatsEndpoint(BaseAPIView):
|
||||
requested_fields = valid_fields
|
||||
|
||||
projects = Project.objects.filter(workspace__slug=slug)
|
||||
|
||||
if project_ids:
|
||||
projects = projects.filter(id__in=project_ids)
|
||||
projects = projects.filter(id__in=project_ids.split(","))
|
||||
|
||||
annotations = {}
|
||||
if "total_issues" in requested_fields:
|
||||
|
||||
@@ -1,29 +1,23 @@
|
||||
/* eslint-disable no-useless-catch */
|
||||
|
||||
import update from "lodash/update";
|
||||
import { action, computed, makeObservable, observable, runInAction } from "mobx";
|
||||
import { action, makeObservable, observable, runInAction } from "mobx";
|
||||
|
||||
// store
|
||||
import { ProjectService } from "@/plane-web/services";
|
||||
import { TProject, TProjectAttributesParams, TProjectAttributesResponse, TProjectFeatures } from "@/plane-web/types";
|
||||
import { ProjectStore as CeProjectStore, IProjectStore as ICeProjectStore } from "@/store/project/project.store";
|
||||
import { CoreRootStore } from "@/store/root.store";
|
||||
import { IProjectAttachmentStore, ProjectAttachmentStore } from "./project-details/attachment.store";
|
||||
import { IProjectLinkStore, ProjectLinkStore } from "./project-details/link.store";
|
||||
import { IProjectReactionStore, ProjectReactionStore } from "./project-details/project_reaction.store";
|
||||
import { IProjectUpdateStore, ProjectUpdateStore } from "./project-details/updates.store";
|
||||
|
||||
export interface IProjectStore extends ICeProjectStore {
|
||||
export interface IProjectStore {
|
||||
reactionStore: IProjectReactionStore;
|
||||
attachmentStore: IProjectAttachmentStore;
|
||||
featuresLoader: boolean;
|
||||
features: Record<string, TProjectFeatures>;
|
||||
//computed
|
||||
publicProjectIds: string[];
|
||||
privateProjectIds: string[];
|
||||
myProjectIds: string[];
|
||||
// actions
|
||||
filteredProjectCount: (filter: string) => number | undefined;
|
||||
toggleFeatures: (workspaceSlug: string, projectId: string, data: Partial<TProject>) => Promise<void>;
|
||||
fetchFeatures: (workspaceSlug: string, projectId: string) => Promise<void>;
|
||||
fetchProjectAttributes: (
|
||||
@@ -35,10 +29,11 @@ export interface IProjectStore extends ICeProjectStore {
|
||||
updatesStore: IProjectUpdateStore;
|
||||
}
|
||||
|
||||
export class ProjectStore extends CeProjectStore implements IProjectStore {
|
||||
export class ProjectStore implements IProjectStore {
|
||||
features: Record<string, TProjectFeatures> = {};
|
||||
featuresLoader: boolean = false;
|
||||
//store
|
||||
rootStore: CoreRootStore;
|
||||
linkStore: IProjectLinkStore;
|
||||
attachmentStore: IProjectAttachmentStore;
|
||||
updatesStore: IProjectUpdateStore;
|
||||
@@ -46,19 +41,14 @@ export class ProjectStore extends CeProjectStore implements IProjectStore {
|
||||
// services
|
||||
projectService;
|
||||
constructor(public store: CoreRootStore) {
|
||||
super(store);
|
||||
makeObservable(this, {
|
||||
// observables
|
||||
featuresLoader: observable.ref,
|
||||
features: observable,
|
||||
// computed
|
||||
publicProjectIds: computed,
|
||||
privateProjectIds: computed,
|
||||
myProjectIds: computed,
|
||||
// actions
|
||||
filteredProjectCount: action,
|
||||
fetchProjectAttributes: action,
|
||||
});
|
||||
this.rootStore = store;
|
||||
this.linkStore = new ProjectLinkStore(this);
|
||||
this.attachmentStore = new ProjectAttachmentStore(this);
|
||||
this.updatesStore = new ProjectUpdateStore();
|
||||
@@ -68,70 +58,6 @@ export class ProjectStore extends CeProjectStore implements IProjectStore {
|
||||
this.projectService = new ProjectService();
|
||||
}
|
||||
|
||||
// computed
|
||||
/**
|
||||
* Returns public project IDs belong to current workspace.
|
||||
*/
|
||||
get publicProjectIds() {
|
||||
const currentWorkspace = this.rootStore.workspaceRoot.currentWorkspace;
|
||||
if (!currentWorkspace) return [];
|
||||
|
||||
const projects = Object.values(this.projectMap ?? {});
|
||||
|
||||
const projectIds = projects
|
||||
.filter((project) => project.workspace === currentWorkspace.id && project.network === 2)
|
||||
.map((project) => project.id);
|
||||
return projectIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns private project IDs belong to current workspace.
|
||||
*/
|
||||
get myProjectIds() {
|
||||
const currentWorkspace = this.rootStore.workspaceRoot.currentWorkspace;
|
||||
if (!currentWorkspace) return [];
|
||||
|
||||
const projects = Object.values(this.projectMap ?? {});
|
||||
|
||||
const projectIds = projects
|
||||
.filter((project) => project.workspace === currentWorkspace.id && project.is_member)
|
||||
.map((project) => project.id);
|
||||
return projectIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns private project IDs belong to current workspace.
|
||||
*/
|
||||
get privateProjectIds() {
|
||||
const currentWorkspace = this.rootStore.workspaceRoot.currentWorkspace;
|
||||
if (!currentWorkspace) return [];
|
||||
|
||||
const projects = Object.values(this.projectMap ?? {});
|
||||
|
||||
const projectIds = projects
|
||||
.filter((project) => project.workspace === currentWorkspace.id && project.network === 0)
|
||||
.map((project) => project.id);
|
||||
return projectIds;
|
||||
}
|
||||
/**
|
||||
* Returns private project IDs belong to current workspace.
|
||||
*/
|
||||
filteredProjectCount = (filter: string) => {
|
||||
console.log(this, filter);
|
||||
switch (filter) {
|
||||
case "all_projects":
|
||||
return this.totalProjectIds?.length;
|
||||
case "public":
|
||||
return this.publicProjectIds.length;
|
||||
case "private":
|
||||
return this.privateProjectIds.length;
|
||||
case "my_projects":
|
||||
return this.myProjectIds.length;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
// actions
|
||||
fetchFeatures = async (workspaceSlug: string, projectId: string): Promise<void> => {
|
||||
try {
|
||||
@@ -177,7 +103,7 @@ export class ProjectStore extends CeProjectStore implements IProjectStore {
|
||||
runInAction(() => {
|
||||
for (const attribute of response) {
|
||||
const { project_id, ...rest } = attribute;
|
||||
update(this.projectMap, [project_id], (p) => ({ ...p, ...rest }));
|
||||
update(this.store.projectRoot.project.projectMap, [project_id], (p) => ({ ...p, ...rest }));
|
||||
}
|
||||
});
|
||||
return response;
|
||||
|
||||
Reference in New Issue
Block a user