@@ -5,7 +5,8 @@ import { useSearch } from '@tanstack/react-router';
55
66import type {
77 HardwareListingResponse ,
8- HardwareListingResponseV2 ,
8+ HardwareRevisionSelection ,
9+ HardwareSelectorsResponse ,
910} from '@/types/hardware' ;
1011
1112import 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} ;
0 commit comments