[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
3 changed files with 54 additions and 38 deletions
|
|
@ -198,16 +198,14 @@ 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)
|
||||||
|
|
||||||
|
|
||||||
|
if modules:
|
||||||
_ = ModuleIssue.objects.bulk_create(
|
_ = ModuleIssue.objects.bulk_create(
|
||||||
[
|
[
|
||||||
ModuleIssue(
|
ModuleIssue(
|
||||||
|
|
@ -239,6 +237,28 @@ class ModuleIssueViewSet(BaseViewSet):
|
||||||
for module in modules
|
for module in modules
|
||||||
]
|
]
|
||||||
|
|
||||||
|
for module_id in removed_modules:
|
||||||
|
module_issue = ModuleIssue.objects.get(
|
||||||
|
workspace__slug=slug,
|
||||||
|
project_id=project_id,
|
||||||
|
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()),
|
||||||
|
notification=True,
|
||||||
|
origin=request.META.get("HTTP_ORIGIN"),
|
||||||
|
)
|
||||||
|
module_issue.delete()
|
||||||
|
|
||||||
return Response({"message": "success"}, status=status.HTTP_201_CREATED)
|
return Response({"message": "success"}, status=status.HTTP_201_CREATED)
|
||||||
|
|
||||||
def destroy(self, request, slug, project_id, module_id, issue_id):
|
def destroy(self, request, slug, project_id, module_id, issue_id):
|
||||||
|
|
|
||||||
|
|
@ -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…
Add table
Add a link
Reference in a new issue