Skip to content

Commit

Permalink
refactor: test details page
Browse files Browse the repository at this point in the history
- reuse test details component in tree and hardware context

Close #507
  • Loading branch information
Francisco2002 committed Nov 6, 2024
1 parent 6ab22f9 commit 8cb0bd9
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 56 deletions.
Original file line number Diff line number Diff line change
@@ -1,37 +1,23 @@
import { useParams, useSearch } from '@tanstack/react-router';

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

import { GiFlatPlatform } from 'react-icons/gi';

import { useMemo } from 'react';

import { PiComputerTowerThin } from 'react-icons/pi';

import { GiFlatPlatform } from 'react-icons/gi';

import { MdFolderOpen } from 'react-icons/md';

import { useTestDetails, useTestIssues } from '@/api/TestDetails';

import type { TTestDetails } from '@/types/tree/TestDetails';

import type { ISubsection } from '@/components/Section/Section';
import { Subsection } from '@/components/Section/Section';

import {
Breadcrumb,
BreadcrumbItem,
BreadcrumbLink,
BreadcrumbList,
BreadcrumbPage,
BreadcrumbSeparator,
} from '@/components/Breadcrumb/Breadcrumb';
import IssueSection from '@/components/Issue/IssueSection';
import { truncateBigText } from '@/lib/string';
import type { TTestDetails } from '@/types/tree/TestDetails';
import { Sheet, SheetTrigger } from '@/components/Sheet';
import { useTestDetails, useTestIssues } from '@/api/TestDetails';

import { TooltipDateTime } from '@/components/TooltipDateTime';
import { LogSheet } from '@/pages/TreeDetails/Tabs/LogSheet';

import { LogSheet } from '../TreeDetails/Tabs/LogSheet';
import { Subsection } from '../Section/Section';
import type { ISubsection } from '../Section/Section';
import { TooltipDateTime } from '../TooltipDateTime';
import IssueSection from '../Issue/IssueSection';

const emptyValue = '-';
const valueOrEmpty = (value: string | undefined): string => value || emptyValue;
Expand Down Expand Up @@ -131,11 +117,17 @@ const TestDetailsSection = ({ test }: { test: TTestDetails }): JSX.Element => {
return <Subsection infos={infos} />;
};

const TestDetails = (): JSX.Element => {
const searchParams = useSearch({ from: '/tree/$treeId/test/$testId/' });
const { testId, treeId } = useParams({ from: '/tree/$treeId/test/$testId/' });
interface TestsDetailsProps {
breadcrumb: JSX.Element;
testId?: string;
}

const TestDetails = ({
breadcrumb,
testId,
}: TestsDetailsProps): JSX.Element => {
const { data, error, isLoading } = useTestDetails(testId ?? '');
const issuesQueryResult = useTestIssues(testId);
const issuesQueryResult = useTestIssues(testId ?? '');

if (error) {
return (
Expand All @@ -158,29 +150,8 @@ const TestDetails = (): JSX.Element => {
return (
<Sheet>
<div className="w-100 px-5 pb-8">
<Breadcrumb className="pb-6 pt-6">
<BreadcrumbList>
<BreadcrumbItem>
<BreadcrumbLink to="/tree" search={searchParams}>
<FormattedMessage id="tree.path" />
</BreadcrumbLink>
</BreadcrumbItem>
<BreadcrumbSeparator />
<BreadcrumbLink
to={`/tree/$treeId`}
params={{ treeId: treeId }}
search={searchParams}
>
<FormattedMessage id="tree.details" />
</BreadcrumbLink>
<BreadcrumbSeparator />
<BreadcrumbItem>
<BreadcrumbPage>
<FormattedMessage id="test.details" />
</BreadcrumbPage>
</BreadcrumbItem>
</BreadcrumbList>
</Breadcrumb>
{breadcrumb}

<h1 className="mb-4 text-2xl font-bold">{data.path}</h1>
<TestDetailsSection test={data} />
<IssueSection {...issuesQueryResult} />
Expand Down
56 changes: 56 additions & 0 deletions dashboard/src/pages/HardwareTestDetails/HardwareTestDetails.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { useParams, useSearch } from '@tanstack/react-router';

import { FormattedMessage } from 'react-intl';

import {
Breadcrumb,
BreadcrumbItem,
BreadcrumbLink,
BreadcrumbList,
BreadcrumbPage,
BreadcrumbSeparator,
} from '@/components/Breadcrumb/Breadcrumb';

import TestDetails from '@/components/TestDetails/TestDetails';

const HardwareTestDetails = (): JSX.Element => {
const searchParams = useSearch({
from: '/hardware/$hardwareId/test/$testId/',
});
const { testId, hardwareId } = useParams({
from: '/hardware/$hardwareId/test/$testId/',
});

return (
<TestDetails
testId={testId}
breadcrumb={
<Breadcrumb className="pb-6 pt-6">
<BreadcrumbList>
<BreadcrumbItem>
<BreadcrumbLink to="/hardware" search={searchParams}>
<FormattedMessage id="hardware.path" />
</BreadcrumbLink>
</BreadcrumbItem>
<BreadcrumbSeparator />
<BreadcrumbLink
to={`/hardware/$hardwareId`}
params={{ hardwareId }}
search={searchParams}
>
<FormattedMessage id="hardware.details" />
</BreadcrumbLink>
<BreadcrumbSeparator />
<BreadcrumbItem>
<BreadcrumbPage>
<FormattedMessage id="test.details" />
</BreadcrumbPage>
</BreadcrumbItem>
</BreadcrumbList>
</Breadcrumb>
}
/>
);
};

export default HardwareTestDetails;
3 changes: 3 additions & 0 deletions dashboard/src/pages/HardwareTestDetails/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import HardwareTestDetails from './HardwareTestDetails';

export default HardwareTestDetails;
3 changes: 0 additions & 3 deletions dashboard/src/pages/TestDetails/index.tsx

This file was deleted.

52 changes: 52 additions & 0 deletions dashboard/src/pages/TreeTestDetails/TreeTestDetails.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { useParams, useSearch } from '@tanstack/react-router';

import { FormattedMessage } from 'react-intl';

import {
Breadcrumb,
BreadcrumbItem,
BreadcrumbLink,
BreadcrumbList,
BreadcrumbPage,
BreadcrumbSeparator,
} from '@/components/Breadcrumb/Breadcrumb';

import TestDetails from '@/components/TestDetails/TestDetails';

const TreeTestDetails = (): JSX.Element => {
const searchParams = useSearch({ from: '/tree/$treeId/test/$testId/' });
const { testId, treeId } = useParams({ from: '/tree/$treeId/test/$testId/' });

return (
<TestDetails
testId={testId}
breadcrumb={
<Breadcrumb className="pb-6 pt-6">
<BreadcrumbList>
<BreadcrumbItem>
<BreadcrumbLink to="/tree" search={searchParams}>
<FormattedMessage id="tree.path" />
</BreadcrumbLink>
</BreadcrumbItem>
<BreadcrumbSeparator />
<BreadcrumbLink
to={`/tree/$treeId`}
params={{ treeId: treeId }}
search={searchParams}
>
<FormattedMessage id="tree.details" />
</BreadcrumbLink>
<BreadcrumbSeparator />
<BreadcrumbItem>
<BreadcrumbPage>
<FormattedMessage id="test.details" />
</BreadcrumbPage>
</BreadcrumbItem>
</BreadcrumbList>
</Breadcrumb>
}
/>
);
};

export default TreeTestDetails;
3 changes: 3 additions & 0 deletions dashboard/src/pages/TreeTestDetails/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import TreeTestDetails from './TreeTestDetails';

export default TreeTestDetails;
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { createFileRoute } from '@tanstack/react-router';

import HardwareTestDetails from '@/pages/HardwareTestDetails';

export const Route = createFileRoute('/hardware/$hardwareId/test/$testId/')({
component: () => <div>Hello /hardware/$hardware/test/$testId/!</div>,
component: () => <HardwareTestDetails />,
});
4 changes: 2 additions & 2 deletions dashboard/src/routes/tree/$treeId/test/$testId/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createFileRoute } from '@tanstack/react-router';

import TestDetails from '@/pages/TestDetails/TestDetails';
import TreeTestDetails from '@/pages/TreeTestDetails/TreeTestDetails';

export const Route = createFileRoute('/tree/$treeId/test/$testId/')({
component: () => <TestDetails />,
component: () => <TreeTestDetails />,
});

0 comments on commit 8cb0bd9

Please sign in to comment.