ФУНКЦИИ - МЕЖПРОЕКТНАЯ КОММУНИКАЦИЯ: web-доступ к внешним контурам и исправление модалки запроса
This commit is contained in:
parent
6d67571b27
commit
3fe3539614
|
|
@ -65,6 +65,8 @@
|
|||
- `POST /external-contours/` создает target issue в целевом проекте
|
||||
- target issue сразу попадает в обычный workflow целевого проекта
|
||||
- source-side `GET /external-contours/` возвращает отправленные запросы с metadata источника и цели
|
||||
- target contour теперь выбирается по policy `same workspace + intake enabled`, а не только из joined projects
|
||||
- прямое membership в target project для отправки не требуется
|
||||
|
||||
## Этап 2. Source-side список и статусная пришлепка
|
||||
|
||||
|
|
@ -144,6 +146,7 @@
|
|||
- source-side detail использует отдельный экран `Внешних контуров`
|
||||
- в карточке отображается блок маршрутизации с ключевой source-target связью
|
||||
- текущий статус берется из фактического state целевой задачи
|
||||
- если у инициатора нет membership в target project, карточка переключается в source-side readonly режим без прямого открытия чужого проекта
|
||||
|
||||
Что остается:
|
||||
- зеркалирование комментариев
|
||||
|
|
@ -235,6 +238,10 @@
|
|||
- должен ли инициатор иметь прямую ссылку на target issue
|
||||
- или доступ к target issue должен быть скрыт, а source-side карточка должна быть единственной точкой просмотра
|
||||
|
||||
Текущее решение:
|
||||
- при отсутствии membership в target project прямой переход в target issue скрывается
|
||||
- карточка остается доступной из source project
|
||||
|
||||
## Рекомендуемый порядок фактической разработки
|
||||
|
||||
1. Этап 0
|
||||
|
|
|
|||
|
|
@ -56,6 +56,8 @@ from .intake import (
|
|||
from .external_contours import (
|
||||
ExternalContourRequestCreateSerializer,
|
||||
ExternalContourRequestSerializer,
|
||||
ExternalContourTargetOptionsSerializer,
|
||||
ExternalContourTargetProjectSerializer,
|
||||
)
|
||||
from .estimate import EstimateSerializer, EstimatePointSerializer
|
||||
from .asset import (
|
||||
|
|
|
|||
|
|
@ -9,7 +9,8 @@ from .issue import IssueSerializer
|
|||
from .project import ProjectLiteSerializer
|
||||
from .state import StateLiteSerializer
|
||||
from .user import UserLiteSerializer
|
||||
from plane.db.models import IntakeIssue, Issue
|
||||
from plane.app.serializers.issue import LabelSerializer
|
||||
from plane.db.models import IntakeIssue, Issue, Label, Project
|
||||
|
||||
|
||||
class ExternalContourIssuePayloadSerializer(serializers.Serializer):
|
||||
|
|
@ -26,6 +27,21 @@ class ExternalContourRequestCreateSerializer(serializers.Serializer):
|
|||
issue = ExternalContourIssuePayloadSerializer()
|
||||
|
||||
|
||||
class ExternalContourTargetProjectSerializer(BaseSerializer):
|
||||
inbox_view = serializers.BooleanField(read_only=True, source="intake_view")
|
||||
|
||||
class Meta:
|
||||
model = Project
|
||||
fields = ["id", "identifier", "name", "logo_props", "inbox_view"]
|
||||
read_only_fields = fields
|
||||
|
||||
|
||||
class ExternalContourTargetOptionsSerializer(serializers.Serializer):
|
||||
project = ExternalContourTargetProjectSerializer(read_only=True)
|
||||
member_ids = serializers.ListField(child=serializers.UUIDField(), read_only=True)
|
||||
labels = LabelSerializer(many=True, read_only=True)
|
||||
|
||||
|
||||
class ExternalContourIssueSerializer(BaseSerializer):
|
||||
assignee_ids = serializers.SerializerMethodField()
|
||||
assignee_details = serializers.SerializerMethodField()
|
||||
|
|
|
|||
|
|
@ -4,7 +4,12 @@
|
|||
|
||||
from django.urls import path
|
||||
|
||||
from plane.api.views import ExternalContourDetailAPIEndpoint, ExternalContourListCreateAPIEndpoint
|
||||
from plane.api.views import (
|
||||
ExternalContourDetailAPIEndpoint,
|
||||
ExternalContourListCreateAPIEndpoint,
|
||||
ExternalContourTargetOptionsAPIEndpoint,
|
||||
ExternalContourTargetProjectListAPIEndpoint,
|
||||
)
|
||||
|
||||
urlpatterns = [
|
||||
path(
|
||||
|
|
@ -12,6 +17,16 @@ urlpatterns = [
|
|||
ExternalContourListCreateAPIEndpoint.as_view(http_method_names=["get", "post"]),
|
||||
name="external-contours",
|
||||
),
|
||||
path(
|
||||
"workspaces/<str:slug>/projects/<uuid:project_id>/external-contours/targets/",
|
||||
ExternalContourTargetProjectListAPIEndpoint.as_view(http_method_names=["get"]),
|
||||
name="external-contour-targets",
|
||||
),
|
||||
path(
|
||||
"workspaces/<str:slug>/projects/<uuid:project_id>/external-contours/targets/<uuid:target_project_id>/options/",
|
||||
ExternalContourTargetOptionsAPIEndpoint.as_view(http_method_names=["get"]),
|
||||
name="external-contour-target-options",
|
||||
),
|
||||
path(
|
||||
"workspaces/<str:slug>/projects/<uuid:project_id>/external-contours/<uuid:request_id>/",
|
||||
ExternalContourDetailAPIEndpoint.as_view(http_method_names=["get"]),
|
||||
|
|
|
|||
|
|
@ -58,6 +58,8 @@ from .intake import (
|
|||
from .external_contours import (
|
||||
ExternalContourListCreateAPIEndpoint,
|
||||
ExternalContourDetailAPIEndpoint,
|
||||
ExternalContourTargetProjectListAPIEndpoint,
|
||||
ExternalContourTargetOptionsAPIEndpoint,
|
||||
)
|
||||
|
||||
from .asset import UserAssetEndpoint, UserServerAssetEndpoint, GenericAssetEndpoint
|
||||
|
|
|
|||
|
|
@ -9,9 +9,11 @@ from rest_framework.response import Response
|
|||
from plane.api.serializers import (
|
||||
ExternalContourRequestCreateSerializer,
|
||||
ExternalContourRequestSerializer,
|
||||
ExternalContourTargetOptionsSerializer,
|
||||
ExternalContourTargetProjectSerializer,
|
||||
)
|
||||
from plane.app.permissions import ProjectLitePermission
|
||||
from plane.db.models import Intake, IntakeIssue, Project, State, StateGroup
|
||||
from plane.db.models import Intake, IntakeIssue, Label, Project, ProjectMember, State, StateGroup
|
||||
from plane.api.serializers.issue import IssueSerializer as IssueCreateSerializer
|
||||
from .base import BaseAPIView
|
||||
from plane.db.models.intake import IntakeIssueStatus, SourceType
|
||||
|
|
@ -74,6 +76,12 @@ class ExternalContourListCreateAPIEndpoint(BaseAPIView):
|
|||
if str(target_project.id) == str(source_project.id):
|
||||
return Response({"error": "Target project must differ from source project"}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
if not target_project.intake_view:
|
||||
return Response(
|
||||
{"error": "Target project is not enabled for external contour routing"},
|
||||
status=status.HTTP_400_BAD_REQUEST,
|
||||
)
|
||||
|
||||
triage_state = State.triage_objects.filter(project=target_project).first()
|
||||
if not triage_state:
|
||||
triage_state = State.objects.create(
|
||||
|
|
@ -158,6 +166,79 @@ class ExternalContourListCreateAPIEndpoint(BaseAPIView):
|
|||
return Response(response_serializer.data, status=status.HTTP_201_CREATED)
|
||||
|
||||
|
||||
class ExternalContourTargetProjectListAPIEndpoint(BaseAPIView):
|
||||
permission_classes = [ProjectLitePermission]
|
||||
serializer_class = ExternalContourTargetProjectSerializer
|
||||
|
||||
def get_source_project(self, slug, project_id):
|
||||
return get_object_or_404(Project, workspace__slug=slug, pk=project_id)
|
||||
|
||||
def get_queryset(self):
|
||||
source_project = self.get_source_project(self.kwargs.get("slug"), self.kwargs.get("project_id"))
|
||||
return (
|
||||
Project.objects.filter(
|
||||
workspace_id=source_project.workspace_id,
|
||||
archived_at__isnull=True,
|
||||
intake_view=True,
|
||||
)
|
||||
.exclude(pk=source_project.id)
|
||||
.order_by("name")
|
||||
)
|
||||
|
||||
def get(self, request, slug, project_id):
|
||||
serializer = ExternalContourTargetProjectSerializer(self.get_queryset(), many=True)
|
||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||
|
||||
|
||||
class ExternalContourTargetOptionsAPIEndpoint(BaseAPIView):
|
||||
permission_classes = [ProjectLitePermission]
|
||||
serializer_class = ExternalContourTargetOptionsSerializer
|
||||
|
||||
def get_source_project(self, slug, project_id):
|
||||
return get_object_or_404(Project, workspace__slug=slug, pk=project_id)
|
||||
|
||||
def get_target_project(self, source_project, target_project_id):
|
||||
return get_object_or_404(
|
||||
Project,
|
||||
workspace_id=source_project.workspace_id,
|
||||
pk=target_project_id,
|
||||
archived_at__isnull=True,
|
||||
intake_view=True,
|
||||
)
|
||||
|
||||
def get(self, request, slug, project_id, target_project_id):
|
||||
source_project = self.get_source_project(slug, project_id)
|
||||
target_project = self.get_target_project(source_project, target_project_id)
|
||||
|
||||
if str(target_project.id) == str(source_project.id):
|
||||
return Response({"error": "Target project must differ from source project"}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
member_ids = list(
|
||||
ProjectMember.objects.filter(
|
||||
project=target_project,
|
||||
workspace_id=target_project.workspace_id,
|
||||
is_active=True,
|
||||
member__is_bot=False,
|
||||
member__member_workspace__workspace_id=target_project.workspace_id,
|
||||
member__member_workspace__is_active=True,
|
||||
)
|
||||
.order_by("member__display_name", "member__email")
|
||||
.values_list("member_id", flat=True)
|
||||
.distinct()
|
||||
)
|
||||
|
||||
labels = Label.objects.filter(project=target_project).order_by("sort_order", "name")
|
||||
|
||||
serializer = ExternalContourTargetOptionsSerializer(
|
||||
{
|
||||
"project": target_project,
|
||||
"member_ids": member_ids,
|
||||
"labels": labels,
|
||||
}
|
||||
)
|
||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||
|
||||
|
||||
class ExternalContourDetailAPIEndpoint(BaseAPIView):
|
||||
permission_classes = [ProjectLitePermission]
|
||||
serializer_class = ExternalContourRequestSerializer
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ from .asset import urlpatterns as asset_urls
|
|||
from .cycle import urlpatterns as cycle_urls
|
||||
from .estimate import urlpatterns as estimate_urls
|
||||
from .external import urlpatterns as external_urls
|
||||
from .external_contours import urlpatterns as external_contour_urls
|
||||
from .intake import urlpatterns as intake_urls
|
||||
from .issue import urlpatterns as issue_urls
|
||||
from .module import urlpatterns as module_urls
|
||||
|
|
@ -29,6 +30,7 @@ urlpatterns = [
|
|||
*cycle_urls,
|
||||
*estimate_urls,
|
||||
*external_urls,
|
||||
*external_contour_urls,
|
||||
*intake_urls,
|
||||
*issue_urls,
|
||||
*module_urls,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,36 @@
|
|||
# Copyright (c) 2023-present Plane Software, Inc. and contributors
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
# See the LICENSE file for details.
|
||||
|
||||
from django.urls import path
|
||||
|
||||
from plane.app.views import (
|
||||
ExternalContourDetailEndpoint,
|
||||
ExternalContourListCreateEndpoint,
|
||||
ExternalContourTargetOptionsEndpoint,
|
||||
ExternalContourTargetProjectListEndpoint,
|
||||
)
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
path(
|
||||
"workspaces/<str:slug>/projects/<uuid:project_id>/external-contours/",
|
||||
ExternalContourListCreateEndpoint.as_view(http_method_names=["get", "post"]),
|
||||
name="external-contours",
|
||||
),
|
||||
path(
|
||||
"workspaces/<str:slug>/projects/<uuid:project_id>/external-contours/targets/",
|
||||
ExternalContourTargetProjectListEndpoint.as_view(http_method_names=["get"]),
|
||||
name="external-contour-targets",
|
||||
),
|
||||
path(
|
||||
"workspaces/<str:slug>/projects/<uuid:project_id>/external-contours/targets/<uuid:target_project_id>/options/",
|
||||
ExternalContourTargetOptionsEndpoint.as_view(http_method_names=["get"]),
|
||||
name="external-contour-target-options",
|
||||
),
|
||||
path(
|
||||
"workspaces/<str:slug>/projects/<uuid:project_id>/external-contours/<uuid:request_id>/",
|
||||
ExternalContourDetailEndpoint.as_view(http_method_names=["get"]),
|
||||
name="external-contour-detail",
|
||||
),
|
||||
]
|
||||
|
|
@ -224,6 +224,12 @@ from .notification.base import (
|
|||
)
|
||||
|
||||
from .exporter.base import ExportIssuesEndpoint
|
||||
from .external_contours import (
|
||||
ExternalContourListCreateEndpoint,
|
||||
ExternalContourDetailEndpoint,
|
||||
ExternalContourTargetProjectListEndpoint,
|
||||
ExternalContourTargetOptionsEndpoint,
|
||||
)
|
||||
|
||||
|
||||
from .webhook.base import (
|
||||
|
|
|
|||
|
|
@ -0,0 +1,266 @@
|
|||
# Copyright (c) 2023-present Plane Software, Inc. and contributors
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
# See the LICENSE file for details.
|
||||
|
||||
from django.shortcuts import get_object_or_404
|
||||
from rest_framework import status
|
||||
from rest_framework.response import Response
|
||||
|
||||
from plane.api.serializers import (
|
||||
ExternalContourRequestCreateSerializer,
|
||||
ExternalContourRequestSerializer,
|
||||
ExternalContourTargetOptionsSerializer,
|
||||
ExternalContourTargetProjectSerializer,
|
||||
)
|
||||
from plane.api.serializers.issue import IssueSerializer as IssueCreateSerializer
|
||||
from plane.app.permissions import ProjectLitePermission
|
||||
from plane.app.views.base import BaseAPIView
|
||||
from plane.db.models import Intake, IntakeIssue, Label, Project, ProjectMember, State, StateGroup
|
||||
from plane.db.models.intake import IntakeIssueStatus, SourceType
|
||||
|
||||
|
||||
class ExternalContourListCreateEndpoint(BaseAPIView):
|
||||
permission_classes = [ProjectLitePermission]
|
||||
serializer_class = ExternalContourRequestSerializer
|
||||
|
||||
def get_source_project(self, slug, project_id):
|
||||
return get_object_or_404(Project, workspace__slug=slug, pk=project_id)
|
||||
|
||||
def get_queryset(self):
|
||||
return (
|
||||
IntakeIssue.objects.filter(
|
||||
workspace__slug=self.kwargs.get("slug"),
|
||||
extra__bridge="external-contours",
|
||||
extra__source_project_id=str(self.kwargs.get("project_id")),
|
||||
)
|
||||
.select_related(
|
||||
"issue",
|
||||
"issue__state",
|
||||
"issue__project",
|
||||
"issue__created_by",
|
||||
)
|
||||
.prefetch_related("issue__issue_assignee__assignee", "issue__label_issue__label")
|
||||
.order_by("-updated_at")
|
||||
)
|
||||
|
||||
def get(self, request, slug, project_id):
|
||||
serializer = ExternalContourRequestSerializer(self.get_queryset(), many=True)
|
||||
return Response(
|
||||
{
|
||||
"results": serializer.data,
|
||||
"next_cursor": "",
|
||||
"prev_cursor": "",
|
||||
"next_page_results": False,
|
||||
"prev_page_results": False,
|
||||
"total_count": len(serializer.data),
|
||||
"count": len(serializer.data),
|
||||
"total_pages": 1,
|
||||
"extra_stats": None,
|
||||
"total_results": len(serializer.data),
|
||||
},
|
||||
status=status.HTTP_200_OK,
|
||||
)
|
||||
|
||||
def post(self, request, slug, project_id):
|
||||
source_project = self.get_source_project(slug, project_id)
|
||||
serializer = ExternalContourRequestCreateSerializer(data=request.data)
|
||||
serializer.is_valid(raise_exception=True)
|
||||
|
||||
target_project = get_object_or_404(
|
||||
Project,
|
||||
workspace_id=source_project.workspace_id,
|
||||
pk=serializer.validated_data["target_project_id"],
|
||||
archived_at__isnull=True,
|
||||
)
|
||||
|
||||
if str(target_project.id) == str(source_project.id):
|
||||
return Response({"error": "Target project must differ from source project"}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
if not target_project.intake_view:
|
||||
return Response(
|
||||
{"error": "Target project is not enabled for external contour routing"},
|
||||
status=status.HTTP_400_BAD_REQUEST,
|
||||
)
|
||||
|
||||
triage_state = State.triage_objects.filter(project=target_project).first()
|
||||
if not triage_state:
|
||||
triage_state = State.objects.create(
|
||||
name="Triage",
|
||||
group=StateGroup.TRIAGE.value,
|
||||
project=target_project,
|
||||
color="#4E5355",
|
||||
sequence=65000,
|
||||
default=False,
|
||||
)
|
||||
|
||||
target_default_state = (
|
||||
State.objects.filter(project=target_project, default=True)
|
||||
.exclude(group=StateGroup.TRIAGE.value)
|
||||
.first()
|
||||
) or State.objects.filter(project=target_project).exclude(group=StateGroup.TRIAGE.value).order_by("sequence", "created_at").first()
|
||||
|
||||
if not target_default_state:
|
||||
return Response({"error": "Target project has no available workflow state"}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
intake = Intake.objects.filter(project=target_project, name="External Contours Bridge").first()
|
||||
if not intake:
|
||||
intake = Intake.objects.create(
|
||||
name="External Contours Bridge",
|
||||
description="System bridge intake used for cross-project routing.",
|
||||
is_default=False,
|
||||
project=target_project,
|
||||
)
|
||||
|
||||
issue_payload = serializer.validated_data["issue"]
|
||||
issue_serializer = IssueCreateSerializer(
|
||||
data={
|
||||
"name": issue_payload["name"],
|
||||
"description_html": issue_payload.get("description_html") or "<p></p>",
|
||||
"priority": issue_payload.get("priority", "none"),
|
||||
"assignees": issue_payload.get("assignee_ids", []),
|
||||
"labels": issue_payload.get("label_ids", []),
|
||||
"target_date": issue_payload.get("target_date"),
|
||||
"state_id": str(triage_state.id),
|
||||
},
|
||||
context={
|
||||
"project_id": str(target_project.id),
|
||||
"workspace_id": str(target_project.workspace_id),
|
||||
"default_assignee_id": target_project.default_assignee_id,
|
||||
},
|
||||
)
|
||||
issue_serializer.is_valid(raise_exception=True)
|
||||
issue = issue_serializer.save(state=triage_state)
|
||||
|
||||
intake_issue = IntakeIssue.objects.create(
|
||||
intake=intake,
|
||||
project=target_project,
|
||||
issue=issue,
|
||||
source=SourceType.IN_APP,
|
||||
status=IntakeIssueStatus.ACCEPTED.value,
|
||||
extra={
|
||||
"bridge": "external-contours",
|
||||
"source_project_id": str(source_project.id),
|
||||
"source_project_name": source_project.name,
|
||||
"target_project_id": str(target_project.id),
|
||||
"target_project_name": target_project.name,
|
||||
"requested_by_id": str(request.user.id),
|
||||
"requested_by_name": request.user.display_name,
|
||||
"requested_at": issue.created_at.isoformat() if issue.created_at else None,
|
||||
},
|
||||
)
|
||||
|
||||
if issue.state_id != target_default_state.id:
|
||||
issue.state = target_default_state
|
||||
issue.save()
|
||||
|
||||
response_serializer = ExternalContourRequestSerializer(
|
||||
IntakeIssue.objects.select_related(
|
||||
"issue",
|
||||
"issue__state",
|
||||
"issue__project",
|
||||
"issue__created_by",
|
||||
)
|
||||
.prefetch_related("issue__issue_assignee__assignee", "issue__label_issue__label")
|
||||
.get(pk=intake_issue.id)
|
||||
)
|
||||
return Response(response_serializer.data, status=status.HTTP_201_CREATED)
|
||||
|
||||
|
||||
class ExternalContourTargetProjectListEndpoint(BaseAPIView):
|
||||
permission_classes = [ProjectLitePermission]
|
||||
serializer_class = ExternalContourTargetProjectSerializer
|
||||
|
||||
def get_source_project(self, slug, project_id):
|
||||
return get_object_or_404(Project, workspace__slug=slug, pk=project_id)
|
||||
|
||||
def get_queryset(self):
|
||||
source_project = self.get_source_project(self.kwargs.get("slug"), self.kwargs.get("project_id"))
|
||||
return (
|
||||
Project.objects.filter(
|
||||
workspace_id=source_project.workspace_id,
|
||||
archived_at__isnull=True,
|
||||
intake_view=True,
|
||||
)
|
||||
.exclude(pk=source_project.id)
|
||||
.order_by("name")
|
||||
)
|
||||
|
||||
def get(self, request, slug, project_id):
|
||||
serializer = ExternalContourTargetProjectSerializer(self.get_queryset(), many=True)
|
||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||
|
||||
|
||||
class ExternalContourTargetOptionsEndpoint(BaseAPIView):
|
||||
permission_classes = [ProjectLitePermission]
|
||||
serializer_class = ExternalContourTargetOptionsSerializer
|
||||
|
||||
def get_source_project(self, slug, project_id):
|
||||
return get_object_or_404(Project, workspace__slug=slug, pk=project_id)
|
||||
|
||||
def get_target_project(self, source_project, target_project_id):
|
||||
return get_object_or_404(
|
||||
Project,
|
||||
workspace_id=source_project.workspace_id,
|
||||
pk=target_project_id,
|
||||
archived_at__isnull=True,
|
||||
intake_view=True,
|
||||
)
|
||||
|
||||
def get(self, request, slug, project_id, target_project_id):
|
||||
source_project = self.get_source_project(slug, project_id)
|
||||
target_project = self.get_target_project(source_project, target_project_id)
|
||||
|
||||
if str(target_project.id) == str(source_project.id):
|
||||
return Response({"error": "Target project must differ from source project"}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
member_ids = list(
|
||||
ProjectMember.objects.filter(
|
||||
project=target_project,
|
||||
workspace_id=target_project.workspace_id,
|
||||
is_active=True,
|
||||
member__is_bot=False,
|
||||
member__member_workspace__workspace_id=target_project.workspace_id,
|
||||
member__member_workspace__is_active=True,
|
||||
)
|
||||
.order_by("member__display_name", "member__email")
|
||||
.values_list("member_id", flat=True)
|
||||
.distinct()
|
||||
)
|
||||
|
||||
labels = Label.objects.filter(project=target_project).order_by("sort_order", "name")
|
||||
|
||||
serializer = ExternalContourTargetOptionsSerializer(
|
||||
{
|
||||
"project": target_project,
|
||||
"member_ids": member_ids,
|
||||
"labels": labels,
|
||||
}
|
||||
)
|
||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||
|
||||
|
||||
class ExternalContourDetailEndpoint(BaseAPIView):
|
||||
permission_classes = [ProjectLitePermission]
|
||||
serializer_class = ExternalContourRequestSerializer
|
||||
|
||||
def get_queryset(self):
|
||||
return (
|
||||
IntakeIssue.objects.filter(
|
||||
workspace__slug=self.kwargs.get("slug"),
|
||||
extra__bridge="external-contours",
|
||||
extra__source_project_id=str(self.kwargs.get("project_id")),
|
||||
pk=self.kwargs.get("request_id"),
|
||||
)
|
||||
.select_related(
|
||||
"issue",
|
||||
"issue__state",
|
||||
"issue__project",
|
||||
"issue__created_by",
|
||||
)
|
||||
.prefetch_related("issue__issue_assignee__assignee", "issue__label_issue__label")
|
||||
)
|
||||
|
||||
def get(self, request, slug, project_id, request_id):
|
||||
contour_request = get_object_or_404(self.get_queryset())
|
||||
serializer = ExternalContourRequestSerializer(contour_request)
|
||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||
|
|
@ -34,6 +34,9 @@ export const ExternalContoursContentRoot = observer(function ExternalContoursCon
|
|||
const issue = contourRequest?.issue;
|
||||
const targetProjectId = issue?.project_id || projectId;
|
||||
const { allowPermissions, getProjectRoleByWorkspaceSlugAndProjectId } = useUserPermissions();
|
||||
const hasDirectTargetAccess = !!(
|
||||
targetProjectId && getProjectRoleByWorkspaceSlugAndProjectId(workspaceSlug, targetProjectId) !== undefined
|
||||
);
|
||||
|
||||
const isIssueAvailable = getIsRequestAvailable(inboxIssueId?.toString() || "");
|
||||
|
||||
|
|
@ -53,11 +56,12 @@ export const ExternalContoursContentRoot = observer(function ExternalContoursCon
|
|||
);
|
||||
|
||||
const isEditable =
|
||||
!!targetProjectId &&
|
||||
hasDirectTargetAccess &&
|
||||
(allowPermissions([EUserPermissions.ADMIN], EUserPermissionsLevel.PROJECT, workspaceSlug, targetProjectId) ||
|
||||
issue?.created_by === currentUser?.id);
|
||||
|
||||
const isGuest = !!targetProjectId && getProjectRoleByWorkspaceSlugAndProjectId(workspaceSlug, targetProjectId) === EUserPermissions.GUEST;
|
||||
const isGuest =
|
||||
!!targetProjectId && getProjectRoleByWorkspaceSlugAndProjectId(workspaceSlug, targetProjectId) === EUserPermissions.GUEST;
|
||||
const isOwner = issue?.created_by === currentUser?.id;
|
||||
const readOnly = !isOwner && isGuest;
|
||||
|
||||
|
|
@ -73,6 +77,7 @@ export const ExternalContoursContentRoot = observer(function ExternalContoursCon
|
|||
sourceProjectId={projectId}
|
||||
contourRequest={contourRequest}
|
||||
isSubmitting={isSubmitting}
|
||||
hasDirectTargetAccess={hasDirectTargetAccess}
|
||||
/>
|
||||
</div>
|
||||
<ContentWrapper className="divide-y-2 divide-subtle-1">
|
||||
|
|
@ -80,6 +85,7 @@ export const ExternalContoursContentRoot = observer(function ExternalContoursCon
|
|||
workspaceSlug={workspaceSlug}
|
||||
sourceProjectId={projectId}
|
||||
contourRequest={contourRequest}
|
||||
hasDirectTargetAccess={hasDirectTargetAccess}
|
||||
isEditable={!!isEditable && !readOnly}
|
||||
isSubmitting={isSubmitting}
|
||||
setIsSubmitting={setIsSubmitting}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ export function ExternalContourCreateModalRoot(props: Props) {
|
|||
return (
|
||||
<ModalCore
|
||||
isOpen={modalState}
|
||||
position={EModalPosition.TOP}
|
||||
position={EModalPosition.CENTER}
|
||||
width={EModalWidth.XXXXL}
|
||||
className="rounded-lg !bg-transparent shadow-none transition-[width] ease-linear"
|
||||
>
|
||||
|
|
|
|||
|
|
@ -8,31 +8,44 @@ import { useMemo } from "react";
|
|||
import { observer } from "mobx-react";
|
||||
import { useTranslation } from "@plane/i18n";
|
||||
import { Badge } from "@plane/propel/badge";
|
||||
import { MembersPropertyIcon } from "@plane/propel/icons";
|
||||
import type { TIssue, TIssuePriorities } from "@plane/types";
|
||||
import { renderFormattedPayloadDate } from "@plane/utils";
|
||||
import { DateDropdown } from "@/components/dropdowns/date";
|
||||
import { MemberDropdown } from "@/components/dropdowns/member/dropdown";
|
||||
import { ButtonAvatars } from "@/components/dropdowns/member/avatar";
|
||||
import { MemberDropdownBase } from "@/components/dropdowns/member/base";
|
||||
import { PriorityDropdown } from "@/components/dropdowns/priority";
|
||||
import { ProjectDropdown } from "@/components/dropdowns/project/dropdown";
|
||||
import { IssueLabelSelect } from "@/components/issues/select";
|
||||
import { useProject } from "@/hooks/store/use-project";
|
||||
import { ProjectDropdownBase } from "@/components/dropdowns/project/base";
|
||||
import { WorkItemLabelSelectBase } from "@/components/issues/select/base";
|
||||
import { useMember } from "@/hooks/store/use-member";
|
||||
import { useProjectExternalContours } from "@/hooks/store/use-project-external-contours";
|
||||
|
||||
type Props = {
|
||||
currentProjectId: string;
|
||||
currentProjectName?: string;
|
||||
data: Partial<TIssue> & { target_project_id?: string | null; priority?: TIssuePriorities };
|
||||
handleData: (issueKey: keyof Props["data"], issueValue: Props["data"][keyof Props["data"]]) => void;
|
||||
};
|
||||
|
||||
export const ExternalContoursCreateProperties = observer(function ExternalContoursCreateProperties(props: Props) {
|
||||
const { currentProjectId, currentProjectName, data, handleData } = props;
|
||||
const { currentProjectName, data, handleData } = props;
|
||||
const { t } = useTranslation();
|
||||
const { getProjectById } = useProject();
|
||||
const { getUserDetails } = useMember();
|
||||
const { targetProjectIds, getTargetOptionsByProjectId, getTargetProjectById } = useProjectExternalContours();
|
||||
|
||||
const selectedTargetProject = useMemo(
|
||||
() => (data.target_project_id ? getProjectById(data.target_project_id) : undefined),
|
||||
[data.target_project_id, getProjectById]
|
||||
const selectedTargetProject = data.target_project_id ? getTargetProjectById(data.target_project_id) : undefined;
|
||||
const selectedTargetOptions = getTargetOptionsByProjectId(data.target_project_id);
|
||||
const targetLabelIds = useMemo(
|
||||
() => selectedTargetOptions?.labels?.map((label) => label.id) ?? [],
|
||||
[selectedTargetOptions?.labels]
|
||||
);
|
||||
const assigneeLabel = useMemo(() => {
|
||||
const assigneeIds = data.assignee_ids || [];
|
||||
if (!assigneeIds.length) return t("external_contours_page.form.assignee");
|
||||
if (assigneeIds.length === 1) return getUserDetails(assigneeIds[0])?.display_name || t("external_contours_page.form.assignee");
|
||||
return `${assigneeIds.length} ${t("assignees").toLocaleLowerCase()}`;
|
||||
}, [data.assignee_ids, getUserDetails, t]);
|
||||
const getTargetLabelById = (labelId: string) =>
|
||||
selectedTargetOptions?.labels?.find((label) => label.id === labelId) ?? null;
|
||||
|
||||
return (
|
||||
<div className="relative flex flex-wrap items-center gap-2">
|
||||
|
|
@ -42,7 +55,7 @@ export const ExternalContoursCreateProperties = observer(function ExternalContou
|
|||
</div>
|
||||
|
||||
<div className="h-7">
|
||||
<ProjectDropdown
|
||||
<ProjectDropdownBase
|
||||
value={data.target_project_id ?? null}
|
||||
onChange={(value) => {
|
||||
if (!Array.isArray(value)) {
|
||||
|
|
@ -52,9 +65,11 @@ export const ExternalContoursCreateProperties = observer(function ExternalContou
|
|||
}
|
||||
}}
|
||||
multiple={false}
|
||||
projectIds={targetProjectIds}
|
||||
getProjectById={getTargetProjectById}
|
||||
buttonVariant="border-with-text"
|
||||
placeholder={t("external_contours_page.form.target_project")}
|
||||
renderCondition={(projectId) => projectId !== currentProjectId}
|
||||
disabled={targetProjectIds.length === 0}
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
|
@ -74,24 +89,33 @@ export const ExternalContoursCreateProperties = observer(function ExternalContou
|
|||
</div>
|
||||
|
||||
<div className="h-7">
|
||||
<MemberDropdown
|
||||
projectId={data.target_project_id ?? undefined}
|
||||
<MemberDropdownBase
|
||||
value={data.assignee_ids || []}
|
||||
onChange={(assigneeIds) => handleData("assignee_ids", assigneeIds)}
|
||||
getUserDetails={getUserDetails}
|
||||
memberIds={selectedTargetOptions?.member_ids ?? []}
|
||||
button={
|
||||
<div className="flex h-full items-center justify-start gap-1.5 rounded-sm border-[0.5px] border-strong px-1.5 text-11 text-secondary">
|
||||
<ButtonAvatars showTooltip={false} userIds={data.assignee_ids || []} icon={MembersPropertyIcon} />
|
||||
<span className="flex-grow truncate text-left text-body-xs-medium leading-5">{assigneeLabel}</span>
|
||||
</div>
|
||||
}
|
||||
buttonVariant={(data.assignee_ids || []).length > 0 ? "transparent-without-text" : "border-with-text"}
|
||||
buttonClassName={(data.assignee_ids || []).length > 0 ? "hover:bg-transparent" : ""}
|
||||
optionsClassName="z-[60]"
|
||||
placeholder={t("external_contours_page.form.assignee")}
|
||||
disabled={!data.target_project_id}
|
||||
disabled={!data.target_project_id || !selectedTargetOptions}
|
||||
multiple
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="h-7">
|
||||
<IssueLabelSelect
|
||||
<WorkItemLabelSelectBase
|
||||
value={data.label_ids || []}
|
||||
onChange={(labelIds) => handleData("label_ids", labelIds)}
|
||||
projectId={data.target_project_id ?? undefined}
|
||||
disabled={!data.target_project_id}
|
||||
getLabelById={getTargetLabelById}
|
||||
labelIds={targetLabelIds}
|
||||
disabled={!data.target_project_id || !selectedTargetOptions}
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
|
||||
import type { FormEvent } from "react";
|
||||
import { useRef, useState } from "react";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { observer } from "mobx-react";
|
||||
import type { EditorRefApi } from "@plane/editor";
|
||||
import { useTranslation } from "@plane/i18n";
|
||||
|
|
@ -46,7 +46,7 @@ export const ExternalContoursCreateRoot = observer(function ExternalContoursCrea
|
|||
const { getWorkspaceBySlug } = useWorkspace();
|
||||
const workspaceId = getWorkspaceBySlug(workspaceSlug)?.id;
|
||||
const { currentProjectDetails } = useProject();
|
||||
const { createRequest } = useProjectExternalContours();
|
||||
const { createRequest, fetchTargetOptions, fetchTargetProjects } = useProjectExternalContours();
|
||||
const descriptionEditorRef = useRef<EditorRefApi>(null);
|
||||
const [createMore, setCreateMore] = useState(false);
|
||||
const [formSubmitting, setFormSubmitting] = useState(false);
|
||||
|
|
@ -59,6 +59,28 @@ export const ExternalContoursCreateRoot = observer(function ExternalContoursCrea
|
|||
const isTitleLengthMoreThan255Character = formData?.name ? formData.name.length > 255 : false;
|
||||
const canSubmit = !!formData.name?.trim() && !!formData.target_project_id;
|
||||
|
||||
useEffect(() => {
|
||||
if (!workspaceSlug || !projectId) return;
|
||||
fetchTargetProjects(workspaceSlug, projectId).catch(() => {
|
||||
setToast({
|
||||
type: TOAST_TYPE.ERROR,
|
||||
title: t("error"),
|
||||
message: t("external_contours_page.modal.error_message"),
|
||||
});
|
||||
});
|
||||
}, [fetchTargetProjects, projectId, t, workspaceSlug]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!workspaceSlug || !projectId || !formData.target_project_id) return;
|
||||
fetchTargetOptions(workspaceSlug, projectId, formData.target_project_id).catch(() => {
|
||||
setToast({
|
||||
type: TOAST_TYPE.ERROR,
|
||||
title: t("error"),
|
||||
message: t("external_contours_page.modal.error_message"),
|
||||
});
|
||||
});
|
||||
}, [fetchTargetOptions, formData.target_project_id, projectId, t, workspaceSlug]);
|
||||
|
||||
const handleFormSubmit = async (event: FormEvent<HTMLFormElement>) => {
|
||||
event.preventDefault();
|
||||
|
||||
|
|
@ -128,7 +150,6 @@ export const ExternalContoursCreateRoot = observer(function ExternalContoursCrea
|
|||
onAssetUpload={() => {}}
|
||||
/>
|
||||
<ExternalContoursCreateProperties
|
||||
currentProjectId={projectId}
|
||||
currentProjectName={currentProjectDetails?.name}
|
||||
data={formData}
|
||||
handleData={handleFormData as any}
|
||||
|
|
|
|||
|
|
@ -25,13 +25,22 @@ type Props = {
|
|||
workspaceSlug: string;
|
||||
sourceProjectId: string;
|
||||
contourRequest: TExternalContourRequest;
|
||||
hasDirectTargetAccess: boolean;
|
||||
isSubmitting: TNameDescriptionLoader;
|
||||
isMobileSidebar: boolean;
|
||||
setIsMobileSidebar: (value: boolean) => void;
|
||||
};
|
||||
|
||||
export const ExternalContoursIssueActionsHeader = observer(function ExternalContoursIssueActionsHeader(props: Props) {
|
||||
const { workspaceSlug, sourceProjectId, contourRequest, isSubmitting, isMobileSidebar, setIsMobileSidebar } = props;
|
||||
const {
|
||||
workspaceSlug,
|
||||
sourceProjectId,
|
||||
contourRequest,
|
||||
hasDirectTargetAccess,
|
||||
isSubmitting,
|
||||
isMobileSidebar,
|
||||
setIsMobileSidebar,
|
||||
} = props;
|
||||
const { t } = useTranslation();
|
||||
const router = useAppRouter();
|
||||
const { currentTab, filteredRequestIds } = useProjectExternalContours();
|
||||
|
|
@ -108,11 +117,13 @@ export const ExternalContoursIssueActionsHeader = observer(function ExternalCont
|
|||
<Button variant="secondary" size="lg" prependIcon={<LinkIcon className="h-2.5 w-2.5" />} onClick={handleCopyLink}>
|
||||
{t("external_contours_page.actions.copy")}
|
||||
</Button>
|
||||
<ControlLink href={workItemLink} onClick={() => router.push(workItemLink)} target="_self">
|
||||
<Button variant="secondary" size="lg" prependIcon={<NewTabIcon className="h-2.5 w-2.5" />}>
|
||||
{t("external_contours_page.actions.open")}
|
||||
</Button>
|
||||
</ControlLink>
|
||||
{hasDirectTargetAccess && (
|
||||
<ControlLink href={workItemLink} onClick={() => router.push(workItemLink)} target="_self">
|
||||
<Button variant="secondary" size="lg" prependIcon={<NewTabIcon className="h-2.5 w-2.5" />}>
|
||||
{t("external_contours_page.actions.open")}
|
||||
</Button>
|
||||
</ControlLink>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</Row>
|
||||
|
|
@ -125,11 +136,13 @@ export const ExternalContoursIssueActionsHeader = observer(function ExternalCont
|
|||
<div className="flex w-full items-center gap-2">
|
||||
<ExternalContourStatePill request={contourRequest} />
|
||||
<div className="ml-auto flex items-center gap-2">
|
||||
<ControlLink href={workItemLink} onClick={() => router.push(workItemLink)} target="_self">
|
||||
<Button variant="secondary" size="sm">
|
||||
{t("external_contours_page.actions.open")}
|
||||
</Button>
|
||||
</ControlLink>
|
||||
{hasDirectTargetAccess && (
|
||||
<ControlLink href={workItemLink} onClick={() => router.push(workItemLink)} target="_self">
|
||||
<Button variant="secondary" size="sm">
|
||||
{t("external_contours_page.actions.open")}
|
||||
</Button>
|
||||
</ControlLink>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</Header>
|
||||
|
|
|
|||
|
|
@ -9,10 +9,11 @@ import { useEffect, useMemo, useRef } from "react";
|
|||
import { observer } from "mobx-react";
|
||||
import type { EditorRefApi } from "@plane/editor";
|
||||
import { useTranslation } from "@plane/i18n";
|
||||
import { Badge } from "@plane/propel/badge";
|
||||
import { TOAST_TYPE, setToast } from "@plane/propel/toast";
|
||||
import type { TExternalContourRequest, TIssue, TNameDescriptionLoader } from "@plane/types";
|
||||
import { EFileAssetType } from "@plane/types";
|
||||
import { getTextContent } from "@plane/utils";
|
||||
import { getTextContent, renderFormattedDate } from "@plane/utils";
|
||||
import { DescriptionVersionsRoot } from "@/components/core/description-versions";
|
||||
import { DescriptionInput } from "@/components/editor/rich-text/description-input";
|
||||
import { DescriptionInputLoader } from "@/components/editor/rich-text/description-input/loader";
|
||||
|
|
@ -38,13 +39,14 @@ type Props = {
|
|||
workspaceSlug: string;
|
||||
sourceProjectId: string;
|
||||
contourRequest: TExternalContourRequest;
|
||||
hasDirectTargetAccess: boolean;
|
||||
isEditable: boolean;
|
||||
isSubmitting: TNameDescriptionLoader;
|
||||
setIsSubmitting: Dispatch<SetStateAction<TNameDescriptionLoader>>;
|
||||
};
|
||||
|
||||
export const ExternalContoursIssueMainContent = observer(function ExternalContoursIssueMainContent(props: Props) {
|
||||
const { workspaceSlug, sourceProjectId, contourRequest, isEditable, isSubmitting, setIsSubmitting } = props;
|
||||
const { workspaceSlug, sourceProjectId, contourRequest, hasDirectTargetAccess, isEditable, isSubmitting, setIsSubmitting } = props;
|
||||
const { t } = useTranslation();
|
||||
const editorRef = useRef<EditorRefApi>(null);
|
||||
const { data: currentUser } = useUser();
|
||||
|
|
@ -100,6 +102,73 @@ export const ExternalContoursIssueMainContent = observer(function ExternalContou
|
|||
|
||||
if (!issue || !issue.project_id || !issue.id) return <></>;
|
||||
|
||||
if (!hasDirectTargetAccess) {
|
||||
return (
|
||||
<>
|
||||
<div className="space-y-4 pb-4">
|
||||
<h1 className="text-xl font-semibold text-primary">{issue.name}</h1>
|
||||
<div
|
||||
className="prose prose-invert max-w-none text-sm text-secondary [&_p]:mb-3"
|
||||
dangerouslySetInnerHTML={{ __html: issue.description_html || "<p></p>" }}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="py-4">
|
||||
<ExternalContoursRequestTraceability contourRequest={contourRequest} />
|
||||
</div>
|
||||
|
||||
<div className="py-4">
|
||||
<div className="mb-2 text-body-sm-medium">{t("external_contours_page.properties.section_title")}</div>
|
||||
<div className="flex flex-col gap-3 text-13 text-secondary">
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<span className="text-tertiary">{t("external_contours_page.properties.target_contour")}</span>
|
||||
<Badge variant="neutral">{issue.project_detail?.name || t("common.none")}</Badge>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<span className="text-tertiary">{t("assignees")}</span>
|
||||
{issue.assignee_details?.length ? (
|
||||
issue.assignee_details.map((assignee) => (
|
||||
<Badge key={assignee.id} variant="neutral">
|
||||
{assignee.display_name}
|
||||
</Badge>
|
||||
))
|
||||
) : (
|
||||
<span>{t("external_contours_page.list.unassigned")}</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<span className="text-tertiary">{t("priority")}</span>
|
||||
<Badge variant="neutral">{issue.priority || t("none")}</Badge>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<span className="text-tertiary">{t("due_date")}</span>
|
||||
<span>{issue.target_date ? renderFormattedDate(issue.target_date) : t("common.none")}</span>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<span className="text-tertiary">{t("labels")}</span>
|
||||
{issue.label_details?.length ? (
|
||||
issue.label_details.map((label) => (
|
||||
<div key={label.id} className="flex items-center gap-1 rounded-sm border border-strong px-2 py-1 text-11">
|
||||
<span className="h-2 w-2 rounded-full" style={{ backgroundColor: label.color }} />
|
||||
<span>{label.name}</span>
|
||||
</div>
|
||||
))
|
||||
) : (
|
||||
<span>{t("common.none")}</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="py-4 text-13 text-secondary">{t("external_contours_page.readonly_source_view")}</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="space-y-4 pb-4">
|
||||
|
|
|
|||
|
|
@ -5,7 +5,13 @@
|
|||
*/
|
||||
|
||||
import { API_BASE_URL } from "@plane/constants";
|
||||
import type { TExternalContourRequest, TExternalContourRequestResponse, TIssue } from "@plane/types";
|
||||
import type {
|
||||
TExternalContourRequest,
|
||||
TExternalContourRequestResponse,
|
||||
TExternalContourTargetOptions,
|
||||
TExternalContourTargetProject,
|
||||
TIssue,
|
||||
} from "@plane/types";
|
||||
import { APIService } from "@/services/api.service";
|
||||
|
||||
export class ExternalContourService extends APIService {
|
||||
|
|
@ -29,6 +35,26 @@ export class ExternalContourService extends APIService {
|
|||
});
|
||||
}
|
||||
|
||||
async listTargetProjects(workspaceSlug: string, projectId: string): Promise<TExternalContourTargetProject[]> {
|
||||
return this.get(`/api/workspaces/${workspaceSlug}/projects/${projectId}/external-contours/targets/`)
|
||||
.then((response) => response?.data)
|
||||
.catch((error) => {
|
||||
throw error?.response?.data;
|
||||
});
|
||||
}
|
||||
|
||||
async retrieveTargetOptions(
|
||||
workspaceSlug: string,
|
||||
projectId: string,
|
||||
targetProjectId: string
|
||||
): Promise<TExternalContourTargetOptions> {
|
||||
return this.get(`/api/workspaces/${workspaceSlug}/projects/${projectId}/external-contours/targets/${targetProjectId}/options/`)
|
||||
.then((response) => response?.data)
|
||||
.catch((error) => {
|
||||
throw error?.response?.data;
|
||||
});
|
||||
}
|
||||
|
||||
async create(
|
||||
workspaceSlug: string,
|
||||
projectId: string,
|
||||
|
|
|
|||
|
|
@ -6,7 +6,13 @@
|
|||
|
||||
import { set } from "lodash-es";
|
||||
import { action, computed, makeObservable, observable, runInAction } from "mobx";
|
||||
import type { TExternalContourRequest, TInboxIssueCurrentTab, TIssue } from "@plane/types";
|
||||
import type {
|
||||
TExternalContourRequest,
|
||||
TExternalContourTargetOptions,
|
||||
TExternalContourTargetProject,
|
||||
TInboxIssueCurrentTab,
|
||||
TIssue,
|
||||
} from "@plane/types";
|
||||
import { EInboxIssueCurrentTab } from "@plane/types";
|
||||
import { ExternalContourService } from "@/services/external-contours";
|
||||
import type { CoreRootStore } from "../root.store";
|
||||
|
|
@ -20,15 +26,22 @@ export interface IProjectExternalContoursStore {
|
|||
loader: TLoader;
|
||||
requestIds: string[];
|
||||
requests: Record<string, TExternalContourRequest>;
|
||||
targetProjectIds: string[];
|
||||
targetProjects: Record<string, TExternalContourTargetProject>;
|
||||
targetOptionsMap: Record<string, TExternalContourTargetOptions>;
|
||||
createRequest: (
|
||||
workspaceSlug: string,
|
||||
projectId: string,
|
||||
data: Partial<TIssue> & { target_project_id?: string | null }
|
||||
) => Promise<TExternalContourRequest | undefined>;
|
||||
fetchTargetProjects: (workspaceSlug: string, projectId: string) => Promise<void>;
|
||||
fetchTargetOptions: (workspaceSlug: string, projectId: string, targetProjectId: string) => Promise<TExternalContourTargetOptions | undefined>;
|
||||
fetchRequestById: (workspaceSlug: string, projectId: string, requestId: string) => Promise<TExternalContourRequest | undefined>;
|
||||
fetchRequests: (workspaceSlug: string, projectId: string, tab?: TInboxIssueCurrentTab) => Promise<void>;
|
||||
getIsRequestAvailable: (requestId: string) => boolean;
|
||||
getRequestById: (requestId: string) => TExternalContourRequest | undefined;
|
||||
getTargetProjectById: (projectId: string | null | undefined) => TExternalContourTargetProject | undefined;
|
||||
getTargetOptionsByProjectId: (projectId: string | null | undefined) => TExternalContourTargetOptions | undefined;
|
||||
handleCurrentTab: (workspaceSlug: string, projectId: string, tab: TInboxIssueCurrentTab) => Promise<void>;
|
||||
openRequestIds: string[];
|
||||
closedRequestIds: string[];
|
||||
|
|
@ -44,6 +57,9 @@ export class ProjectExternalContoursStore implements IProjectExternalContoursSto
|
|||
loader: TLoader = "init-loading";
|
||||
requestIds: string[] = [];
|
||||
requests: Record<string, TExternalContourRequest> = {};
|
||||
targetProjectIds: string[] = [];
|
||||
targetProjects: Record<string, TExternalContourTargetProject> = {};
|
||||
targetOptionsMap: Record<string, TExternalContourTargetOptions> = {};
|
||||
|
||||
externalContourService;
|
||||
|
||||
|
|
@ -55,9 +71,14 @@ export class ProjectExternalContoursStore implements IProjectExternalContoursSto
|
|||
loader: observable.ref,
|
||||
requestIds: observable.shallow,
|
||||
requests: observable,
|
||||
targetProjectIds: observable.shallow,
|
||||
targetProjects: observable,
|
||||
targetOptionsMap: observable,
|
||||
openRequestIds: computed,
|
||||
closedRequestIds: computed,
|
||||
filteredRequestIds: computed,
|
||||
fetchTargetProjects: action,
|
||||
fetchTargetOptions: action,
|
||||
fetchRequests: action,
|
||||
fetchRequestById: action,
|
||||
createRequest: action,
|
||||
|
|
@ -82,6 +103,9 @@ export class ProjectExternalContoursStore implements IProjectExternalContoursSto
|
|||
}
|
||||
|
||||
getRequestById = (requestId: string) => this.requests[requestId];
|
||||
getTargetProjectById = (projectId: string | null | undefined) => (projectId ? this.targetProjects[projectId] : undefined);
|
||||
getTargetOptionsByProjectId = (projectId: string | null | undefined) =>
|
||||
projectId ? this.targetOptionsMap[projectId] : undefined;
|
||||
|
||||
getIsRequestAvailable = (requestId: string) => this.requestIds.includes(requestId);
|
||||
|
||||
|
|
@ -97,6 +121,40 @@ export class ProjectExternalContoursStore implements IProjectExternalContoursSto
|
|||
});
|
||||
};
|
||||
|
||||
fetchTargetProjects = async (workspaceSlug: string, projectId: string) => {
|
||||
try {
|
||||
const projects = await this.externalContourService.listTargetProjects(workspaceSlug, projectId);
|
||||
runInAction(() => {
|
||||
this.targetProjectIds = [];
|
||||
this.targetProjects = {};
|
||||
projects.forEach((project) => {
|
||||
set(this.targetProjects, project.id, project);
|
||||
this.targetProjectIds.push(project.id);
|
||||
});
|
||||
});
|
||||
} catch (error) {
|
||||
runInAction(() => {
|
||||
this.targetProjectIds = [];
|
||||
this.targetProjects = {};
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
fetchTargetOptions = async (workspaceSlug: string, projectId: string, targetProjectId: string) => {
|
||||
try {
|
||||
const options = await this.externalContourService.retrieveTargetOptions(workspaceSlug, projectId, targetProjectId);
|
||||
runInAction(() => {
|
||||
set(this.targetOptionsMap, targetProjectId, options);
|
||||
set(this.targetProjects, targetProjectId, options.project);
|
||||
if (!this.targetProjectIds.includes(targetProjectId)) this.targetProjectIds.push(targetProjectId);
|
||||
});
|
||||
return options;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
handleCurrentTab = async (workspaceSlug: string, projectId: string, tab: TInboxIssueCurrentTab) => {
|
||||
this.currentTab = tab;
|
||||
await this.fetchRequests(workspaceSlug, projectId, tab);
|
||||
|
|
|
|||
|
|
@ -335,6 +335,8 @@ export default {
|
|||
add_due_date: "Add due date",
|
||||
duplicate_of: "Duplicate of",
|
||||
},
|
||||
readonly_source_view:
|
||||
"This request is shown in source-side mode. Direct access to the target contour is not required, and detailed activity and attachments will be synchronized in the next stage.",
|
||||
traceability: {
|
||||
title: "Routing",
|
||||
description:
|
||||
|
|
|
|||
|
|
@ -492,6 +492,8 @@ export default {
|
|||
add_due_date: "Добавить срок выполнения",
|
||||
duplicate_of: "Дубликат",
|
||||
},
|
||||
readonly_source_view:
|
||||
"Запрос показан в source-side режиме. Прямой доступ к целевому контуру не требуется, а подробная активность и вложения будут синхронизированы следующим этапом.",
|
||||
traceability: {
|
||||
title: "Маршрутизация",
|
||||
description: "Здесь отображается, из какого контура ушёл запрос, куда он направлен и с каким связанным элементом он сейчас работает.",
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
import type { TPaginationInfo } from "./common";
|
||||
import type { TIssue } from "./issues/issue";
|
||||
import type { IIssueLabel } from "./issues";
|
||||
import type { IProjectLite } from "./project";
|
||||
import type { IStateLite } from "./state";
|
||||
import type { IUser } from "./users";
|
||||
|
|
@ -37,3 +38,13 @@ export type TExternalContourRequest = {
|
|||
export type TExternalContourRequestResponse = TPaginationInfo & {
|
||||
results: TExternalContourRequest[];
|
||||
};
|
||||
|
||||
export type TExternalContourTargetProject = IProjectLite & {
|
||||
inbox_view: boolean;
|
||||
};
|
||||
|
||||
export type TExternalContourTargetOptions = {
|
||||
project: TExternalContourTargetProject;
|
||||
member_ids: string[];
|
||||
labels: Pick<IIssueLabel, "id" | "name" | "color" | "parent" | "project_id" | "workspace_id" | "sort_order">[];
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue