-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use TestTable in BuildDetails page
- Loading branch information
1 parent
fd741e0
commit 559df75
Showing
8 changed files
with
89 additions
and
187 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,25 @@ | ||
from django.http import JsonResponse | ||
from django.views import View | ||
from django.db.models import Q, TextField, Sum, Count, Case, When, F, Func, Value, Min | ||
from django.db.models.functions import Concat | ||
from django.contrib.postgres.aggregates import ArrayAgg | ||
|
||
from kernelCI_app.models import Tests | ||
from kernelCI_app.serializers import BuildTestsSerializer | ||
|
||
|
||
class BuildTests(View): | ||
|
||
def get(self, request, build_id): | ||
path = request.GET.get('path', '') | ||
path_level = 1 | ||
|
||
if path: | ||
if not path.endswith('.'): | ||
path += '.' | ||
path_level += path.count('.') | ||
filterQ = Q(path__startswith=path) | Q(path=path.rstrip('.')) | ||
else: | ||
filterQ = Q(path__startswith=path) | ||
|
||
result = ( | ||
Tests.objects | ||
.filter(filterQ, build=build_id,) | ||
.values( | ||
path_sublevel=Func( | ||
F('path'), Value('.'), Value(path_level), | ||
function='SPLIT_PART', output_field=TextField())) | ||
.annotate( | ||
fail_tests=Sum(Case(When(status='FAIL', then=1), default=0)), | ||
error_tests=Sum(Case(When(status='ERROR', then=1), default=0)), | ||
miss_tests=Sum(Case(When(status='MISS', then=1), default=0)), | ||
pass_tests=Sum(Case(When(status='PASS', then=1), default=0)), | ||
done_tests=Sum(Case(When(status='DONE', then=1), default=0)), | ||
skip_tests=Sum(Case(When(status='SKIP', then=1), default=0)), | ||
null_tests=Sum(Case(When(status__isnull=True, then=1), default=0)), | ||
total_tests=Count('id'), | ||
current_path=Concat(Value(path), F('path_sublevel'), output_field=TextField()), | ||
origins=ArrayAgg('origin', distinct=True), | ||
start_time=Min('start_time'), | ||
) | ||
result = Tests.objects.filter(build_id=build_id).values( | ||
'id', 'duration', 'status', 'path', 'start_time' | ||
) | ||
|
||
serializer = BuildTestsSerializer(result, many=True) | ||
return JsonResponse(serializer.data, safe=False) | ||
camel_case_result = [ | ||
{ | ||
'id': test['id'], | ||
'duration': test['duration'], | ||
'status': test['status'], | ||
'path': test['path'], | ||
'startTime': test['start_time'], | ||
} | ||
for test in result | ||
] | ||
|
||
return JsonResponse(camel_case_result, safe=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,20 @@ | ||
import { useQuery, UseQueryResult } from '@tanstack/react-query'; | ||
|
||
import { TBuildTests } from '@/types/general'; | ||
import { TestHistory } from '@/types/general'; | ||
|
||
import http from './api'; | ||
|
||
const fetchBuildTestsData = async ( | ||
buildId: string, | ||
path: string, | ||
): Promise<TBuildTests[]> => { | ||
const params = path ? { path } : {}; | ||
const res = await http.get(`/api/build/${buildId}/tests`, { params }); | ||
const fetchBuildTestsData = async (buildId: string): Promise<TestHistory[]> => { | ||
const res = await http.get(`/api/build/${buildId}/tests`); | ||
|
||
return res.data; | ||
}; | ||
|
||
export const useBuildTests = ( | ||
buildId: string, | ||
path = '', | ||
): UseQueryResult<TBuildTests[]> => { | ||
): UseQueryResult<TestHistory[]> => { | ||
return useQuery({ | ||
queryKey: ['buildTests', buildId, path], | ||
queryFn: () => fetchBuildTestsData(buildId, path), | ||
queryKey: ['buildTests', buildId], | ||
queryFn: () => fetchBuildTestsData(buildId), | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,16 @@ | ||
import { createFileRoute } from '@tanstack/react-router'; | ||
|
||
import { z } from 'zod'; | ||
|
||
import BuildDetails from '@/pages/BuildDetails/BuildDetails'; | ||
|
||
import { zTableFilterInfo } from '@/types/tree/TreeDetails'; | ||
|
||
const buildDetailsSearchSchema = z.object({ | ||
tableFilter: zTableFilterInfo, | ||
}); | ||
|
||
export const Route = createFileRoute('/tree/$treeId/build/$buildId/')({ | ||
component: BuildDetails, | ||
validateSearch: buildDetailsSearchSchema, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters