1
- import React , { useContext , useEffect , useRef } from 'react' ;
1
+ import React , { useContext , useEffect , useRef , useMemo } from 'react' ;
2
2
3
3
import type { WidgetProps } from '@rjsf/utils' ;
4
+ import { isNil , omit } from 'lodash' ;
4
5
import { useTranslation } from 'react-i18next' ;
5
6
6
7
import EditorForm from 'applications/editor/components/EditorForm' ;
7
8
import EntityError from 'applications/editor/components/EntityError' ;
8
9
import EditorContext from 'applications/editor/context' ;
9
- import { NEW_ENTITY_ID } from 'applications/editor/data/utils' ;
10
+ import {
11
+ NEW_ENTITY_ID ,
12
+ getJsonSchemaForLayer ,
13
+ getLayerForObjectType ,
14
+ } from 'applications/editor/data/utils' ;
10
15
import type {
11
16
TrackEditionState ,
12
17
TrackSectionEntity ,
@@ -32,7 +37,7 @@ const TrackEditionLeftPanel: React.FC = () => {
32
37
const dispatch = useAppDispatch ( ) ;
33
38
const { t } = useTranslation ( ) ;
34
39
const infraID = useInfraID ( ) ;
35
- const { state, setState, isFormSubmited, setIsFormSubmited } = useContext (
40
+ const { state, setState, isFormSubmited, setIsFormSubmited, editorState } = useContext (
36
41
EditorContext
37
42
) as ExtendedEditorContextType < TrackEditionState > ;
38
43
const submitBtnRef = useRef < HTMLButtonElement > ( null ) ;
@@ -49,14 +54,40 @@ const TrackEditionLeftPanel: React.FC = () => {
49
54
}
50
55
} , [ isFormSubmited ] ) ;
51
56
57
+ const schema = useMemo (
58
+ ( ) =>
59
+ getJsonSchemaForLayer (
60
+ editorState . editorSchema ,
61
+ getLayerForObjectType ( editorState . editorSchema , track . objType ) || ''
62
+ ) ,
63
+ [ editorState . editorSchema , track . objType ]
64
+ ) ;
65
+
52
66
return (
53
67
< >
54
68
< EditorForm
55
69
data = { track }
70
+ // Remove the source from schema if there is no source in the object
71
+ // To avoid to display it on the form
72
+ overrideSchema = {
73
+ isNil ( track . properties . extensions ?. source )
74
+ ? omit ( schema , [ '$defs.TrackSectionExtensions.properties.source' ] )
75
+ : schema
76
+ }
56
77
overrideUiSchema = { {
57
78
length : {
58
79
'ui:widget' : CustomLengthInput ,
59
80
} ,
81
+ extensions : {
82
+ source : {
83
+ id : {
84
+ 'ui:readonly' : true ,
85
+ } ,
86
+ name : {
87
+ 'ui:readonly' : true ,
88
+ } ,
89
+ } ,
90
+ } ,
60
91
} }
61
92
onSubmit = { async ( savedEntity ) => {
62
93
// eslint-disable-next-line @typescript-eslint/no-explicit-any
0 commit comments