@@ -10,7 +10,6 @@ import { generatePreviewPath } from '../../utils/properties';
1010import { useConfig } from '../../../../hooks' ;
1111import { NavigationItemFormSchema } from '../../utils/form' ;
1212import { StrapiContentTypeItemSchema } from 'src/api/validators' ;
13- import { isEmpty } from 'lodash' ;
1413
1514type PathFieldProps = {
1615 contentTypeItems : StrapiContentTypeItemSchema [ ] | undefined ;
@@ -35,9 +34,9 @@ export const PathField: React.FC<PathFieldProps> = ({
3534 values . type === 'INTERNAL'
3635 ? values
3736 : {
38- related : undefined ,
39- relatedType : undefined ,
40- } ;
37+ related : undefined ,
38+ relatedType : undefined ,
39+ } ;
4140
4241 const pathDefault = generatePreviewPath ( {
4342 currentPath : values . path ,
@@ -53,7 +52,15 @@ export const PathField: React.FC<PathFieldProps> = ({
5352
5453 const disabled = ! canUpdate || ( values . autoSync && values . type === 'INTERNAL' ) ;
5554
56- const [ pathDefaultFieldsValue ] = Object . values ( configQuery . data ?. pathDefaultFields ?? { } ) . flat ( ) ;
55+ const pathDefaultFieldsValue = internalValues . relatedType
56+ ? ( configQuery . data ?. pathDefaultFields ?. [ internalValues . relatedType ] ?? [ ] )
57+ : [ ] ;
58+
59+ const selectedEntity = contentTypeItems ?. find (
60+ ( { documentId } ) => documentId === internalValues . related
61+ ) ;
62+
63+ const validPathFieldName = pathDefaultFieldsValue . find ( ( field ) => selectedEntity ?. [ field ] ) ;
5764
5865 return (
5966 < Grid . Item alignItems = "flex-start" key = "title" col = { 12 } >
@@ -65,13 +72,13 @@ export const PathField: React.FC<PathFieldProps> = ({
6572 formatMessage ( getTrad ( `popup.item.form.${ pathSourceName } .placeholder` , 'e.g. Blog' ) ) ,
6673 pathDefault
6774 ? formatMessage ( getTrad ( 'popup.item.form.type.external.description' ) , {
68- value : pathDefault ,
69- } )
75+ value : pathDefault ,
76+ } )
7077 : '' ,
7178 disabled
7279 ? formatMessage ( getTrad ( 'popup.item.form.type.internal.source' ) , {
73- value : ! isEmpty ( pathDefaultFieldsValue ) ? pathDefaultFieldsValue : 'id' ,
74- } )
80+ value : validPathFieldName || 'id' ,
81+ } )
7582 : '' ,
7683 ] . join ( ' ' ) }
7784 >
0 commit comments