Skip to content

Commit 4876379

Browse files
authored
fix: LogViewer Breadcrumb links (#1803)
* The self link to Log Viewer is disabled (following the behaviour of other pages) * The dynamic link to Hardware Details now redirects to the proper page, using the hardwareId from the page that launched the log. Closes #1506
1 parent 464b520 commit 4876379

3 files changed

Lines changed: 37 additions & 15 deletions

File tree

dashboard/src/components/Log/LogViewerCard.tsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { FormattedMessage, useIntl } from 'react-intl';
22

33
import { useMemo, type JSX } from 'react';
44

5-
import { Link, useRouterState } from '@tanstack/react-router';
5+
import { Link, useParams, useRouterState } from '@tanstack/react-router';
66

77
import { SearchIcon } from '@/components/Icons/SearchIcon';
88
import { StatusIcon } from '@/components/Icons/StatusIcons';
@@ -61,6 +61,7 @@ export const LogViewerCard = ({
6161
}
6262
}, [logUrl]);
6363

64+
const { hardwareId } = useParams({ strict: false });
6465
const { treeName, branch, id } = useRouterState({
6566
select: s => s.location.state,
6667
});
@@ -70,13 +71,17 @@ export const LogViewerCard = ({
7071
const logDataHash = logData?.git_commit_hash;
7172

7273
const stateIsSetted = treeName && branch && id;
73-
const stateParams = useMemo(
74-
() =>
75-
!stateIsSetted
76-
? { treeName: logDataTreeName, branch: logDataBranch, id: logDataHash }
77-
: {},
78-
[stateIsSetted, logDataTreeName, logDataBranch, logDataHash],
79-
);
74+
const stateParams = useMemo(() => {
75+
if (stateIsSetted) {
76+
return hardwareId ? { hardwareId } : {};
77+
}
78+
return {
79+
hardwareId: hardwareId,
80+
treeName: logDataTreeName,
81+
branch: logDataBranch,
82+
id: logDataHash,
83+
};
84+
}, [stateIsSetted, hardwareId, logDataTreeName, logDataBranch, logDataHash]);
8085

8186
const linkComponent = useMemo(() => {
8287
if (logUrl) {

dashboard/src/main.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ declare module '@tanstack/react-router' {
4444
from?: RedirectFrom;
4545
treeName?: string;
4646
branch?: string;
47+
hardwareId?: string;
4748
treeStatusCount?: {
4849
builds?: RequiredStatusCount;
4950
boots?: RequiredStatusCount;

dashboard/src/pages/LogViewer.tsx

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ export function LogViewer(): JSX.Element {
6969
) : undefined;
7070
const { data: logData, isLoading } = useLogData(itemId ?? '', type);
7171

72-
const { treeName, branch, id } = historyState;
73-
const canGoDirect = treeName && branch && id;
72+
const { treeName, branch, id, hardwareId } = historyState;
73+
const hasTreeDetailsLink = treeName && branch && id;
74+
const hasHardwareDetailsLink = !!hardwareId;
7475

7576
const breadcrumbComponent = useMemo(() => {
7677
if (!type || !itemId) {
@@ -92,15 +93,25 @@ export function LogViewer(): JSX.Element {
9293
messageId: base.messageId,
9394
});
9495

95-
if (canGoDirect) {
96+
if (hasHardwareDetailsLink) {
97+
components.push({
98+
linkProps: {
99+
to: '/hardware/$hardwareId',
100+
params: { hardwareId },
101+
state: s => s,
102+
search: previousSearch,
103+
},
104+
messageId: 'hardware.details',
105+
});
106+
} else if (hasTreeDetailsLink) {
96107
components.push({
97108
linkProps: {
98109
to: '/tree/$treeName/$branch/$hash',
99110
params: { treeName: treeName, branch: branch, hash: id },
100111
state: s => s,
101112
search: previousSearch,
102113
},
103-
messageId: details.messageId,
114+
messageId: 'tree.details',
104115
});
105116
} else {
106117
components.push({
@@ -127,7 +138,7 @@ export function LogViewer(): JSX.Element {
127138
components.push({
128139
linkProps: {
129140
to: test.path,
130-
params: { [details.paramKey]: id, buildId: itemId },
141+
params: { [details.paramKey]: id, testId: itemId },
131142
state: s => s,
132143
},
133144
messageId: test.messageId,
@@ -153,7 +164,10 @@ export function LogViewer(): JSX.Element {
153164
}
154165
}
155166

156-
components.push({ linkProps: {}, messageId: 'logSheet.title' });
167+
components.push({
168+
linkProps: { disabled: true },
169+
messageId: 'logSheet.title',
170+
});
157171

158172
return <MemoizedBreadcrumbGenerator components={components} />;
159173
}, [
@@ -164,7 +178,9 @@ export function LogViewer(): JSX.Element {
164178
branch,
165179
treeName,
166180
id,
167-
canGoDirect,
181+
hardwareId,
182+
hasHardwareDetailsLink,
183+
hasTreeDetailsLink,
168184
]);
169185

170186
return (

0 commit comments

Comments
 (0)