1
- import { Combobox , FormControl , FormLabel } from '@invoke-ai/ui-library' ;
1
+ import { FormControl , FormLabel } from '@invoke-ai/ui-library' ;
2
2
import { useAppDispatch , useAppSelector } from 'app/store/storeHooks' ;
3
- import { useModelCombobox } from 'common/hooks/useModelCombobox' ;
3
+ import { InformationalPopover } from 'common/components/InformationalPopover/InformationalPopover' ;
4
+ import { selectBase } from 'features/controlLayers/store/paramsSlice' ;
5
+ import { ModelPicker } from 'features/parameters/components/ModelPicker' ;
4
6
import { selectTileControlNetModel , tileControlnetModelChanged } from 'features/parameters/store/upscaleSlice' ;
5
- import { memo , useCallback } from 'react' ;
7
+ import { memo , useCallback , useMemo } from 'react' ;
6
8
import { useTranslation } from 'react-i18next' ;
7
9
import { useControlNetModels } from 'services/api/hooks/modelsByType' ;
8
10
import type { ControlNetModelConfig } from 'services/api/types' ;
@@ -11,26 +13,51 @@ const ParamTileControlNetModel = () => {
11
13
const dispatch = useAppDispatch ( ) ;
12
14
const { t } = useTranslation ( ) ;
13
15
const tileControlNetModel = useAppSelector ( selectTileControlNetModel ) ;
16
+ const currentBaseModel = useAppSelector ( selectBase ) ;
14
17
const [ modelConfigs , { isLoading } ] = useControlNetModels ( ) ;
15
18
16
19
const _onChange = useCallback (
17
- ( controlNetModel : ControlNetModelConfig | null ) => {
20
+ ( controlNetModel : ControlNetModelConfig ) => {
18
21
dispatch ( tileControlnetModelChanged ( controlNetModel ) ) ;
19
22
} ,
20
23
[ dispatch ]
21
24
) ;
22
25
23
- const { options, value, onChange, noOptionsMessage } = useModelCombobox ( {
24
- modelConfigs,
25
- onChange : _onChange ,
26
- selectedModel : tileControlNetModel ,
27
- isLoading,
28
- } ) ;
26
+ const filteredModelConfigs = useMemo ( ( ) => {
27
+ if ( ! currentBaseModel ) {
28
+ return [ ] ;
29
+ }
30
+ return modelConfigs . filter ( ( model ) => {
31
+ const isCompatible = model . base === currentBaseModel ;
32
+ const isTileOrMultiModel = model . name . toLowerCase ( ) . includes ( 'tile' ) || model . name . toLowerCase ( ) . includes ( 'union' ) ;
33
+ return isCompatible && isTileOrMultiModel ;
34
+ } ) ;
35
+ } , [ modelConfigs , currentBaseModel ] ) ;
36
+
37
+ const getIsOptionDisabled = useCallback (
38
+ ( model : ControlNetModelConfig ) : boolean => {
39
+ const isCompatible = currentBaseModel === model . base ;
40
+ const hasMainModel = Boolean ( currentBaseModel ) ;
41
+ return ! hasMainModel || ! isCompatible ;
42
+ } ,
43
+ [ currentBaseModel ]
44
+ ) ;
29
45
30
46
return (
31
- < FormControl isDisabled = { ! options . length } isInvalid = { ! options . length } minW = { 0 } flexGrow = { 1 } gap = { 2 } >
32
- < FormLabel m = { 0 } > { t ( 'controlNet' ) } </ FormLabel >
33
- < Combobox value = { value } options = { options } onChange = { onChange } noOptionsMessage = { noOptionsMessage } />
47
+ < FormControl isDisabled = { ! filteredModelConfigs . length } isInvalid = { ! filteredModelConfigs . length } minW = { 0 } flexGrow = { 1 } gap = { 2 } >
48
+ < InformationalPopover feature = "controlNet" >
49
+ < FormLabel m = { 0 } > { t ( 'upscaling.tileControl' ) } </ FormLabel >
50
+ </ InformationalPopover >
51
+ < ModelPicker
52
+ modelConfigs = { filteredModelConfigs }
53
+ selectedModelConfig = { tileControlNetModel ?? undefined }
54
+ onChange = { _onChange }
55
+ getIsOptionDisabled = { getIsOptionDisabled }
56
+ placeholder = { t ( 'common.placeholderSelectAModel' ) }
57
+ noOptionsText = { t ( 'upscaling.missingTileControlNetModel' ) }
58
+ isDisabled = { isLoading || ! filteredModelConfigs . length }
59
+ isInvalid = { ! filteredModelConfigs . length }
60
+ />
34
61
</ FormControl >
35
62
) ;
36
63
} ;
0 commit comments