[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
This commit is contained in:
guru_sainath
2025-05-01 18:37:01 +05:30
committed by GitHub
parent 1a2f9d6fd9
commit 73672cafce

View File

@@ -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