Skip to content

Commit

Permalink
fix(dashboard): fixing datetime at builds list
Browse files Browse the repository at this point in the history
Now tooltip shows right date and time.

Closes #318
  • Loading branch information
Lucas Bracher committed Sep 20, 2024
1 parent 96c292c commit f384e29
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 21 deletions.
2 changes: 2 additions & 0 deletions dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"pypush": "cd .. && cd backend && sh pre-push"
},
"dependencies": {
"@date-fns/tz": "^1.0.1",
"@emotion/react": "^11.13.3",
"@emotion/styled": "^11.13.0",
"@mui/material": "^5.16.7",
Expand All @@ -42,6 +43,7 @@
"class-variance-authority": "^0.7.0",
"classnames": "^2.5.1",
"clsx": "^2.1.1",
"date-fns": "^4.0.0",
"eslint-import-resolver-typescript": "^3.6.3",
"lucide-react": "^0.396.0",
"react": "^18.3.1",
Expand Down
16 changes: 16 additions & 0 deletions dashboard/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 22 additions & 2 deletions dashboard/src/components/Accordion/Accordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import {
CollapsibleTrigger,
} from '@/components/ui/collapsible';

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

import AccordionBuildContent from './BuildAccordionContent';

export interface IAccordion {
Expand Down Expand Up @@ -165,7 +167,18 @@ const AccordionBuildsTrigger = ({
<>
<TableCell>{triggerInfo.config}</TableCell>
<TableCell>{triggerInfo.compiler}</TableCell>
<TableCell>{triggerInfo.date}</TableCell>
<TableCell>
{triggerInfo.date ? (
<TooltipDateTime
dateTime={triggerInfo.date}
lineBreak={true}
showLabelTime={true}
showLabelTZ={true}
/>
) : (
'-'
)}
</TableCell>
<TableCell>
<ColoredCircle
className="max-w-6"
Expand Down Expand Up @@ -255,7 +268,14 @@ const TestTableRow = ({ test, onClick }: ITestTableRow): JSX.Element => {
>
<TableCell>{test.path}</TableCell>
<TableCell>{test.status}</TableCell>
<TableCell>{test.start_time ?? '-'}</TableCell>
<TableCell>
<TooltipDateTime
dateTime={test.start_time}
lineBreak={true}
showLabelTime={true}
showLabelTZ={true}
/>
</TableCell>
<TableCell>{test.duration ?? '-'}</TableCell>
<TableCell>
<ChevronRightAnimate />
Expand Down
10 changes: 9 additions & 1 deletion dashboard/src/components/Table/BootsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useNavigate, useSearch } from '@tanstack/react-router';
import { MdChevronRight } from 'react-icons/md';

import BaseTable from '@/components/Table/BaseTable';
import { TooltipDateTime } from '@/components/TooltipDateTime';
import { TableInfo } from '@/components/Table/TableInfo';
import { TableCell, TableRow } from '@/components/ui/table';
import { usePagination } from '@/hooks/usePagination';
Expand Down Expand Up @@ -124,7 +125,14 @@ const BootsTable = ({ treeId, testHistory }: ITestsTable): JSX.Element => {
<TableRow onClick={() => onClickName(test.id)} key={test.id}>
<TableCell>{test.path}</TableCell>
<TableCell>{test.status}</TableCell>
<TableCell>{test.startTime ?? '-'}</TableCell>
<TableCell>
<TooltipDateTime
dateTime={test.startTime}
lineBreak={true}
showLabelTime={true}
showLabelTZ={true}
/>
</TableCell>
<TableCell>{test.duration ?? '-'}</TableCell>
<TableCell>
<MdChevronRight />
Expand Down
19 changes: 3 additions & 16 deletions dashboard/src/components/Table/TreeTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { TreeTableBody, zOrigin } from '@/types/tree/Tree';

import { TableRow, TableCell, TableBody } from '@/components/ui/table';

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

import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/Tooltip';

import HeaderWithInfo from '@/pages/TreeDetails/Tabs/HeaderWithInfo';
Expand Down Expand Up @@ -101,10 +103,6 @@ const TreeTableRow = (row: TreeTableBody): JSX.Element => {
],
);

const dateObj = new Date(row.date);
const date = dateObj.toLocaleDateString();
const time = dateObj.toLocaleTimeString();

return (
<TableRow>
<TableCell
Expand Down Expand Up @@ -138,18 +136,7 @@ const TreeTableRow = (row: TreeTableBody): JSX.Element => {
onClick={navigateToTreeDetailPage}
data-target="treeDetails.builds"
>
<Tooltip>
<TooltipTrigger>
<div>{date}</div>
</TooltipTrigger>
<TooltipContent>
<div className="text-center">
{date}
<br />
{time}
</div>
</TooltipContent>
</Tooltip>
<TooltipDateTime dateTime={row.date} lineBreak={true} />
</TableCell>
<TableCell
onClick={navigateToTreeDetailPage}
Expand Down
56 changes: 56 additions & 0 deletions dashboard/src/components/TooltipDateTime/TooltipDateTime.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { format, isValid } from 'date-fns';

import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/Tooltip';
import { getDateOffset } from '@/utils/utils';

type TooltipDateTimeProps = {
dateTime: string;
dateFormat?: string;
timeFormat?: string;
lineBreak?: boolean;
showLabelTime?: boolean;
showLabelTZ?: boolean;
showTooltip?: boolean;
};

const TooltipDateTime = ({
dateTime,
dateFormat,
timeFormat,
lineBreak = true,
showLabelTime = false,
showLabelTZ = false,
showTooltip = true,
}: TooltipDateTimeProps): JSX.Element => {
const dateObj = new Date(dateTime);
if (!isValid(dateObj)) return <div>-</div>;

const date = dateFormat
? format(dateObj, dateFormat)
: dateObj.toLocaleDateString();
const time = timeFormat
? format(dateObj, timeFormat)
: dateObj.toLocaleTimeString();
const tz = getDateOffset(dateObj);

return (
<Tooltip>
<TooltipTrigger>
<div>
{date} {showLabelTime ? time : ''} {showLabelTZ ? tz : ''}
</div>
</TooltipTrigger>
{(showTooltip || showTooltip === undefined) && (
<TooltipContent>
<div className="text-center">
{date}
{lineBreak ? <br /> : ' '}
{time} {tz}
</div>
</TooltipContent>
)}
</Tooltip>
);
};

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

export { TooltipDateTime };
4 changes: 3 additions & 1 deletion dashboard/src/pages/BuildDetails/BuildDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { ISection } from '@/components/Section/Section';
import { useBuildDetails } from '@/api/BuildDetails';
import UnexpectedError from '@/components/UnexpectedError/UnexpectedError';

import { formatDate } from '@/utils/utils';

import {
Breadcrumb,
BreadcrumbItem,
Expand Down Expand Up @@ -85,7 +87,7 @@ const BuildDetails = (): JSX.Element => {
},
{
title: intl.formatMessage({ id: 'global.date' }),
linkText: valueOrEmpty(data.timestamp),
linkText: formatDate(valueOrEmpty(data.start_time)),
},
{
title: intl.formatMessage({ id: 'global.defconfig' }),
Expand Down
2 changes: 1 addition & 1 deletion dashboard/src/pages/TreeDetails/Tabs/Build/BuildTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ const BuildTab = ({ treeDetailsData }: BuildTab): JSX.Element => {
) : (
'-'
),
date: row.date?.split('T')[0],
date: row.date,
}));
}, [treeDetailsData?.builds]);

Expand Down
6 changes: 6 additions & 0 deletions dashboard/src/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { format } from 'date-fns';

export function formatDate(date: Date | string): string {
const options: Intl.DateTimeFormatOptions = {
year: 'numeric',
Expand All @@ -14,3 +16,7 @@ export function formatDate(date: Date | string): string {

return new Intl.DateTimeFormat('en-US', options).format(date);
}

export const getDateOffset = (date: Date): string => {
return format(date, 'z');
};

0 comments on commit f384e29

Please sign in to comment.