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..4a70fd06 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', @@ -175,7 +176,9 @@ export const messages = { 'issue.noIssueFound': 'No issue found.', 'logSheet.fileName': 'File Name', 'logSheet.fileSize': 'File Size', - 'logSheet.indexOf': 'Index of {link}', + 'logSheet.indexOf': 'You can download the full log here: {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.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..232859bd 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,17 +179,20 @@ export const LogSheet = ({ - }> -
+ } + > +
- {truncateBigText(logUrl)} + {truncateUrl(logUrl)} ), @@ -202,7 +205,7 @@ export const LogSheet = ({ skeletonClassname="h-[3rem]" customError={
- This log url is not supported in the log viewer yet +
} >