1- import { useCallback , useMemo , useState , useContext , useEffect } from 'react' ;
1+ import {
2+ useCallback ,
3+ useMemo ,
4+ useState ,
5+ useContext ,
6+ useEffect ,
7+ useRef ,
8+ } from 'react' ;
29import { fromJS } from 'immutable' ;
310import pluralize from 'pluralize' ;
411import { useTranslation } from 'react-i18next' ;
@@ -22,7 +29,7 @@ import {
2229} from './helpers/immutableConverter' ;
2330import { useVariables } from './hooks/useVariables' ;
2431import { prepareRules } from './helpers/prepareRules' ;
25- import { merge } from 'lodash' ;
32+ import { cloneDeep , merge } from 'lodash' ;
2633
2734import { TriggerContext , TriggerContextProvider } from './contexts/Trigger' ;
2835import { useAtomValue } from 'jotai' ;
@@ -69,6 +76,7 @@ export function ExtensibilityCreateCore({
6976 const [ initialResource , setInitialResource ] = useState (
7077 initialExtensibilityResource ,
7178 ) ;
79+ const hasSetInitialResource = useRef ( false ) ;
7280
7381 useEffect ( ( ) => {
7482 if ( layoutState ?. showEdit ?. resource ) return ;
@@ -85,9 +93,24 @@ export function ExtensibilityCreateCore({
8593 const presets = usePreparePresets ( createResource ?. presets , emptyTemplate ) ;
8694 const resource = useMemo ( ( ) => getResourceObjFromUIStore ( store ) , [ store ] ) ;
8795
96+ useEffect ( ( ) => {
97+ if (
98+ ! initialResource &&
99+ ! initialExtensibilityResource &&
100+ ! hasSetInitialResource . current &&
101+ resource
102+ ) {
103+ const excludedResource = cloneDeep ( resource ) ;
104+ delete excludedResource . status ;
105+ delete excludedResource . metadata ;
106+ setInitialResource ( excludedResource ) ;
107+ hasSetInitialResource . current = true ;
108+ }
109+ } , [ initialExtensibilityResource , initialResource , resource ] ) ;
110+
88111 const isEdit = useMemo (
89112 ( ) =>
90- ! ! initialResource ?. metadata ?. name && ! ! ! layoutState ?. showCreate ?. resource ,
113+ ! ! initialResource ?. metadata ?. name && ! layoutState ?. showCreate ?. resource ,
91114 [ initialResource , layoutState ?. showCreate ?. resource ] ,
92115 ) ;
93116
0 commit comments