Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: analytic query params #1035

Merged
merged 2 commits into from
May 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 10 additions & 27 deletions apiserver/plane/api/views/analytic.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from plane.api.serializers import AnalyticViewSerializer
from plane.utils.analytics_plot import build_graph_plot
from plane.bgtasks.analytic_plot_export import analytic_export_task
from plane.utils.issue_filters import issue_filters


class AnalyticsEndpoint(BaseAPIView):
Expand All @@ -44,19 +45,10 @@ def get(self, request, slug):
status=status.HTTP_400_BAD_REQUEST,
)

project_ids = request.GET.getlist("project")
cycle_ids = request.GET.getlist("cycle")
module_ids = request.GET.getlist("module")

segment = request.GET.get("segment", False)
filters = issue_filters(request.GET, "GET")

queryset = Issue.objects.filter(workspace__slug=slug)
if project_ids:
queryset = queryset.filter(project_id__in=project_ids)
if cycle_ids:
queryset = queryset.filter(issue_cycle__cycle_id__in=cycle_ids)
if module_ids:
queryset = queryset.filter(issue_module__module_id__in=module_ids)
queryset = Issue.objects.filter(workspace__slug=slug, **filters)

total_issues = queryset.count()
distribution = build_graph_plot(
Expand All @@ -75,18 +67,18 @@ def get(self, request, slug):

colors = (
State.objects.filter(
workspace__slug=slug, project_id__in=project_ids
workspace__slug=slug, project_id__in=filters.get("project__in")
).values(key, "color")
if project_ids
if filters.get("project__in", False)
else State.objects.filter(workspace__slug=slug).values(key, "color")
)

if x_axis in ["labels__name"] or segment in ["labels__name"]:
colors = (
Label.objects.filter(
workspace__slug=slug, project_id__in=project_ids
workspace__slug=slug, project_id__in=filters.get("project__in")
).values("name", "color")
if project_ids
if filters.get("project__in", False)
else Label.objects.filter(workspace__slug=slug).values(
"name", "color"
)
Expand Down Expand Up @@ -213,18 +205,9 @@ class DefaultAnalyticsEndpoint(BaseAPIView):

def get(self, request, slug):
try:
queryset = Issue.objects.filter(workspace__slug=slug)

project_ids = request.GET.getlist("project")
cycle_ids = request.GET.getlist("cycle")
module_ids = request.GET.getlist("module")

if project_ids:
queryset = queryset.filter(project_id__in=project_ids)
if cycle_ids:
queryset = queryset.filter(issue_cycle__cycle_id__in=cycle_ids)
if module_ids:
queryset = queryset.filter(issue_module__module_id__in=module_ids)
filters = issue_filters(request.GET, "GET")

queryset = Issue.objects.filter(workspace__slug=slug, **filters)

total_issues = queryset.count()

Expand Down