@@ -46,21 +46,37 @@ const AppEditorInternalView = lazy(
4646) ;
4747
4848const AppEditor = React . memo ( ( ) => {
49- const showAppSnapshot = useSelector ( showAppSnapshotSelector ) ;
49+ const dispatch = useDispatch ( ) ;
5050 const params = useParams < AppPathParams > ( ) ;
5151 const isUserViewModeCheck = useUserViewMode ( ) ;
52- const isUserViewMode = params . viewMode ? isUserViewModeCheck : true ;
53- const applicationId = params . applicationId || window . location . pathname . split ( "/" ) [ 2 ] ;
54- const paramViewMode = params . viewMode || window . location . pathname . split ( "/" ) [ 3 ] ;
55- const viewMode = ( paramViewMode === "view" || paramViewMode === "admin" ) ? "published" : paramViewMode === "view_marketplace" ? "view_marketplace" : "editing" ;
52+ const showAppSnapshot = useSelector ( showAppSnapshotSelector ) ;
5653 const currentUser = useSelector ( getUser ) ;
57- const application = useSelector ( currentApplication ) ;
58- const dispatch = useDispatch ( ) ;
5954 const fetchOrgGroupsFinished = useSelector ( getFetchOrgGroupsFinished ) ;
6055 const isCommonSettingsFetching = useSelector ( getIsCommonSettingFetching ) ;
61- const orgId = currentUser . currentOrgId ;
56+ const application = useSelector ( currentApplication ) ;
57+
58+ const isUserViewMode = useMemo (
59+ ( ) => params . viewMode ? isUserViewModeCheck : true ,
60+ [ params . viewMode , isUserViewModeCheck ]
61+ ) ;
62+ const applicationId = useMemo (
63+ ( ) => params . applicationId || window . location . pathname . split ( "/" ) [ 2 ] ,
64+ [ params . applicationId , window . location . pathname ]
65+ ) ;
66+ const paramViewMode = useMemo (
67+ ( ) => params . viewMode || window . location . pathname . split ( "/" ) [ 3 ] ,
68+ [ params . viewMode , window . location . pathname ]
69+ ) ;
70+ const viewMode = useMemo (
71+ ( ) => ( paramViewMode === "view" || paramViewMode === "admin" )
72+ ? "published"
73+ : paramViewMode === "view_marketplace" ? "view_marketplace" : "editing" ,
74+ [ paramViewMode ]
75+ ) ;
76+
6277 const firstRendered = useRef ( false ) ;
6378 const fetchInterval = useRef < number > ( 0 ) ;
79+ const orgId = useMemo ( ( ) => currentUser . currentOrgId , [ currentUser . currentOrgId ] ) ;
6480 const [ isDataSourcePluginRegistered , setIsDataSourcePluginRegistered ] = useState ( false ) ;
6581 const [ appError , setAppError ] = useState ( '' ) ;
6682 const [ blockEditing , setBlockEditing ] = useState < boolean > ( false ) ;
@@ -99,7 +115,8 @@ const AppEditor = React.memo(() => {
99115 if ( currentUser && application ) {
100116 const lastEditedAt = dayjs ( application ?. lastEditedAt ) ;
101117 const lastEditedDiff = dayjs ( ) . diff ( lastEditedAt , 'minutes' ) ;
102- const shouldBlockEditing = currentUser . id !== application ?. createBy && lastEditedDiff < 5 ;
118+ // const shouldBlockEditing = currentUser.id !== application?.createBy && lastEditedDiff < 5;
119+ const shouldBlockEditing = lastEditedDiff < 5 ;
103120 setBlockEditing ( shouldBlockEditing ) ;
104121 console . log ( 'blockEditing' , shouldBlockEditing , { user_id : currentUser . id , editingUserId : application . createBy , lastEditedDiff} ) ;
105122 }
@@ -120,16 +137,22 @@ const AppEditor = React.memo(() => {
120137 dispatch ( fetchQueryLibraryDropdown ( ) ) ;
121138 }
122139 } , [ dispatch , applicationId , paramViewMode ] ) ;
123-
124- const fetchJSDataSourceByApp = ( ) => {
140+
141+ const fetchJSDataSourceByApp = useCallback ( ( ) => {
125142 DatasourceApi . fetchJsDatasourceByApp ( applicationId ) . then ( ( res ) => {
126143 res . data . data . forEach ( ( i ) => {
127144 registryDataSourcePlugin ( i . type , i . id , i . pluginDefinition ) ;
128145 } ) ;
129146 setIsDataSourcePluginRegistered ( true ) ;
130147 } ) ;
131148 dispatch ( setShowAppSnapshot ( false ) ) ;
132- } ;
149+ } , [
150+ applicationId ,
151+ registryDataSourcePlugin ,
152+ setIsDataSourcePluginRegistered ,
153+ setShowAppSnapshot ,
154+ dispatch ,
155+ ] ) ;
133156
134157 useEffect ( ( ) => {
135158 if ( ! fetchOrgGroupsFinished ) {
@@ -160,7 +183,7 @@ const AppEditor = React.memo(() => {
160183 }
161184 } )
162185 ) ;
163- } , [ viewMode , applicationId , dispatch ] ) ;
186+ } , [ viewMode , applicationId , dispatch , fetchJSDataSourceByApp ] ) ;
164187
165188 useEffect ( ( ) => {
166189 fetchApplication ( ) ;
0 commit comments