@@ -4,29 +4,21 @@ import { Description } from '../../../components/Description/Description';
44import { Divider } from '../../../components/Divider/Divider' ;
55import { ErrorWrapper } from '../../../components/Error/Error' ;
66import { InlineError } from '../../../components/Error/InlineError' ;
7- import { Form , Input , Label , Select , TextArea , Toggle } from '../../../components/Form' ;
8- import { FormResponseContext } from '../../../components/Form/FormContext' ;
7+ import { Form , Input , Label , TextArea , Toggle } from '../../../components/Form' ;
98import { modal } from '../../../components/Modal/Modal' ;
109import { useAPI } from '../../../providers/ApiProvider' ;
1110import { ProjectContext } from '../../../providers/ProjectProvider' ;
1211import { MachineLearningList } from './MachineLearningList' ;
12+ import { ProjectModelVersionSelector } from './ProjectModelVersionSelector' ;
13+ import { ModelVersionSelector } from './ModelVersionSelector' ;
14+ import { FF_DEV_1682 , isFF } from '../../../utils/feature-flags' ;
1315import './MachineLearningSettings.styl' ;
1416
1517export const MachineLearningSettings = ( ) => {
1618 const api = useAPI ( ) ;
17- const { project, fetchProject, updateProject } = useContext ( ProjectContext ) ;
19+ const { project, fetchProject } = useContext ( ProjectContext ) ;
1820 const [ mlError , setMLError ] = useState ( ) ;
1921 const [ backends , setBackends ] = useState ( [ ] ) ;
20- const [ versions , setVersions ] = useState ( [ ] ) ;
21-
22- const resetMLVersion = useCallback ( async ( e ) => {
23- e . preventDefault ( ) ;
24- e . stopPropagation ( ) ;
25-
26- await updateProject ( {
27- model_version : null ,
28- } ) ;
29- } , [ api , project ] ) ;
3022
3123 const fetchBackends = useCallback ( async ( ) => {
3224 const models = await api . callApi ( 'mlBackends' , {
@@ -35,33 +27,12 @@ export const MachineLearningSettings = () => {
3527 } ,
3628 } ) ;
3729
38-
3930 if ( models ) setBackends ( models ) ;
4031 } , [ api , project , setBackends ] ) ;
4132
42- const fetchMLVersions = useCallback ( async ( ) => {
43- const modelVersions = await api . callApi ( "modelVersions" , {
44- params : {
45- pk : project . id ,
46- } ,
47- } ) ;
48-
49- var versions = [ ] ;
50-
51- for ( const [ key , value ] of Object . entries ( modelVersions ) ) {
52- versions . push ( {
53- value : key ,
54- label : key + " (" + value + " predictions)" ,
55- } ) ;
56- }
57-
58- setVersions ( versions ) ;
59- } , [ api , project . id ] ) ;
60-
6133 const showMLFormModal = useCallback ( ( backend ) => {
6234 const action = backend ? "updateMLBackend" : "addMLBackend" ;
6335
64- console . log ( { backend } ) ;
6536 const modalProps = {
6637 title : `${ backend ? 'Edit' : 'Add' } model` ,
6738 style : { width : 760 } ,
@@ -89,7 +60,22 @@ export const MachineLearningSettings = () => {
8960 < TextArea name = "description" label = "Description" style = { { minHeight : 120 } } />
9061 </ Form . Row >
9162
92- < Form . Row columnCount = { 1 } >
63+ < Form . Row columnCount = { isFF ( FF_DEV_1682 ) ? 3 : 1 } >
64+ { isFF ( FF_DEV_1682 ) && (
65+ < >
66+ < ModelVersionSelector
67+ object = { backend }
68+ apiName = "modelVersions"
69+ valueName = "version"
70+ label = "Version"
71+ />
72+
73+ < Toggle
74+ name = "auto_update"
75+ label = "Allow version auto-update"
76+ />
77+ </ >
78+ ) }
9379 < Toggle
9480 name = "is_interactive"
9581 label = "Use for interactive preannotations"
@@ -126,7 +112,6 @@ export const MachineLearningSettings = () => {
126112 useEffect ( ( ) => {
127113 if ( project . id ) {
128114 fetchBackends ( ) ;
129- fetchMLVersions ( ) ;
130115 }
131116 } , [ project ] ) ;
132117
@@ -177,34 +162,16 @@ export const MachineLearningSettings = () => {
177162 </ div >
178163 </ Form . Row >
179164
180- { versions . length > 1 && (
181- < Form . Row columnCount = { 1 } >
182- < Label
183- text = "Model Version"
184- description = "Model version allows you to specify which prediction will be shown to the annotators."
185- style = { { marginTop : 16 } }
186- large
187- />
188-
189- < div style = { { display : 'flex' , alignItems : 'center' , width : 400 , paddingLeft : 16 } } >
190- < div style = { { flex : 1 , paddingRight : 16 } } >
191- < Select
192- name = "model_version"
193- defaultValue = { null }
194- options = { [
195- ...versions ,
196- ] }
197- placeholder = "No model version selected"
198- />
199- </ div >
200-
201- < Button onClick = { resetMLVersion } >
202- Reset
203- </ Button >
204- </ div >
205-
206- </ Form . Row >
165+ { ! isFF ( FF_DEV_1682 ) && (
166+ < ProjectModelVersionSelector />
207167 ) }
168+
169+ < Form . Actions >
170+ < Form . Indicator >
171+ < span case = "success" > Saved!</ span >
172+ </ Form . Indicator >
173+ < Button type = "submit" look = "primary" style = { { width : 120 } } > Save</ Button >
174+ </ Form . Actions >
208175 </ Form >
209176
210177 < MachineLearningList
0 commit comments