Skip to content

Commit

Permalink
feat: small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
theodu committed Aug 25, 2023
1 parent b911848 commit b18ce31
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 42 deletions.
13 changes: 0 additions & 13 deletions src/kili/core/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,6 @@
"VIDEO_LEGACY",
]


IssueStatus = Literal[
"OPEN",
"SOLVED",
]


IssueType = Literal[
"ISSUE",
"QUESTION",
]


LabelFormat = Literal[
"RAW",
"SIMPLE",
Expand Down
34 changes: 7 additions & 27 deletions src/kili/gateways/kili_api_gateway/issue/__init__.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,21 @@
"""GraphQL Mixin extending GraphQL Gateway class with Issue related operations."""
"""Mixin extending Kili API Gateway class with Issue related operations."""

from dataclasses import dataclass
from typing import List, Optional

from kili.core.enums import IssueStatus
from kili.core.graphql.graphql_client import GraphQLClient
from kili.core.utils.pagination import BatchIteratorBuilder
from kili.domain.issue import Issue, IssueType
from kili.domain.issue import Issue, IssueStatus, IssueType
from kili.gateways.kili_api_gateway.issue.operations import (
GQL_COUNT_ISSUES,
GQL_CREATE_ISSUES,
)
from kili.gateways.kili_api_gateway.issue.types import IssueToCreateKiliAPIGatewayInput
from kili.gateways.kili_api_gateway.issue.types import (
IssueToCreateKiliAPIGatewayInput,
IssueWhere,
)
from kili.utils import tqdm


@dataclass
class IssueWhere:
"""Tuple to be passed to the IssueQuery to restrict query."""

project_id: str
asset_id: Optional[str] = None
asset_id_in: Optional[List[str]] = None
issue_type: Optional[IssueType] = None
status: Optional[IssueStatus] = None

def get_graphql_input(self):
"""Build the GraphQL IssueWhere payload to be sent in an operation."""
return {
"project": {"id": self.project_id},
"asset": {"id": self.asset_id},
"assetIn": self.asset_id_in,
"status": self.status,
"type": self.issue_type,
}


class IssueOperationMixin:
"""GraphQL Mixin extending GraphQL Gateway class with Issue related operations."""

Expand Down Expand Up @@ -82,7 +62,7 @@ def count_issues( # pylint: disable=too-many-arguments,
"""Send a GraphQL request calling countIssues resolver."""
where = IssueWhere(project_id, asset_id, asset_id_in, issue_type, status)
payload = {
"where": where.get_graphql_input(),
"where": where.get_graphql_where_value(),
}
count_result = self.graphql_client.execute(GQL_COUNT_ISSUES, payload)
return count_result["data"]
25 changes: 24 additions & 1 deletion src/kili/gateways/kili_api_gateway/issue/types.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Types for the Issue-related Kili API gateway functions."""
from dataclasses import dataclass
from typing import Optional
from typing import List, Optional

from kili.domain.issue import IssueStatus, IssueType


@dataclass
Expand All @@ -12,3 +14,24 @@ class IssueToCreateKiliAPIGatewayInput:
object_mid: Optional[str]
asset_id: str
text: Optional[str]


@dataclass
class IssueWhere:
"""Tuple to be passed to the IssueQuery to restrict query."""

project_id: str
asset_id: Optional[str] = None
asset_id_in: Optional[List[str]] = None
issue_type: Optional[IssueType] = None
status: Optional[IssueStatus] = None

def get_graphql_where_value(self):
"""Build the GraphQL IssueWhere variable value to be sent in an operation."""
return {
"project": {"id": self.project_id},
"asset": {"id": self.asset_id},
"assetIn": self.asset_id_in,
"status": self.status,
"type": self.issue_type,
}
2 changes: 1 addition & 1 deletion src/kili/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from kili.core.enums import (
InputType,
IssueStatus,
LabelType,
LicenseType,
LockType,
Expand All @@ -17,6 +16,7 @@
Status,
)
from kili.core.helpers import deprecate
from kili.domain.issue import IssueStatus


#######
Expand Down

0 comments on commit b18ce31

Please sign in to comment.