Skip to content

Commit db1a452

Browse files
author
Gustavo Flores
committed
feat: add hardware tree selection flow on the frontend
1 parent b6cc16e commit db1a452

12 files changed

Lines changed: 843 additions & 136 deletions

File tree

dashboard/src/api/hardware.ts

Lines changed: 59 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import { useSearch } from '@tanstack/react-router';
55

66
import type {
77
HardwareListingResponse,
8-
HardwareListingResponseV2,
8+
HardwareRevisionSelection,
9+
HardwareSelectorsResponse,
910
} from '@/types/hardware';
1011

1112
import type { HardwareListingRoutesMap } from '@/utils/constants/hardwareListing';
@@ -57,17 +58,13 @@ export const useHardwareListing = (
5758
});
5859
};
5960

60-
const fetchHardwareListingV2 = async (
61+
const fetchHardwareSelectors = async (
6162
origin: string,
62-
startTimestampInSeconds: number,
63-
endTimestampInSeconds: number,
64-
): Promise<HardwareListingResponseV2> => {
65-
const data = await RequestData.get<HardwareListingResponseV2>(
66-
'/api/hardware-v2/',
63+
): Promise<HardwareSelectorsResponse> => {
64+
const data = await RequestData.get<HardwareSelectorsResponse>(
65+
'/api/hardware/selectors/',
6766
{
6867
params: {
69-
startTimestampInSeconds,
70-
endTimestampInSeconds,
7168
origin,
7269
},
7370
},
@@ -76,28 +73,68 @@ const fetchHardwareListingV2 = async (
7673
return data;
7774
};
7875

79-
export const useHardwareListingV2 = (
80-
startTimestampInSeconds: number,
81-
endTimestampInSeconds: number,
76+
export const useHardwareSelectors = (
77+
searchFrom: HardwareListingRoutesMap['v2']['search'],
78+
): UseQueryResult<HardwareSelectorsResponse> => {
79+
const { origin } = useSearch({ from: searchFrom });
80+
81+
return useQuery({
82+
queryKey: ['hardwareSelectors', origin],
83+
queryFn: () => fetchHardwareSelectors(origin),
84+
refetchOnWindowFocus: false,
85+
});
86+
};
87+
88+
const fetchHardwareListingByRevision = async (
89+
selection: HardwareRevisionSelection,
90+
origin: string,
91+
): Promise<HardwareListingResponse> => {
92+
const data = await RequestData.get<HardwareListingResponse>(
93+
'/api/hardware-by-revision/',
94+
{
95+
params: {
96+
origin,
97+
tree_name: selection.treeName,
98+
git_repository_url: selection.gitRepositoryUrl,
99+
git_repository_branch: selection.gitBranch,
100+
git_commit_hash: selection.gitCommitHash,
101+
},
102+
},
103+
);
104+
105+
return data;
106+
};
107+
108+
export const useHardwareListingByRevision = (
109+
selection: HardwareRevisionSelection | null,
82110
searchFrom: HardwareListingRoutesMap['v2']['search'],
83-
): UseQueryResult<HardwareListingResponseV2> => {
111+
): UseQueryResult<HardwareListingResponse> => {
84112
const { origin } = useSearch({ from: searchFrom });
85113

86114
const queryKey = [
87-
'hardwareListingV2',
88-
startTimestampInSeconds,
89-
endTimestampInSeconds,
115+
'hardwareListingByRevision',
90116
origin,
117+
selection?.treeName,
118+
selection?.gitRepositoryUrl,
119+
selection?.gitBranch,
120+
selection?.gitCommitHash,
121+
selection,
91122
];
92123

93124
return useQuery({
94125
queryKey,
95-
queryFn: () =>
96-
fetchHardwareListingV2(
97-
origin,
98-
startTimestampInSeconds,
99-
endTimestampInSeconds,
100-
),
126+
queryFn: () => {
127+
if (selection === null) {
128+
return { hardware: [] };
129+
}
130+
return fetchHardwareListingByRevision(selection, origin);
131+
},
132+
enabled: Boolean(
133+
selection?.treeName &&
134+
selection?.gitRepositoryUrl &&
135+
selection?.gitBranch &&
136+
selection?.gitCommitHash,
137+
),
101138
refetchOnWindowFocus: false,
102139
});
103140
};

dashboard/src/locales/messages/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,20 @@ export const messages = {
214214
'hardwareDetails.timeFrame':
215215
'Results from {startDate} and {startTime} to {endDate} {endTime}',
216216
'hardwareListing.bannerTitle': 'Hardware Listing',
217+
'hardwareListing.branchSelectorLabel': 'Branch',
217218
'hardwareListing.description': 'List of hardware from kernel tests',
218219
'hardwareListing.notFound': 'No hardware information available',
220+
'hardwareListing.revisionCapNote': 'Showing latest 50 revisions',
221+
'hardwareListing.revisionEmpty':
222+
'The selected revision has no hardware rows yet. Data ingestion may still be in progress.',
223+
'hardwareListing.revisionSelectorLabel': 'Revision',
224+
'hardwareListing.selectionResetDescription':
225+
'The previous tree/branch/revision selection has no qualifying data for the selected origin and was reset to the latest available revision.',
226+
'hardwareListing.selectionResetTitle': 'Hardware selection reset',
227+
'hardwareListing.selectorsNoData':
228+
'No qualifying hardware data is available for the selected origin yet.',
219229
'hardwareListing.title': 'Hardware Listing ― KCI Dashboard',
230+
'hardwareListing.treeSelectorLabel': 'Tree',
220231
'issue.alsoPresentTooltip': 'Issue also present in {tree}',
221232
'issue.firstSeen': 'First seen',
222233
'issue.newIssue': 'New issue: This is the first time this issue was seen',

0 commit comments

Comments
 (0)