Skip to content

Commit 7d53fde

Browse files
fixup! feat(dashboard): add labs listing page
Signed-off-by: Felipe Bergamin <felipebergamin6@gmail.com>
1 parent fd52fdc commit 7d53fde

4 files changed

Lines changed: 9 additions & 47 deletions

File tree

dashboard/src/api/labs.ts

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,24 @@ import { RequestData } from './commonRequest';
1111

1212
const fetchLabsListing = async (
1313
origin: string,
14-
startTimestampInSeconds: number,
15-
endTimestampInSeconds: number,
14+
intervalInDays: number,
1615
): Promise<LabListingResponse> => {
1716
return RequestData.get<LabListingResponse>('/api/labs/', {
1817
params: {
19-
startTimestampInSeconds,
20-
endTimestampInSeconds,
2118
origin,
19+
interval_in_days: intervalInDays,
2220
},
2321
});
2422
};
2523

2624
export const useLabsListing = (
27-
startTimestampInSeconds: number,
28-
endTimestampInSeconds: number,
2925
searchFrom: LabsListingRoutesMap['search'],
3026
): UseQueryResult<LabListingResponse> => {
31-
const { origin } = useSearch({ from: searchFrom });
27+
const { origin, intervalInDays } = useSearch({ from: searchFrom });
3228

3329
return useQuery({
34-
queryKey: [
35-
'labsListing',
36-
startTimestampInSeconds,
37-
endTimestampInSeconds,
38-
origin,
39-
],
40-
queryFn: () =>
41-
fetchLabsListing(origin, startTimestampInSeconds, endTimestampInSeconds),
30+
queryKey: ['labsListing', origin, intervalInDays],
31+
queryFn: () => fetchLabsListing(origin, intervalInDays),
4232
refetchOnWindowFocus: false,
4333
});
4434
};

dashboard/src/pages/Labs/LabsPage.tsx

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import { useMemo, type JSX } from 'react';
22

3-
import { roundToNearestMinutes } from 'date-fns';
4-
5-
import { useSearch } from '@tanstack/react-router';
6-
73
import type { LabListingItem } from '@/types/lab';
84

95
import { useLabsListing } from '@/api/labs';
@@ -14,9 +10,6 @@ import { matchesRegexOrIncludes } from '@/lib/string';
1410

1511
import type { LabsListingRoutesMap } from '@/utils/constants/labsListing';
1612

17-
import { dateObjectToTimestampInSeconds, daysToSeconds } from '@/utils/date';
18-
import { REDUCED_TIME_SEARCH } from '@/utils/constants/general';
19-
2013
import { LabsTable } from './LabsTable';
2114

2215
export function LabsPage({
@@ -26,25 +19,7 @@ export function LabsPage({
2619
inputFilter: string;
2720
urlFromMap: LabsListingRoutesMap;
2821
}): JSX.Element {
29-
const { intervalInDays = REDUCED_TIME_SEARCH } = useSearch({
30-
from: urlFromMap.search,
31-
});
32-
33-
const { startTimestampInSeconds, endTimestampInSeconds } = useMemo(() => {
34-
const end = dateObjectToTimestampInSeconds(
35-
roundToNearestMinutes(new Date(), { nearestTo: 30 }),
36-
);
37-
return {
38-
startTimestampInSeconds: end - daysToSeconds(intervalInDays),
39-
endTimestampInSeconds: end,
40-
};
41-
}, [intervalInDays]);
42-
43-
const { data, error, status, isLoading } = useLabsListing(
44-
startTimestampInSeconds,
45-
endTimestampInSeconds,
46-
urlFromMap.search,
47-
);
22+
const { data, error, status, isLoading } = useLabsListing(urlFromMap.search);
4823

4924
const listItems: LabListingItem[] = useMemo(() => {
5025
if (!data) {

dashboard/src/pages/Labs/LabsTable.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
} from '@/components/Table/PaginationInfo';
3232

3333
import type { LabListingItem } from '@/types/lab';
34+
import type { ShortStatusCount } from '@/types/general';
3435

3536
import { sumStatus } from '@/utils/status';
3637

@@ -41,9 +42,7 @@ import { MemoizedSectionError } from '@/components/DetailsPages/SectionError';
4142

4243
import type { LabsListingRoutesMap } from '@/utils/constants/labsListing';
4344

44-
const statusCell = (
45-
summary: LabListingItem['build_status_summary'],
46-
): JSX.Element => (
45+
const statusCell = (summary: ShortStatusCount): JSX.Element => (
4746
<GroupedTestStatus
4847
preCalculatedGroupedStatus={{
4948
successCount: summary.PASS,

dashboard/src/types/lab.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ export type LabListingItem = {
77
test_status_summary: ShortStatusCount;
88
};
99

10-
export type LabListingApiItem = LabListingItem;
11-
1210
export interface LabListingResponse {
13-
labs: LabListingApiItem[];
11+
labs: LabListingItem[];
1412
}

0 commit comments

Comments
 (0)