From 73672cafce85c83c64dfc1abeb7adee36730fc30 Mon Sep 17 00:00:00 2001 From: guru_sainath Date: Thu, 1 May 2025 18:37:01 +0530 Subject: [PATCH] [MOBIL-907] chore: ddd order field in states list for rendering state icons (#3092) * chore: added order in states list * chore: handled the default as 1 for state order * chore: handled the default as null for state order --- apiserver/plane/graphql/types/state.py | 32 ++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/apiserver/plane/graphql/types/state.py b/apiserver/plane/graphql/types/state.py index a2cdf8172d..fa9e91c5e7 100644 --- a/apiserver/plane/graphql/types/state.py +++ b/apiserver/plane/graphql/types/state.py @@ -1,11 +1,26 @@ +# Third-party library imports +from typing import Optional + # Strawberry Imports import strawberry import strawberry_django +# Django Imports +from asgiref.sync import sync_to_async + # Module imports from plane.db.models import State +@sync_to_async +def get_group_states(project_id: str, state_group: str) -> list[State]: + states = State.objects.filter( + project_id=project_id, group=state_group, deleted_at__isnull=True + ).order_by("sequence") + + return list(states) + + @strawberry_django.type(State) class StateType: id: strawberry.ID @@ -27,3 +42,20 @@ class StateType: @strawberry.field def project(self) -> int: return self.project_id + + @strawberry.field + async def order(self) -> Optional[float]: + if self.group in ["started", "unstarted"]: + project_id = self.project_id + state_group = self.group + + group_states = await get_group_states( + project_id=project_id, state_group=state_group + ) + + current_state_index = group_states.index(self) + 1 + group_states_count = len(group_states) + + return current_state_index / group_states_count + + return None