Skip to content

Commit f6bd778

Browse files
feat: add job_count and project_count to environment list API
BE: Query UserTaskDetails and ProjectDetails counts per environment FE: Wire "Used by" column to show "X jobs · Y projects" from API data
1 parent d376890 commit f6bd778

2 files changed

Lines changed: 31 additions & 5 deletions

File tree

backend/backend/application/session/env_session.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from backend.application.utils import get_filter
77
from backend.core.models.environment_models import EnvironmentModels
88
from backend.core.models.project_details import ProjectDetails
9+
from backend.core.scheduler.models import UserTaskDetails
910
from backend.errors.exceptions import EnvironmentAlreadyExist, EnvironmentNotExists
1011
from backend.utils.pagination import CustomPaginator
1112

@@ -89,6 +90,12 @@ def get_all_environments(self, page: int, limit: int, filter_condition: dict[str
8990

9091
env_data = []
9192
for env_model in env_models.get("page_items"):
93+
job_count = UserTaskDetails.objects.filter(
94+
environment=env_model
95+
).count()
96+
project_count = ProjectDetails.objects.filter(
97+
environment_model=env_model
98+
).count()
9299
env_data.append(
93100
{
94101
"id": env_model.environment_id,
@@ -104,6 +111,8 @@ def get_all_environments(self, page: int, limit: int, filter_condition: dict[str
104111
"connection_flag": env_model.connection_model.connection_flag,
105112
},
106113
"is_tested": env_model.is_tested,
114+
"job_count": job_count,
115+
"project_count": project_count,
107116
}
108117
)
109118
env_models["page_items"] = env_data

frontend/src/base/components/environment/EnvList.jsx

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -304,11 +304,28 @@ const EnvList = () => {
304304
title: "Used by",
305305
key: "usedBy",
306306
width: 140,
307-
render: () => (
308-
<Text type="secondary" style={{ fontSize: 12 }}>
309-
310-
</Text>
311-
),
307+
render: (_, record) => {
308+
const jobs = record.job_count || 0;
309+
const projects = record.project_count || 0;
310+
if (jobs === 0 && projects === 0) {
311+
return (
312+
<Text
313+
type="secondary"
314+
style={{ fontSize: 12, fontStyle: "italic" }}
315+
>
316+
Not used
317+
</Text>
318+
);
319+
}
320+
return (
321+
<Text type="secondary" style={{ fontSize: 12 }}>
322+
{jobs > 0 && `${jobs} job${jobs !== 1 ? "s" : ""}`}
323+
{jobs > 0 && projects > 0 && " · "}
324+
{projects > 0 &&
325+
`${projects} project${projects !== 1 ? "s" : ""}`}
326+
</Text>
327+
);
328+
},
312329
},
313330
{
314331
title: "Actions",

0 commit comments

Comments
 (0)