@@ -2,16 +2,16 @@ import { v1 } from '@docker/extension-api-client-types';
2
2
import CheckOutlined from '@mui/icons-material/CheckOutlined' ;
3
3
import CloseOutlined from '@mui/icons-material/CloseOutlined' ;
4
4
import {
5
- ButtonGroup ,
6
5
CircularProgress ,
7
6
IconButton ,
8
7
Stack ,
9
8
TextField ,
10
- Typography ,
9
+ Typography
11
10
} from '@mui/material' ;
12
11
import * as JsonSchema from 'json-schema-library' ;
13
12
import { useEffect , useMemo , useState } from 'react' ;
14
13
14
+ import * as JsonSchemaLibrary from "json-schema-library" ;
15
15
import {
16
16
buildObjectFromFlattenedObject ,
17
17
deepFlattenObject ,
@@ -50,9 +50,9 @@ const ConfigEditor = ({
50
50
( ) =>
51
51
configSchema
52
52
? deepFlattenObject ( {
53
- ...catalogItem . configTemplate ,
54
- ...existingConfigForItem ,
55
- } )
53
+ ...catalogItem . configTemplate ,
54
+ ...existingConfigForItem ,
55
+ } )
56
56
: { } ,
57
57
[ catalogItem . configTemplate , existingConfigForItem , configSchema ]
58
58
) ;
@@ -101,7 +101,7 @@ const ConfigEditor = ({
101
101
fullWidth
102
102
size = "small"
103
103
label = { key }
104
- value = { localConfig [ key ] || '' }
104
+ value = { localConfig [ key ] }
105
105
onChange = { ( e ) =>
106
106
setLocalConfig ( { ...localConfig , [ key ] : e . target . value } )
107
107
}
@@ -115,12 +115,19 @@ const ConfigEditor = ({
115
115
< Stack direction = "row" spacing = { 1 } >
116
116
< IconButton
117
117
size = "small"
118
- onClick = { ( ) =>
119
- updateExistingConfig (
120
- catalogItem . name ,
121
- buildObjectFromFlattenedObject ( localConfig )
122
- )
123
- }
118
+ onClick = { ( ) => {
119
+ const newConfig = buildObjectFromFlattenedObject ( localConfig ) ;
120
+
121
+ // Remove all attributes which are optional and which have the defautl value
122
+ const schema = new JsonSchemaLibrary . Draft2019 ( catalogItem . config [ 0 ] ) ;
123
+ const requiredAttributes = ( schema . rootSchema . required || [ ] ) as string [ ] ;
124
+ const template = schema . getTemplate ( { } ) ;
125
+ const requiredConfig = Object . fromEntries ( Object . entries ( newConfig ) . filter ( ( [ key , value ] ) => {
126
+ return requiredAttributes . includes ( key ) || ( value !== template [ key ] ) ;
127
+ } ) ) ;
128
+
129
+ updateExistingConfig ( catalogItem . name , requiredConfig )
130
+ } }
124
131
disabled = { isSaving }
125
132
>
126
133
< CheckOutlined
0 commit comments