1
- import type { ChakraProps } from '@invoke-ai/ui-library' ;
2
- import { Combobox , FormControl , FormLabel } from '@invoke-ai/ui-library' ;
1
+ import { FormControl , FormLabel } from '@invoke-ai/ui-library' ;
3
2
import { createSelector } from '@reduxjs/toolkit' ;
4
3
import { useAppDispatch , useAppSelector } from 'app/store/storeHooks' ;
5
4
import { InformationalPopover } from 'common/components/InformationalPopover/InformationalPopover' ;
6
5
import { useRelatedGroupedModelCombobox } from 'common/hooks/useRelatedGroupedModelCombobox' ;
7
6
import { loraAdded , selectLoRAsSlice } from 'features/controlLayers/store/lorasSlice' ;
8
7
import { selectBase } from 'features/controlLayers/store/paramsSlice' ;
8
+ import { ModelPicker } from 'features/parameters/components/ModelPicker' ;
9
9
import { memo , useCallback , useMemo } from 'react' ;
10
10
import { useTranslation } from 'react-i18next' ;
11
11
import { useLoRAModels } from 'services/api/hooks/modelsByType' ;
@@ -20,14 +20,17 @@ const LoRASelect = () => {
20
20
const addedLoRAs = useAppSelector ( selectLoRAs ) ;
21
21
const currentBaseModel = useAppSelector ( selectBase ) ;
22
22
23
- const getIsDisabled = ( model : LoRAModelConfig ) : boolean => {
24
- const isCompatible = currentBaseModel === model . base ;
25
- const isAdded = Boolean ( addedLoRAs . find ( ( lora ) => lora . model . key === model . key ) ) ;
26
- const hasMainModel = Boolean ( currentBaseModel ) ;
27
- return ! hasMainModel || ! isCompatible || isAdded ;
28
- } ;
23
+ const getIsDisabled = useCallback (
24
+ ( model : LoRAModelConfig ) : boolean => {
25
+ const isCompatible = currentBaseModel === model . base ;
26
+ const isAdded = Boolean ( addedLoRAs . find ( ( lora ) => lora . model . key === model . key ) ) ;
27
+ const hasMainModel = Boolean ( currentBaseModel ) ;
28
+ return ! hasMainModel || ! isCompatible || isAdded ;
29
+ } ,
30
+ [ addedLoRAs , currentBaseModel ]
31
+ ) ;
29
32
30
- const _onChange = useCallback (
33
+ const onChange = useCallback (
31
34
( model : LoRAModelConfig | null ) => {
32
35
if ( ! model ) {
33
36
return ;
@@ -37,10 +40,10 @@ const LoRASelect = () => {
37
40
[ dispatch ]
38
41
) ;
39
42
40
- const { options, onChange } = useRelatedGroupedModelCombobox ( {
43
+ const { options } = useRelatedGroupedModelCombobox ( {
41
44
modelConfigs,
42
45
getIsDisabled,
43
- onChange : _onChange ,
46
+ onChange,
44
47
} ) ;
45
48
46
49
const placeholder = useMemo ( ( ) => {
@@ -55,28 +58,22 @@ const LoRASelect = () => {
55
58
return t ( 'models.addLora' ) ;
56
59
} , [ isLoading , options . length , t ] ) ;
57
60
58
- const noOptionsMessage = useCallback ( ( ) => t ( 'models.noMatchingLoRAs' ) , [ t ] ) ;
59
-
60
61
return (
61
- < FormControl isDisabled = { ! options . length } gap = { 2 } >
62
+ < FormControl gap = { 2 } >
62
63
< InformationalPopover feature = "lora" >
63
64
< FormLabel > { t ( 'models.concepts' ) } </ FormLabel >
64
65
</ InformationalPopover >
65
- < Combobox
66
- placeholder = { placeholder }
67
- value = { null }
68
- options = { options }
69
- noOptionsMessage = { noOptionsMessage }
66
+ < ModelPicker
67
+ modelConfigs = { modelConfigs }
70
68
onChange = { onChange }
71
- data-testid = "add-lora"
72
- sx = { selectStyles }
69
+ grouped
70
+ selectedModelConfig = { undefined }
71
+ allowEmpty
72
+ placeholder = { placeholder }
73
+ getIsOptionDisabled = { getIsDisabled }
73
74
/>
74
75
</ FormControl >
75
76
) ;
76
77
} ;
77
78
78
79
export default memo ( LoRASelect ) ;
79
-
80
- const selectStyles : ChakraProps [ 'sx' ] = {
81
- w : 'full' ,
82
- } ;
0 commit comments