@@ -46,21 +46,37 @@ const AppEditorInternalView = lazy(
46
46
) ;
47
47
48
48
const AppEditor = React . memo ( ( ) => {
49
- const showAppSnapshot = useSelector ( showAppSnapshotSelector ) ;
49
+ const dispatch = useDispatch ( ) ;
50
50
const params = useParams < AppPathParams > ( ) ;
51
51
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 ) ;
56
53
const currentUser = useSelector ( getUser ) ;
57
- const application = useSelector ( currentApplication ) ;
58
- const dispatch = useDispatch ( ) ;
59
54
const fetchOrgGroupsFinished = useSelector ( getFetchOrgGroupsFinished ) ;
60
55
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
+
62
77
const firstRendered = useRef ( false ) ;
63
78
const fetchInterval = useRef < number > ( 0 ) ;
79
+ const orgId = useMemo ( ( ) => currentUser . currentOrgId , [ currentUser . currentOrgId ] ) ;
64
80
const [ isDataSourcePluginRegistered , setIsDataSourcePluginRegistered ] = useState ( false ) ;
65
81
const [ appError , setAppError ] = useState ( '' ) ;
66
82
const [ blockEditing , setBlockEditing ] = useState < boolean > ( false ) ;
@@ -99,7 +115,8 @@ const AppEditor = React.memo(() => {
99
115
if ( currentUser && application ) {
100
116
const lastEditedAt = dayjs ( application ?. lastEditedAt ) ;
101
117
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 ;
103
120
setBlockEditing ( shouldBlockEditing ) ;
104
121
console . log ( 'blockEditing' , shouldBlockEditing , { user_id : currentUser . id , editingUserId : application . createBy , lastEditedDiff} ) ;
105
122
}
@@ -120,16 +137,22 @@ const AppEditor = React.memo(() => {
120
137
dispatch ( fetchQueryLibraryDropdown ( ) ) ;
121
138
}
122
139
} , [ dispatch , applicationId , paramViewMode ] ) ;
123
-
124
- const fetchJSDataSourceByApp = ( ) => {
140
+
141
+ const fetchJSDataSourceByApp = useCallback ( ( ) => {
125
142
DatasourceApi . fetchJsDatasourceByApp ( applicationId ) . then ( ( res ) => {
126
143
res . data . data . forEach ( ( i ) => {
127
144
registryDataSourcePlugin ( i . type , i . id , i . pluginDefinition ) ;
128
145
} ) ;
129
146
setIsDataSourcePluginRegistered ( true ) ;
130
147
} ) ;
131
148
dispatch ( setShowAppSnapshot ( false ) ) ;
132
- } ;
149
+ } , [
150
+ applicationId ,
151
+ registryDataSourcePlugin ,
152
+ setIsDataSourcePluginRegistered ,
153
+ setShowAppSnapshot ,
154
+ dispatch ,
155
+ ] ) ;
133
156
134
157
useEffect ( ( ) => {
135
158
if ( ! fetchOrgGroupsFinished ) {
@@ -160,7 +183,7 @@ const AppEditor = React.memo(() => {
160
183
}
161
184
} )
162
185
) ;
163
- } , [ viewMode , applicationId , dispatch ] ) ;
186
+ } , [ viewMode , applicationId , dispatch , fetchJSDataSourceByApp ] ) ;
164
187
165
188
useEffect ( ( ) => {
166
189
fetchApplication ( ) ;
0 commit comments