Skip to content

Commit

Permalink
feat: use new query on tests and boots tab
Browse files Browse the repository at this point in the history
  • Loading branch information
loadez committed Sep 12, 2024
1 parent 07d182f commit acc2317
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 112 deletions.
30 changes: 4 additions & 26 deletions dashboard/src/api/TreeDetails.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { useQuery, UseQueryResult } from '@tanstack/react-query';

import {
TTreeTestsData,
BuildsTab,
TTreeDetailsFilter,
TTestByCommitHashResponse,
TTreeCommitHistoryResponse,
BuildCountsResponse,
TTreeTestsFullData,
} from '@/types/tree/TreeDetails';

import { TPathTests } from '@/types/general';
Expand Down Expand Up @@ -60,49 +60,27 @@ const fetchTreeTestsData = async (
git_url: string;
},
filter: TTreeDetailsFilter = {},
): Promise<TTreeTestsData> => {
): Promise<TTreeTestsFullData> => {
const urlParams = mapFiltersToUrlSearchParams(filter);
if (params !== undefined) {
Object.entries(params).forEach(([k, v]) =>
urlParams.append(k, v.toString()),
);
}
const res = await http.get<TTreeTestsData>(`/api/tree/${treeId}/tests`, {
const res = await http.get<TTreeTestsFullData>(`/api/tree/${treeId}/full`, {
params: urlParams,
});

return res.data;
};

export const useBootsTab = (
treeId: string,
origin: string,
git_branch: string,
git_url: string,
filter: TTreeDetailsFilter,
): UseQueryResult<TTreeTestsData> => {
const params = {
path: 'boot.',
origin: origin,
git_branch: git_branch,
git_url: git_url,
};

const bootsFilter = getTargetFilter(filter, 'boot');

return useQuery({
queryKey: ['treeBootTests', treeId, bootsFilter, params],
queryFn: () => fetchTreeTestsData(treeId, params, bootsFilter),
});
};

export const useTestsTab = (
treeId: string,
origin: string,
git_branch: string,
git_url: string,
filter: TTreeDetailsFilter,
): UseQueryResult<TTreeTestsData> => {
): UseQueryResult<TTreeTestsFullData> => {
const params = {
origin: origin,
git_branch: git_branch,
Expand Down
41 changes: 21 additions & 20 deletions dashboard/src/components/Table/BootsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import { TableInfo } from '@/components/Table/TableInfo';
import { TableCell, TableRow } from '@/components/ui/table';
import { usePagination } from '@/hooks/usePagination';

import { useTestsByTreeAndCommitHash } from '@/api/TreeDetails';

import {
TTestByCommitHashResponse,
TestByCommitHash,
TestHistory,
TestsTableFilter,
possibleTestsTableFilter,
} from '@/types/tree/TreeDetails';
Expand Down Expand Up @@ -42,27 +43,31 @@ const ITEMS_PER_PAGE = 10;

export interface ITestsTable {
treeId: string;
isBootTable?: boolean;
testHistory: TestHistory[];
}

const BootsTable = ({
treeId,
isBootTable = false,
}: ITestsTable): JSX.Element => {
const BootsTable = ({ treeId, testHistory }: ITestsTable): JSX.Element => {
const navigate = useNavigate({ from: '/tree/$treeId' });
const intl = useIntl();
const { origin, treeInfo, diffFilter } = useSearch({
const { diffFilter } = useSearch({
from: '/tree/$treeId/',
});
const { tableFilter } = useSearch({
from: '/tree/$treeId/',
});
const { data, error, isLoading } = useTestsByTreeAndCommitHash(
treeId,
isBootTable,
origin,
treeInfo.gitUrl,
treeInfo.gitBranch,
const data = useMemo(
(): TTestByCommitHashResponse => ({
tests: testHistory.map(
(e): TestByCommitHash => ({
duration: e.duration?.toString() ?? '',
id: e.id,
path: e.path,
startTime: e.startTime,
status: e.status,
}),
),
}),
[testHistory],
);

const onClickName = useCallback(
Expand Down Expand Up @@ -105,7 +110,7 @@ const BootsTable = ({
useState<TestsTableFilter>(tableFilter.bootsTable);

const rows = useMemo(() => {
if (!data || error) return <></>;
if (!data) return <></>;

if (filteredData?.length === 0) {
return (
Expand All @@ -126,7 +131,7 @@ const BootsTable = ({
</TableCell>
</TableRow>
));
}, [filteredData, data, error, startIndex, endIndex, onClickName]);
}, [filteredData, data, startIndex, endIndex, onClickName]);

const tableInfoElement = (
<div className="flex flex-col items-end">
Expand Down Expand Up @@ -190,10 +195,6 @@ const BootsTable = ({
[intl, checkIfFilterIsSelected],
);

if (error) return <FormattedMessage id="global.error" />;

if (isLoading) return <FormattedMessage id="global.loading" />;

return (
<div className="flex flex-col gap-6">
<div className="flex flex-row justify-between">
Expand Down
82 changes: 60 additions & 22 deletions dashboard/src/components/Table/TestsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,19 @@ import { useNavigate, useSearch } from '@tanstack/react-router';

import { useMemo } from 'react';

import { useIntl, FormattedMessage } from 'react-intl';
import { useIntl } from 'react-intl';

import { TableInfo } from '@/components/Table/TableInfo';
import { usePagination } from '@/hooks/usePagination';

import { useTreeTest } from '@/api/TreeDetails';

import {
TestHistory,
TestsTableFilter,
possibleTestsTableFilter,
} from '@/types/tree/TreeDetails';

import { Skeleton } from '@/components/Skeleton';

import { getStatusGroup } from '@/utils/status';
import { TPathTests } from '@/types/general';

import Accordion from '../Accordion/Accordion';

Expand All @@ -25,21 +23,68 @@ import TableStatusFilter from './TableStatusFilter';
const ITEMS_PER_PAGE = 10;

export interface ITestsTable {
treeId: string;
testHistory: TestHistory[];
}

const TestsTable = ({ treeId }: ITestsTable): JSX.Element => {
const { testPath, treeInfo, origin, tableFilter } = useSearch({
const TestsTable = ({ testHistory }: ITestsTable): JSX.Element => {
const { tableFilter } = useSearch({
from: '/tree/$treeId/',
});
const navigate = useNavigate({ from: '/tree/$treeId' });
const { data, isLoading } = useTreeTest(
treeId,
testPath,
treeInfo.gitBranch ?? '',
treeInfo.gitUrl ?? '',
origin,
);

const data = useMemo((): TPathTests[] => {
type Groups = {
[K: string]: TPathTests;
};
const groups: Groups = {};
testHistory.forEach(e => {
const parts = e.path.split('.', 1);
const group = parts.length > 0 ? parts[0] : '-';
if (!(group in groups)) {
groups[group] = {
done_tests: 0,
fail_tests: 0,
miss_tests: 0,
pass_tests: 0,
null_tests: 0,
skip_tests: 0,
error_tests: 0,
total_tests: 0,
path_group: group,
individual_tests: [],
};
}
groups[group].total_tests++;
groups[group].individual_tests.push({
duration: e.duration?.toString() ?? '',
path: e.path,
start_time: e.startTime,
status: e.status,
});
switch (e.status) {
case 'DONE':
groups[group].done_tests++;
break;
case 'ERROR':
groups[group].error_tests++;
break;
case 'FAIL':
groups[group].fail_tests++;
break;
case 'MISS':
groups[group].miss_tests++;
break;
case 'PASS':
groups[group].pass_tests++;
break;
case 'SKIP':
groups[group].skip_tests++;
break;
}
});
return Object.values(groups);
}, [testHistory]);

const data_len = data?.length || 0;
const { startIndex, endIndex, onClickGoForward, onClickGoBack } =
usePagination(data_len, ITEMS_PER_PAGE);
Expand Down Expand Up @@ -141,13 +186,6 @@ const TestsTable = ({ treeId }: ITestsTable): JSX.Element => {
}
}, [tableFilter.testsTable, data]);

if (isLoading)
return (
<Skeleton>
<FormattedMessage id="global.loading" />
</Skeleton>
);

return (
<div className="flex flex-col gap-6">
<div className="flex flex-row justify-between">
Expand Down
28 changes: 13 additions & 15 deletions dashboard/src/pages/TreeDetails/Tabs/Boots/BootsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { FormattedMessage } from 'react-intl';

import { useParams, useSearch } from '@tanstack/react-router';

import { useBootsTab } from '@/api/TreeDetails';
import { useTestsTab } from '@/api/TreeDetails';
import BaseCard from '@/components/Cards/BaseCard';
import { Skeleton } from '@/components/Skeleton';

Expand Down Expand Up @@ -34,7 +34,7 @@ const BootsTab = ({ reqFilter }: BootsTabProps): JSX.Element => {
const { origin, treeInfo } = useSearch({
from: '/tree/$treeId/',
});
const { isLoading, data, error } = useBootsTab(
const { isLoading, data, error } = useTestsTab(
treeId ?? '',
origin,
treeInfo.gitBranch ?? '',
Expand Down Expand Up @@ -78,61 +78,59 @@ const BootsTab = ({ reqFilter }: BootsTabProps): JSX.Element => {
<div>
<MemoizedStatusChart
title={<FormattedMessage id="bootsTab.bootStatus" />}
statusCounts={data.statusCounts}
statusCounts={data.bootStatusSummary}
/>
<MemoizedConfigList
title={<FormattedMessage id="bootsTab.configs" />}
configStatusCounts={data.configStatusCounts}
configStatusCounts={data.bootConfigs}
/>
<MemoizedErrorsSummary
title={<FormattedMessage id="global.summary" />}
architectureStatusCounts={data.architectureStatusCounts}
compilersPerArchitecture={data.compilersPerArchitecture}
archCompilerErrors={data.bootArchSummary}
/>
</div>
<div>
<CommitNavigationGraph />
<MemoizedPlatformsWithError
title={<FormattedMessage id="bootsTab.platformsFailingAtBoot" />}
platformsWithError={data.platformsWithError}
platformsWithError={data.bootPlatformsFailing}
/>
<MemoizedErrorCountList
title={<FormattedMessage id="bootsTab.fail" />}
errorMessageCounts={data.errorMessageCounts}
errorMessageCounts={data.bootFailReasons}
/>
</div>
</DesktopGrid>
<MobileGrid>
<MemoizedStatusChart
title={<FormattedMessage id="bootsTab.bootStatus" />}
statusCounts={data.statusCounts}
statusCounts={data.bootStatusSummary}
/>
<CommitNavigationGraph />
<InnerMobileGrid>
<div>
<MemoizedConfigList
title={<FormattedMessage id="bootsTab.configs" />}
configStatusCounts={data.configStatusCounts}
configStatusCounts={data.bootConfigs}
/>
<MemoizedErrorsSummary
title={<FormattedMessage id="global.summary" />}
architectureStatusCounts={data.architectureStatusCounts}
compilersPerArchitecture={data.compilersPerArchitecture}
archCompilerErrors={data.bootArchSummary}
/>
</div>
<div>
<MemoizedPlatformsWithError
title={<FormattedMessage id="bootsTab.platformsFailingAtBoot" />}
platformsWithError={data.platformsWithError}
platformsWithError={data.bootPlatformsFailing}
/>
<MemoizedErrorCountList
title={<FormattedMessage id="bootsTab.fail" />}
errorMessageCounts={data.errorMessageCounts}
errorMessageCounts={data.bootFailReasons}
/>
</div>
</InnerMobileGrid>
</MobileGrid>
<BootsTable treeId={treeId} isBootTable={true} />
<BootsTable treeId={treeId} testHistory={data.bootHistory} />
</div>
);
};
Expand Down
Loading

0 comments on commit acc2317

Please sign in to comment.