From a73b1a180718c37fee9bf3b9e587bf4d6e453bac Mon Sep 17 00:00:00 2001 From: Murilo Geraldini Date: Wed, 11 Dec 2024 14:29:21 -0300 Subject: [PATCH] feat(LogSheet): Update UI of log download links - Added a new function `truncateUrl` used to truncate the URL in the log viewer - Changed the title of the download log table to "Full logs" - Changed the messaged of the QuerySwitcher to "Download your logs here" - Changed the style of the log links, making their font size greater and their color blue with an underline hover effect Closes #655 --- dashboard/src/lib/string.ts | 24 ++++++ dashboard/src/locales/messages/index.ts | 6 +- .../src/pages/TreeDetails/Tabs/LogSheet.tsx | 83 +++++++++++-------- 3 files changed, 76 insertions(+), 37 deletions(-) diff --git a/dashboard/src/lib/string.ts b/dashboard/src/lib/string.ts index 559983bf..95f76c5d 100644 --- a/dashboard/src/lib/string.ts +++ b/dashboard/src/lib/string.ts @@ -8,3 +8,27 @@ export const truncateBigText = ( text && text.length > maxTextLength ? text.slice(0, maxTextLength) + '...' : valueOrEmpty(text); + +export const truncateUrl = ( + url: string | undefined, + domainLength = 50, + endPathLength = 20, +): string => { + if (url) { + if (url.length <= domainLength + endPathLength) { + return url; + } + const protocolRegex = /^\w+:\/\//; + const searchParamsRegex = /\?.*$/; + const replacedUrl = url + .replace(protocolRegex, '') + .replace(searchParamsRegex, ''); + const splittedUrl = replacedUrl.split('/'); + const hostname = splittedUrl[0]; + const pathname = splittedUrl?.pop(); + const domain = hostname ? hostname.slice(0, domainLength) : ''; + const lastPath = pathname ? pathname.slice(-endPathLength) : ''; + return `${domain}...${lastPath}`; + } + return valueOrEmpty(url); +}; diff --git a/dashboard/src/locales/messages/index.ts b/dashboard/src/locales/messages/index.ts index c5d3b5e4..5d435753 100644 --- a/dashboard/src/locales/messages/index.ts +++ b/dashboard/src/locales/messages/index.ts @@ -125,6 +125,7 @@ export const messages = { 'global.failedCount': 'Failed: {count}', 'global.fails': 'Fails', 'global.filters': 'Filters', + 'global.fullLogs': 'Full logs', 'global.github': 'GitHub', 'global.hardware': 'Hardware', 'global.hardwares': 'Hardwares', @@ -173,9 +174,12 @@ export const messages = { 'hardware.searchPlaceholder': 'Search by hardware name', 'hardwareDetails.treeBranch': 'Tree / Branch', 'issue.noIssueFound': 'No issue found.', + 'logSheet.downloadLog': 'You can download the full log here: {link}', 'logSheet.fileName': 'File Name', 'logSheet.fileSize': 'File Size', - 'logSheet.indexOf': 'Index of {link}', + 'logSheet.logQueryCustomError': + 'This log url is not supported in the log viewer yet, but you can still download the log in the link above', + 'logSheet.noLogFound': 'No logs available', 'logSheet.title': 'Logs Viewer', 'routes.buildDetails': 'Build', 'routes.hardwareMonitor': 'Hardware', diff --git a/dashboard/src/pages/TreeDetails/Tabs/LogSheet.tsx b/dashboard/src/pages/TreeDetails/Tabs/LogSheet.tsx index bc96b505..259874e9 100644 --- a/dashboard/src/pages/TreeDetails/Tabs/LogSheet.tsx +++ b/dashboard/src/pages/TreeDetails/Tabs/LogSheet.tsx @@ -15,7 +15,7 @@ import { import { DumbTableHeader, TableHead } from '@/components/Table/BaseTable'; import { Button } from '@/components/ui/button'; import { Table, TableBody, TableCell, TableRow } from '@/components/ui/table'; -import { truncateBigText } from '@/lib/string'; +import { truncateUrl } from '@/lib/string'; import { useLogFiles } from '@/api/treeDetails'; import QuerySwitcher from '@/components/QuerySwitcher/QuerySwitcher'; import type { LogFile } from '@/types/tree/TreeDetails'; @@ -179,42 +179,53 @@ export const LogSheet = ({ - }> -
- - {truncateBigText(logUrl)} - - - ), - }} - /> + } + > +
+ {navigationLogsActions?.isLoading ? ( + + ) : ( + + {truncateUrl(logUrl)} + + + ), + }} + /> + )}
- - This log url is not supported in the log viewer yet -
- } - > - - {logFilesData?.log_files && !!logUrl && ( - - )} -
- + {logUrl ? ( + + + + } + > + + {logFilesData?.log_files && !!logUrl && ( + + )} +
+
+ ) : ( +
+ )}
{navigationLogsActions?.isLoading ? (