mirror of
https://github.com/makeplane/plane.git
synced 2026-07-13 22:09:12 +02:00
[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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user