-
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.
fix(dashboard): fixing datetime at builds list
Now tooltip shows right date and time. Closes #318
- Loading branch information
Lucas Bracher
committed
Sep 20, 2024
1 parent
96c292c
commit f384e29
Showing
10 changed files
with
121 additions
and
21 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
56 changes: 56 additions & 0 deletions
56
dashboard/src/components/TooltipDateTime/TooltipDateTime.tsx
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 |
---|---|---|
@@ -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; |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import TooltipDateTime from './TooltipDateTime'; | ||
|
||
export { TooltipDateTime }; |
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