@@ -12,21 +12,41 @@ import {
1212 WizardHeader ,
1313 WizardStep ,
1414} from '@patternfly/react-core' ;
15+ import { useSearchParams } from 'react-router-dom' ;
1516
1617import { useGetBlueprintQuery } from '@/store/api/backend' ;
1718import { selectSelectedBlueprintId } from '@/store/slices/blueprint' ;
1819import { selectIsOnPremise } from '@/store/slices/env' ;
19- import { loadWizardState } from '@/store/slices/wizard' ;
20+ import {
21+ addImageType ,
22+ changeArchitecture ,
23+ changeDistribution ,
24+ changeTimezone ,
25+ initializeWizard ,
26+ loadWizardState ,
27+ selectDistribution ,
28+ selectImageTypes ,
29+ selectTimezone ,
30+ } from '@/store/slices/wizard' ;
2031import {
2132 closeWizardModal ,
33+ openWizardModal ,
2234 selectIsWizardModalOpen ,
2335 selectWizardModalMode ,
2436} from '@/store/slices/wizardModal' ;
2537
2638import CustomWizardFooter from './components/CustomWizardFooter' ;
2739import ReviewWizardFooter from './components/ReviewWizardFooter' ;
2840
41+ import {
42+ AARCH64 ,
43+ DEFAULT_TIMEZONE ,
44+ RHEL_10 ,
45+ RHEL_8 ,
46+ RHEL_9 ,
47+ } from '../../constants' ;
2948import { useAppDispatch , useAppSelector } from '../../store/hooks' ;
49+ import { getHostArch , getHostDistro } from '../../Utilities/getHostInfo' ;
3050import DetailsStep from '../CreateImageWizard/steps/Details' ;
3151import FileSystemStep from '../CreateImageWizard/steps/FileSystem' ;
3252import FirewallStep from '../CreateImageWizard/steps/Firewall' ;
@@ -65,12 +85,17 @@ export const CreateImageWizard3 = () => {
6585 const mode = useAppSelector ( selectWizardModalMode ) ;
6686 const blueprintId = useAppSelector ( selectSelectedBlueprintId ) ;
6787 const isOnPremise = useAppSelector ( selectIsOnPremise ) ;
88+ const [ searchParams , setSearchParams ] = useSearchParams ( ) ;
6889
6990 const { data : blueprintDetails , isSuccess } = useGetBlueprintQuery (
7091 { id : blueprintId || '' } ,
7192 { skip : ! ( mode === 'edit' && ! ! blueprintId ) } ,
7293 ) ;
7394
95+ const distribution = useAppSelector ( selectDistribution ) ;
96+ const timezone = useAppSelector ( selectTimezone ) ;
97+ const targetEnvironments = useAppSelector ( selectImageTypes ) ;
98+
7499 // Validation hooks
75100 const detailsValidation = useDetailsValidation ( ) ;
76101 const registrationValidation = useRegistrationValidation ( ) ;
@@ -84,15 +109,97 @@ export const CreateImageWizard3 = () => {
84109 const firewallValidation = useFirewallValidation ( ) ;
85110 const firstBootValidation = useFirstBootValidation ( ) ;
86111
112+ useEffect ( ( ) => {
113+ const hasUrlParams =
114+ searchParams . has ( 'release' ) ||
115+ searchParams . has ( 'target' ) ||
116+ searchParams . has ( 'arch' ) ;
117+
118+ if ( hasUrlParams && ! showWizardModal ) {
119+ dispatch ( openWizardModal ( 'create' ) ) ;
120+ return ;
121+ }
122+
123+ if ( mode === 'create' && showWizardModal ) {
124+ dispatch ( initializeWizard ( ) ) ;
125+ if ( searchParams . get ( 'release' ) === 'rhel8' ) {
126+ dispatch ( changeDistribution ( RHEL_8 ) ) ;
127+ }
128+ if ( searchParams . get ( 'release' ) === 'rhel9' ) {
129+ dispatch ( changeDistribution ( RHEL_9 ) ) ;
130+ }
131+ if ( searchParams . get ( 'release' ) === 'rhel10' ) {
132+ dispatch ( changeDistribution ( RHEL_10 ) ) ;
133+ }
134+ if ( searchParams . get ( 'arch' ) === AARCH64 ) {
135+ dispatch ( changeArchitecture ( AARCH64 ) ) ;
136+ }
137+ if ( searchParams . get ( 'target' ) === 'iso' ) {
138+ dispatch ( addImageType ( 'image-installer' ) ) ;
139+ }
140+ if ( searchParams . get ( 'target' ) === 'qcow2' ) {
141+ dispatch ( addImageType ( 'guest-image' ) ) ;
142+ }
143+
144+ const initializeHostDistro = async ( ) => {
145+ const distro = await getHostDistro ( ) ;
146+ dispatch ( changeDistribution ( distro ) ) ;
147+ } ;
148+
149+ const initializeHostArch = async ( ) => {
150+ const arch = await getHostArch ( ) ;
151+ dispatch ( changeArchitecture ( arch ) ) ;
152+ } ;
153+
154+ if ( isOnPremise ) {
155+ if ( ! searchParams . get ( 'release' ) ) {
156+ initializeHostDistro ( ) ;
157+ }
158+ if ( ! searchParams . get ( 'arch' ) ) {
159+ initializeHostArch ( ) ;
160+ }
161+ }
162+ }
163+ // This useEffect hook should run *only* when the modal opens in create mode
164+ // eslint-disable-next-line react-hooks/exhaustive-deps
165+ } , [ mode , showWizardModal ] ) ;
166+
87167 useEffect ( ( ) => {
88168 if ( mode === 'edit' && blueprintId && blueprintDetails ) {
89169 const editBlueprintState = mapRequestToState ( blueprintDetails ) ;
90170 dispatch ( loadWizardState ( editBlueprintState ) ) ;
91171 }
92172 } , [ mode , blueprintId , blueprintDetails , dispatch ] ) ;
93173
174+ useEffect ( ( ) => {
175+ if ( mode !== 'create' ) {
176+ return ;
177+ }
178+
179+ const defaultTimezone =
180+ distribution === RHEL_10 || targetEnvironments . includes ( 'azure' )
181+ ? DEFAULT_TIMEZONE
182+ : 'America/New_York' ;
183+
184+ if ( ! timezone ) {
185+ dispatch ( changeTimezone ( defaultTimezone ) ) ;
186+ }
187+ } , [ distribution , targetEnvironments , mode , dispatch ] ) ;
188+
94189 const handleClose = ( ) => {
95190 dispatch ( closeWizardModal ( ) ) ;
191+
192+ if (
193+ searchParams . has ( 'release' ) ||
194+ searchParams . has ( 'target' ) ||
195+ searchParams . has ( 'arch' )
196+ ) {
197+ const params = new URLSearchParams ( searchParams ) ;
198+ params . delete ( 'release' ) ;
199+ params . delete ( 'target' ) ;
200+ params . delete ( 'arch' ) ;
201+ setSearchParams ( params ) ;
202+ }
96203 } ;
97204
98205 const REVIEW_STEP_INDEX = 4 ;
0 commit comments