@@ -15,11 +15,10 @@ import {
15
15
TextContent ,
16
16
TextInput ,
17
17
} from '@patternfly/react-core' ;
18
- import { SelectOption as SelectOptionPF } from '@patternfly/react-core/deprecated' ;
19
18
import { ExclamationTriangleIcon , ExternalLinkAltIcon } from '@patternfly/react-icons' ;
20
19
import { CheckIcon } from '@patternfly/react-icons' ;
21
20
import { Operation } from 'fast-json-patch' ;
22
- import { ReactNode , useCallback , useEffect , useRef , useState } from 'react' ;
21
+ import { ReactNode , useCallback , useEffect , useMemo , useRef , useState } from 'react' ;
23
22
import { Link , useNavigate , useParams } from 'react-router' ;
24
23
25
24
import { BuildConfiguration , Environment , Product , ProductVersion , SCMRepository , SCMRepositoryPage } from 'pnc-api-types-ts' ;
@@ -28,7 +27,7 @@ import { PncError } from 'common/PncError';
28
27
import { breadcrumbData } from 'common/breadcrumbData' ;
29
28
import { buildConfigEntityAttributes } from 'common/buildConfigEntityAttributes' ;
30
29
import { buildTypeData } from 'common/buildTypeData' ;
31
- import { ButtonTitles , EntityTitles , PageTitles } from 'common/constants' ;
30
+ import { ButtonTitles , EntityTitles , PageTitles , dummyPaginatedAxiosResponse } from 'common/constants' ;
32
31
import { productEntityAttributes } from 'common/productEntityAttributes' ;
33
32
import { scmRepositoryEntityAttributes } from 'common/scmRepositoryEntityAttributes' ;
34
33
import { BuildConfigCreationResponseCustomized } from 'common/types' ;
@@ -45,7 +44,6 @@ import { ActionConfirmModal } from 'components/ActionConfirmModal/ActionConfirmM
45
44
import { ConfigsAddList } from 'components/ConfigsEditList/ConfigsAddList' ;
46
45
import { ConfigsChangesList } from 'components/ConfigsEditList/ConfigsChangesList' ;
47
46
import { ContentBox } from 'components/ContentBox/ContentBox' ;
48
- import { CreatableSelect } from 'components/CreatableSelect/CreatableSelect' ;
49
47
import { ExpandableSection } from 'components/ExpandableSection/ExpandableSection' ;
50
48
import { FormInput } from 'components/FormInput/FormInput' ;
51
49
import { FormInputHelperText } from 'components/FormInputHelperText/FormInputHelperText' ;
@@ -63,6 +61,7 @@ import { Toolbar } from 'components/Toolbar/Toolbar';
63
61
import { ToolbarItem } from 'components/Toolbar/ToolbarItem' ;
64
62
import { TooltipSimple } from 'components/TooltipSimple/TooltipSimple' ;
65
63
import { TooltipWrapper } from 'components/TooltipWrapper/TooltipWrapper' ;
64
+ import { TypeaheadSelect } from 'components/TypeaheadSelect/TypeaheadSelect' ;
66
65
67
66
import * as buildConfigApi from 'services/buildConfigApi' ;
68
67
import * as environmentApi from 'services/environmentApi' ;
@@ -306,7 +305,9 @@ export const BuildConfigCreateEditPage = ({ isEditPage = false }: IBuildConfigCr
306
305
307
306
const fetchProductVersions = useCallback (
308
307
( requestConfig = { } ) => {
309
- return selectedProduct ? productApi . getProductVersions ( { id : selectedProduct . id } , requestConfig ) : Promise . resolve ( [ ] ) ;
308
+ return selectedProduct
309
+ ? productApi . getProductVersions ( { id : selectedProduct . id } , requestConfig )
310
+ : Promise . resolve ( dummyPaginatedAxiosResponse ) ;
310
311
} ,
311
312
[ selectedProduct ]
312
313
) ;
@@ -481,15 +482,15 @@ export const BuildConfigCreateEditPage = ({ isEditPage = false }: IBuildConfigCr
481
482
482
483
const productSearchSelect = (
483
484
< SearchSelect
484
- selectedItem = { selectedProduct ?. name }
485
- onSelect = { ( event , _ , product : Product ) => {
485
+ selectedValue = { selectedProduct ?. name }
486
+ onSelect = { ( _ , product ) => {
486
487
setSelectedProduct ( product ) ;
487
- productVersionRegisterObject . onChange ( event , '' ) ;
488
+ productVersionRegisterObject . onChange ( undefined , '' ) ;
488
489
setSelectedProductVersion ( undefined ) ;
489
490
} }
490
- onClear = { ( event ) => {
491
+ onClear = { ( ) => {
491
492
setSelectedProduct ( undefined ) ;
492
- productVersionRegisterObject . onChange ( event , '' ) ;
493
+ productVersionRegisterObject . onChange ( undefined , '' ) ;
493
494
setSelectedProductVersion ( undefined ) ;
494
495
} }
495
496
fetchCallback = { productApi . getProducts }
@@ -503,19 +504,19 @@ export const BuildConfigCreateEditPage = ({ isEditPage = false }: IBuildConfigCr
503
504
{ ...productVersionRegisterObject }
504
505
render = { ( { value, validated, onChange } ) => (
505
506
< SearchSelect
506
- selectedItem = { value }
507
- validated = { validated }
508
- onSelect = { ( event , _ , productVersion : ProductVersion ) => {
509
- onChange ( event , productVersion . version ) ;
507
+ selectedValue = { value }
508
+ onSelect = { ( _ , productVersion ) => {
509
+ onChange ( undefined , productVersion ?. version || '' ) ;
510
510
setSelectedProductVersion ( productVersion ) ;
511
511
} }
512
- onClear = { ( event ) => {
513
- onChange ( event , '' ) ;
512
+ onClear = { ( ) => {
513
+ onChange ( undefined , '' ) ;
514
514
setSelectedProductVersion ( undefined ) ;
515
515
} }
516
516
fetchCallback = { fetchProductVersions }
517
517
titleAttribute = "version"
518
518
placeholderText = "Select Version"
519
+ validated = { validated }
519
520
isDisabled = { ! selectedProduct }
520
521
/>
521
522
) }
@@ -561,26 +562,29 @@ export const BuildConfigCreateEditPage = ({ isEditPage = false }: IBuildConfigCr
561
562
{ ...register < string > ( buildConfigEntityAttributes . environment . id , fieldConfigs . environment ) }
562
563
render = { ( { value, validated, onChange } ) => (
563
564
< SearchSelect
564
- selectedItem = { value }
565
- validated = { validated }
566
- onSelect = { ( event , _ , environment : Environment ) => {
567
- onChange ( event , environment . description ! ) ;
565
+ selectedValue = { value }
566
+ onSelect = { ( _ , environment ) => {
567
+ onChange ( undefined , environment ?. description || '' ) ;
568
568
setSelectedEnvironment ( environment ) ;
569
569
} }
570
- onClear = { ( event ) => {
571
- onChange ( event , '' ) ;
570
+ onClear = { ( ) => {
571
+ onChange ( undefined , '' ) ;
572
572
setSelectedEnvironment ( undefined ) ;
573
573
} }
574
574
fetchCallback = { fetchEnvironments }
575
575
titleAttribute = "description"
576
- placeholderText = "Select Environment"
577
- getCustomDescription = { ( environment : Environment ) =>
576
+ getCustomDescription = { ( environment ) =>
578
577
environment . deprecated ? (
579
- < Icon status = "warning" >
580
- < ExclamationTriangleIcon /> DEPRECATED
581
- </ Icon >
578
+ < >
579
+ < Icon status = "warning" >
580
+ < ExclamationTriangleIcon />
581
+ </ Icon > { ' ' }
582
+ DEPRECATED
583
+ </ >
582
584
) : null
583
585
}
586
+ placeholderText = "Select Environment"
587
+ validated = { validated }
584
588
/>
585
589
) }
586
590
/>
@@ -714,19 +718,19 @@ export const BuildConfigCreateEditPage = ({ isEditPage = false }: IBuildConfigCr
714
718
{ ...register < string > ( scmRepositoryEntityAttributes . scmUrl . id , fieldConfigs . scmUrl ) }
715
719
render = { ( { value, validated, onChange } ) => (
716
720
< SearchSelect
717
- selectedItem = { value }
718
- validated = { validated }
719
- onSelect = { ( event , _ , scmRepository : SCMRepository ) => {
720
- onChange ( event , scmRepository . internalUrl ! ) ;
721
+ selectedValue = { value }
722
+ onSelect = { ( _ , scmRepository ) => {
723
+ onChange ( undefined , scmRepository ?. internalUrl || '' ) ;
721
724
setSelectedScmRepository ( scmRepository ) ;
722
725
} }
723
- onClear = { ( event ) => {
724
- onChange ( event , '' ) ;
726
+ onClear = { ( ) => {
727
+ onChange ( undefined , '' ) ;
725
728
setSelectedScmRepository ( undefined ) ;
726
729
} }
727
730
fetchCallback = { scmRepositoryApi . getScmRepositories }
728
731
titleAttribute = "internalUrl"
729
732
placeholderText = "Select SCM Repository"
733
+ validated = { validated }
730
734
/>
731
735
) }
732
736
/>
@@ -857,53 +861,45 @@ export const BuildConfigCreateEditPage = ({ isEditPage = false }: IBuildConfigCr
857
861
< ServiceContainerLoading { ...serviceContainerParameters } title = "Build parameters" variant = "inline" >
858
862
< InputGroup >
859
863
< InputGroupItem isFill >
860
- < CreatableSelect
861
- onSelect = { ( _ , selection ) => {
862
- if ( selection ) {
863
- setSelectedBuildParamOption ( selection as string ) ;
864
- setBuildParamData ( {
865
- ...buildParamData ,
866
- [ selection as string ] : {
867
- value : '' ,
868
- } ,
869
- } ) ;
870
- setIsBuildParamSelectOpen ( false ) ;
871
- }
872
- } }
873
- onCreateOption = { ( newOption ) => {
874
- setSelectedBuildParamOption ( undefined ) ;
875
- setBuildParamOptions ( [ ...buildParamOptions , { title : newOption } ] ) ;
864
+ < TypeaheadSelect
865
+ isMenuOpen = { isBuildParamSelectOpen }
866
+ onMenuToggle = { setIsBuildParamSelectOpen }
867
+ selectedValue = { selectedBuildParamOption }
868
+ onSelect = { ( selection ) => {
869
+ setSelectedBuildParamOption ( selection ) ;
876
870
setBuildParamData ( {
877
871
...buildParamData ,
878
- [ newOption ] : {
872
+ [ selection as string ] : {
879
873
value : '' ,
880
874
} ,
881
875
} ) ;
882
- setIsBuildParamSelectOpen ( false ) ;
883
876
} }
884
- onToggle = { ( _ , value ) => setIsBuildParamSelectOpen ( value ) }
885
- selectedItem = { selectedBuildParamOption }
886
- isOpen = { isBuildParamSelectOpen }
887
- placeholderText = "Select Parameter or type a new one"
877
+ onCreateOption = { ( newOption ) => {
878
+ setBuildParamOptions ( [ ...buildParamOptions , { title : newOption } ] ) ;
879
+ } }
888
880
creatableOptionText = "Create custom Parameter"
889
- width = "40%"
890
- dropdownDirection = "up"
891
- >
892
- { buildParamOptions . map ( ( option , index ) => (
893
- < SelectOptionPF
894
- key = { index }
895
- value = { option . title }
896
- description = {
897
- option . title === 'ALIGNMENT_PARAMETERS' ? (
898
- < i > Once selected, more detailed information will be displayed.</ i >
899
- ) : (
900
- option . description
901
- )
902
- }
903
- isDisabled = { ! ! buildParamData [ option . title ] }
904
- />
905
- ) ) }
906
- </ CreatableSelect >
881
+ onClear = { ( ) => {
882
+ setSelectedBuildParamOption ( '' ) ;
883
+ } }
884
+ placeholderText = "Select Parameter or type a new one"
885
+ selectOptions = { useMemo (
886
+ ( ) =>
887
+ buildParamOptions . map ( ( option ) => {
888
+ return {
889
+ value : option . title ,
890
+ children : option . title ,
891
+ isDisabled : ! ! buildParamData [ option . title ] ,
892
+ description :
893
+ option . title === 'ALIGNMENT_PARAMETERS' ? (
894
+ < i > Once selected, more detailed information will be displayed.</ i >
895
+ ) : (
896
+ option . description
897
+ ) ,
898
+ } ;
899
+ } ) ,
900
+ [ buildParamOptions , buildParamData ]
901
+ ) }
902
+ />
907
903
</ InputGroupItem >
908
904
</ InputGroup >
909
905
</ ServiceContainerLoading >
@@ -920,6 +916,7 @@ export const BuildConfigCreateEditPage = ({ isEditPage = false }: IBuildConfigCr
920
916
< TooltipWrapper tooltip = "Remove the parameter" >
921
917
< RemoveItemButton
922
918
onRemove = { ( ) => {
919
+ setSelectedBuildParamOption ( '' ) ;
923
920
setBuildParamData ( Object . fromEntries ( Object . entries ( buildParamData ) . filter ( ( [ k ] ) => k !== key ) ) ) ;
924
921
unregister ( key ) ;
925
922
} }
0 commit comments