mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
[WEB-1343] chore: add and remove modules in kanban view (#4549)
* chore: removing and adding an issue to module * chore: removed empty module validation * modules single API call * chore: removed the script --------- Co-authored-by: rahulramesha <rahulramesham@gmail.com>
This commit is contained in:
parent
e99a7accec
commit
794183b640
@ -198,46 +198,66 @@ class ModuleIssueViewSet(BaseViewSet):
|
|||||||
]
|
]
|
||||||
return Response({"message": "success"}, status=status.HTTP_201_CREATED)
|
return Response({"message": "success"}, status=status.HTTP_201_CREATED)
|
||||||
|
|
||||||
# create multiple module inside an issue
|
# add multiple module inside an issue and remove multiple modules from an issue
|
||||||
def create_issue_modules(self, request, slug, project_id, issue_id):
|
def create_issue_modules(self, request, slug, project_id, issue_id):
|
||||||
modules = request.data.get("modules", [])
|
modules = request.data.get("modules", [])
|
||||||
if not modules:
|
removed_modules = request.data.get("removed_modules", [])
|
||||||
return Response(
|
|
||||||
{"error": "Modules are required"},
|
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
|
||||||
)
|
|
||||||
|
|
||||||
project = Project.objects.get(pk=project_id)
|
project = Project.objects.get(pk=project_id)
|
||||||
_ = ModuleIssue.objects.bulk_create(
|
|
||||||
[
|
|
||||||
ModuleIssue(
|
if modules:
|
||||||
|
_ = ModuleIssue.objects.bulk_create(
|
||||||
|
[
|
||||||
|
ModuleIssue(
|
||||||
|
issue_id=issue_id,
|
||||||
|
module_id=module,
|
||||||
|
project_id=project_id,
|
||||||
|
workspace_id=project.workspace_id,
|
||||||
|
created_by=request.user,
|
||||||
|
updated_by=request.user,
|
||||||
|
)
|
||||||
|
for module in modules
|
||||||
|
],
|
||||||
|
batch_size=10,
|
||||||
|
ignore_conflicts=True,
|
||||||
|
)
|
||||||
|
# Bulk Update the activity
|
||||||
|
_ = [
|
||||||
|
issue_activity.delay(
|
||||||
|
type="module.activity.created",
|
||||||
|
requested_data=json.dumps({"module_id": module}),
|
||||||
|
actor_id=str(request.user.id),
|
||||||
issue_id=issue_id,
|
issue_id=issue_id,
|
||||||
module_id=module,
|
|
||||||
project_id=project_id,
|
project_id=project_id,
|
||||||
workspace_id=project.workspace_id,
|
current_instance=None,
|
||||||
created_by=request.user,
|
epoch=int(timezone.now().timestamp()),
|
||||||
updated_by=request.user,
|
notification=True,
|
||||||
|
origin=request.META.get("HTTP_ORIGIN"),
|
||||||
)
|
)
|
||||||
for module in modules
|
for module in modules
|
||||||
],
|
]
|
||||||
batch_size=10,
|
|
||||||
ignore_conflicts=True,
|
for module_id in removed_modules:
|
||||||
)
|
module_issue = ModuleIssue.objects.get(
|
||||||
# Bulk Update the activity
|
workspace__slug=slug,
|
||||||
_ = [
|
|
||||||
issue_activity.delay(
|
|
||||||
type="module.activity.created",
|
|
||||||
requested_data=json.dumps({"module_id": module}),
|
|
||||||
actor_id=str(request.user.id),
|
|
||||||
issue_id=issue_id,
|
|
||||||
project_id=project_id,
|
project_id=project_id,
|
||||||
current_instance=None,
|
module_id=module_id,
|
||||||
|
issue_id=issue_id,
|
||||||
|
)
|
||||||
|
issue_activity.delay(
|
||||||
|
type="module.activity.deleted",
|
||||||
|
requested_data=json.dumps({"module_id": str(module_id)}),
|
||||||
|
actor_id=str(request.user.id),
|
||||||
|
issue_id=str(issue_id),
|
||||||
|
project_id=str(project_id),
|
||||||
|
current_instance=json.dumps(
|
||||||
|
{"module_name": module_issue.module.name}
|
||||||
|
),
|
||||||
epoch=int(timezone.now().timestamp()),
|
epoch=int(timezone.now().timestamp()),
|
||||||
notification=True,
|
notification=True,
|
||||||
origin=request.META.get("HTTP_ORIGIN"),
|
origin=request.META.get("HTTP_ORIGIN"),
|
||||||
)
|
)
|
||||||
for module in modules
|
module_issue.delete()
|
||||||
]
|
|
||||||
|
|
||||||
return Response({"message": "success"}, status=status.HTTP_201_CREATED)
|
return Response({"message": "success"}, status=status.HTTP_201_CREATED)
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ export class ModuleService extends APIService {
|
|||||||
workspaceSlug: string,
|
workspaceSlug: string,
|
||||||
projectId: string,
|
projectId: string,
|
||||||
issueId: string,
|
issueId: string,
|
||||||
data: { modules: string[] }
|
data: { modules: string[]; removed_modules?: string[] }
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
return this.post(`/api/workspaces/${workspaceSlug}/projects/${projectId}/issues/${issueId}/modules/`, data)
|
return this.post(`/api/workspaces/${workspaceSlug}/projects/${projectId}/issues/${issueId}/modules/`, data)
|
||||||
.then((response) => response?.data)
|
.then((response) => response?.data)
|
||||||
|
@ -431,15 +431,11 @@ export class ModuleIssues extends IssueHelperStore implements IModuleIssues {
|
|||||||
this.rootStore.issues.updateIssue(issueId, { module_ids: uniq(currentModuleIds) });
|
this.rootStore.issues.updateIssue(issueId, { module_ids: uniq(currentModuleIds) });
|
||||||
}
|
}
|
||||||
|
|
||||||
//Perform API calls
|
//Perform API call
|
||||||
if (!isEmpty(addModuleIds)) {
|
await this.moduleService.addModulesToIssue(workspaceSlug, projectId, issueId, {
|
||||||
await this.moduleService.addModulesToIssue(workspaceSlug, projectId, issueId, {
|
modules: addModuleIds,
|
||||||
modules: addModuleIds,
|
removed_modules: removeModuleIds,
|
||||||
});
|
});
|
||||||
}
|
|
||||||
if (!isEmpty(removeModuleIds)) {
|
|
||||||
await this.moduleService.removeModulesFromIssueBulk(workspaceSlug, projectId, issueId, removeModuleIds);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// revert the issue back to its original module ids
|
// revert the issue back to its original module ids
|
||||||
set(this.rootStore.issues.issuesMap, [issueId, "module_ids"], originalModuleIds);
|
set(this.rootStore.issues.issuesMap, [issueId, "module_ids"], originalModuleIds);
|
||||||
|
Loading…
Reference in New Issue
Block a user